Configuring Java Development kit and writing a hello world program in Java

In this tutorial:

  • Learn How to install and set-up Java Development Environment
  • Writing your first Java code – “Hello World”

Terms and Abbreviations used:

JDK
Java Development Kit
JRE
Java Runtime Environment
<version>
Version of Java Environment
cmd
Command Prompt in Windows

Requirements and Recommendations:

  • Beginner level knowledge in any Object Oriented Programming (OOP)Language
  • Windows Operating System
  • JDK
  • An advanced text editor like Notepad++

Procedure or Steps to follow:

1.

Download and Install JDK

Download the latest version of JDK from Oracle’s website. You are advised to download the latest version of JDK and install it.

2.

Reboot and start Command Prompt

After installing, a reboot may be required, so restart your system. After restarting, Go to Run ( press windows + r button ) and type cmd in it followed by an enter. OR Click on Windows button, search for cmd in it and start.

Command Prompt in windows search

Command Prompt in windows search

running command prompt using run

running command prompt using run

3.

[Optional] Check java version

type javac -version (executable file javac.exe located in C:\Program Files\Java\jdk<version>\bin\) followed by enter. You would see an error saying – “javac is not recognized as an internal or external command, operable program or batch file.” that implies that javac (java compliler) is not recognized by your system.

java version check failed

java version check failed

4.

Navigate to Advanced System Settings

Right click My Computer and select properties. In the new Window, click on “Advanced System Settings” in the left pane. A new smaller window dialog box opens.

Advanced System settings in windows

Advanced System settings in windows

5.

Setting the java path

Must proceed with attention
In the Advanced tab, click on Environment Variables situated below startup and recovery settings. After clicking, a newer window pops. Now in the System Variables, scroll down to Search variable “path” and click on edit.

Edit path in System environment variables

Edit path in System variables

In the edit box, append the following path to “variable value“. Make sure that you DO NOT delete the previous info. Add the path to your javac.exe in it.
Must start adding line by ; (semi colon) followed by the path. For example:-
;C:\Program Files\Java\jdk1.8.0_25\bin\

add and append javac path

add and append javac path

The version of your jdk may differ, but the path will look “similar”. Just add it in the last without editing the previous data. Click ok, ok and ok and then reboot (MUST)

6.

Restart and Check version

After restarting, try step 3 again, i.e., type javac -version in CMD and check result. If the output is something like javac <a version> then you have successfully set up the java development environment.

javac version check pass

javac version check – pass

Creating your first Java Program – Hello World code

1.

Write your code

Open Notepad++, create a new file and write the following code in it:

class FirstProg
{
	public static void main(String arguments[])
	{
		System.out.print("Hello World!");
	}
}
2.

Create a work directory

Create a new folder just for sake of cleanliness something like- java-dev. Save the code file as FirstProg.java in your newly created folder. Please note that the name of the file must match the name of the class in which main method exists. You are recommended to use the first letter in uppercase.

3.

[Optional] Change the present working directory for cmd

Open command prompt and change the current directory to your new folder that you just created (java-dev)
Use command cd C:/java-dev
syntaxcd <Directory_path>
Or
Go to that folder, Press and hold shift key and press right click, select – “open command window here

4.

Compile your first code

Compile your code by typing javac FirstProg.java in cmd
syntaxjavac <relative_path>

If you skipped step 3

then type – javac C:/java-dev/FirstProg.java
syntaxjavac <absolute_path>

5.

Run your very first Java program

Run your code by typing java FirstProg
syntaxjava <Name_Of_Class>

compile and run FirstProg hello world

compile and run FirstProg

6.

Well, you just made it

Look at the output, yes! it says Hello World!. Congratulations, you are a java developer 😉
[highlighter]

If you liked this article and the information shared in it, then please like and share it to your friends. Your valuable feedback is appreciated, do not hesitate to leave comments below.