Hello World in Java

Hello World I’m Learning Java Programming

Java No Comments

I decided to learn Java Programming since it is really popular and I have a goal of learning how to develop Android applications. I thought I would get started with it.

So, the first thing you have to do is install Java SE. It contains both Java Development Kit (JDK) and Java Runtime Environment (JRE). You can download it from here.

Since, I am going to be developing in Windows 10, we can add java.exe and javac.exe to the environment variable so that you can compile from the command prompt as well. To add it:

  • Go to Control Panel > System > Advanced system settings.
  • A dialog will open where you click on Environment variables.
  • Add the path C:\Program Files\Java\jdk1.8.0_102\ to the User variables from admin.
    Setting the Environment Variables
  • Click on OK (two times) to save the changes and close the dialog boxes

I decided to use the popular IntelliJ Idea Community Edition as the IDE. Download it and install it like you would install any program. The default settings work great and you do not need those add-ons at least from the start.

Run the program and follow the on-screen wizard to start a new project in it. When you run it for the first time, you will have to give it the path to the JRE as the project SDK.

Creating a New Project

Remember that unlike the environment variable, you are pointing to the JRE instead of JDK.

Using the reverse format to name your project like com.yourdomain.example is widely popular.

New Project in IntelliJ

In the project window, you write the code file and organize them in the src folder. Right click or use the file menu and then click on New > Java Class.

New Java Class

Give it a name like Main and click on Ok.

Creating a New Class

Now we are ready to write our first Hello World Program.

Here is how it looks like in Java:

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

Since, java is totally object oriented, you can see that there is a Main class. Under it is a method called main which contains the code to for our first Hello World program.

To compile it:

  • Click on Run > Run [Shortcut: Alt + Shift + F10).
  • Since you are compiling it for the first time, click on the class like Main in this case. From the next time you can just select Run > Run Main.

You will see the output in the output window present at the bottom.

Hello World in Java

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.