Configure Java development environment in Ubuntu 20.04 LTS

Configure Java development environment in Ubuntu 20.04 LTS

Download the Java Development Kit jdk

The download address of JDK is: http://www.oracle.com/technetwork/java/javase/downloads/index.html . Click the JDK Download link in the red box.


On the download page, select the corresponding jdk version according to your system. Here, take Ubuntu 20.04 LTS (64bits) system as an example and select the compressed type jdk-14.0.1_linux-x64_bin.tar.gz for download.

Installation Steps

Move the downloaded JDK to桌面and install it according to the following steps:

cd desktop # Locate the directory where the jdk compressed package is located sudo cp /home/ym/Desktop/jdk-14.0.1_linux-x64_bin.tar.gz /opt # Copy the jdk to the specified jdk installation directory cd /opt # Locate the specified jdk installation directory sudo tar -xzvf jdk-14.0.1_linux-x64_bin.tar.gz # Unzip the jdk and get the folder jdk-14.0.1
sudo rm jdk-14.0.1_linux-x64_bin.tar.gz # The jdk compressed package is no longer useful, delete it

At this point, the installation of JDK is halfway done. Next is to configure JDK. The configuration steps are as follows:

# Open the system-level configuration file profile
sudo vi /etc/profile
# Add the following configuration content at the end of the file JAVA_HOME=/opt/jdk-14.0.1 # Configuration content CLASSPATH=.
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
#Make the modified configuration effective source /etc/profilec

Enter the following command to view, create, or update environment variables:

# View the value of the environment variable echo $JAVA_HOME   
echo $CLASSPATH
echo $PATH 

Test whether jdk is installed successfully

Open a terminal;

Type: java -version、javac -version . If the following version information about Java and Java compiler appears, it means that JDK has been installed successfully and the system environment variables have been configured successfully.

First Java Program

Code Listing: HelloWorld.java

public class HelloWorld {
  //Entry method of Java program, the program will start execution from here public static void main(String[] args) {
    // Print a statement to the console System.out.println("Hello World");
  }
}

To edit, compile and run the HelloWorld.java program:

  • Open the code editor, add the above code, and save the file name as: HelloWorld.java;
  • Open a terminal and enter the location of the target file. In this system, it is /home/ym/desktop.
  • Enter the program compilation command: javac HelloWorld.java, press the Enter key to compile the program to generate the bytecode file: HelloWorld.class. If there is no error in the code, the command prompt will enter the next line (provided that the system environment variables have been set);
  • Enter the program run command: java HelloWorld and press Enter to run the program.

uninstall

cd /opt # Enter the jdk installation directory sudo rm -rf jdk-14.0.1 # Uninstall jdk

This is the end of this article about configuring Java development environment in Ubuntu 20.04 LTS. For more information about configuring Java development environment in Ubuntu 20.04 LTS, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Java ResultSet Case Study
  • Java SQL ResultSet getRow() usage instructions
  • ResultSet traversal data operation in java
  • Java uses the PreparedStatement interface and ResultSet result set method example
  • How to use the <results> tag in the Java Struts framework
  • Java 17: Faster LTS cadence

<<:  Detailed explanation of Vuex overall case

>>:  What you need to know about MySQL auto-increment ID

Recommend

Nested display implementation of vue router-view

Table of contents 1. Routing Configuration 2. Vue...

How to prompt and open hyperlink a

<br />The countless information on the Inter...

Detailed explanation of single-row function code of date type in MySQL

Date-type single-row functions in MySQL: CURDATE(...

How to modify the group to which a user belongs in Linux

Modify the group to which a user belongs in Linux...

JavaScript to achieve a simple magnifying glass effect

There is a picture in a big box. When you put the...

How to set the memory size of Docker tomcat

When installing Tomcat in Docker, Tomcat may over...

Detailed explanation of Mybatis special character processing

Preface: Mybatis special character processing, pr...

Linux server SSH cracking prevention method (recommended)

1. The Linux server configures /etc/hosts.deny to...

Detailed explanation of the process of docker packaging Python environment

The steps of docker packaging Python environment ...

React implements infinite loop scrolling information

This article shares the specific code of react to...

The most common mistakes in HTML tag writing

We better start paying attention, because HTML Po...

Docker uses root to enter the container

First run the docker container Run the command as...