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:
Main Method Class (or) Statement Section
Documentation section describes programmer, Description of program, date of the program written etc.. .
- 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.
- 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.
- 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.
This statement is used for using members of other packages into current Java program or file.
public class <name>
- public: This is access modifier keyword which tells compiler access to the class.
- class: This keyword used to declare a class. Name of class (Ex: HelloWorld) followed by this keyword.
The section contains executable code/statements of Java language
ex: System.out.println(“Hello World from Java”);
- System: It is a name of Java utility class.
- out: It is an object which belongs to System class.
- println: It is utility method name which is used to send any String to console.
- “Hello World from Java”: It is String literal set as argument to a println method.