Settings up your development environment for Java on Ubuntu is straight forward. We are going to install the Java SDK and VS code with the Java extension then create a simple Hello World app.
Find the available versions of Java JDK
First, we will search for the available packages to install. I'm looking for version 11, so my search will be.
$ sudo apt search openjdk-11
You will get similar to the following.
Sorting... Done
Full Text Search... Done
default-jdk/focal 2:1.11-72 amd64
Standard Java or Java compatible Development Kit
openjdk-11-dbg/focal-security,focal-updates 11.0.8+10-0ubuntu1~20.04 amd64
Java runtime based on OpenJDK (debugging symbols)
openjdk-11-demo/focal-security,focal-updates 11.0.8+10-0ubuntu1~20.04 amd64
Java runtime based on OpenJDK (demos and examples)
openjdk-11-doc/focal-security,focal-security,focal-updates,focal-updates 11.0.8+10-0ubuntu1~20.04 all
OpenJDK Development Kit (JDK) documentation
openjdk-11-jdk/focal-security,focal-updates 11.0.8+10-0ubuntu1~20.04 amd64
OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless/focal-security,focal-updates 11.0.8+10-0ubuntu1~20.04 amd64
OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre/focal-security,focal-updates,now 11.0.8+10-0ubuntu1~20.04 amd64 [installed,automatic]
OpenJDK Java runtime, using Hotspot JIT
openjdk-11-jre-dcevm/focal 11.0.3+1-1 amd64
Alternative VM for OpenJDK 11 with enhanced class redefinition
uwsgi-plugin-servlet-openjdk-11/focal 2.0.18-11ubuntu1 amd64
JWSGI plugin for uWSGI (OpenJDK 11)
You can change the number
11
and look for other versions of Java.As you can see
openjdk-11-jdk
is available. So let's install it.
Install Java JDK
Now we will install the Java JDK using one command.
$ sudo apt install openjdk-11-jdk
Verify that Java installation using the following.
$ sudo java -version
The output should be similar to.
openjdk version "11.0.1" 2020-04-14
OpenJDK Runtime Environment (build 11.0.1+7-Ubuntu-1ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.1+7-Ubuntu-1ubuntu1, mixed mode, sharing)
Install VS code
You can use the following command to do so.
sudo snap install --classic code
If snap
is not available, you can use apt
by following this post.
Install Java Extension Pack
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install vscjava.vscode-java-pack
Run A Hello World App
1 - Open VS code.
2 - Create a file called Hello.java
.
3 - Paste the following code. And save it.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
4- Open the Debug
tab and click on Run and Debug
.
5- The output in the terminal should be.
Credit
This post was based on the information from the linuxconfig post .
Top comments (0)