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

Sructure of Java

Uploaded by

abhikannadiga20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Sructure of Java

Uploaded by

abhikannadiga20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

STRUCTURE OF JAVA PROGRAM

A Java program involves the following sections:

 Documentation Section
 Package Statement
 Import Statements
 Interface Statement
 Class Definition
 Main Method Class
 Main Method Definition
Section Description
Documentation You can write a comment in this section. Comments are beneficial for the
Section programmer because they help them understand the code. These are
optional, but we suggest you use them because they are useful to
understand the operation of the program, so you must write comments within
the program.

Ex : // First java program


/* Write java program addition of
Two numbers */

Package You can create a package with any name. A package is a group of classes
statement that are defined by a name. That is, if you want to declare many classes
within one element, then you can declare it within a package. It is an optional
part of the program, i.e., if you do not want to declare any package, then
there will be no problem with it, and you will not get any errors. Here, the
package is a keyword that tells the compiler that package has been created.
It is declared as:

Ex : package package_name;
Import This line indicates that if you want to use a class of another package, then
statements you can do this by importing it directly into your program.
Example:

Ex : import calc.add;

Interface Interfaces are like a class that includes a group of method declarations. It's
statement an optional section and can be used when programmers want to implement
multiple inheritances within a program.

Class Definition A Java program may contain several class definitions. Classes are the main
and essential elements of any Java program.

Ex : Class classname

Main Method Every Java stand-alone program requires the main method as the starting
Class point of the program. This is an essential part of a Java program. There may
be many classes in a Java program, and only one class defines the main
method. Methods contain data type declaration and executable statements.

Ex : public static void main(String


[]args)
{
//Statements
}

Example:
//Name of this file will be "Hello.java"

public class Hello

public static void main(String[] args)

System.out.println("Hello Java");

You might also like