(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{425:function(e,a,t){e.exports=t.p+"assets/img/getting-started.5caac49f.png"},795:function(e,a,t){"use strict";t.r(a);var o=t(56),r=Object(o.a)({},(function(){var e=this,a=e.$createElement,o=e._self._c||a;return o("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[o("h1",{attrs:{id:"getting-started-with-java-in-vs-code"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#getting-started-with-java-in-vs-code"}},[e._v("#")]),e._v(" Getting Started with Java in VS Code")]),e._v(" "),o("p",[e._v("This tutorial shows you how to write and run Hello World program in Java with Visual Studio Code. It also covers a few advanced features, which you can explore by reading other documents in this section.")]),e._v(" "),o("p",[e._v("For an overview of the features available for Java in VS Code, see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/languages/java",target:"_blank",rel:"noopener noreferrer"}},[e._v("Java Language Overview"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("p",[e._v("If you run into any issues when following this tutorial, you can contact us by entering an "),o("a",{attrs:{href:"https://github.com/microsoft/vscode-java-pack/issues",target:"_blank",rel:"noopener noreferrer"}},[e._v("issue"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("h2",{attrs:{id:"setting-up-vs-code-for-java-development"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#setting-up-vs-code-for-java-development"}},[e._v("#")]),e._v(" Setting up VS Code for Java development")]),e._v(" "),o("h3",{attrs:{id:"coding-pack-for-java"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#coding-pack-for-java"}},[e._v("#")]),e._v(" Coding Pack for Java")]),e._v(" "),o("p",[e._v("To help you set up quickly, you can install the "),o("strong",[e._v("Coding Pack for Java")]),e._v(", which includes VS Code, the Java Development Kit (JDK), and essential Java extensions. The Coding Pack can be used as a clean installation, or to update or repair an existing development environment.")]),e._v(" "),o("p",[o("a",{attrs:{href:"https://aka.ms/vscode-java-installer-win",target:"_blank",rel:"noopener noreferrer"}},[e._v("Install the Coding Pack for Java - Windows"),o("OutboundLink")],1)]),e._v(" "),o("p",[o("a",{attrs:{href:"https://aka.ms/vscode-java-installer-mac",target:"_blank",rel:"noopener noreferrer"}},[e._v("Install the Coding Pack for Java - macOS"),o("OutboundLink")],1)]),e._v(" "),o("blockquote",[o("p",[o("strong",[e._v("Note")]),e._v(": The Coding Pack for Java is only available for Windows and macOS. For other operating systems, you will need to manually install a JDK, VS Code, and Java extensions.")])]),e._v(" "),o("h3",{attrs:{id:"installing-extensions"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#installing-extensions"}},[e._v("#")]),e._v(" Installing extensions")]),e._v(" "),o("p",[e._v("If you are an existing VS Code user, you can also add Java support by installing the "),o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack",target:"_blank",rel:"noopener noreferrer"}},[e._v("Extension Pack for Java"),o("OutboundLink")],1),e._v(", which includes these extensions:")]),e._v(" "),o("ul",[o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=redhat.java",target:"_blank",rel:"noopener noreferrer"}},[e._v("Language Support for Java™ by Red Hat"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug",target:"_blank",rel:"noopener noreferrer"}},[e._v("Debugger for Java"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test",target:"_blank",rel:"noopener noreferrer"}},[e._v("Test Runner for Java"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven",target:"_blank",rel:"noopener noreferrer"}},[e._v("Maven for Java"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency",target:"_blank",rel:"noopener noreferrer"}},[e._v("Project Manager for Java"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode",target:"_blank",rel:"noopener noreferrer"}},[e._v("Visual Studio IntelliCode"),o("OutboundLink")],1)])]),e._v(" "),o("p",[o("a",{attrs:{href:"vscode:extension/vscjava.vscode-java-pack"}},[e._v("Install the Extension Pack for Java")])]),e._v(" "),o("p",[e._v("The "),o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack",target:"_blank",rel:"noopener noreferrer"}},[e._v("Extension Pack for Java"),o("OutboundLink")],1),e._v(" provides a Quick Start guide and tips for code editing and debugging. It also has a FAQ that answers some frequently asked questions. Use the command "),o("strong",[e._v("Java: Tips for Beginners")]),e._v(" from the Command Palette (Ctrl+Shift+P) to launch the guide.")]),e._v(" "),o("p",[o("img",{attrs:{src:t(425),alt:"getting-started"}})]),e._v(" "),o("p",[e._v("You can also install extensions separately. The "),o("strong",[e._v("Extensions Guide")]),e._v(" is provided to help you. You can launch the guide with the "),o("strong",[e._v("Java: Extensions Guide")]),e._v(" command.")]),e._v(" "),o("p",[e._v("For this tutorial, the only required extensions are:")]),e._v(" "),o("ul",[o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=redhat.java",target:"_blank",rel:"noopener noreferrer"}},[e._v("Language Support for Java™ by Red Hat"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug",target:"_blank",rel:"noopener noreferrer"}},[e._v("Debugger for Java"),o("OutboundLink")],1)])]),e._v(" "),o("h2",{attrs:{id:"installing-and-setting-up-a-java-development-kit-jdk"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#installing-and-setting-up-a-java-development-kit-jdk"}},[e._v("#")]),e._v(" Installing and setting up a Java Development Kit (JDK)")]),e._v(" "),o("p",[e._v("To use Java within Visual Studio Code, you need to install a Java Development Kit (JDK) on your local environment. JDK is a software development environment used for developing Java applications.")]),e._v(" "),o("h3",{attrs:{id:"supported-java-versions"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#supported-java-versions"}},[e._v("#")]),e._v(" Supported Java versions")]),e._v(" "),o("p",[e._v("The "),o("a",{attrs:{href:"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack",target:"_blank",rel:"noopener noreferrer"}},[e._v("Extension Pack for Java"),o("OutboundLink")],1),e._v(" supports Java version 1.5 or above.")]),e._v(" "),o("blockquote",[o("p",[o("strong",[e._v("Note")]),e._v(": To configure JDKs for your projects, see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-project#_configure-runtime-for-projects",target:"_blank",rel:"noopener noreferrer"}},[e._v("Configure Runtime for Projects"),o("OutboundLink")],1),e._v(". To enable Java preview features, see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-faq#_how-can-i-use-visual-studio-code-with-new-java-versions",target:"_blank",rel:"noopener noreferrer"}},[e._v("How can I use VS Code with new Java versions"),o("OutboundLink")],1),e._v(".")])]),e._v(" "),o("h3",{attrs:{id:"installing-a-java-development-kit-jdk"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#installing-a-java-development-kit-jdk"}},[e._v("#")]),e._v(" Installing a Java Development Kit (JDK)")]),e._v(" "),o("p",[e._v("If you have never installed a JDK before and need to install one, we recommend you to choose from one of these sources:")]),e._v(" "),o("ul",[o("li",[o("a",{attrs:{href:"https://aws.amazon.com/corretto",target:"_blank",rel:"noopener noreferrer"}},[e._v("Amazon Corretto"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://www.azul.com/downloads/?package=jdk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Azul Zulu"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://adoptium.net/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Eclipse Adoptium's Temurin"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://www.microsoft.com/openjdk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Microsoft Build of OpenJDK"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://www.oracle.com/java/technologies/javase-downloads.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("Oracle Java SE"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://developers.redhat.com/products/openjdk/download",target:"_blank",rel:"noopener noreferrer"}},[e._v("Red Hat build of OpenJDK"),o("OutboundLink")],1)]),e._v(" "),o("li",[o("a",{attrs:{href:"https://sapmachine.io/",target:"_blank",rel:"noopener noreferrer"}},[e._v("SapMachine"),o("OutboundLink")],1)])]),e._v(" "),o("h2",{attrs:{id:"creating-a-source-code-file"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-source-code-file"}},[e._v("#")]),e._v(" Creating a source code file")]),e._v(" "),o("p",[e._v("Create a folder for your Java program and open the folder with VS Code. Then in VS Code, create a new file and save it with the name "),o("code",[e._v("Hello.java")]),e._v(". When you open that file, the Java Language Server automatically starts loading, and you should see a loading icon on the right side of the Status Bar. After it finishes loading, you will see a thumbs-up icon.")]),e._v(" "),o("p",[o("video",{attrs:{src:"https://code.visualstudio.com/docs/java/java-tutorial/JavaHelloWorld.Standalone.mp4"}})]),e._v(" "),o("blockquote",[o("p",[o("strong",[e._v("Note")]),e._v(": If you open a Java file in VS Code without opening its folder, the Java Language Server might not work properly.")])]),e._v(" "),o("p",[e._v("VS Code will also try to figure out the correct package for the new type and fill the new file from a template. See "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-editing#_create-new-file",target:"_blank",rel:"noopener noreferrer"}},[e._v("Create new file"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("p",[e._v("You can also create a Java project using the "),o("strong",[e._v("Java: Create Java Project")]),e._v(" command. Bring up the "),o("strong",[e._v("Command Palette")]),e._v(" (Ctrl+Shift+P) and then type "),o("code",[e._v("java")]),e._v(" to search for this command. After selecting the command, you will be prompted for the location and name of the project. You can also choose your build tool from this command.")]),e._v(" "),o("p",[o("video",{attrs:{src:"https://code.visualstudio.com/docs/java/java-tutorial/JavaHelloWorld.Project.mp4"}})]),e._v(" "),o("p",[e._v("Visual Studio Code also supports more complex Java projects — see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-project",target:"_blank",rel:"noopener noreferrer"}},[e._v("Project Management"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("h2",{attrs:{id:"editing-source-code"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#editing-source-code"}},[e._v("#")]),e._v(" Editing source code")]),e._v(" "),o("p",[e._v("You can use code snippets to scaffold your classes and methods. VS Code also provides IntelliSense for code completion, and various refactor methods.")]),e._v(" "),o("p",[o("video",{attrs:{src:"https://code.visualstudio.com/docs/java/java-tutorial/edit-code.mp4"}})]),e._v(" "),o("p",[e._v("To learn more about editing Java, see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-editing",target:"_blank",rel:"noopener noreferrer"}},[e._v("Java Editing"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("h2",{attrs:{id:"running-and-debugging-your-program"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#running-and-debugging-your-program"}},[e._v("#")]),e._v(" Running and debugging your program")]),e._v(" "),o("p",[e._v("To run and debug Java code, set a breakpoint, then either press F5 on your keyboard or use the "),o("strong",[e._v("Run")]),e._v(" > "),o("strong",[e._v("Start Debugging")]),e._v(" menu item. You can also use the "),o("strong",[e._v("Run|Debug")]),e._v(" CodeLens option in the editor. After the code compiles, you can see all your variables and threads in the Run view.")]),e._v(" "),o("p",[o("video",{attrs:{src:"https://code.visualstudio.com/docs/java/java-tutorial/run-debug.mp4"}})]),e._v(" "),o("p",[e._v("The debugger also supports advanced features such as "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-debugging#_hot-code-replace",target:"_blank",rel:"noopener noreferrer"}},[e._v("Hot Code Replace"),o("OutboundLink")],1),e._v(" and conditional breakpoints.")]),e._v(" "),o("p",[e._v("For more information, see "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-debugging",target:"_blank",rel:"noopener noreferrer"}},[e._v("Java Debugging"),o("OutboundLink")],1),e._v(".")]),e._v(" "),o("h2",{attrs:{id:"more-features"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#more-features"}},[e._v("#")]),e._v(" More features")]),e._v(" "),o("p",[e._v("The editor also has many more capabilities to assist with your Java workload.")]),e._v(" "),o("ul",[o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-editing",target:"_blank",rel:"noopener noreferrer"}},[e._v("Editing Java"),o("OutboundLink")],1),e._v(" explains how to navigate and edit Java in more details")]),e._v(" "),o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-debugging",target:"_blank",rel:"noopener noreferrer"}},[e._v("Debugging"),o("OutboundLink")],1),e._v(" illustrates all the key features of the Java Debugger")]),e._v(" "),o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-testing",target:"_blank",rel:"noopener noreferrer"}},[e._v("Testing"),o("OutboundLink")],1),e._v(" provides comprehensive support for JUnit and TestNG framework")]),e._v(" "),o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-project",target:"_blank",rel:"noopener noreferrer"}},[e._v("Java Project Management"),o("OutboundLink")],1),e._v(" shows you how to use a project view and work with Maven")]),e._v(" "),o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-spring-boot",target:"_blank",rel:"noopener noreferrer"}},[e._v("Spring Boot"),o("OutboundLink")],1),e._v(" and "),o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-tomcat-jetty",target:"_blank",rel:"noopener noreferrer"}},[e._v("Tomcat and Jetty"),o("OutboundLink")],1),e._v(" demonstrate great framework support")]),e._v(" "),o("li",[o("a",{attrs:{href:"https://code.visualstudio.com/docs/java/java-webapp",target:"_blank",rel:"noopener noreferrer"}},[e._v("Java Web Apps"),o("OutboundLink")],1),e._v(" shows how to work with Java Web App in VS Code")])]),e._v(" "),o("p",[e._v("原文链接: https://code.visualstudio.com/docs/java/java-tutorial")])])}),[],!1,null,null,null);a.default=r.exports}}]);