Java on Visual Studio Code Update — April 2019
Catch the latest updates on Visual Studio Code, which now supports Java 12!
Join the DZone community and get the full member experience.Join For Free
Welcome to the 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 the 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
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>12</source> <compilerArgs>--enable-preview</compilerArgs> </configuration> </plugin> </plugins> </build>
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.
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 enhancements to improve performance in recent releases.
- Improved editing performance when dealing with a large amount of source file opened in the editor
- Optimize startup and load time with better server initialization 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 the location, configuring the project, updating Maven dependencies, refreshing workspace, and building a 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 a 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 candidates 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 of popular ways for you to specify which code elements should be considered as a region to fold.
Debugger is one of the most used extensions 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 features 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 of new features for Maven as well.
Debug Maven Plug-in Goal
Now, you can easily configure your breakpoint and start to 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.
Command Palette -> Maven: Add a dependency.
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 the 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's 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 manage 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.
Published at DZone with permission of Bruno Borges. See the original article here.
Opinions expressed by DZone contributors are their own.