Home / Computer Science / Java Language / First Java Program

First Java Program

Java Program – Basic Syntax:

public class ClassName {

public static void main(String args[]){





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.

About GSK

I'm Santosh Gadagamma, an Experienced Software Engineer passionate about sharing knowledge in technologies like Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts, and all levels of software design, development, deployment, and maintenance. I believe computers are essential for the world's functioning, and I'm committed to helping others learn the skills they need to succeed in tech. My website is a valuable learning tool to help you reach greater heights in your education and career, and I believe that education has no end points.

Check Also

String Builder

String Builder : A Comprehensive Guide

String builder in Java is a class. It is like string objects, except that they …