Introduction to Java

Java is a programming language that uses classes to define inheritance occurring in objects. Java is portable hence can run the same application on any computer regardless of its system features. The latest version of Java is Java 17 LTS for Java SE Platform which you can find in Java Downloads page

The latest features of Oracle Java 17 include; 

  • Sealed Classes which restricts which classes implement which classes
  • Pattern Matching for Switch Statements
  • New API for Accessing Large Icons
  • Source details in Error Messages
  • Related Packages” on a Package Summary Page

In this guide we shall;

  • Install the Java JDK on Windows 10 / Windows 11,
  • Add the environment variables,
  • Set JAVA_HOME path,
  • Run a simple Java Hello World script on Notepad++ and CMD.

Install Oracle Java 17 on Windows 10 / Windows 11

If you are not sure if you have installed Java or not you can use the command prompt to check.

Use the code java -version and javac -version.

If you get an error ike the one shown below, You do not have Java installed, Thus can proceed with the next step

Downloading Java 17 on Windows 10 / Windows 11

Go to the official oracle website here, under resources then software downloads.

The next page opens which shows various downloads available. Click on Java

Click on Java SE to go to its download page

Next click Windows then select the one you want. I chose the setup direct

The download starts immediately.

Installing Java 17 on Windows 10 / Windows 11

Once the download is done, Find the setup from your downloads and click on it to install

The installation wizard opens as shown below

Then the next step will be to choose the destination which I chose to go with the default folder. 

If you change the destination Folder, Kindly note where you have installed it,  as you will use the destination to add java path to the environment system variable.

Pressing next will take you to the installation which will then finish the installation.

To check if Java has been installed in your system, you can use the CMD.

Use the code java -version and javac -version and it shows as below

The installation was successful!

Set Java Environment Variables on Windows 10 / Windows 11

The next thing we want to do is to add the environment variable for the java in our system.

Go to the search bar and type env then select Edit the system environment variables as shown below.

The window opens as below, Click on Environment Variables

Another window opens up as below. Click on Path which highlights to show you have selected it then click Edit

Another window opens.

Before this, kindly locate where you installed the Java components and open the bin folder and copy its directory.

Mine is as shown

 In the previous environment window add the path as follows, Click on New then paste the directory then press OK to save.

Once That is done it takes you back to the previous window. Click on New button to set JAVA_HOME

Go back again to the Java folder installed and identify the JDK folder. Copy the directory.

At the variable value paste the directory for the Java JDK 17 folder as shown below, then press OK to save

The new system variable is added as shown

Press OK to finish.

So we have set the JAVA_HOME environment variable. We can check if it was successful by using cmd

Use code echo %JAVA_HOME% to show the path.

Hello World Example with Java

We can use notepad/notepad++ to write down the code. I will be using the notepad++.

If you don’t have notepad++, you can install it form Here. Or you can use any other editor you have.

Open notepad++ and type in a simple hello world code as below

Use code:

// Your First Program

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

Save the file as .java as below to your preferred directory. I went with a folder on the desktop for ease of access.

Run the Java Program

I will show you 2 ways to run the program;

  1. Using notepad++
  2. Using CMD

Using notepad++

In the spirit of notepad++, Find the Plugin tab then select Plugins Admin.

A new window opens, search for nppexec and select the checkbox next to it then press Install.

The notepad++ reboots to install the plugin.

After the reboot, you can then run the program by using the plugin like below.

Another minor command window opens to specify on the program to run and how to run it.

Use the code below to specify the directory, filename and the specific name of the java program to run with reference to the program you are running at that moment.

cd $(CURRENT_DIRECTORY)
javac $(FILE_NAME)
java $(NAME_PART)

You can save the script to ease up running another java program

Then it will run the program and give the output as follows.

And there you have the output.

Using CMD to Run Java Program

Open the command prompt

Enter the following code.

cd [FolderName] to change the directory of where the java program file is.

As mine is on the desktop I will use

cd desktop

Then onto my next folder javaPrograms which I used to save the java program

cd javaPrograms

From there i can use 

javac Hello.java to specify the file name

Lastly use java Hello to produce the output as shown.

It is prudent to note that Java is a case-sensitive programming language and thus you have to be careful on how you type your code.

So, we have installed Java JDK on windows, set the environments variable and the JAVA_HOME path and run a simple Hello world script on notepad++ and via CMD.

More guides:

LEAVE A REPLY

Please enter your comment!
Please enter your name here