
{{ $('Map tags to IDs').item.json.title }}
Getting Started with Java Development Kit (JDK) on Ubuntu
The Java Development Kit (JDK) is an essential toolkit for developing and running Java applications. This tutorial will guide you through the process of installing and configuring the JDK on an Ubuntu system.
Prerequisites
- An Ubuntu system (preferably version 20.04 or later).
- Root or sudo privileges to install software.
- Access to the terminal.
1. Updating Your System
Before you begin the installation, ensure your package index is up to date. Open your terminal and run:
sudo apt update
2. Installing OpenJDK
Ubuntu provides the OpenJDK package, which is an open-source implementation of the JDK. You can install OpenJDK using the following command:
- For the standard OpenJDK:
sudo apt install default-jdk -y
- For a specific version (e.g., OpenJDK 11):
sudo apt install openjdk-11-jdk -y
This will install the JDK along with its dependencies.
3. Verifying the Installation
After the installation, you can verify if the JDK is installed correctly by checking the version:
java -version
You should see output indicating the installed version of Java. Additionally, you can check for the JDK specifically:
javac -version
This command outputs the version of the Java compiler.
4. Setting JAVA_HOME Environment Variable
Setting the JAVA_HOME
environment variable is good practice, particularly for development:
sudo nano /etc/environment
Add the following line at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Make sure to replace the path with your version of Java if necessary. After editing, save and close the file.
To apply the changes, run:
source /etc/environment
5. Writing a Sample Java Program
To ensure everything is set up correctly, let’s write a simple Java program:
nano HelloWorld.java
Add the following code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save and exit the editor.
6. Compiling and Running the Java Program
To compile your Java program, use:
javac HelloWorld.java
Run the program with:
java HelloWorld
You should see the output:
Hello, World!
7. Conclusion
You have successfully installed the Java Development Kit (JDK) on Ubuntu and run your first Java application. With the JDK set up, you can now start developing Java applications and explore the vast ecosystem of libraries and frameworks available for Java development.