Java on Visual Studio Code April Update
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
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.
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()
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
trueto generate shorter code which calls
- You can also set
java.codeGeneration.hashCodeEquals.useInstanceofto check the object type instead of calling
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 + .
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.
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 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
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.
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.
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
- Java Extension Pack includes essential Java tools including Language Support for Java™ by Red Hat, Debugger for Java, Maven, Java Test Runner and IntelliCode Extension for Visual Studio Code.
- There’re also other Java related extensions you can choose from, including
- Tomcat and Jetty for quickly deploy and manage local app servers.
- In case you’re working on Spring Boot, there’re also great support provided by Pivotal and Microsoft available on Visual Studio Code including Spring Boot Tools, Spring Initializr and Spring Boot Dashboard.
- Java Dependencies provides you a package view of your Java project and helps you managing your dependencies.
- Checkstyle could be handy when you need coherence code style especially cross multiple team members.
- Learn more about Java on Visual Studio Code.
- Explore our step by step Java Tutorials on Visual Studio Code.