Hello World – Java

Welcome to the first tutorial. The Hello World Program. This program helps understand beginner developers the basic syntax of Java. So, let’s begin.

Before we dive directly into coding. I would like to show you how to make a simple Java Program in IntelliJ IDEA (The IDE we are using to write and compile Java). Start with downloading and installing IntelliJ IDEA. After installation, run the IDE. The Welcome Screen will appear after the loading.

I am using IntelliJ IDEA Version 2018.3.5. Click on Create New Project. A New Project Window appears.

Note: Java Development Kit (JDK) should be installed on your OS before proceeding.

Select Java from the Menu and do not check mark for any Additional Libraries and Frameworks. Press Next and the Template Selection window appears

Click the Create project from template and select Command Line App because we are going to create a Command Line App. Click Next and Project Details Screen appears

In the Project Details window, enter the name of the project as Hello World in the Project name field and set the location for the project to be saved on your local hard drive by clicking on the icon with the 3 dots (…). Leave the Base Package as it is. Click Finish and the IDE loads. From the left menu, select Project and a window containing some folders will open. Double click on the hello-word folder and then on src folder, within the folder there would be a package (folders in Java) with the title of our base package com.company. The file within the package is the Java class titled/named as Main.java. The Java class will contain the following code

package com.company;

public class Main {
    public static void main(String[] args) {
    // write your code here
    }
}

All this gibberish for you is Java. Yes! This is the Java syntax. Moving further, for every Java class to run, The main method is required which works as the starting point for the Java Class. Following is the main method within your code.

 public static void main(String[] args) {
// write your code here
}

So, how are we going to print “Hello, World!” in the console, by simply calling the System to output it in the console. We do this by adding the following line of code.

package com.company;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

The line System.out.println(“Hello, World!”) means that Java calls the System class which has the out function and within the out function is the println method which takes multiple datatype arguments. The one we used is called String. Press the play button in the top right menu. The green play button compiles & executes your program and displays the result in the console.

Congratulations, you have created your first program in Java. Try taking the challenge below to practice. The only way to be a better programmer is to practice.

Challenge: Try printing your name in the console.

You can find the complete tutorial code here.

Tell us in the comments on how to improve this article and help developers learn better.