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 which also supports 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 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 language 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.
Download VS Code - If you haven't downloaded VS Code yet, quickly install for your platform (Windows, macOS, Linux).
Install Java extensions
VS Code is a fast editor and ships with great editing features. Add Java language support to VS Code by installing the popular Java extensions. To help set up Java on VS Code, there is a Java Extension Pack, which contains the most popular extensions for most Java developers:
- Language Support for Java(TM) by Red Hat
- Debugger for Java
- Java Test Runner
- Maven for Java
- Java Dependency Viewer
There are also other popular Java extensions you can pick for your own needs, including:
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:
- Go to the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
- Filter the extensions list by typing "java".
This document describes some of the key features included in those Java extensions.
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.
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.
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.
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.
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
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.
Learn more about Java in VS Code
- Java Tutorial with VS Code
- Code Editing and Navigation
- Java Debugging
- Java Testing
- Java Project Management
- Spring Boot with VS Code
- Tomcat and Jetty Support
Read on to find out more about Visual Studio Code: