General format of JAVA program
import statements
global declaration
class name
{
public static void main (String args [])
{
statements
-------------
}
}
- Import Statement: -
Java provide us different library classes. These
classes are different packages, so, if we want to use them we
have to import them by using import statement. Eg: - import java.awt. *;
import java.awt.button;
- Global declaration: -
In this section we can define classes & interface
(user define data type) we can not define global variable &
function like C & C++.
- Function main:-
This is the entry point of our program execution
of the program being with function main.
Java is complete object – oriented language. So
even function main must be defined with in class.
- void: - Indicates that this function main doesn’t
return any value.
- static: -Indicates that this function can be called
without creating object of that class.
- public: - Indicates that the function is
accessible.
- String args[]: - It is an array of string object
containing command line argument.
Output statements: -
- System.out.println (value): Will print the value & new
line character.
- System.out.print (value): Will print the value on console.
- System.out.printf (“format String”,arg1,…): Will print the
formatted String on console
For eg:
class test
{
public static void main (string args [ ])
{
System.out.println (“Welcome to JAVA”);
}
}
Post a Comment