Java in Visual Studio Code

The Java support in Visual Studio Code is provided through a wide range of extensions. By installing extensions, you can have a lightweight and performant code editor that also supports many popular Java development tools. VS Code provides essential language features such as code completion, refactoring, linting, formatting, and code snippets along with convenient debugging and unit test support. VS Code can also integrate with tooling and frameworks such as Maven, Tomcat, Jetty, and Spring Boot. Leveraging the power of Visual Studio Code, Java developers get an excellent tool for both quick code editing and also the full debugging and testing cycle. It's a great choice for your Java work if you're looking for a tool which:

  • Is fast and lightweight, free, and open source
  • Supports multiple, or all the programming languages you use
  • Helps start your Java journey without installing and learning a complex IDE
  • Provides great microservices support including popular framework, container tooling and cloud integration
  • Improves your productivity through smartness and collaboration features

This article will give you an overview of different capabilities of Visual Studio Code for Java developers. For a quick walkthrough of editing, running, and debugging a Java program with Visual Studio Code, see the Java Tutorial.

Install Visual Studio Code for Java

VS Code is a fast editor and ships with great editing features. Before you begin, you must have the Java SE Development Kit (JDK) on your local environment. Visual Studio Code works with all major Java versions up to 12.

To help you get started quickly, we created a special Installer of Visual Studio Code for Java developers. The package can be used as a clean install or an update for an existing development environment to add Java or Visual Studio Code. Once downloaded and opened, it automatically detects if you have the fundamental components in your local development environment, including the JDK, Visual Studio Code, and essential Java extensions. During install, it downloads the stable versions of those tools from trusted online sources and installs them on your system.

Download Visual Studio Code Java Pack Installer

Note: The installer is currently only available for Windows. For other OS, please install those components (JDK, VS Code and Java extensions) individually. We're working on the macOS version, please stay tuned.

Alternatively, you can also add Java language support to VS Code by installing the popular Java extensions by yourself.

Download VS Code - If you haven't downloaded VS Code yet, quickly install for your platform (Windows, macOS, Linux).

To help set up Java on VS Code, there is a Java Extension Pack, which contains the most popular extensions for most Java developers:

  1. Language Support for Java(TM) by Red Hat
  2. Debugger for Java
  3. Java Test Runner
  4. Maven for Java
  5. Java Dependency Viewer
  6. Visual Studio IntelliCode

Install the Java Extension Pack

There are also other popular Java extensions you can pick for your own needs, including:

  1. Spring Boot Tools
  2. Spring Initializr Java Support
  3. Spring Boot Dashboard
  4. Tomcat
  5. Jetty
  6. CheckStyle

Thanks to the great Java community around VS Code, the list doesn't end there. You can search for more Java extensions easily within VS Code:

  1. Go to the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
  2. Filter the extensions list by typing "java".

Java Extensions

This document describes some of the key features included in those Java extensions.

Getting started

For developers new to Java or new to VS Code, we provide a Getting Started experience. Once you've installed the Java Extension Pack, you can use the command Java: Getting Started to get the Quick Start guide.

Java Getting Started

Java project support

Maven, Eclipse, and Gradle Java projects are supported through Language Support for Java(TM) by Red Hat, by utilizing M2Eclipse, which provides Maven support, and Buildship, which provides Gradle support through the Eclipse JDT Language Server.

With Maven for Java, you can generate projects from Maven Archetype, browse through all the Maven projects within your workspace, and execute Maven goals easily from an embedded explorer. Projects can also be created and managed with the Java Dependency Viewer extension.

More details about Java project support can be found in Java Project Management in Visual Studio Code.

Visual Studio Code also supports working with standalone Java files outside of a Java project, described in the Java Tutorial with VS Code.

Editing

IntelliSense

IntelliSense is a general term for language features, including intelligent code completion (in-context method and variable suggestions) across all your files and for built-in and third-party modules. VS Code supports code completion and IntelliSense for Java through Language Support for Java(TM) by Red Hat. It also provides AI-assisted IntelliSense called IntelliCode by putting what you're most likely to use at the top of your completion list.

Navigating

Java in Visual Studio Code also supports source code navigation features such as search for symbol, Peek Definition, and Go to Definition. The Spring Boot Tools extension provides enhanced navigation and code completion support for Spring Boot projects.

There are also other editing related features available for Java, such as refactoring and formatting. To learn more, read Editing Java in Visual Studio Code.

Debugging

Debugger for Java is a lightweight Java Debugger based on Java Debug Server. It works with Language Support for Java by Red Hat to allow users to debug Java code within Visual Studio Code.

Starting a debugging session is easy, click on the Run|Debug button available at the CodeLens of your main() function, or press F5. The debugger will automatically generate the proper configuration for you.

Although it's lightweight, the Java debugger supports advanced features such as expression evaluation, conditional breakpoints, and hot code replacement. For more debugging related information, visit Java Debugging.

Testing

With the support from the Java Test Runner extension, you can easily run, debug, and manage your JUnit and TestNG test cases.

For more about testing, read Testing Java.

Spring Boot, Tomcat, and Jetty

To further improve your Java productivity in VS Code, there are extensions for most popular frameworks and tools such as Spring Boot, Tomcat, and Jetty created by the community.

The Tomcat extension includes an explorer to easily navigate and manage your Tomcat servers. You can create, start, debug, stop, and rename your Tomcat server with the extension.

See Tomcat and Jetty Support to learn more about Tomcat and Jetty support with VS Code.

Spring Boot support is provided by Pivotal. There are also Spring Initializr Java Support and Spring Boot Dashboard extensions available from Microsoft to further improve your experience with Spring Boot in Visual Studio Code.

See Spring Boot with VS Code to learn more about Spring Boot support with VS Code.

Next steps

You may Sign up to follow the latest of Java on Visual Studio Code.

Learn more about Java in VS Code

Read on to find out more about Visual Studio Code:

  • Basic Editing - Learn about the powerful VS Code editor.
  • Code Navigation - Move quickly through your source code.
  • Tasks - use tasks to build your project and more
  • Debugging - find out how to use the debugger with your project