Skip to main content

Java Programe Structure

 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

Popular posts from this blog

Introduction of Java

 What is Java? Java is an object-oriented programming language developed by Sun Microsystem in 1995. It is a combination of C and C++ features with some essential and additional concepts. Java is suited for both standalone and web application development. Java can run on any hardware OR software environment which make it platform independent. Java Example:                                                                                           class Simple{     public static void main(String args[]){          System.out.println("Welcome In Java World");     } } In above example the 'Simple' is a Class name, public is access specifier , Main is a method with argument, St...

Java Package

 Introduction      A java package is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Here, we will have the detailed learning of creating and using user-defined packages. Simple example of java package The package keyword is used to create a package in java. //save as Simple.java   package mypack;   public class Simple{    public static void main(String args[]){       System.out.println("Welcome to package");      }   }   How to access package from another package? There are three ways to access the package from outside the package. 1. import package.*; 2. import package.classname; 3. fully qualified name. 1. Using packagename.*      If you use package.* the...

Java Classes, Object and Methods, Constructors

 Defining a class     A class is a user-defined data type or group of object with a template or blueprint that serves to define its properties. It is a logical entity. Once a class type has been define, we can create " Variables " which are similar to basic type declaration. In java, variables are termed as instance of class, which actual object. The basic form class defination is as follows: class classname [extends superclassname]{     [fields declaration]     [method declaration] } The classname and superclassname are valid java identifiers. The keyword extends indicate that superclassname properties extended into classname. It is a pert of inheritance. (We will discuss inheritance in later part.) Everything inside square brackets is optional that means we can use as per the requirements. For example, class Empty{ } In above example, the Empty class is class name. This class does not have any properties and therefor cannot do anything. A java cla...