Java on Visual Studio Code April Update

Xiaokai He

Xiaokai

Welcome to April update! Java 12 is now officially supported with Visual Studio Code. We’d also like to show you some new and helpful code actions now available, along with new features from Debugger, Maven and CheckStyle.

Try these new features by installing Java Extension Pack with Visual Studio Code. See below for more details!

Java 12 Support

Java is now updating with a faster pace and we’re following closely. Thanks to the upstream update from JDT, you can build your project with Java 12 features now with VS Code as well. To use the experimental language features such as the new switch statement, add the following settings to pom.xml:

Easier Getting Started

Although Java has been there for a long time, it still attracts new developers, and we’d like to make sure it’s easy enough for anyone to start programming Java with VS Code. One of the improvement we made recently is to provide you more detailed information to fix your environment setting.

What if you don’t yet have JDK installed? No problem. When the Java extension pack is loaded, we will automatically detect whether a JDK is present. If not, we will provide you links to download reliable JDK at your choice.

Better yet, we’re also working on a customized VS Code distribution which will help get you ready with everything needed for Java development with a single installer. To learn more, please sign up at the end of this post to receive latest news and updates for Java on VS Code.

Performance Improvements

We’ve been benchmarking and profiling the performance of VS Code for Java, on all platforms and major scenarios including loading and editing. There were several enhancement to improve performance in recent releases.

  • Improved editing performance when dealing with large amount of source file opened in the editor
  • Optimize start up and load time with better server initilization and lazy downloading Java source

As we try our best improving performance, it would still take some time when importing a big Java project to Visual Studio Code. In this case, it would be helpful to show more progress details and let you know what’s actually happening behind the scene. Instead of just showing the percentage of progress, we now added detailed step information into the status, such as inspecting location, configuring project, updating Maven dependencies, refreshing workspace and build workspace to let you know the wait is meaningful.

More Code Actions

Code actions are key to your productivity, so we keep bringing more of them to Visual Studio Code.

Resolve ambiguous imports

To deal with ambiguous imports, you now have a dropdown list to pick the right one. The code line with the unresolved type is also presented to you to help you decide.

Generate hashCode() and equals()

Now hashCode() & equals() can be generated with default implementations. All the non-static member variables are listed, and you can customize the generated code using the check list.

There are two options for you to customize the generated code:

  • If you use Java 7+, you can set java.codeGeneration.hashCodeEquals.useJava7Objects to true to generate shorter code which calls Objects.hash and Objects.equals.
  • You can also set java.codeGeneration.hashCodeEquals.useInstanceof to check the object type instead of calling Object.getClass().

Generate toString()

Picking which fields to be included in the toString() method and configure its template are all supported with the Generate toString() code action.

Extract to local variable

To create a new variable (correctly typed) from the return value of an expression, the new quick fix extract to local variable provides a quick fix bulb which appears when the cursor stops at the bracket (). The keyboard shortcut is ctrl + .

Override/Implement methods

With this new source action, all the cadidates are presented to you with a checklist. Then you can decide what to override or implement.

Add static import

You can now convert static functions calls to static imports.

Folding Range

Now you can expand or collapse sections of code to make your Java file easy to read. We’ve enabled a couple popular ways for you to specify which code elements should be considered as a region to fold.

Debugger Updates

Debugger is one of the most used extension in the Java extension family, and we’re excited to show you the improvements below

Display Logical Structure of Collections

The debugger is now showing the logical structure of lists and maps, instead of the physical layout of the collections. If you prefer the physical layout view, you can go back by setting java.debug.settings.showLogicalStructure to false.

Hightlight Exceptions in Editor

Exceptions are now highlighted with extra info in the editor window. Before that, you need to hover on the exception to see details. Now the most important info is presented to you right at where it occurs.

Go to Definition by Clicking Stack Trace in Debug Console

When there an exception, you can now click on the stack trace to see the definition of the function calls.

Other notable featutes include

  • Auto-completion in debug console for types without source code
  • Auto shorten the command line when file name or extension is too long.

Maven Updates

And a couple new features for Maven as well.

Debug Maven Plug-in Goal

Now you can easily configure your breakpoint and start debug any Maven goals with just a couple clicks.

Customize maven commands

Now you are able to specify your favorite commands in settings for future execution.

Show Dependency Tree

We also support showing dependencies in a tree view which allows you to inspect all dependencies in your project at a single place and check for potential issues.

One more thing. There’s one more shortcut to add dependencies. When editing a POM file, there is a shortcut command to search and add a dependency. Try Command Palette -> Maven: Add a dependency.

Sign up

If you’d like to follow the latest of Java on VS Code, please provide your email with us using the form below. We will send out updates and tips every couple weeks and invite you to test our unreleased feature and provide feedback early on.

Try it out

Please don’t hesitate to give it a try! Your feedback and suggestions are very important to us and will help shape our product in future. You may take this survey to share your thoughts!

Visual Studio Code is a fast and lightweight code editor with great Java support from many extensions

Xiaokai He
Xiaokai He

Senior Program Manager, Java on Visual Studio Code and Azure

Follow Xiaokai   

3 Comments
Avatar
Tony Henrique 2019-05-06 11:27:42
It is very interesting to see this move to give support to Java on Visual Studio.
Avatar
J. Elias Lugo 2019-05-07 19:56:49
Hi, I'm started to use vscode for my java develompments but when I'm try to run my project I'm get this error message "Build failed, do you want to continue? Source: Debugger for Java (Extension). Can you help me, thanks...