Welcome to the February update of Visual Studio Code Java, this month we're bringing you an educational special edition. The beginning of each year is when many schools start, and in order to provide students and teachers with a better Java development experience on Visual Studio Code, we have made a series of improvements in unit testing, GUI project development, and Gralde project creation. Let's take a look at these new features!
Easily enable unit testing in base Java projects
We have received feedback from many students that when developing a simple Java project, they always have to manually add a test framework JAR package (such as JUnit) to the project, and our Java plugin does not provide functionality to help them solve this often repetitive operation. To fix this, we've added a new "Start Unit Tests" feature to the plugin, so that if your project (assuming it's a base project without build tools) doesn't contain any test-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 Testing" (as shown in the image below).
This function will do two things for you:
- Download test-related JAR packages of your choice (JUnit, JUnit Jupiter, TestNG)
- Add the downloaded JAR to the project library folder
Here is a demo of the function:
Once you use this feature, you can start writing unit tests right away! You can get this feature in the latest update of Extension Pack for Java.
Better support for GUI projects (JavaFX, Swing and AWT)
GUI-based Java application development is common in school computer courses. The most commonly used GUI frameworks are JavaFX, Swing, and AWT. In this blog, we will introduce some recent optimizations to these frameworks.
01 JavaFX
Users can now create JavaFX projects directly through the new functionality. To use this new feature, just bring up the Command Palette (Ctrl+Shift+P) and run the command "Java: Create Java Project". From the drop-down list, select JavaFX. When selected, a Maven archetype based JavaFX project will be created for you.
To run a JavaFX application, you can open the Maven view, expand hellofx > Plugins > javafx and run the Maven goal: javafx:run .
We also realize that students may be developing JavaFX projects using other build tools (Gradle) or no build tools, so we provide complete JavaFX examples for all of these different situations. Please find the latest JavaFX samples for Visual Studio Code in this sample repository.
02 Abstract Window Toolkit (AWT)
AWT is another popular framework for Java GUI application development. However, types in AWT are hidden by default for code completion due to some limitations, so you may notice that code completion doesn't prompt for AWT classes when working with AWT applications. To enable code completion for AWT, you can open the Command Palette (Ctrl+Shift+P) and choose the command Java: Help Center . Go to the Student section and select Enable AWT Development . Note that this will update the settings at the workspace level, so make sure the workspace is open in Visual Studio Code. Here is a demo of the function:
Once the setting is enabled, code completion is ready to work in AWT projects! You can use this basic sample code to test your AWT on Visual Studio Code.
03 Swing
By default, the Java plugin package supports Swing application development. You can directly develop any Swing application without additional setup. To find more Swing examples, you can visit the official Oracle documentation.
04 Related documents
In addition to these feature updates, we've added a dedicated Java GUI application development article to the official Visual Studio Code documentation. We hope this article helps students and educators easily get started with GUI development and setup projects.
Simpler Gradle project creation process
In addition to unit testing and GUI applications, we've also seen Gradle become more popular among students and professional developers. Therefore, we have added support for Gradle project creation to the Java project creation workflow. This feature will help you bootstrap a simple Gradle project in a few steps. To use this feature, just bring up the Command Palette (Ctrl+Shift+P), then run "Java: Create Java Project" and select "Gradle" from the list. Currently, this feature supports both Groovy and Kotlin as your DSL. Please note that this new feature requires you to install the Gradle for Java plugin separately (not currently included in the Java plugin package).
You can also call this function directly through the "Create Java Project" button in the Java Project view.
To use all the new features above, download the latest version of the Extension Pack for Java.
Feedback and suggestions
There will be many exciting updates to Java on Visual Studio Code in 2022, and as always, your feedback and suggestions are very important to us and will help shape our future products. There are several ways to leave us feedback
- Fill out the Chinese questionnaire
- comment under this post
- Create an Issue on our GitHub repo
Email vscjfeedback@microsoft.com
Resources
The following links and resources can help you better understand Java on Visual Studio Code
- Learn more about Java on Visual Studio Code
- Step-by-step exploration of Java tutorials on Visual Studio Code
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。