Java Programe Structure
Java class contains may classes but only one class contain main method. Class contain data members and methods that operate on the data members of the class. Method may contend data type declaration and executable statements. To write program, we first need to define classes and then put them together. A java may contain one or more sections.
Document Section: The documentation section comprises a set of comment lines giving the name of programes, author details and other details of program. Comments must explain why and what are the cases. This will help in maintaining the program. For single line comment comment programer will use '//' forword slash and for multiline comment programer will use '/* */' syntax.
Package Statement:
The first statement allowed in a java file is Package statement. This statement declares a package name and inform the compiler that class defined here belong to this package. For example,
package student;
The package statement is optional.
Import Statement:
The next thing after a package statement may be number of import statements. For example,
import student.text;
This statement instructs the interpreter to load the text class contained in the package student. Useing import statement, we can have access to class that part of other name package.
Interface Statement:
An interface is like a class but includes a group of method declarations. This optional section and use only when programmer wish to implement the multiple inheritance feature in the programe.
Class Definitions:
Classes are the primary and essential elements of a java program. These are use to map the object of real-world problems. Programer can use number of classes, it is depend on complexity of the problem.
Main Method Class:
Every java stand-alone program requires a main method as it's starting point, this is the essential part of java program. The main method creates objects of various classes and establishes communication between them.
Comments
Post a Comment