java program structure tutorial

Bodhak java program structure tutorial we will discuss in detail about Structure of Java Program, Writing first java program, Compiling and Execution of Java program.

Here you are going to write your first Java program.



java program structure tutorial

Structure of Java Program:

Documentation Section

Package Statement

Import Statements

Interface Statements

Class Declarations

Main Method Class (or) Statement Section



Documentation section describes programmer, Description of program, date of the program written etc..  .

  1. Line comments: It starts with two forward slashes (//) and continues to the end of the current line. Line comments do not require an ending symbol.
  2. Block comments start with a forward slash and an asterisk (/*) and end with an asterisk and a forward slash (*/).Block comments can also extend across as many lines as needed.
  3. documented comment: actually, a special kind of multi-line comment as defined by the Sun Javadoc specification; all text from the ASCII characters “/**” to the ASCII characters “*/”


It is package declaration statement. The package statement defines a namespace in which classes are stored. The package is used to organize the classes based on functionality. If you omit the package statement, the class names are put into the default package, which has no name. Package statement cannot appear anywhere in the program. It must be the first line of your program or you can omit it.


Import statement

This statement is used for using members of other packages into current Java program or file.

Class declaration:

public class <name>

  1. public: This is access modifier keyword which tells compiler access to the class.
  2. class: This keyword used to declare a class. Name of class (Ex: HelloWorld) followed by this keyword.

Statement section:

The section contains executable code/statements of Java language

ex: System.out.println(“Hello World from Java”);

Here :
  1. System: It is a name of Java utility class.
  2. out: It is an object which belongs to System class.
  3. println: It is utility method name which is used to send any String to console.
  4. “Hello World from Java”: It is String literal set as argument to a println method.

Next Page