Friends of OpenJDK Today

Java on Visual Studio Code Update: February 2022

February 22, 2022

Author(s)

  • Avatar photo
    Nick Zhu

    Senior Program Manager at Developer Division in Microsoft. Our team is currently based in Shanghai, China. I have worked on various product areas at Microsoft, such as Bing Ads, Azure ... Learn more

Hi everyone, welcome to the February update of Visual Studio Code Java and this time we have a special edition for education!

Many schools are back in session after the winter holidays, and in order to provide student and educators a better experience using Java on Visual Studio Code this semester, we have been making a series of improvements regarding unit testing, GUI application development and Gradle project creation.

Let us take a look at these new features!

Easily enabling unit testing in basic Java projects

We have received a lot of feedback from students that when working on a simple Java project, they always have to manually add the testing framework JARs (such as JUnit) to the project, and our Java extensions does not offer any functionality to easily help them with this common task.

To address this, we have added a new feature in our extensions so that if your project (assuming it is a basic project without build tools) does not contain any testing related libraries, you can easily add the JAR and enable unit testing in your project.

To use this feature, simply go to the "Testing" view and select "Enable Java Tests" (shown in the picture below).

Enable test button

This button will do two things for you:

  • Download the testing related JARs based on your choice (JUnit, JUnit Jupiter, TestNG)
  • Add the downloaded JAR to the libraries folder

Here is a demo of the feature:

After this step is done, simply create a Java file and start writing unit tests! You can get this feature in the latest update of Extension Pack for Java.

Better support for GUI application development (JavaFX, Swing and AWT)

GUI-based Java applications are quite common in school projects. The most commonly used GUI frameworks are JavaFX, Swing and AWT. In this section, we are going to highlight some optimizations we have made to support these frameworks better.

JavaFX

We have added built-in support to create a JavaFX based project with Maven archetype in our Java extensions. To use this new feature, simply bring up the Command Palette (Ctrl+Shift+P) and run command "Java: Create Java Project". From the drop-down list, select "JavaFX". After selecting this item, a JavaFX project based on Maven will be created for you.

create javafx

To run the JavaFX application, you can open the Maven view, expand hellofx > Plugins > javafx and run the Maven goal: javafx:run.

More Visual Studio Code sample projects for JavaFX

We also realize students might be working on JavaFX projects using other build tools (Gradle) or no build tools at all, therefore we have provided complete JavaFX samples for all those different cases. Please find the latest JavaFX samples for Visual Studio Code in this sample repository.

Abstract Window Toolkit (AWT)

AWT is another framework that is popular among Java GUI application development. However, the types from the Abstract Window Toolkit (AWT) are hidden by default due to some constraints, therefore you may notice that code completion does not prompt AWT classes when you are working on an AWT application.

To enable the code completion for AWT, you can open the Command Palette (Ctrl+Shift+P) and then select the command Java: Help Center. Go to the Student section and select Enable AWT Development. Please note that this action will update a setting at the workspace level, so please make sure a workspace is opened in Visual Studio Code. Here is a demo of this feature:

After the setting is enabled, code completion will work on AWT applications! You can use this basic sample code to test your AWT on Visual Studio Code.

Swing

Swing application development is supported in the Extension Pack for Java by default. You can directly develop any Swing application without additional setup. To find more Swing examples, you can visit the official Oracle documentation.

Documentation for Java GUI application development on Visual Studio Code

Apart from these feature updates, we have also added a dedicated article for Java GUI application development on official Visual Studio Code documentation. We hope this article can help students and educators to easily get started on GUI development and set up the project.

New Gradle project creation workflow

In addition to unit testing and GUI applications, we are also seeing that Gradle is becoming more popular among students as well as professional developers. Therefore, we have added support for Gradle project creation in our Java project creation workflow.

This feature will help you to bootstrap a simple Gradle project with just a few steps. To use this feature, simply bring up the command palette (Ctrl+Shift+P), then run the "Java: Create Java Project", and select "Gradle" from the list. Currently this workflow supports both Groovy and Kotlin as your Domain Specific Language (DSL).

Create gradle project

You can also click the "Create Java Project" button to use this feature.

Create Java Project

Note that you will need to install the Gradle for Java extension to use this feature. To use all the new features mentioned above, please download the latest version of Extension Pack for Java.

Feedback and suggestions

There will be lots of exciting updates for Java on Visual Studio Code in 2022, and as always, your feedback and suggestions are very important to us and will help shape our product in future. There are several ways to give us feedback

Resources

Here is a list of links that are helpful to learn Java on Visual Studio Code.

Related Articles

View All

Author(s)

  • Avatar photo
    Nick Zhu

    Senior Program Manager at Developer Division in Microsoft. Our team is currently based in Shanghai, China. I have worked on various product areas at Microsoft, such as Bing Ads, Azure ... Learn more

Comments (0)

Your email address will not be published. Required fields are marked *

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

Save my name, email, and website in this browser for the next time I comment.

Subscribe to foojay updates:

https://foojay.io/feed/
Copied to the clipboard