Installing & Setting up JDK + Netbeans IDE | First Java Program | Hello World

In this tutorial we will first install and setup our Netbeans IDE that we will be using for writing and running java programs. We will also write our first Hello World program in Java which will print the message – Hello World on the command prompt. We will then try to understand the program line by line at an overview level.

Installing and Setting up Netbeans IDE

If you are starting with Java for the first time, you might want to install the Java + Netbeans bundle from the official website as follows – http://www.oracle.com/technetwork/java/javase/downloads/index.html

jdk + netbeans download website

Just select the Netbeans with JDK 8 option and download the full bundle. It is free and open source. Next task is to install both Java and Netbeans IDE. Once you have finished downloading the bundle simply install it with Default setting. Thats it, pretty much everything is sorted out except one thing – Setting up the PATH variable.

Setting up the PATH variable

The path variable is system variable which holds values to executables files that the system requires(not jsut for Java). So when you compile the java code, a exe file called javac.exe is invoked which resides in the java directory as follows – C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe 

Now this location needs to be set in the PATH variable so that when you compile any java code, the program knows where exactly to locate the java compiler. It is possible to invoke the compiler without setting up the PATH variable, however you will need to provide the path everytime you want to invoke the compiler. Thus its easier to set the PATH variable once in the system settings.

Steps to set PATH variable –
  • Step 1 : Right Click on MyComputer and click on properties
  • Step 2 : Click on Advanced System Settings (Windows 10)

advanced-system-settings

  • Step 3: In the System properties, advanced tab, you can see a button named environment variables, Click on it.

setup path variable

  • Step 4: Here you can see 2 windows – uservariables and system variables. In the system variables search the variable named – path. Double click on it or click edit.

system variables

  • Step 5: Once you click edit you will see a list of entries (shown in the image below) of different executables. Search for the entry of the path of the java jdk bin as show below in the diagram. If you cannot find it, just go to your windows explorer and do the directory as follows – C:\Program Files\Java\jdk1.8.0_161\bin\. Copy this directory location and paste it as a new entry in this list as shown in the below diagram and then click okay.

path variable location

  • Step 6: Click okay/Apply and then you are good to go. Your PATH variable is all set. SO the next time you try to execute a java program, the program will know exactly where the java compiler is located.

So this was all about the Setting up of Netbeans IDE and the PATH variable. Now lets see our very first java program. So quickly open up your Netbeans IDE (for the first program you can also use a basic text editor however I always prefer Netbeans IDE or any other IDE)

  • Open up your Netbeans IDE
  • Click on -> File -> New Project -> Java -> Java Application -> Next
  • Set a project name and click Finish
  • Inside the main function paste the code typed below –
First Hello World Program in Java

Output
Hello Simple Snippets
Program Explanation

Let’s see what is the meaning of class, public, static, void, main, String[], System.out.println().

  • class keyword is used to declare a class in java.
  • public keyword is an access modifier which represents visibility, public means visible in the entire program.
  • static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn’t require to create object to invoke the main method.
  • void is the return type of the method, it means it doesn’t return any value, not even 0.
  • main represents the starting point of the program. This is a special function without which you cannot execute any java program. All execution process starts from the main() function.
  • String[] args is used for command line argument. We can take in arguments via this method and we will discuss about them in detail in future videos.
  • System.out.println() is used print statement. We will study about this in detail in further tutorials. For now, just understand that this is used to strings, values on the console screen.
Watch it on YouTube

One thought on “Installing & Setting up JDK + Netbeans IDE | First Java Program | Hello World

  • May 14, 2018 at 10:38 pm
    Permalink

    Hey There. I found your blog using msn. This is a really well written article.

    I will make sure to bookmark it and come back to read more of your
    useful info. Thanks for the post. I will definitely comeback.

    Reply

Leave a Reply

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