Java – How to use Packages to organize code ?

Published on March 13, 2016 by admin

Filed under Java

Last modified March 13, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3.3 (10 votes)

This article have been viewed 19915 times

Problem Statement

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


Your Java program might the following
Other types

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.


Leave a Comment


You might be Interested in these Posts

Video - Angular Router - Brian Ford

Video - Angular Router - Brian Ford ...

Video - An Angular2 Todo App: First look at App Development in Angular2

In this screencast , David East , one of the core contributor of the Angular provides a glimpse of A...

Video - Getting started with Angular 2

In this screencast , Alex Eagle , developer on the Angular team talks about Angular 2 developer prev...