Visual Studio Code + Java Feb 2022 updates
Published Feb 17 2022 12:58 AM 2,179 Views
Microsoft

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).

LeeStott_0-1645086920351.png

 

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:

LeeStott_4-1645087006936.gif

 

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.

LeeStott_1-1645086920385.png


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

run-javafx

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:

 

enableawt-1

 

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).

LeeStott_2-1645086920389.png

 

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

LeeStott_3-1645086920394.png

 

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

  • Leave your comment on this blog post
  • Open an issue on our GitHub Issues page
  • Send an email to: vscjfeedback@microsoft.com

Resources

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

Co-Authors
Version history
Last update:
‎Feb 17 2022 12:57 AM
Updated by: