First Java Program

Java Program – Basic Syntax:

public class ClassName {

public static void main(String args[]){

Variables;

Statements;

}

}

First Java Program:

public class FirstJavaProgram {

/* This is my first java program.
* This will print ‘Hello World’ as the output
*/
public static void main(String []args) {

System.out.println(“Welcome to java world”); // prints welcome to java World

}
}

First type the above code in Note pad and save with name “FirstJavaProgram.java” .

Compilation of Java program:

C:\>mydisk>javac FirstJavaProgram.java

Run the above program.

C:\>mydisk>java FirstJavaProgram

Out put is:

Welcome to java world.

Have a look at the Public static void main().

Public: main() method is the first method called by java environment when a program is executed so it has to accessible to from the java environment. Hence the access specifier is Public.

static: Java environment should be able to call this method without creating an instance of the class.so this method must be declared as static.

void: Void does not return any thing so main() method is void.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top