Java – How to use Packages to organize code ?

This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

You need to use packages in java to organize your code.


Your Java program might the following
Other types

Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book

There are times when your program might grow larger including th number of java classes used. You might want to organize these source files to that it is easier to maintain and avoid other issues like class name conflicts.

Inorder to organize the code for the application (Eg: websites) , you can create an group of nested packages with the following structure.

When you place your sourcecode inside the package must have package name mentioned as the first line in the file. For example , if the main application is named as  abundantcodeconsole under the package abundantcode , you will have the sourcecode as shown below.

package abundantcode;


public class abundantcodeconsole {
    public static void main(String[] args) {

        BufferedReader input = new BufferedReader(new InputStreamReader(;
        System.out.println("Enter data");
        try {
            String data = input.readLine();
        catch(Exception ex)

        Boolean b1 = Boolean.valueOf("false");



The file actually resides in the folder abundantcode and the path of the is as shown below.


%d bloggers like this: