Sructure of Java
Sructure of Java
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.
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.
Example:
//Name of this file will be "Hello.java"
System.out.println("Hello Java");