STRUCTURE OF JAVA PROGRAM
//comments about the class
public class myprogram (class header)
{
public static void main(String args[]) (method header)
{
Method body
}
}
EXAMPLE PROGRAM:
public class HelloProgram
{
public static void main(String args[])
{
System.out.println(“Hello World!”);
}
}
Output
Hello World
EXPLANATION OF THE ABOVE PROGRAM:
First and foremost, Java is case sensitive. If you made any mistakes in capitalization (such as typing Main
instead of main ), the program will not run.
The keyword public is called an access modifier; these modifiers control the level of access other parts of
a program have to this code.
//comments about the class
public class myprogram (class header)
{
public static void main(String args[]) (method header)
{
Method body
}
}
EXAMPLE PROGRAM:
public class HelloProgram
{
public static void main(String args[])
{
System.out.println(“Hello World!”);
}
}
Output
Hello World
EXPLANATION OF THE ABOVE PROGRAM:
First and foremost, Java is case sensitive. If you made any mistakes in capitalization (such as typing Main
instead of main ), the program will not run.
The keyword public is called an access modifier; these modifiers control the level of access other parts of
a program have to this code.