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

A brief discussion on Flex layout and scaling calculation

1. Introduction to Flex Layout Flex is the abbrev...

MySQL slow query operation example analysis [enable, test, confirm, etc.]

This article describes the MySQL slow query opera...

Examples of 4 methods for inserting large amounts of data in MySQL

Preface This article mainly introduces 4 methods ...

User Experience Summary

Nowadays, whether you are working on software or w...

Example of using CSS3 to create Pikachu animated wallpaper

text OK, next it’s time to show the renderings. O...

Implementation code of short video (douyin) watermark removal tool

Table of contents 1. Get the first link first 2. ...

Detailed examples of ajax usage in js and jQuery

Table of contents Native JS How to send a get req...

Detailed explanation of the difference between flex and inline-flex in CSS

inline-flex is the same as inline-block. It is a ...

CSS3 to achieve dynamic background gradient effect

Learning CSS3 is more about getting familiar with...

Pull-down refresh and pull-up loading components based on Vue encapsulation

Based on Vue and native javascript encapsulation,...

jQuery implements ad display and hide animation

We often see ads appear after a few seconds and t...