Your First Java Program

Your First Java Program

You now have everything you need to write your first Java program. Follow these steps:

  • Open IntelliJ IDEA
  • Create a new project:
    • From the welcome screen, select New Project.
    • Choose Empty Project as the project type.
    • Name your project (e.g., intro-to-java) and pick a location to save it.
  • In your project, right-click on the root folder (e.g., intro-to-java), choose New, and then Java Class.
  • Name your class HelloWorld and press Enter.
  • In the HelloWorld.java file that opens, write the following code:
public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
  • To run your program, right-click anywhere inside the HelloWorld.java file and select Run ‘HelloWorld.main()’.
  • Or, you can click the green play button in the top right corner of the IDE.

Output

Hello, World!

Congratulations on completing your first Java program! In the next tutorial, we’ll explore how it works.