Java 15 implementation and VS Code preferences

Introduction

This is a memo of environment construction for Java development on a PC with VS Code installed.

If you haven't installed VS Code yet, please install it here. https://code.visualstudio.com/ image.png

JDK installation

download

There are also Oracle JDK etc. in JDK, but this time we will introduce ** OpenJDK **.

By the way, the Oracle JDK has been making noise for a fee a while ago, but it can be used for free for development purposes. The OpenJDK used this time can also be used for free for development purposes, and there is no difference.

The difference is that OpenJDK can be used for commercial purposes only for open source. Yes, "only for open source". To be honest, both can be used for free, but they are not suitable for full-scale commercial use ...

Rabbits are also horny, there is no difference in development purpose, so either is OK!

The introduction has become long, but this time I would like to include ** Java15 ** in OpenJDK.

There is no particular reason to stick to Java 15, but since 15 is the current Latest version, leave it at 15.

Please download from here. http://jdk.java.net/15/

Since the author is Windows 10 64bit, I will download the Windows/x64 zip file. image.png The DL file is a compressed file, so decompress it.

Also, move each folder to an easy-to-understand location (C drive is recommended). I decided to put it directly under C: \ Program Files \ OpenJDK. (Please note that administrator privileges are required) image.png

Setting the JDK location (environment variable)

If you are a beginner, this is probably the place where you feel a barrier to Java installation. Keep in mind that environment variables are often tampered with not only when installing Java but also when installing other languages.

That said, it's simple to do. The point is that all you have to do is tell the PC the location of the program (Java this time).

Let's do it. This time, I will introduce the setting method in Windows 10.

You need to set the following two JDK locations.

You can jump to the environment variable settings by opening the search window with the Win + S key and typing env. image.png First of all, the above screen will be displayed, so select "Environment Variables".

When you jump to the environment variable setting screen, add the above two to ** system environment variables **. image.png First of all, JAVA_HOME. Select ** New ** and do the following: image.png For the variable value, specify the location where you put the JDK earlier with the full path.

Next is PATH, but I think that this environment variable already exists, so select it and select ** Edit **. image.png

image.png You can see that we are already using some environment variables called PATH. If you select ** New **, you can add a new one, so add it at an appropriate position. Again, specify the location of the JDK, but be careful, specify up to … bin.

You have now set up your Java location!

Version confirmation

The installation procedure is now complete. Finally, you can check if the JDK was installed correctly by checking the version of the JDK.

Open your favorite command line tool. If you don't put anything in particular, ** Windows Powershell ** will be included, so please use that.

Run the following command:

java -version

If the version information is returned as follows, it is successful.

openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)

If you do not see it like this, please review the Java location settings. If the path is not correct, the java command cannot be executed.

If you can execute it correctly, Java installation is complete!

VS Code Java development environment settings

Java works without an editor in the first place, but it is difficult to develop on the command line, so let's use VS Code as an editor.

VS Code starts up faster than other IDEs, and I think it's easy to understand with a simple UI. Another strength is that we can code various things, not limited to Java.

Introducing useful extensions for Java development

** Extensions ** are the reason why we can support many languages. It will help you in coding and building by inserting the optimum extension each time.

This time, let's introduce the Java Extension Pack required for Java development.

Open VS Code and open the extension screen from the icon on the left. image.png If you enter "Java" in the search window, the Java Extension Pack will appear. Select ** install ** to install it. (The image is the screen after installation)

This extension is a set of several extensions. All of them help Java development.

This completes the extension installation!

Setting JAVA_HOME with VS Code

Speaking of JAVA_HOME, I set it with an environment variable, but I need to specify it separately with VS Code.

VS Code uses JSON for configuration, so you'll be able to tweak the JSON file a bit.

Open the setting screen from the following location. image.png

On the next screen, enter "javahome" in the search window and the JAVA_HOME setting will appear. Select Edit in setting.json. image.png

The setting.json will open, so add the following line.

{
  "java.home": "C:\\Program Files\\OpenJDK\\jdk-15.0.1",
}

Specify the full path of the JDK as you set in the environment variables.

Note that in the case of JSON, it is necessary to overlap the \ mark twice to make it \\. Also, since it is JSON, please do not forget the last ,.

Here is the image after setting. image.png

Save setting.json and restart VS Code just in case.

Now everything is ready!

Creating a sample program

Now you can finally develop Java with VS Code. Let's create a trial sample program.

With VS Code running, press Ctrl + Shift + P, then type" java ". image.png In this way, Java: Create Java Project ... will appear, so press the Enter key while it is selected.

image.png You will be asked which build tool to use next. I will not use it this time, so press the Enter key with No build tools.

After that, you will be asked for the folder path to store the project, so select the workspace folder you created.

image.png Finally, you will be asked for the project name. Enter the project name and press the Enter key. This will create a Java project.

image.png It was created like this. A Java file called App.java is included in the folder called src from the beginning. With this open, press the ▶ Execute button on the upper right.

image.png If a terminal appears at the bottom and the execution result is output, it is successful.

Recommended Posts

Java 15 implementation and VS Code preferences
Java Spring environment in vs Code
Java 9 new features and sample code
Java build with mac vs code
BloomFilter description and implementation sample (JAVA)
Java development environment (Mac, VS Code)
Prepare Java development environment with VS Code
Link Java and C ++ code with SWIG
Java implementation to create and solve mazes
Hello World on Mac VS Code Java
Page number logic and reference code (java)
Script Java code
Java code TIPS
Java sample code 04
Java and JavaScript
XXE and Java
Java sample code 01
Java character code
[ev3 × Java] Interface, implementation and inheritance (event handling)
[Swift vs Java] Let's understand static and final
PostgreSQL Pub / Sub functionality and Java client implementation
Using Gradle with VS Code, build Java → run
Java and Swift comparison (3) Class implementation / Class inheritance / Class design
Try debugging a Java program with VS Code
[Mac] Install Java in Visual Studio Code (VS Code)
Build a Java development environment with VS Code
Interpreter implementation in Java
Build Java development environment with VS Code on Mac
Build VS Code + WSL + Java + Gradle environment from scratch
Lombok with VS Code
Getters and setters (Java)
Check Java toString () implementation
Create a Java (Gradle) project with VS Code and develop it on a Docker container
[Java] Thread and Runnable
Java true and false
[Mac] VS Code development environment construction (Java, Gradle, Node.js)
[Java] String comparison and && and ||
Introduce JavaFX 15 and do GUI development with VS Code
Boyer-Moore implementation in Java
Java --Serialization and Deserialization
Heapsort implementation (in java)
[Java] Arguments and parameters
timedatectl and Java TimeZone
Build Java development environment with WSL2 Docker VS Code
How to build Java development environment with VS Code
[Java] Branch and repeat
[Environment construction] Build a Java development environment with VS Code!
Java --StringBuilder vs StringBuffer
Create a Java (Maven) project with VS Code and develop it on a Docker container
About synchronized and Reentrant Lock (Java & Kotlin implementation example)
[Java] Variables and types
[Java] [Spring] Java EE (JAX-RS) vs. Spring REST implementation comparison memo
java (classes and instances)
[Java] Overload and override
Understand the Singleton pattern by comparing Java and JavaScript code
Java web application development environment construction with VS Code (struts2)
Sample code to parse date and time with Java SimpleDateFormat
Correct the character code in Java and read from the URL
Eclipse installation and code completion enhancements (Mac for Java development)
Understand the Iterator pattern by comparing Java and JavaScript code
A memo to start Java programming with VS Code (2020-04 version)