Java development environment (Mac, VS Code)

Introduction

On Mac, with VsCode (Visual Studio Code) instead of Eclipse This article is for those who want to develop Java.

For those who want to develop in Eclipse instead of VsCode Please refer to "Java Development Environment (Mac, Eclipse)" in Qiita.

If you haven't installed Java yet "Install Java (Mac, Homebrew, multiple version control)" Please complete the installation first by referring to.

My environment that I confirmed the operation is as follows.

OS: macOS Catalina(Version 10.15.4)
Java: 11.0.2

Install VsCode

If you have already installed it, please skip it.

[Download page] on the official website (https://code.visualstudio.com/download) Select your Mac and download it.

vscodeダウンロードページ.png

I think that a file called "VSCode-darwin-stable.zip" will be downloaded. Double click.

A file called "Visual Studio Code.app" will be created in the same folder.

Copy this file to your application folder.

Right-click "Visual Studio Code.app" in the application folder and click Press "Open" to start.

Install "Java Extension Pack" with extension

  1. Open the extension screen from the menu on the far left
  2. Search for "Java Extension"
  3. Select "Java Extension Pack" from the search results
  4. Press the install button to install

拡張機能__Java_Extension_Pack_と_「Javaの開発環境_Mac__VS_Code_」を編集_-_Qiita.png

The Java Overview and preview page are displayed. When "Enable Semantic highlighting for Java by default?" Is displayed at the bottom right of the window, press "Enable".

Java_プレビュー__v0_9_0_md.png

Write a Java program

First, prepare a file called Main.java

  1. Open Explorer from the leftmost menu
  2. Press the "Open Folder" button
  3. Select any folder
  4. Press the open button
  5. Create a new file
  6. Name the file "Main.java"

Visual_Studio_Code_explorer.png フォルダを開く.png ファイルを作成.png ファイル名を書く.png

Next, implement it in Main.java.

Enter the following code.

class Main {
  public static void main(String[] args) {
    String msg = "";
    msg += "Hello ";
    msg += "World!";
    System.out.println(msg);
  }
}

Mainjavaを書く.png

As a test, I will erase one semicolon

If you remove the semicolon (even if you haven't saved it), a red squiggly line will tell you the error.

コンパイルエラー.png

Click the error display icon at the bottom left to see the details of the error. エラー情報を表示.png

Run Java programs

First try to run normally

class Main When public static void main(String[] args) { A button "Run | Debug" is displayed between, so press it to execute it. "Hello World!" Is displayed in the terminal. デバッグ実行1.png

When you see the link "Create a launch.json file" in the menu on the left Press it. Then, the menu on the left changes to a screen that looks like debug execution. launch_json作成.png

Debug run

Click the left edge of the 5th line of Main.java to set a "breakpoint". ブレークポイントをはる.png

Then press the run button at the top of the left menu. Then the processing stops at the 5th line. デバッグ実行2.png

When you press the "Step over" button among the icons displayed at the top Go line by line

ステップオーバー1.png ステップオーバー2.png

in conclusion

How was building a Java development environment using Visual Studio Code on Mac?

Buttons such as Step Over and Step In when debugging I think the watch expression, call stack, breakpoints, etc. are the same as those used in the IDE (Integrated Environment). I think that a lot of information about this area will come out if you google with "debug execution" etc., so I will omit it here.

end.

Recommended Posts

Java development environment (Mac, VS Code)
Build Java development environment with VS Code on Mac
[Mac] VS Code development environment construction (Java, Gradle, Node.js)
Java development environment (Mac, Eclipse)
Build a Java development environment with VS Code
Java Spring environment in vs Code
Java development environment
Build Java development environment (for Mac)
Build Java development environment with WSL2 Docker VS Code
[Environment construction] Build a Java development environment with VS Code!
Install Java development environment on Mac
Java web application development environment construction with VS Code (struts2)
What is Java and Development Environment (MAC)
Hello World on Mac VS Code Java
Java development environment memo
java development environment construction
Let me do VS Code Remote Development + Java development in Proxy environment
[Mac] Install Java in Visual Studio Code (VS Code)
Introduction to Java development environment & Spring Boot application created with VS Code
Rails6 development environment construction [Mac]
Create a Java development environment using jenv on Mac
Build VS Code + WSL + Java + Gradle environment from scratch
Build Java program development environment with Visual Studio Code
[Eclipse Java] Development environment setting memo
Prepare Java development environment with Atom
Play Framework 2.6 (Java) development environment creation
Java 15 implementation and VS Code preferences
Eclipse installation and code completion enhancements (Mac for Java development)
[Java & SpringBoot] Environment Construction for Mac
Build WebAPP development environment with Java + Spring with Visual Studio Code
[ev3 × Java] leJOS development environment construction (Eclipse on Mac OSX / bluetooth)
[Processing x Java] Construction of development environment
Laravel development environment construction with Docker (Mac)
Sample code collection for Azure Java development
Let's create a Java development environment (updating)
Build Java 8 development environment on AWS Cloud9
[Personal memo] Java development environment is ready
[Mac] Install Java in Visual Studio Code
Java application development environment created in VM environment
Java development training
Script Java code
Java code TIPS
A record of setting up a Java development environment with Visual Studio Code
[Java development] Java memory
[Java] Environment construction
Java sample code 02
Java sample code 03
Java environment construction
Java sample code 04
Java sample code 01
Java character code
Create a java web application development environment with docker for mac part2
Summary of Java environment settings for myself [mac]
Java Development Basics ~ Development Environment Settings and Project Creation ~
Using Gradle with VS Code, build Java → run
Ruby on Rails development environment construction on M1 Mac
Create Spring Boot environment with Windows + VS Code
Build a development environment for Docker, java, vscode
Points stuck in building VSCode & Java development environment
Try debugging a Java program with VS Code
[Beginner] Install java development tool in cloud9 development environment.