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/
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. 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)
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.
JAVA_HOME
Path
You can jump to the environment variable settings by opening the search window with the Win + S
key and typing env
.
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 **.
First of all, JAVA_HOME
. Select ** New ** and do the following:
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 **.
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!
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!
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.
** 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.
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!
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.
On the next screen, enter "javahome" in the search window and the JAVA_HOME setting will appear. Select Edit in setting.json
.
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.
Save setting.json and restart VS Code just in case.
Now everything is ready!
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 ".
In this way, Java: Create Java Project ...
will appear, so press the Enter
key while it is selected.
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.
Finally, you will be asked for the project name.
Enter the project name and press the Enter
key.
This will create a Java project.
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.
If a terminal appears at the bottom and the execution result is output, it is successful.
Recommended Posts