0% found this document useful (0 votes)
2K views

Java Program Structure

The structure of a Java program contains documentation, import statements, interfaces, classes, and a main method class. The documentation section contains comments that provide information about the program. Import statements are used to import classes from other packages. Interfaces define methods but not implementations. Classes define the core code and logic of the program. The main method class contains the main method, which is where program execution begins.

Uploaded by

krish47mk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Java Program Structure

The structure of a Java program contains documentation, import statements, interfaces, classes, and a main method class. The documentation section contains comments that provide information about the program. Import statements are used to import classes from other packages. Interfaces define methods but not implementations. Classes define the core code and logic of the program. The main method class contains the main method, which is where program execution begins.

Uploaded by

krish47mk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java program Structure

Structure of a Java program contains the following elements:

o Documentation Section
o Package Declaration
o Import Statements
o Interface Section
o Class Definition
o Main Method Class

Documentation Section:

 It consists of comments in Java which include basic information


 The information includes the author's name, date of creation, version, program
name, company name, and description of the program
 The compiler ignores these comments during the time of execution.
 The comments may be
o Single-line comments (//).
o Multi-line comments (starts with a /* and ends with */).
o Documentation comments (starts with the delimiter (/**) and ends with */).

Package Declaration
 The package declaration is optional.
 It is placed just after the documentation section
 This statement declares a package name and informs the compiler that the classes
defined here belong to this package.

EX: package student;

Import Statements:

 If we want to use any class of a particular package, we need to import that class.
 We use the import keyword to import the class.
 We use the import statement in two ways, either import a specific class or import all
classes of a particular package.

1. import java.util.Scanner; //it imports the Scanner class only


2. import java.util.*; //it imports all the class of the java.util package
Interface Section:

 We can create an interface in this section if required.


 We use the interface keyword to create an interface.
 It contains only constants and method declarations.

Ex:

interface car
{
void start();
void stop();
}
Class Definition:

 In this section, we define the class.


 A Java program may conation more than one class definition.
 We use the class keyword to define the class.

EX:

class Student //class definition


{
}

Main Method Class:

 In this section, we define the main() method.


 It is essential for all Java programs. Because the execution of all Java programs starts
from the main() method.
 It must be inside the class. Inside the main method, we create objects and call the
methods.

Example:

public class Student //class definition


{
public static void main(String args[])
{
//statements
}
}

You might also like