{"id":228610,"date":"2021-12-15T18:45:09","date_gmt":"2021-12-16T02:45:09","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/java\/?p=228610"},"modified":"2021-12-15T18:46:52","modified_gmt":"2021-12-16T02:46:52","slug":"java-on-visual-studio-code-update-november-2021","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/java\/java-on-visual-studio-code-update-november-2021\/","title":{"rendered":"Java on Visual Studio Code Update \u2013 November 2021"},"content":{"rendered":"<p>Hi everyone, welcome to the November edition of the Visual Studio Code Java update! In this end-of-year post, we are going to look at several new improvements related to fundamental Java development experience as well as our updates related to encoding issues.<\/p>\n<p>Inner-loop dev experience directly impacts developer&#8217;s day-to-day productivity and this area will always be our top focus. In November, we have made several improvements in this area:<\/p>\n<p><span style=\"font-size: 16pt;\"><strong>Project Management &#8211; Remove .project metadata files<\/strong><\/span><\/p>\n<p>If you are doing Java development using the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vscjava.vscode-java-pack\">Extension Pack for Java<\/a>, we have good news for you &#8211; Visual Studio Code no longer generates those hidden &#8220;.project&#8221; metadata files in the project path when you import a new Java project! This is <a href=\"https:\/\/github.com\/redhat-developer\/vscode-java\/issues\/618\">an issue<\/a> that has been there for over three years, and our fix was delivered in November. If you are interested in finding out how we solved it, please visit <a href=\"https:\/\/devblogs.microsoft.com\/java\/say-goodbye-to-project-files-in-1-1-0\/\">this dedicated blog post<\/a>.<\/p>\n<p><strong><span style=\"font-size: 16pt;\">Testing &#8211; Navigating between tests and corresponding test subjects<\/span>\n<\/strong><\/p>\n<p>In the November release, we added a new feature that allows the developer to navigate between test and corresponding test subjects. This feature may come in handy when writing unit test cases<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/test-navigation.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228613\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/test-navigation.gif\" alt=\"Testing Navigation\" width=\"1024\" height=\"768\" \/><\/a><\/p>\n<p><span style=\"font-size: 16pt;\"><strong>Code Actions &#8211; Generate constructors and override\/implement methods<\/strong><\/span><\/p>\n<p>As mentioned in <a href=\"https:\/\/devblogs.microsoft.com\/java\/java-on-visual-studio-code-update-october-2021\/\">previous blog post<\/a>, we are constantly making common code actions more visible and easier to use. In the latest release, developers can now use the &#8220;lightbulb icon&#8221; next to the Java class to conveniently generate constructors or override\/implement methods! Here is a quick demo on how to do this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/codeactions.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228614\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/codeactions.gif\" alt=\"Code Actions\" width=\"1024\" height=\"768\" \/><\/a><\/p>\n<p><span style=\"font-size: 16pt;\"><strong>Dealing with encoding issues<\/strong><\/span><\/p>\n<p>It is quite common that developer nowadays deal with various languages and run into some kind of encoding issues. We&#8217;ve been hearing this kind of feedback from our users, so we wanted to share our latest finding and suggestions in this blog post.<\/p>\n<p><strong><span style=\"font-size: 14pt;\">Background<\/span><\/strong><\/p>\n<p>Computers can only understand the binary data such as 0 and 1, and it uses charset to encode\/decode the data into real-world characters. When two processes interact with each other for I\/O, they have to use the compatible charset for encoding and decoding, otherwise garbled characters might appear. MacOS and Linux use UTF-8 everywhere so encoding is not a problem for them. For Windows, however, the default charset is not UTF-8 and is platform-dependent, which can lead to inconsistent encoding between different tools.<\/p>\n<p><strong><span style=\"font-size: 14pt;\">Common Problems<\/span><\/strong><\/p>\n<p dir=\"auto\">Below are the typical encoding problems when running a Java program on Windows terminal.<\/p>\n<ul>\n<li dir=\"auto\">The file or directory name contains Unicode characters, Java launcher cannot find the corresponding classpath or main class well.<\/li>\n<\/ul>\n<pre class=\"prettyprint\">\u4e2d\u6587\u76ee\u5f55\r\n\u251c\u2500\u2500 Hello.class\r\n\u2514\u2500\u2500 Hello.java<\/pre>\n<pre class=\"prettyprint\">C:\\Test&gt;java -cp \u4e2d\u6587\u76ee\u5f55 Hello\r\nError: Could not find or load main class Hello<\/pre>\n<ul>\n<li>The string literals with Unicode characters appear garbled when printed to the terminal.<\/li>\n<\/ul>\n<pre class=\"prettyprint\">Exercises\r\n\u251c\u2500\u2500 \u7ec3\u4e60.class\r\n\u2514\u2500\u2500 \u7ec3\u4e60.java<\/pre>\n<pre class=\"prettyprint\">C:\\Test&gt;java -cp .\/Exercises \u7ec3\u4e60\r\nError: Could not find or load main class ??\r\nCaused by: java.lang.ClassNotFoundException: ??<\/pre>\n<ul>\n<li>Garbled characters when Java program interacts with terminal for I\/O<\/li>\n<\/ul>\n<pre class=\"prettyprint\">public class Hello {\r\n    public static void main(String[] args) {\r\n        System.out.println(\"\u4f60\u597d\uff01\");\r\n    }\r\n}<\/pre>\n<pre class=\"prettyprint\">C:\\Test&gt;chcp\r\n65001\r\nC:\\Test&gt;java -cp .\/Exercises Hello\r\n??!\r\nC:\\Test&gt;java -Dfile.encoding=UTF-8 -cp .\/Exercises Hello\r\n\u4f60\u597d\uff01<\/pre>\n<ul>\n<li>The program needs to read Unicode characters from stdin, and print Unicode characters to stdout.<\/li>\n<\/ul>\n<pre class=\"prettyprint\">import java.util.Scanner;\r\n\r\npublic class Hello {\r\n    public static void main(String[] args) {\r\n        Scanner scanner = new Scanner(System.in);\r\n        System.out.println(scanner.nextLine());\r\n    }\r\n}<\/pre>\n<pre class=\"prettyprint\">C:\\Test&gt;chcp\r\n65001\r\n\r\nC:\\Test&gt;java -Dfile.encoding=UTF-8 -cp .\/Exercises Hello\r\n\u4f60\u597d\r\n\ufffd\ufffd<\/pre>\n<p dir=\"auto\"><strong><span style=\"font-size: 14pt;\">Our investigation and advice to handle these issues<\/span><\/strong><\/p>\n<p dir=\"auto\">Previously, to mitigate the encoding issue, we added some workarounds in Java Debugger side to force to use UTF-8 in our toolchain. For example, adding a launcher.bat to force the terminal&#8217;s code page to be\u00a0<strong>65001<\/strong>, and set the default &#8220;file.encoding&#8221; property to be &#8220;UTF-8&#8221;. But it turns out they don&#8217;t solve the encoding problem systematically, and introduce some additional side effects as well (see\u00a0<a class=\"issue-link js-issue-link\" href=\"https:\/\/github.com\/microsoft\/vscode-java-pack\/issues\/756\" data-error-text=\"Failed to load title\" data-id=\"1007232699\" data-permission-text=\"Title is private\" data-url=\"https:\/\/github.com\/microsoft\/vscode-java-pack\/issues\/756\" data-hovercard-type=\"issue\" data-hovercard-url=\"\/microsoft\/vscode-java-pack\/issues\/756\/hovercard\">#756<\/a>,\u00a0<a class=\"issue-link js-issue-link\" href=\"https:\/\/github.com\/microsoft\/vscode-java-debug\/issues\/622\" data-error-text=\"Failed to load title\" data-id=\"477687268\" data-permission-text=\"Title is private\" data-url=\"https:\/\/github.com\/microsoft\/vscode-java-debug\/issues\/622\" data-hovercard-type=\"issue\" data-hovercard-url=\"\/microsoft\/vscode-java-debug\/issues\/622\/hovercard\">microsoft\/vscode-java-debug#622<\/a>,\u00a0<a class=\"issue-link js-issue-link\" href=\"https:\/\/github.com\/microsoft\/vscode-java-debug\/issues\/646\" data-error-text=\"Failed to load title\" data-id=\"486976312\" data-permission-text=\"Title is private\" data-url=\"https:\/\/github.com\/microsoft\/vscode-java-debug\/issues\/646\" data-hovercard-type=\"issue\" data-hovercard-url=\"\/microsoft\/vscode-java-debug\/issues\/646\/hovercard\">microsoft\/vscode-java-debug#646<\/a>).<\/p>\n<p dir=\"auto\">After more investigation into the issue, we found that the workaround we added seemed unnecessary. The user only needs to set windows system locale to the language they want, then the JVM and terminal will automatically change to an encoding that is compatible with your system locale. This is also suggested by the official Java documentation (<a href=\"https:\/\/www.java.com\/en\/download\/help\/locale.html\" rel=\"nofollow\">https:\/\/www.java.com\/en\/download\/help\/locale.html<\/a>).<\/p>\n<p dir=\"auto\">The following screenshot shows how to change the system locale in Windows. for example, if you want to use a terminal to enter Chinese characters into a Java program, you can set the Windows system locale to Chinese. The default Java charset will be <code>\"GBK\"<\/code>\u00a0and the cmd codepage will be\u00a0<code>\"936\"<\/code>, which will support Chinese characters nicely.<\/p>\n<p dir=\"auto\"><a href=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-228619\" src=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding.png\" alt=\"Encoding Screenshot\" width=\"1736\" height=\"920\" srcset=\"https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding.png 1736w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding-300x159.png 300w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding-1024x543.png 1024w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding-768x407.png 768w, https:\/\/devblogs.microsoft.com\/java\/wp-content\/uploads\/sites\/51\/2021\/12\/encoding-1536x814.png 1536w\" sizes=\"(max-width: 1736px) 100vw, 1736px\" \/><\/a><\/p>\n<p dir=\"auto\">Here&#8217;s the <a href=\"https:\/\/github.com\/microsoft\/vscode-java-debug\/blob\/main\/Troubleshooting_encoding.md\">detailed documentation<\/a> on how to deal with the encoding issues.<\/p>\n<h3 id=\"try-it-out\" class=\"x-hidden-focus\"><strong><span class=\"x-hidden-focus\"><span style=\"font-size: 16pt;\">End of year update<\/span><\/span><\/strong><\/h3>\n<p>We are almost at the end of 2021 and for the past 12 months, we&#8217;ve been working hard to provide better Java development experience on Visual Studio Code. For 2022, there will be lots of exciting things coming for Java support on Visual Studio Code, so please stay tuned for future updates. As always, we are grateful for support from the community and we wish everyone a wonderful Christmas and happy new year!<\/p>\n<h3 id=\"try-it-out\" class=\"x-hidden-focus\"><strong><span class=\"x-hidden-focus\"><span style=\"font-size: 16pt;\">Feedback and suggestions<\/span><\/span><\/strong><\/h3>\n<p>Please don\u2019t hesitate to try our product! Your feedback and suggestions are very important to us and will help shape our product in future. There are several ways to leave 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<\/ul>\n<h3 id=\"try-it-out\" class=\"x-hidden-focus\"><strong><span class=\"x-hidden-focus\"><span style=\"font-size: 16pt;\">Resources<\/span><\/span><\/strong><\/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","protected":false},"excerpt":{"rendered":"<p>Hi everyone, welcome to the November edition of the Visual Studio Code Java update! In this end-of-year post, we are going to look at several new improvements related to fundamental Java development experience as well as our updates related to encoding issues. Inner-loop dev experience directly impacts developer&#8217;s day-to-day productivity and this area will always [&hellip;]<\/p>\n","protected":false},"author":31999,"featured_media":228630,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[22,1,8,15],"tags":[],"class_list":["post-228610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-desktop","category-java","category-open-source","category-vscode"],"acf":[],"blog_post_summary":"<p>Hi everyone, welcome to the November edition of the Visual Studio Code Java update! In this end-of-year post, we are going to look at several new improvements related to fundamental Java development experience as well as our updates related to encoding issues. Inner-loop dev experience directly impacts developer&#8217;s day-to-day productivity and this area will always [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/228610","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=228610"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/posts\/228610\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media\/228630"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/media?parent=228610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/categories?post=228610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/java\/wp-json\/wp\/v2\/tags?post=228610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}