How to write "Hello World" in Java

The first step to getting familiar with a new language is to write a simple “Hello World” program. To create a “Hello World” program in Java, just follow these simple steps:

  • Create a file (i.e., helloworld.java).
  • Make sure that the outer class is of the same name as the filename, ​without extension (i.e., helloworld).
  • Now write the main method for the helloworld class.
svg viewer

Code

In the code below, the same steps are followed for the Hello World program.

Remember, every program in Java consists of a main method with the same signature, ​i.e., public static void main(String []args).​

class HelloWorld {
public static void main( String []args ) {
System.out.println( "Hello World!" );
}
}
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved