{"id":66,"date":"2024-04-13T12:39:49","date_gmt":"2024-04-13T12:39:49","guid":{"rendered":"https:\/\/tuhintech.com\/tutorials\/?p=66"},"modified":"2024-04-13T12:39:49","modified_gmt":"2024-04-13T12:39:49","slug":"java-get-started","status":"publish","type":"post","link":"https:\/\/tuhintech.com\/tutorials\/java\/java-get-started\/","title":{"rendered":"Java Get Started"},"content":{"rendered":"<section class=\"kc-elm kc-css-987789 kc_row\"><div class=\"kc-row-container  kc-container\"><div class=\"kc-wrap-columns\"><div class=\"kc-elm kc-css-406315 kc_col-sm-3 kc_column kc_col-sm-3\"><div class=\"kc-col-container\"><div class=\"widget widget_nav_menu kc-elm kc-css-977080\"><h2 class=\"widgettitle\">Java Tutorials<\/h2><nav class=\"menu-java-menu-container\" aria-label=\"Java Tutorials\"><ul id=\"menu-java-menu\" class=\"menu\"><li id=\"menu-item-72\" class=\"menu-item menu-item-type-post_type menu-item-object-post menu-item-72\"><a href=\"https:\/\/tuhintech.com\/tutorials\/java\/java-home\/\" class=\"menu-link\">Java Home<\/a><\/li>\n<li id=\"menu-item-71\" class=\"menu-item menu-item-type-post_type menu-item-object-post menu-item-71\"><a href=\"https:\/\/tuhintech.com\/tutorials\/java\/java-intro\/\" class=\"menu-link\">Java Intro<\/a><\/li>\n<li id=\"menu-item-70\" class=\"menu-item menu-item-type-post_type menu-item-object-post menu-item-70\"><a href=\"https:\/\/tuhintech.com\/tutorials\/java\/java-get-started\/\" class=\"menu-link\">Java Get Started<\/a><\/li>\n<li id=\"menu-item-81\" class=\"menu-item menu-item-type-post_type menu-item-object-post menu-item-81\"><a href=\"https:\/\/tuhintech.com\/tutorials\/java\/java-get-started-2\/\" class=\"menu-link\">Java Syntax<\/a><\/li>\n<\/ul><\/nav><\/div><\/div><\/div><div class=\"kc-elm kc-css-198039 kc_col-sm-9 kc_column kc_col-sm-9\"><div class=\"kc-col-container\"><div class=\"kc-elm kc-css-575609 kc_text_block\"><\/p>\n<h1>Java\u00a0<span class=\"color_h1\">Getting Started<\/span><\/h1>\n<div class=\"w3-clear nextprev\"><a class=\"w3-left w3-btn\" href=\"https:\/\/www.w3schools.com\/java\/java_intro.asp\">\u276e Previous<\/a><a class=\"w3-right w3-btn\" href=\"https:\/\/www.w3schools.com\/java\/java_syntax.asp\">Next \u276f<\/a><\/div>\n<hr \/>\n<h2>Java Install<\/h2>\n<p>Some PCs might have Java already installed.<\/p>\n<p>To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):<\/p>\n<div class=\"w3-example\">\n<div class=\"w3-code notranslate w3-black\">C:\\Users\\<em>Your Name<\/em>&gt;java -version<\/div>\n<\/div>\n<p>If Java is installed, you will see something like this (depending on version):<\/p>\n<div class=\"w3-example w3-padding-16\">\n<div class=\"notranslate w3-black w3-padding\"><code>java version \"11.0.1\" 2018-10-16 LTS<br \/>Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)<br \/>Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)<\/code><\/div>\n<\/div>\n<p>If you do not have Java installed on your computer, you can download it for free at\u00a0<a href=\"https:\/\/www.oracle.com\/technetwork\/java\/javase\/overview\/index.html\" target=\"_blank\" rel=\"noopener\">oracle.com<\/a>.<\/p>\n<p><strong>Note:<\/strong>\u00a0In this tutorial, we will write Java code in a text editor. However, it is possible to write Java in an Integrated Development Environment, such as IntelliJ IDEA, Netbeans or Eclipse, which are particularly useful when managing larger collections of Java files.<\/p>\n<hr \/>\n<h2>Setup for Windows<\/h2>\n<p>To install Java on Windows:<\/p>\n<ol>\n<li>Go to &#8220;System Properties\" (Can be found on Control Panel &gt; System and Security &gt; System &gt; Advanced System Settings)<\/li>\n<li>Click on the &#8220;Environment variables\" button under the &#8220;Advanced\" tab<\/li>\n<li>Then, select the &#8220;Path\" variable in System variables and click on the &#8220;Edit\" button<\/li>\n<li>Click on the &#8220;New\" button and add the path where Java is installed, followed by\u00a0<strong>\\bin<\/strong>. By default, Java is installed in C:\\Program Files\\Java\\jdk-11.0.1 (If nothing else was specified when you installed it). In that case, You will have to add a new path with:\u00a0<strong>C:\\Program Files\\Java\\jdk-11.0.1\\bin<\/strong><br \/>Then, click &#8220;OK\", and save the settings<\/li>\n<li>At last, open Command Prompt (cmd.exe) and type\u00a0<strong>java -version<\/strong>\u00a0to see if Java is running on your machine<\/li>\n<\/ol>\n<h1><button class=\"w3-btn w3-block w3-left-align xx w3-border-bottom\">Show how to install Java step-by-step with images \u00bb<\/button><button class=\"w3-btn w3-block w3-left-align xx w3-border-bottom\">Step 2 \u00bb<\/button><button class=\"w3-btn w3-block w3-left-align xx w3-border-bottom\">Step 3 \u00bb<\/button><button class=\"w3-btn w3-block w3-left-align xx w3-border-bottom\">Step 4 \u00bb<\/button><button class=\"w3-btn w3-block w3-left-align xx w3-border-bottom\">Step 5 \u00bb<\/button><\/h1>\n<hr \/>\n<hr \/>\n<h2>Java Quickstart<\/h2>\n<p>In Java, every application begins with a class name, and that class must match the filename.<\/p>\n<p>Let&#8217;s create our first Java file, called Main.java, which can be done in any text editor (like Notepad).<\/p>\n<p>The file should contain a &#8220;Hello World\" message, which is written with the following code:<\/p>\n<div class=\"w3-example\">\n<p>Main.java<\/p>\n<pre class=\"w3-white language-java\" tabindex=\"0\"><code class=\"language-java\"><span class=\"token keyword keyword-public\">public<\/span> <span class=\"token keyword keyword-class\">class<\/span> <span class=\"token class-name\">Main<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token keyword keyword-public\">public<\/span> <span class=\"token keyword keyword-static\">static<\/span> <span class=\"token keyword keyword-void\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"Hello World\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token punctuation\">}<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><a class=\"w3-btn\" href=\"https:\/\/www.w3schools.com\/java\/tryjava.asp?filename=demo_helloworld\" target=\"_blank\" rel=\"noopener\">Try it Yourself \u00bb<\/a><\/p>\n<\/div>\n<p>Don&#8217;t worry if you don&#8217;t understand the code above &#8211; we will discuss it in detail in later chapters. For now, focus on\u00a0<strong>how<\/strong>\u00a0to run the code above.<\/p>\n<p>Save the code in Notepad as &#8220;Main.java\". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type &#8220;javac Main.java\":<\/p>\n<div class=\"w3-example\">\n<div class=\"w3-code notranslate w3-black\">C:\\Users\\<em>Your Name<\/em>&gt;javac Main.java<\/div>\n<\/div>\n<p>This will compile your code. If there are no errors in the code, the command prompt will take you to the next line. Now, type &#8220;java Main\" to run the file:<\/p>\n<div class=\"w3-example\">\n<div class=\"w3-code notranslate w3-black\">C:\\Users\\<em>Your Name<\/em>&gt;java Main<\/div>\n<\/div>\n<p>The output should read:<\/p>\n<div class=\"w3-example w3-padding-16\">\n<div class=\"notranslate w3-black w3-padding\"><code class=\"notranslate\">Hello World<\/code><\/div>\n<p><a class=\"w3-btn w3-margin-top\" href=\"https:\/\/www.w3schools.com\/java\/tryjava.asp?filename=demo_helloworld\" target=\"_blank\" rel=\"noopener\">Try it Yourself \u00bb<\/a><\/div>\n<p><strong>Congratulations!<\/strong>\u00a0You have written and executed your first Java program.<\/p>\n<p>\n<\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"site-sidebar-layout":"no-sidebar","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"boxed","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-java"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/posts\/66"}],"collection":[{"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":1,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/posts\/66\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tuhintech.com\/tutorials\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}