{"id":1077,"date":"2024-02-21T23:29:37","date_gmt":"2024-02-21T14:29:37","guid":{"rendered":"https:\/\/itstudy365.com\/blog\/?page_id=1077"},"modified":"2024-02-22T20:41:00","modified_gmt":"2024-02-22T11:41:00","slug":"visual-studio-code-practice-with-java1","status":"publish","type":"page","link":"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/","title":{"rendered":"Visual Studio Code Practice with Java(1)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"1024\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo-1024x1024.png\" alt=\"\" class=\"wp-image-1078\" style=\"aspect-ratio:1;width:193px;height:auto\" srcset=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo-1024x1024.png 1024w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo-300x300.png 300w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo-150x150.png 150w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo-768x768.png 768w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/VSCode_logo.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >\u76ee\u6b21<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step1Install_VSCode\" title=\"Step1.Install VSCode\">Step1.Install VSCode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step2Install_Java_Development_Kit_JDK\" title=\"Step2.Install Java Development Kit (JDK)\">Step2.Install Java Development Kit (JDK)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step3Install_Visual_Studio_Code_Extensions\" title=\"Step3.Install Visual Studio Code Extensions\">Step3.Install Visual Studio Code Extensions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step4Install_Maven\" title=\"Step4.Install Maven\">Step4.Install Maven<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step5Create_a_Maven_Project\" title=\"Step5.Create a Maven Project\">Step5.Create a Maven Project<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step6Add_JUnit_Dependency_to_pomxml\" title=\"Step6.Add JUnit Dependency to pom.xml\">Step6.Add JUnit Dependency to pom.xml<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step7Install_Dependencies\" title=\"Step7.Install Dependencies\">Step7.Install Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step8Create_JUnit_Test\" title=\"Step8.Create JUnit Test\">Step8.Create JUnit Test<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itstudy365.com\/blog\/visual-studio-code-practice-with-java1\/#Step9Run_JUnit_Tests\" title=\"Step9.Run JUnit Tests\">Step9.Run JUnit Tests<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step1Install_VSCode\"><\/span>Step1.<strong>Install VSCode<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you haven&#8217;t already, download and install Visual Studio Code from the official website.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step2Install_Java_Development_Kit_JDK\"><\/span>Step2.<strong>Install Java Development Kit (JDK)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Make sure you have the Java Development Kit installed on your system. You can download it from the official Oracle website or use OpenJDK. Ensure that you set up the <code>JAVA_HOME<\/code> environment variable to point to your JDK installation directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step3Install_Visual_Studio_Code_Extensions\"><\/span>Step3.<strong>Install Visual Studio Code Extensions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul>\n<li>Open VSCode and go to the Extensions view by clicking on the square icon in the sidebar or by pressing <code>Ctrl+Shift+X<\/code>.<\/li>\n\n\n\n<li>Search for &#8220;Extension Pack for Java&#8221; and install it. This extension pack includes essential tools for Java development in VSCode.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" width=\"526\" height=\"163\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-5.png\" alt=\"\" class=\"wp-image-1087\" style=\"aspect-ratio:3.226993865030675;width:298px;height:auto\" srcset=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-5.png 526w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-5-300x93.png 300w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step4Install_Maven\"><\/span>Step4.<strong>Install Maven<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul>\n<li>Download and install Apache Maven from the official website.<\/li>\n\n\n\n<li>Follow the installation instructions for your operating system.<\/li>\n\n\n\n<li>Open a terminal or command prompt.<\/li>\n\n\n\n<li>Type <code>mvn -v<\/code> and press Enter.<\/li>\n\n\n\n<li>You should see the Maven version and other information if it&#8217;s installed correctly.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"451\" height=\"81\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-7.png\" alt=\"\" class=\"wp-image-1089\" srcset=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-7.png 451w, https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-7-300x54.png 300w\" sizes=\"(max-width: 451px) 100vw, 451px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step5Create_a_Maven_Project\"><\/span>Step5.<strong>Create a Maven Project<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul>\n<li>Open VSCode and create a new folder for your Maven project.<\/li>\n\n\n\n<li>Open a terminal in VSCode by clicking on <code>Terminal<\/code> > <code>New Termina<\/code>l.<\/li>\n\n\n\n<li>In the terminal, navigate to your project folder.<\/li>\n\n\n\n<li>Run the command:<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>mvn archetype:generate -DgroupId=com.example -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false<\/code><\/pre><\/div>\n\n\n\n<ul>\n<li>This command generates a basic Maven project structure with a sample Java class and a <code>pom.xml<\/code> file.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"137\" height=\"41\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-9.png\" alt=\"\" class=\"wp-image-1091\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step6Add_JUnit_Dependency_to_pomxml\"><\/span>Step6.<strong>Add JUnit Dependency to pom.xml<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Add the JUnit dependency inside the <code>&lt;dependencies><\/code> section:<\/p>\n\n\n\n<p>(version 3.8.1 may be installed already)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;junit&lt;\/groupId&gt;\n    &lt;artifactId&gt;junit&lt;\/artifactId&gt;\n    &lt;version&gt;4.12&lt;\/version&gt; &lt;!-- or any other version --&gt;\n    &lt;scope&gt;test&lt;\/scope&gt;\n&lt;\/dependency&gt;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step7Install_Dependencies\"><\/span>Step7.Install Dependencies<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ mvn install<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step8Create_JUnit_Test\"><\/span>Step8.<strong>Create JUnit Test<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Probably AppTest.java was created already. You can add test here.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"220\" height=\"47\" src=\"https:\/\/itstudy365.com\/blog\/wp-content\/uploads\/2024\/02\/image-10.png\" alt=\"\" class=\"wp-image-1096\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step9Run_JUnit_Tests\"><\/span>Step9.<strong>Run JUnit Tests<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Right click the project and execute test.<\/p>\n\n\n\n<p>Or you can execute &#8220;mvn test&#8221; from console.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ mvn test<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Step1.Install VSCode If you ha&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/1077"}],"collection":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/comments?post=1077"}],"version-history":[{"count":5,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/1077\/revisions"}],"predecessor-version":[{"id":1098,"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/pages\/1077\/revisions\/1098"}],"wp:attachment":[{"href":"https:\/\/itstudy365.com\/blog\/wp-json\/wp\/v2\/media?parent=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}