OOPS Syntax In Java

OOPS Syntax

Every java program should be written with the following structure.
import packagename;
..
..
class ClassName1
{
list of variables;
..
list of methods()
{
..
..
}
..
}
class ClassName2
{
list of variables;
..
list of methods()
{
..
..
}
..
}

class MainClass
{
public static void main(String args[])
{
ClassName1 c1=new ClassName1();
..
..
c1.methods();
..
..
}
}

Import Statemnets:

In java language import is a keyword.It is used to import the predefined Properties java library or API(Application Programming Interface) into current java program.
java API is a collection of packages.Package is a container which is collection of related classes or interfaces.Class is collection of related variables and methods.

Main Class:

If any class contains 'main' method known as main class.Main method is a starting execution block of any java program
public static void main(String args[])
{
..
..
}
  • In the above syntax public is a keyword.If it is preceded by main method that is available for every JVM of any 'OS' at the time of execution in otherwords this method can be accessed any where in the java environment.
  • Main method always should executed only once .So that we must allocate the memory only once in the program to achieve this that must be preceded static keyword.
  • String args is a string array .It is used to holds commmand line values.
  • If any valuees argument passed through command prompt is known as command line arguments.
Note:
  • In the above structure of java program main class very vary mandatory,at nornal classes are optional
  • Package statement is mandatory.If we want to used the predefined property in the current java program.
  • One java program can contain number of classes.It should contain only one main class.