What is Java Development Kit (JDK)?

Java Development Kit is required by Java developer and programmers in order to compile and run Java programs. It is also used in security tools which is built in Java.

Install JDK on Kali Linux

sudo apt install default-jdk
Install JDK on kali linux by command line

Open a command line terminal and follow the steps to install Java. We’ll test the installation afterwards by checking the Java version and compiling a test program.

  • Step 1- Use the apt package manager to update your system’s repositories and install the default JDK package.
$ sudo apt update
$ sudo apt install default-jdk

If you want to install a specific version of the JDK, use the following command to search for the exact package you want. This will show all the JDK packages available for installation.

$ sudo apt-cache search openjdk
  • Step 2- Once the process is finished, you can verify the Java installation with the following command.
$ java --version
  • Step 3- For further verification that you can compile and run Java programs, try compiling java Hello World program.
public class HelloWorld {
   public static void main(String[] args) {
      System.out.println("Hello World");
   }
}

Compile Java Program

Now that the coding part is behind us, the next step is to compile the Java Hello World program using the javac command line compiler. Open the terminal and enter:

$ javac HeloWorld.java

The above command should not produce any output and errors. The result will be a new Java HelloWorld.class file located within your current working directory:

$ ls
HelloWorld.class  HelloWorld.java

Run Java Program

The last step is to execute the newly compiled java program. To do so we run the java command with a single parameter which will be the name of our class HelloWorld:

$ java HelloWorld 
Hello World
  • step 4-To switch between Java versions, execute the following two commands while selecting the Java version you require.
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

In this guide, we saw how to install Java JDK on Kali Linux. We also saw how to test the installation with a Java command and Hello World program, as well as the process for switching between installed versions of Java.

You can visit my profile and follow me on :

Linkedin : https://www.linkedin.com/in/aakash-patel-6250/

Twitter https://twitter.com/AAKASH_6250

Youtube : https://youtube.com/channel/UCOjZF3dnFCXhZ4yUtNc7DHA