Java First Program

Structure of Java Program

Lets see the basic structure of java program 


class- is write to create a class.

class_name – is a name of class. It is a identifier.

public–  is a access modifier is used for main() method accessible for every one.

static- class contain a main() method not have a object and if we want a access a class without create a object of that class then method main() must be declare  as a static.

void- is a return type. Void denotes that main() method return noting.

main()– main is a method from where execution of program starts.

Syntax to print statement


System: System is a predefined class, it is a final class in java.lang package

out:  is a static member of the System class, and is an instance 

println() or print(): is a method of Any thing written inside the round bracket will be print.

Simple java program to print Hello Students

Save and Run Program

Save this program  with name.

Goto start menu and type ”cmd” and press enter to open command prompt.

Use the cd command ( cd dir_name or .. to go up one directory) to navigate to the directory where program is save.

For example: saved in a “x” folder of c directory.

Then type cd c:\          [press enter]

            c:>cd c:\ x        [press enter]


for compile write (with file name) : javac                   // here javac is a colpiler

for run write (with class name): java HelloStudents