Explain The Structure Of Java Program?
https://www.computersprofessor.com/2016/05/explain-structure-java-program.html
Java program may contain may
classes of which only one class defines a main method.
|
Classes
contain data members (of the class) and methods that operate on the data
members of the class.
|
A java
program may contain one or more sections.
Document Section :
Document section is a set of
comment lines giving the name of the program, the author name and other details.
|
Comments
must explain why and what of classes and how of algorithms.
|
We have two
types of comments.
1) //single
line comments
2) /* …. */
multiple line comments.
|
Package Statement :
|
The first
statement allowed in a Java file is a package statement.
|
This
statement declares a package name and informs the compiler that the classes
defined here belong to this package.
Ex : Package Student ;
|
Import Statement :
The next thing after a package statement
may be a number of import statement.
|
This is
similar to # include statement in C import java. io. * ;
|
Interface Statements :
|
An interface is like a class but
includes a group of method declarations. This is also an optional section and
is used only when we wish to implement the multiple inheritance.
|
Class definitions :
|
A Java program may contain
multiple class definitions.
|
Classes are
primary and essential elements of a Java program.
|
Main method class:
|
Since every Java alone program
require a main method as starting point.
|
A simple Java program may contain only this part.
|
The main
method creates objects of various classes and establish, communication
between them.
class sample.
{
public
static void main (String args [ ])
{
System out
printer (“hai every one”) :
}
}
|
|