How to setup JDK and print HelloWorld in Java

How to setup JDK and print HelloWorld in Java

In this tutorial we can learn how to setup Latest JDK in Windows platform and how to write a simple helloworld program, compile a java program and run a java program.

Download JDK from Oracle Site like below:

Now click on java SE and go to Download Page like below:

Now click on JDK download and goto next page like below:

After this you need to accept license then you can download JDK like below:

After download JDK zip file you need to extract zip file and after this you can keep this JDK folder where you keep all java related software.

We have two way to set JDK location with window platform.

  • Set Temporary Path
  • Set Permanent Path

Set Temporary Path

Firstly you need to open cmd and type like below:

Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Deep Singh>set path=D:\jdk-16.0.2\bin

C:\Users\Deep Singh>javac -version
javac 16.0.2

C:\Users\Deep Singh>java -version
java version "16.0.2" 2021-07-20
Java(TM) SE Runtime Environment (build 16.0.2+7-67)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)

Set Permanent Path

You need to go to start window and type env like below:

After this you need to click on Environment Variable like below:

After this if you see a path variable like below:

Then you need to double click on path and select new and paste jdk/bin location like below

Then click on Ok -> Ok -> Ok.

After this if you want to check version so you need to reopen cmd and type below command:

C:\Users\Deep Singh>javac -version
javac 16.0.2

C:\Users\Deep Singh>java -version
java version "16.0.2" 2021-07-20
Java(TM) SE Runtime Environment (build 16.0.2+7-67)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
  

If you get above result that means path is setup successfully.

Now lets write a helloworld program then compile and run it. For this you need to open notepad and write below program:

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

Now you can save your file with any name .java extension but if your class is public then you must have to save with class name .java.

  Save     -> .java
  Compile  -> javac .java
  Run      -> java Hello
  

No comments: