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

Vue.js front-end web page pop-up asynchronous behavior example analysis

Table of contents 1. Preface 2. Find two pop-up c...

MySQL 8.0.12 installation and configuration method graphic tutorial

Record the installation and configuration method ...

Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin to work with Apache on...

Learn how to write neat and standard HTML tags

Good HTML code is the foundation of a beautiful w...

Object.entries usage you don't know in JavaScript

Table of contents Preface 1. Use for...of to iter...

MySQL uses frm files and ibd files to restore table data

Table of contents Introduction to frm files and i...

Detailed tutorial on how to create a user in mysql and grant user permissions

Table of contents User Management Create a new us...

This article takes you into the world of js data types and data structures

Table of contents 1. What is dynamic typing? 2. D...

JavaScript data visualization: ECharts map making

Table of contents Overview Precautions 1. Usage 2...

Detailed explanation of Strict mode in JavaScript

Table of contents Introduction Using Strict mode ...

Install MySQL in Ubuntu 18.04 (Graphical Tutorial)

Tip: The following operations are all performed u...

MySQL 8.0.11 installation tutorial with pictures and text

There are many tutorials on the Internet, and the...

HTML Tutorial: Collection of commonly used HTML tags (4)

Related articles: Beginners learn some HTML tags ...

Pure CSS to achieve cool neon light effect (with demo)

I have recently been following the CSS Animation ...