{"id":230932,"date":"2024-06-03T02:43:18","date_gmt":"2024-06-03T09:43:18","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/java\/?p=230932"},"modified":"2024-06-03T20:05:14","modified_gmt":"2024-06-04T03:05:14","slug":"java-on-visual-studio-code-update-may-2024","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/java\/java-on-visual-studio-code-update-may-2024\/","title":{"rendered":"Java on Visual Studio Code Update &#8211; May 2024"},"content":{"rendered":"<p>Hi everyone, welcome to the May update for Visual Studio Code for Java! In this blog we are going to share an exciting new AI related feature for Java developers on Visual Studio Code. In addition, there will be several important Spring updates, so let&#8217;s get started.<\/p>\n<h3><strong>Rewriting your Java code with Copilot-based suggestions<\/strong><\/h3>\n<p>As our code undergoes updates and iterations, our business logic continues to grow in complexity. Meanwhile, Java versions are constantly evolving. Often, our older code can be replaced with newer, more efficient alternatives, not only improving their performance but also making the code more elegant, concise and secure. Previously, these tasks may have been done manually, but with the power of AI, many tasks can now be handled automatically.<\/p>\n<p>With the <a href=\"https:\/\/blogs.microsoft.com\/blog\/2024\/05\/21\/whats-next-microsoft-build-continues-the-evolution-and-expansion-of-ai-tools-for-developers\/\">release of various AI products<\/a> at the Build conference 2024, we&#8217;re excited to announce an exciting update for Java developers on Visual Studio Code. In the Insider (Pre-release) version of our Extension Pack for Java, we&#8217;ve introduced a new feature: &#8220;<strong>Rewrite with new Java syntax<\/strong>&#8221; with Copilot! This feature integrates seamlessly with GitHub Copilot, so developers will need a GitHub Copilot license to access it.<\/p>\n<p>Here&#8217;s how the feature works, on your Java class, a new CodeLens text will appear above the name of the class: &#8220;<strong>Rewrite with new Java syntax<\/strong>&#8220;. Once the user clicks on this, it will trigger an inspection on the current Java class. Once the inspection is complete, Visual Studio Code will show several improvement suggestions and point users to the location.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/trigger.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-231079\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/trigger.gif\" alt=\"\" width=\"1192\" height=\"974\" \/><\/a><\/p>\n<p>For each suggestion, additional CodeLens will appear and shows what the solution is (and what needs to be improved). The user can directly click on the CodeLens and this will bring up the GitHub Copilot inline chat dialog. The user can then see the code diff, and will be offered the choice of &#8220;Accept or &#8220;Discard&#8221;. If the user accepts the suggestion, then the workflow is over. Let&#8217;s see the first example where the for-loop can be refactored using IntStream.<\/p>\n<p><a style=\"background-color: #f7f7f9; font-size: 1rem; text-align: var(--bs-body-text-align);\" href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/intstream.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-231080\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/intstream.gif\" alt=\"For loop to instream\" width=\"1192\" height=\"938\" \/><\/a><\/p>\n<p>Let&#8217;s look at another example, where our feature suggests that a multiple if and else-if logic can be directly re-written as a switch expression. By clicking on the CodeLens text, the code can be directly re-written as the improved code.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/06\/switchtoif.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-231104\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/06\/switchtoif.gif\" alt=\"Switch to if\" width=\"1344\" height=\"1080\" \/><\/a><\/p>\n<h5>Inspecting part of the class<\/h5>\n<p>Sometimes, we may not want inspect the whole class because the code is too complex. The feature above also supports inspecting the part of the code. We just need select the code we want to inspect, and then click on the lightbulb on the left, select &#8220;Rewrite with Java syntax&#8221;. Here&#8217;s an example:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/06\/partial.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-231103\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/06\/partial.gif\" alt=\"Partial inspection\" width=\"1344\" height=\"1080\" \/><\/a><\/p>\n<p>In this way, developers can inspect the code in a much more flexible way.<\/p>\n<p>This feature aims to leverage AI to offer helpful suggestions and seamless refactoring for Java developers for their code. We hope this can greatly boost developer&#8217;s productivity. If you have any feedback about this feature, please <a href=\"https:\/\/github.com\/microsoft\/vscode-java-pack\/issues\">open an issue<\/a> on our GitHub repo!<\/p>\n<p><span class=\"TextRun SCXW240440128 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW240440128 BCX0\">To use this feature, developer needs to install both Insider (Pre-release) version <\/span><\/span><a class=\"Hyperlink SCXW240440128 BCX0\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-java-pack\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW240440128 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW240440128 BCX0\" data-ccp-charstyle=\"Hyperlink\">Extension Pack for Java<\/span><\/span><\/a><span class=\"TextRun SCXW240440128 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW240440128 BCX0\"> and <\/span><\/span><a class=\"Hyperlink SCXW240440128 BCX0\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=GitHub.copilot\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW240440128 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW240440128 BCX0\" data-ccp-charstyle=\"Hyperlink\">GitHub Copilot<\/span><\/span><\/a><span class=\"TextRun SCXW240440128 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW240440128 BCX0\"> extensions. (with a GitHub Copilot license).<\/span><\/span><\/p>\n<h3><strong>Spring updates<\/strong><\/h3>\n<h4>JPQL syntax highlighting<\/h4>\n<p>The Spring Boot Tools extension now features syntax highlighting for JPQL query strings. The syntax highlighting works for @Query annotations inside of Java source files as well as for named query property files. This makes reading those query strings much easier.\n(screenshot JPQL query syntax highlighting)<\/p>\n<h4><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-230933\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting.png\" alt=\"JPQL Syntax highlighting\" width=\"1948\" height=\"524\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting.png 1948w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting-300x81.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting-1024x275.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting-768x207.png 768w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/jpql-syntax-highlighting-1536x413.png 1536w\" sizes=\"(max-width: 1948px) 100vw, 1948px\" \/><\/a><\/h4>\n<h4>Add Starters directly from within `pom.xml` files<\/h4>\n<p>We added a clickable hint to pom.xml files of Spring Boot projects, directly\u00a0 in their dependency section. This clickable hint directly invokes the support to add additional Spring Boot starter modules. This improves discoverability and usability of this feature and makes it super easy to find and use.\n(screenshot add pom starters)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters.png\"><img decoding=\"async\" class=\"size-full wp-image-230936\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters.png\" alt=\"Image thumbnail hint add starters\" width=\"1398\" height=\"354\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters.png 1398w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters-300x76.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters-1024x259.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/thumbnail_hint-add-starters-768x194.png 768w\" sizes=\"(max-width: 1398px) 100vw, 1398px\" \/><\/a><\/p>\n<h4>Dashboard shows active profiles<\/h4>\n<p>The Spring Boot Dashboard now shows the active profiles of a running Spring Boot application directly side by side with the port the app runs on. This is available in the pre-release version.\n(screenshot active profiles in dashboard)<\/p>\n<h4><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/dashboard-profiles.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-230935\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/dashboard-profiles.gif\" alt=\"Dashboard profiles \" width=\"2144\" height=\"1316\" \/><\/a><\/h4>\n<h4>Automatically convert application properties to YAML and back<\/h4>\n<p>The Spring Boot tools now offer actions to automatically convert `application.properties` files to YAML format and the other way around. This makes the switch to your (newly) preferred format super easy.\n(screenshot property conversion<\/p>\n<h3><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/convert-properties.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-230934\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2024\/05\/convert-properties.gif\" alt=\"Convert properties\" width=\"2140\" height=\"1362\" \/><\/a><\/h3>\n<h4>Performance and footprint improvements<\/h4>\n<p>The indexing infrastructure for Spring projects got improved. Previously, the mechanism was able to index about 6.5k Java source files inside of a single project before running out of memory. The latest versions can now index up to 60k Java source files instead within the same memory constraints. In addition to that the initial as well as ongoing performance of reconciling Java source files for Spring specific validations is now twice as fast as before.<\/p>\n<h3><strong>Testing Coverage<\/strong><\/h3>\n<p>In April, we released the Testing Coverage feature for our Test Runner extension in Stable version on Visual Studio Code. After release, we have received lots of positive feedback. However, we also received questions on how to use the feature. One popular question was around how coverage data can be reset for every execution.<\/p>\n<p>By default, the extension will append the coverage data (we use jacoco as the coverage tool, and\u00a0<a href=\"https:\/\/www.eclemma.org\/jacoco\/trunk\/doc\/agent.html\" target=\"_blank\" rel=\"noopener\">jacoco appends the coverage data by default<\/a>)<\/p>\n<p>If you want to reset the coverage data before every coverage execution, you can set the below setting:<\/p>\n<pre class=\"prettyprint prettyprinted\"><code class=\"hljs language-json\" data-highlighted=\"yes\"><span class=\"hljs-attr\">\"java.test.config\"<\/span><span class=\"hljs-punctuation\">:<\/span> <span class=\"hljs-punctuation\">{<\/span>\r\n     <span class=\"hljs-attr\">\"coverage\"<\/span><span class=\"hljs-punctuation\">:<\/span> <span class=\"hljs-punctuation\">{<\/span>\r\n         <span class=\"hljs-attr\">\"appendResult\"<\/span><span class=\"hljs-punctuation\">:<\/span> <span class=\"hljs-literal\"><span class=\"hljs-keyword\">false<\/span><\/span>\r\n     <span class=\"hljs-punctuation\">}<\/span>\r\n<span class=\"hljs-punctuation\">}<\/span><\/code><\/pre>\n<h3><strong>Install Extension Pack for Java<\/strong><\/h3>\n<p>To use all features mentioned above, please download and install <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-java-pack\">Extension Pack for Java<\/a> on Visual Studio Code.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-229421\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack.png\" alt=\"Extension pack for Java\" width=\"1215\" height=\"238\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack.png 1215w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack-300x59.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack-1024x201.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/09\/javapack-768x150.png 768w\" sizes=\"(max-width: 1215px) 100vw, 1215px\" \/><\/a><\/p>\n<p>If you are a Spring developer working on a Spring Boot application, you can also download the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=Pivotal.vscode-boot-dev-pack\">Spring Boot Extension Pack<\/a> for specialized Spring experience.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-229533\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring.png\" alt=\"Spring boot extension pack\" width=\"1221\" height=\"224\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring.png 1221w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring-300x55.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring-1024x188.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2022\/10\/spring-768x141.png 768w\" sizes=\"(max-width: 1221px) 100vw, 1221px\" \/><\/a><\/p>\n<h3><span style=\"font-size: 18pt;\"><strong><span class=\"x-hidden-focus\">Feedback and suggestions<\/span><\/strong><\/span><\/h3>\n<p>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<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone, welcome to the May update for Visual Studio Code for Java! In this blog we are going to share an exciting new AI related feature for Java developers on Visual Studio Code. In addition, there will be several important Spring updates, so let&#8217;s get started. Rewriting your Java code with Copilot-based suggestions As [&hellip;]<\/p>\n","protected":false},"author":31999,"featured_media":231102,"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-230932","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 May update for Visual Studio Code for Java! In this blog we are going to share an exciting new AI related feature for Java developers on Visual Studio Code. In addition, there will be several important Spring updates, so let&#8217;s get started. Rewriting your Java code with Copilot-based suggestions As [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/230932","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=230932"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/230932\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media\/231102"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media?parent=230932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/categories?post=230932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/tags?post=230932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}