Understanding the Structure of a JAVA Program

Harsh Gupta - Tech Writer
Java is a high level, general purpose, object oriented language developed by Sun Microsystems of USA in 1991. This JAVA team discovered that languages like c and c++ had limitations like less reliability and portability. By inheriting some features of c and c++ and with its own features JAVA is really a simple, reliable, and portable language.

A JAVA program contains many classes but only one class defines a main function. Any type of real world problem can be solved easily with the help of object based concept in JAVA programming. As JAVA is a pure object oriented language, each program in JAVA should start with "class". So JAVA program is only a collection of classes and put them together. A JAVA program contains one or more sections. A JAVA program is basically divided into following section:

Documentation section:

This section contains comment lines. Basically this section comprises author and other related information and all the information about classes and how the program is working so that any user can easily understand the program or, in the maintenance of the program at later stage.

Package statement:

The first statement in JAVA is "package" statement but, it is an optional statement. By this statement, you can declare a "package" or, you can also give the particular "package" name to which the particular class is belonging. Package in a JAVA program are declared as:

Package employee;

Import statement:

After declaring "packages" in program you have to include header files. Header files in a program can be defined by "IMPORT" statement. By "import" statement we can include a particular class of any package. The import statement is declared as:

import employee.Salary;

This statement will include class salary from package employee. You can include any number of classes by "import" statement.

Interface statement:

Interface is a new concept in JAVA programming. This is an optional statement and mainly used when you want to implement "multiple inheritance" in you program. An interface is nothing but simply a class that includes a group of abstract methods. Abstract methods are those methods where body of the method is not declared only the method is declared. With interface, you can call same method from different classes present in different class hierarchies.

Class definition:

Classes are the essential part of a JAVA programming. You can include any number of classes in a single program. But more the number of classes in your program, your program will become more complex. Classes are use to define object which are very close to your real world problem.

Main method class:

This is the most essential part of your program. "MAIN" method is the starting point of your JAVA program. This will create objects of various classes defined in your program and linking between them is done in this section. Main method is the starting point in a Java program and the JVM (Java Virtual Machine) automatically executes the main method first by default. If a main method is not found in any class, then as the program is run, it will show an error message saying no main method was found in the class.

Published by Harsh Gupta - Tech Writer

I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com  View profile

  • Classes are the essential part of a JAVA programming.
  • You can include any number of classes in a single java program.
Interface is a new concept in JAVA programming. This is an optional statement and mainly used when you want to implement "multiple inheritance" in you program. An interface is nothing but simply a class that includes a group of abstract methods.

To comment, please sign in to your Yahoo! account, or sign up for a new account.