Java Program Structure
In Java Program Structure, the Java system may contain numerous classes, of which one and only one class characterizes the main technique. Classes contain information members and techniques that work on the information members from the class. Strategies may contain information, sort of revelation, and executable statements.
To compose a Java program, we first characterize classes and afterward set them up together. A Java project may contain one or more segments, as demonstrated in the figure:
documentation section |
package statement |
import statement |
interface statement |
class definitions |
main method class{main method definition} |
Documentation Section
The documentation area contains an arrangement of comment lines giving the name of the project, the creator, and different elements, which the developer might want to refer to at a later stage. Comments must clarify the why and what of classes and the how of algorithms. This would be incredibly helpful in keeping up the project. notwithstanding the two styles of remark single line comment and twofold line comment Java additionally utilizes a third style comment /**—-*/ known as documentation comment. This type of comment is utilized for producing documentation naturally.
Package Statement
The 1st statement permitted in a Java document is a Package Statement. This statement pronounces a bundle name and informs the compiler that the classes characterized here have a place of this package.
Case:
package student;
The package statement is discretionary. That is, our classes don’t need to be a part of a package.
Import Statement
The following thing, after a package statement (however, before any class definition), might be various import explanations. This is like the #include an explanation in C. Illustration,
import student.test;
This explanation teaches the interpreter to weigh the test class contained in the student package. Utilizing import explanation, we can have admittance to classes that are a piece of other named packages.
Interface Statement
An interface resembles a class yet incorporates a collection of method declarations. This is likewise a discretionary segment and is utilized only when we wish to actualize the various inheritance highlighted in the project.
Class Definitions
A Java project may contain numerous class definitions. Classes are the essential and vital components of a Java program. These classes are utilized to delineate objects of certifiable issues. The quantity of classes utilized relies on the unpredictability of the issue.
class abc
Main Method Class
Since each Java stand-alone project requires a principle strategy as its beginning stage, this class is the key to some portion of the Java system. A straightforward Java project may contain just this part. The principle technique makes objects of different classes and builds up communications between them. On achieving the end of the principle, the project ends, and the control goes back to the working framework.
public static void main(String args[])
Java Example
Execution of a Java Program includes a progression of steps. They incorporate.
- Making the program
- Compiling the project
- Running the system
Keep in mind that, before we start making the project, the Java Development Kit (JDK) must be appropriately installed on our framework.
Creating the Program
We can make a project utilizing any content tool. Accept that we have entered the accompanying project:
Case:
import java.lang.*; class Test { public static void main(String [] args) { System.out.println("xcnotes.com"); System.out.println("Welcome to the java programming world"); System.out.println("Let us learn Java."); }}
We should save this project in a record called Test.java, guaranteeing that the file name contains the class name legitimately. This document is known as the source record. Note that all Java source documents will have the expansion .java. Note additionally that if a system contains numerous classes, the record name must be the class name of the class containing the principle technique.

Compiling the project
To compile the system, we should run the Java compiler javac, with the name of the source record on the command line, as demonstrated as follows:
javac Test.java
In the case that all is well, the javac compiler makes a record called Test.class containing the bytecode of the system. Note that the compiler consequently names the bytecode document as <classname>.class
Running the system
We have to utilize the Java Interpreter to run a stand-alone program. At the order prompt, sort Java Test
Presently, the Interpreter searches for the fundamental strategy in the project and starts execution from that point. Note that we essentially sort Test at the order line and not Test.java or Test.class