{"id":815,"date":"2022-08-25T06:00:05","date_gmt":"2023-09-03T17:25:50","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/the-program-in-java-for-displaying-hello-world\/"},"modified":"2024-03-12T15:30:23","modified_gmt":"2024-03-12T15:30:23","slug":"the-program-in-java-for-displaying-hello-world","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/","title":{"rendered":"The program in Java for displaying &#8220;Hello World&#8221;"},"content":{"rendered":"<p>When we begin learning a programming language, our initial task is always to display the phrase &#8220;Hello World&#8221;. In our previous article, we gained knowledge on how to install Java on Windows 10. Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program.<\/p>\n<h2>Program in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Java_(programming_language)\">Java<\/a> that displays the message &#8220;Hello World&#8221;<\/h2>\n<p>For the benefit of beginners, we have provided a basic example of a hello world program that is uncomplicated and functional.<\/p>\n<pre class=\"post-pre\"><code>public class JavaHelloWorldProgram {\r\n\r\n\tpublic static void main(String args[]){\r\n\t\tSystem.out.println(\"Hello World\");\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>Save the program mentioned above as JavaHelloWorldProgram.java in any desired directory.<\/p>\n<h3>Compile and execute the Java Hello World Program.<\/h3>\n<p>Firstly, open the Command Prompt and navigate to the folder where the hello world program file is stored. After that, run the following commands sequentially.<\/p>\n<pre class=\"post-pre\"><code>$javac JavaHelloWorldProgram.java\r\n\r\n$java JavaHelloWorldProgram\r\nHello World\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655ce6b3c40ba52feef2abde\/8-0.png\" alt=\"java hello world program\" \/><\/div>\n<p>If you are running Java 11 or a newer version, you can directly run the command java JavaHelloWorldProgram.java to compile and execute the program without the need to separately compile and run the Java program.<\/p>\n<h3>2. Key aspects of a Java Program<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>In Java, a source file can contain multiple classes, but only one of them can be declared as public. It is important for the name of the Java source file to match the name of the public class. That&#8217;s why our program file is named JavaHelloWorldProgram.java.<\/ol>\n<\/li>\n<\/ol>\n<p>When we compile the code, it is converted into byte code and saved with a .class extension, using the name of the class. If you check the directory where we compiled the Java file, you will find a new file called JavaHelloWorldProgram.class.<\/p>\n<p>When we execute the class file, we only need to provide the public class name, without the entire file name.<\/p>\n<p>To run the program using the java command, the class is loaded into the Java Virtual Machine (JVM) which searches for the main method in the class and executes it. The syntax of the main function must match the specifications in the program, otherwise it will not run and throw an exception with the message &#8220;Exception in thread &#8220;main&#8221; java.lang.NoSuchMethodError: main&#8221;.<\/p>\n<p>I recently made a brief video demonstrating how to create a Java Hello World Program using both Notepad and Eclipse. You can watch the video on YouTube for a clearer understanding: https:\/\/www.youtube.com\/watch?v=ZREpFyjTDho That&#8217;s all for now, and you can now begin experimenting with your first class. In my next post, I will delve deeper into classes, JDK, JVM, and other features offered by the Java programming language. Additionally, don&#8217;t forget to check out this post for a comparison between JDK, JRE, and JVM in Java.<\/p>\n<p>&nbsp;<\/p>\n<p>more tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/tutorial-on-java-server-faces-jsf\/\" target=\"_blank\" rel=\"noopener\">Tutorial on Java Server Faces (JSF)<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/the-java-read-eval-print-loop-commonly-known-as-jshell-is-a-tool-for-interactive-java-programming\/\" target=\"_blank\" rel=\"noopener\">jshell for interactive Java programming<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/the-java-read-eval-print-loop-commonly-known-as-jshell-is-a-tool-for-interactive-java-programming\/\" target=\"_blank\" rel=\"noopener\">jshell for interactive Java programming<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/spring-webflux-refers-to-the-reactive-programming-model-provided-by-the-spring-framework-for-building-web-applications\/\" target=\"_blank\" rel=\"noopener\">Spring WebFlux the Spring Reactive Programming<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/spring-boot-cli\/\" target=\"_blank\" rel=\"noopener\">Spring Boot CLI<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we begin learning a programming language, our initial task is always to display the phrase &#8220;Hello World&#8221;. In our previous article, we gained knowledge on how to install Java on Windows 10. Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program. Program in Java [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-815","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The program in Java for displaying &quot;Hello World&quot; - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The program in Java for displaying &quot;Hello World&quot;\" \/>\n<meta property=\"og:description\" content=\"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-03T17:25:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-12T15:30:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655ce6b3c40ba52feef2abde\/8-0.png\" \/>\n<meta name=\"author\" content=\"Liam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\"},\"author\":{\"name\":\"Liam\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\"},\"headline\":\"The program in Java for displaying &#8220;Hello World&#8221;\",\"datePublished\":\"2023-09-03T17:25:50+00:00\",\"dateModified\":\"2024-03-12T15:30:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\"},\"wordCount\":502,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\",\"name\":\"The program in Java for displaying \\\"Hello World\\\" - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-09-03T17:25:50+00:00\",\"dateModified\":\"2024-03-12T15:30:23+00:00\",\"description\":\"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The program in Java for displaying &#8220;Hello World&#8221;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\",\"name\":\"Liam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"caption\":\"Liam\"},\"sameAs\":[\"http:\/\/Wilson\"],\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"The program in Java for displaying \"Hello World\" - Blog - Silicon Cloud","description":"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/","og_locale":"en_US","og_type":"article","og_title":"The program in Java for displaying \"Hello World\"","og_description":"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program","og_url":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-09-03T17:25:50+00:00","article_modified_time":"2024-03-12T15:30:23+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655ce6b3c40ba52feef2abde\/8-0.png"}],"author":"Liam","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Liam","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/"},"author":{"name":"Liam","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671"},"headline":"The program in Java for displaying &#8220;Hello World&#8221;","datePublished":"2023-09-03T17:25:50+00:00","dateModified":"2024-03-12T15:30:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/"},"wordCount":502,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/","url":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/","name":"The program in Java for displaying \"Hello World\" - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-09-03T17:25:50+00:00","dateModified":"2024-03-12T15:30:23+00:00","description":"Consequently, we are now prepared to compose and execute our primary Java program, which is the Hello World program","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/the-program-in-java-for-displaying-hello-world\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"The program in Java for displaying &#8220;Hello World&#8221;"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671","name":"Liam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","caption":"Liam"},"sameAs":["http:\/\/Wilson"],"url":"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=815"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}