The Hello World Java program is used to print “Hello World!” on the screen. It is a simple program and hence used as a beginner’s guide to introducing Java programming language. Since we are talking about the beginning, let's start from scratch and learn about some basic requirements to write Java code.

What Are the Basic Requirements for Writing Your First Java Code?

The primary requirements to write a code in Java are following:

  • Installing the JDK
  • Setting the path to JDK/bin directory
  • Writing the program
  • Compiling the Java program
  • Running the program

Here's How to Land a Top Software Developer Job

Full Stack Developer - MERN StackExplore Program
Here's How to Land a Top Software Developer Job

How to Write Simple Codes in Java?

After installing the JDK, you can easily write and execute simple codes in Java. Considering that you have already downloaded and installed JDK, here’s how to write Java codes: 

1. Firstly open a notepad and write the code that you want to execute. In this example, we will use the ‘Java hello world code’. So open the notepad and type the code given in the image below:


2. Next, save the file as We are saving it as because our public class is Example. It means that your file name and public class should be identical.


3. Now open your command prompt to start compiling and execution.


4. After opening the command prompt, set the path of the JDK/bin directory. If you don’t set the path, the JVM compiler may throw an error “javac is not recognized as an internal or external command.”


5. At last, you have to compile and run the written code. Write javac to compile the code and java Example to run it and get the output.


You can also use other Integrated Development Environments (IDEs) for executing Java files, but it is better to start with an easy procedure. Hence, we have used the command prompt here.

How to Write a Hello World Java Program?

Here’s how to write the Hello World Java program.

public class Example{  

     public static void main(String args[]){  

      System.out.println("Hello World!");  





Now since we know how to write the Hello World Java program, let’s learn about its parameters.

What Are the Parameters Used in Hello World Java Code?

In the above Hello World Java program, we have used the following parameters/keywords:

  • class: This keyword is used for class declaration in Java.
  • public: It is an access modifier keyword used to define visibility. Public means that it is visible to all.
  • static: This keyword declares a method as static. The most significant advantage of static methods is that they can save memory as object declaration is not required to invoke such methods.
  • void: The parameter void is used to define the return type. It means that the method will have no return type.
  • main: The main method is the starting point of a Java program that JVM looks for. Without the main method, the compiler will throw an error.
  • String args[]: It represents and stores command line arguments. The String args[] is an array of java.lang.String class in Java.
  • System.out.println(): This is the line of code that prints everything mentioned in the bracket. The System is a class, while out is an object, and println() is a pre-defined method of the PrintStream class.

Become a Certified UI UX Expert in Just 5 Months!

UMass Amherst UI UX BootcampExplore Program
Become a Certified UI UX Expert in Just 5 Months!

What Are the Different Ways to Write a Java Program?

You can write a Java program in multiple ways, some of the ways are following:

  • Change Modifiers’ Sequence

You can write the main method as:

static public void main(String args[])  

  • Write Subscript Notation of an Array After the Type or Before or After the Variable

You can write the main method code also as:

public static void main(String[] args)

public static void main(String args[])

public static void main(String []args)

  • Provide var-args Support by Passing Three Ellipses in the Main Method

You can write it as:

public static void main(String... args)

  • A Semicolon After the Class End Is on You

Both the below hello world Java programs will give the same output:

public class Example{  

     public static void main(String args[]){  

      System.out.println("Hello World!");  





public class Example{  

     public static void main(String args[]){  

      System.out.println("Hello World!");  





Get a firm foundation in Java, the most commonly used programming language in software development with the Java Certification Training Course.

In this hello world Java program article, you have learned to execute a basic Java program. Although hello world Java program is simple, it is essential to clarify various keywords and concepts of the Java programming language. If you are fond of programming, then Java is the easiest one to start with, you can learn the basics of Java by referring to Simplilearn's Free Java Course for Beginners. This course will help you to clear the basic concepts and lay a programming foundation. However, if you want to build the skillset in Java, you can apply for our Online Java Certification Course. It will assist you in learning advanced concepts and provide hands-on experience in multiple frameworks that will help you to build up your software development career.

Our Software Development Courses Duration And Fees

Software Development Course typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Caltech Coding Bootcamp

Cohort Starts: 5 Aug, 2024

6 Months$ 8,000
Full Stack Java Developer

Cohort Starts: 30 Jul, 2024

6 Months$ 1,449
Full Stack Developer - MERN Stack

Cohort Starts: 30 Jul, 2024

6 Months$ 1,449
Automation Test Engineer

Cohort Starts: 7 Aug, 2024

11 Months$ 1,499