Keywords: Hello World, JDK, IDE, IntelliJ
It’s time to write your first program in Java! It’s a tradition that a programmer’s first program in a new language print the text “Hello World!”. This article shows step by step how to download the IDE IntelliJ and how to write your first program.
Now you are finally going to write your first program in Java by following seven simple steps! The only thing our program should do is print the text “Hello World!”. Why “Hello World!”? Well, it is an old tradition that a programmer’s first program prints the words “Hello World!”.
The steps and images in this article are based on you using IntelliJ as your IDE, but you can, of course, take the corresponding steps in another IDE. If you have not downloaded any JDK or IDE yet, you can easily get started with our article: “Compiler, IDE, JDK and JVM in Java: This is what you need to start programming in Java“.
Before we start writing actual code in Java, you first need to have:
How to get started with programming in Java
First of all, start by launching the IntelliJ program and creating a new project.
Press create new project
or use file > new > Project…
Under the heading “Software Development Kit (SDK)”, select the JDK you downloaded in the previous section. For example, choose JDK 1.8 or a newer version.
Press next, and then press next again
Decide what the project should be called:
In our case, we will name our project HelloWorld and then select the folder where we want to save our project. Since we are using IntelliJ, it automatically adds the .java file extension to our file.
Then press finish
Start by right-clicking on the src (source) folder, then select new and finally Java Class.
You have now created a so-called java class where we can write our code. We will look a lot closer at what classes in Java are in later chapters, but for now, let’s just be content with creating the class.
Moreover, select the name that you want the class to have, and keep in mind that the same rules as the list for java file also apply here. For example, name the class file HelloWorld and press ok.
Finally, now it’s time to write your first program in Java! Try writing the following code in the text editor:
public class HelloWorld { public static void main (String[] args){ // Prints "Hello World!" System.out.print("Hello World!"); } }
Note the first line:
public class HelloWorld {
After public class, you must enter the same name as the class file. In the previous step, we created a class file named HelloWorld, which means that you must use the same class name here as well. Since we named the class file HelloWorld in our example, we also enter HelloWorld here.
Just right-click somewhere in the text editor and press the green arrow with the text “Run ‘HelloWorld.main ()’“
You have now programmed your first program, a program that prints “Hello World” in the terminal.
And remember, since your first program was “Hello World!”, you could say that you are keeping the tradition of “Hello World!” alive.
To conclude, now you have hopefully created your first Java application that prints the text “Hello World!”. Feel free to reach out to us if something went wrong, or if you need help to get started. Additionally, we would gladly like to hear your ambitions and ideas why you started with Java programming, so feel free to send us an email with your ideas for your own Java project.
Please leave feedback and help us continue to make our site better.
How useful was this article?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
To write a program in Java, you need:
So far, it may be difficult to understand what the code actually does, but by going through chapter by chapter here on Code-Knowledge.com, you will gradually learn how everything works and interacts. As you are progressing and are diving into Java programming, you will notice how you can use the code to solve complex problems.
IDE stands for Integrated Development Environment, that is, a development environment where we can write code. There are many different IDEs to use and which one you choose is based on your preferences. In the article: “Compiler and JDK: This you need to start programming in Java“, we explain how an IDE works.
There are several different IDEs, such as IntelliJ, Eclipse, BlueJ or NetBeans, but there are many, many more. Which one you decide to use is mostly about your preference and liking, or if your job or school has a predetermined IDE you should use.
To program in Java, you need a JDK (Java Development Kit). More about JDK and how to download it can be found in our article: “Compiler and JDK: This is what you need to start programming in Java“.