$ 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
$ java --version
For further verification that you can compile and run Java programs, try compiling a Java Hello World program.
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
source: https://linuxconfig.org/how-to-install-java-on-kali-linux