Structure of Java Program:-
Documentation Section: - The documentation section is an important section but
optional for a Java program. It includes basic information about a Java program. The
information includes the author's name, date of creation, version, program name,
company name, and description of the program.
o Single-line Comment: It starts with a pair of forwarding slash (//).
For example:
//First Java Program
o Multi-line Comment: It starts with a /* and ends with */. We write
between these two symbols. For example:
o /*It is an example of
multiline comment*/
Package Declaration:-
The package declaration is optional. It is placed just after the documentation section.
In this section, we declare the package name in which the class is placed.
package javatpoint; //where javatpoint is the package name
package [Link]; //where com is the root directory and javatpoint
is the subdirectory
Import Statements:-
The package contains the many predefined classes and interfaces. If we want to use
any class of a particular package, we need to import that class. The import statement
represents the class stored in the other package. We use the import keyword to import
the class.
import [Link];
import [Link].*; /
Interface Section:-
It is an optional section. We can create an interface in this section if required. We use
the interface keyword to create an interface. An interface is a slightly different from the
class. It contains only constants and method declarations.
interface car
{
void start();
void stop();
}
Class Definition:-
class Student //class definition
{
}
class Student //class definition
{
String sname; //variable
int id;
double percentage;
}