{"id":228719,"date":"2022-02-10T05:24:01","date_gmt":"2022-02-10T13:24:01","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/java\/?p=228719"},"modified":"2022-02-10T05:24:01","modified_gmt":"2022-02-10T13:24:01","slug":"java-on-visual-studio-code-update-february-2022","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/java\/java-on-visual-studio-code-update-february-2022\/","title":{"rendered":"Java on Visual Studio Code Update \u2013 February 2022"},"content":{"rendered":"<p>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!<\/p>\n<p><span style=\"font-size: 18pt;\"><strong>Easily enabling unit testing in basic Java projects\u00a0<\/strong><\/span><\/p>\n<p>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<strong> (assuming it is a basic project without build tools)<\/strong> does not contain any testing related libraries, you can easily add the JAR and enable unit testing in your project.<\/p>\n<p>To use this feature, simply go to the &#8220;<strong>Testing<\/strong>&#8221; view and select &#8220;<strong>Enable Java Tests<\/strong>&#8221; (shown in the picture below).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enabletest.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228734\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enabletest.png\" alt=\"Enable test button\" width=\"424\" height=\"441\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enabletest.png 424w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enabletest-288x300.png 288w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enabletest-24x24.png 24w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/a><\/p>\n<p>This button will do two things for you:<\/p>\n<ul>\n<li>Download the testing related JARs based on your choice (JUnit, JUnit Jupiter, TestNG)<\/li>\n<li>Add the downloaded JAR to the libraries folder<\/li>\n<\/ul>\n<p>Here is a demo of the feature:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enable-tests.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228723\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enable-tests.gif\" alt=\"Enable Test demo\" width=\"1024\" height=\"768\" \/><\/a><\/p>\n<p>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 <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-java-pack\">Extension Pack for Java<\/a>.<\/p>\n<h3><span style=\"font-size: 18pt;\"><strong>Better support for GUI application development (JavaFX, Swing and AWT)<\/strong><\/span><\/h3>\n<p>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.<\/p>\n<h4><span style=\"font-size: 16pt;\"><strong>JavaFX<\/strong><\/span><\/h4>\n<p>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 <strong>(Ctrl+Shift+P) <\/strong>and run command &#8220;<strong>Java: Create Java Project<\/strong>&#8220;. From the drop-down list, select &#8220;<strong>JavaFX<\/strong>&#8220;. After selecting this item, a JavaFX project based on Maven will be created for you.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228721\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx.png\" alt=\"create javafx\" width=\"1038\" height=\"598\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx.png 1038w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx-300x173.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx-1024x590.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/create-javafx-768x442.png 768w\" sizes=\"(max-width: 1038px) 100vw, 1038px\" \/><\/a><\/p>\n<p>To run the JavaFX application, you can open the <strong>Maven<\/strong> view, expand <code>hellofx<\/code>\u00a0&gt;\u00a0<code>Plugins<\/code>\u00a0&gt;\u00a0<code>javafx<\/code>\u00a0and run the Maven goal:\u00a0<code>javafx:run<\/code>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/run-javafx.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228725\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/run-javafx.gif\" alt=\"Image run javafx\" width=\"1024\" height=\"768\" \/><\/a><\/p>\n<h4><span style=\"font-size: 16pt;\"><strong>More Visual Studio Code sample projects for JavaFX<\/strong><\/span><\/h4>\n<p>We also realize students might be working on JavaFX projects using other build tools (<strong>Gradle<\/strong>) 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 <a href=\"https:\/\/github.com\/openjfx\/samples\/tree\/master\/IDE\/VSCode\">in this sample repository<\/a>.<\/p>\n<h4><span style=\"font-size: 16pt;\"><strong>Abstract Window Toolkit (AWT)<\/strong><\/span><\/h4>\n<p>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 <strong>(<span class=\"dynamic-keybinding keybinding win\" title=\"macOS: \u21e7\u2318P, Linux: Ctrl+Shift+P\" data-commandid=\"workbench.action.showCommands\" data-osx=\"\u21e7\u2318P\" data-win=\"Ctrl+Shift+P\" data-linux=\"Ctrl+Shift+P\">Ctrl+Shift+P<\/span>)<\/strong> and then select the command\u00a0<strong>Java: Help Center<\/strong>. Go to the\u00a0<strong>Student<\/strong>\u00a0section and select\u00a0<strong>Enable AWT Development<\/strong>. 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:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enableawt-1.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228732\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/enableawt-1.gif\" alt=\"Enable AWT\" width=\"1474\" height=\"996\" \/><\/a><\/p>\n<p>After the setting is enabled, code completion will work on AWT applications! You can use <a href=\"https:\/\/code.visualstudio.com\/docs\/java\/java-gui#_develop-awt-applications\">this basic sample code<\/a> to test your AWT on Visual Studio Code.<\/p>\n<h4><span style=\"font-size: 16pt;\"><strong>Swing<\/strong><\/span><\/h4>\n<p>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 <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/examples\/components\/index.html\">official Oracle documentation<\/a>.<\/p>\n<h4><span style=\"font-size: 16pt;\"><strong>Documentation for Java GUI application development on Visual Studio Code<\/strong><\/span><\/h4>\n<p>Apart from these feature updates, we have also added <a href=\"https:\/\/code.visualstudio.com\/docs\/java\/java-gui#_develop-awt-applications\">a dedicated article<\/a> 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.<\/p>\n<p><span style=\"font-size: 18pt;\"><strong><span class=\"x-hidden-focus\">New Gradle project creation workflow<\/span><\/strong><\/span><\/p>\n<p>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 <strong>(<span class=\"dynamic-keybinding keybinding win\" title=\"macOS: \u21e7\u2318P, Linux: Ctrl+Shift+P\" data-commandid=\"workbench.action.showCommands\" data-osx=\"\u21e7\u2318P\" data-win=\"Ctrl+Shift+P\" data-linux=\"Ctrl+Shift+P\">Ctrl+Shift+P<\/span>)<\/strong>, then run the <strong>&#8220;Java: Create Java Project<\/strong>&#8220;, and select &#8220;<strong>Gradle<\/strong>&#8221; from the list. Currently this workflow supports both <strong>Groovy<\/strong> and <strong>Kotlin<\/strong> as your Domain Specific Language (<strong>DSL<\/strong>).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228737\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle.png\" alt=\"Create gradle project\" width=\"1226\" height=\"462\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle.png 1226w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle-300x113.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle-1024x386.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/gradle-768x289.png 768w\" sizes=\"(max-width: 1226px) 100vw, 1226px\" \/><\/a><\/p>\n<p>You can also click the &#8220;Create Java Project&#8221; button to use this feature.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/createjavaproject.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228739\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/createjavaproject.png\" alt=\"Create Java Project\" width=\"509\" height=\"254\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/createjavaproject.png 509w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/02\/createjavaproject-300x150.png 300w\" sizes=\"(max-width: 509px) 100vw, 509px\" \/><\/a><\/p>\n<p>Note that you will need to install the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-gradle\">Gradle for Java extension<\/a> to use this feature. To use all the new features mentioned above, please download the latest version of <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-java-pack\">Extension Pack for Java.<\/a><\/p>\n<p><span style=\"font-size: 18pt;\"><strong><span class=\"x-hidden-focus\">Feedback and suggestions<\/span><\/strong><\/span><\/p>\n<p>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<\/p>\n<ul>\n<li>Leave your comment on this blog post<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/vscode-java-pack\/issues\/new\/choose\" target=\"_blank\" rel=\"noopener\">Open an issue<\/a>\u00a0on our GitHub Issues page<\/li>\n<li>Send an email to: vscjfeedback@microsoft.com<\/li>\n<\/ul>\n<h3 id=\"try-it-out\" class=\"x-hidden-focus\"><span style=\"font-size: 18pt;\"><strong><span class=\"x-hidden-focus\">Resources<\/span><\/strong><\/span><\/h3>\n<p>Here is a list of links that are helpful to learn Java on Visual Studio Code.<\/p>\n<ul>\n<li class=\"x-hidden-focus\">Learn more about\u00a0<a class=\"x-hidden-focus\" href=\"https:\/\/code.visualstudio.com\/docs\/languages\/java\" target=\"_blank\" rel=\"noopener noreferrer\">Java on Visual Studio Code<\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":31999,"featured_media":228741,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,22,1,8,15],"tags":[],"class_list":["post-228719","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud","category-desktop","category-java","category-open-source","category-vscode"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/228719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/users\/31999"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/comments?post=228719"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/228719\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media\/228741"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media?parent=228719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/categories?post=228719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/tags?post=228719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}