{"id":62,"date":"2026-06-02T07:56:26","date_gmt":"2026-06-02T07:56:26","guid":{"rendered":"https:\/\/gigz.pk\/javaapp\/?post_type=lesson&#038;p=62"},"modified":"2026-06-05T06:00:09","modified_gmt":"2026-06-05T06:00:09","slug":"writing-first-java-program","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javaapp\/?lesson=writing-first-java-program","title":{"rendered":"Writing First Java Program"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Writing your first Java program is an exciting milestone in your programming journey. It helps you understand the basic structure of Java code, how programs execute, and how output is displayed. Learning to create and run a simple Java program builds a strong foundation for advanced Java programming and Android app development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to Java Programming<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java is a powerful and object-oriented programming language used to develop desktop applications, web applications, Android apps, enterprise software, and cloud-based solutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before writing your first Java program, make sure you have installed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Java Development Kit (JDK)<\/li>\n\n\n\n<li>Android Studio or another Java IDE<\/li>\n\n\n\n<li>Properly configured Java environment variables<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Once your setup is complete, you are ready to create your first Java application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Your First Java Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Java program is written inside a class, and execution always starts from the main() method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Java Program Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n\n    public static void main(String&#91;] args) {\n\n        System.out.println(\"Hello World\");\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello World<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This simple program displays the text &#8220;Hello World&#8221; on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Java Program Structure<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Class Declaration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every Java application contains at least one class.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>public<\/code> is an access modifier<\/li>\n\n\n\n<li><code>class<\/code> is a Java keyword<\/li>\n\n\n\n<li><code>Main<\/code> is the class name<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The file name must match the class name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Main.java<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Main Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The main method is the entry point of every Java application.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String&#91;] args)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Java starts program execution from this method.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Components of the Main Method<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>public<\/code> allows access from anywhere<\/li>\n\n\n\n<li><code>static<\/code> enables execution without creating an object<\/li>\n\n\n\n<li><code>void<\/code> indicates no return value<\/li>\n\n\n\n<li><code>main<\/code> is the method name<\/li>\n\n\n\n<li><code>String[] args<\/code> stores command-line arguments<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Output Statement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java uses <code>System.out.println()<\/code> to display information on the screen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.println(\"Welcome to Java\");<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This statement prints the specified text and moves the cursor to the next line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Run Your First Java Program<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create a Java File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file named:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Main.java<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Write the Java Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the Java program into the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Save the File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file with the <code>.java<\/code> extension.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Compile the Program<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open Command Prompt or Terminal and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>javac Main.java<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command converts the source code into Java bytecode.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Execute the Program<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the compiled program using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output will appear on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Important Rules in Java Programming<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">File Name Must Match Class Name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the class name is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file name must be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Main.java<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Java is Case Sensitive<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java treats uppercase and lowercase letters differently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Correct:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Incorrect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>main<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Statements End with Semicolons<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Most Java statements must end with a semicolon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int age = 20;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Missing semicolons can cause compilation errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use Curly Braces Correctly<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Curly braces define code blocks for classes and methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n   \/\/ code block\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Why Writing Your First Java Program is Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating your first Java application helps you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand Java syntax<\/li>\n\n\n\n<li>Learn program structure<\/li>\n\n\n\n<li>Practice compiling and executing code<\/li>\n\n\n\n<li>Gain confidence in programming<\/li>\n\n\n\n<li>Build a foundation for advanced concepts<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">It is the first step toward becoming a Java developer or Android app developer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Beginner Mistakes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many beginners encounter simple errors when writing their first Java program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common mistakes include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Missing semicolons<\/li>\n\n\n\n<li>Incorrect class names<\/li>\n\n\n\n<li>Wrong file extensions<\/li>\n\n\n\n<li>Typing mistakes<\/li>\n\n\n\n<li>Missing curly braces<\/li>\n\n\n\n<li>Incorrect capitalization<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Carefully reviewing your code helps prevent these issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Importance of Java Programming<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java is used in many industries and technologies, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Android App Development<\/li>\n\n\n\n<li>Web Development<\/li>\n\n\n\n<li>Enterprise Software<\/li>\n\n\n\n<li>Banking Systems<\/li>\n\n\n\n<li>E-commerce Applications<\/li>\n\n\n\n<li>Cloud Computing<\/li>\n\n\n\n<li>Educational Platforms<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Learning Java opens opportunities to build professional software solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of Learning Java<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java offers many advantages for beginners and professionals:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy to learn<\/li>\n\n\n\n<li>Platform independent<\/li>\n\n\n\n<li>High industry demand<\/li>\n\n\n\n<li>Strong developer community<\/li>\n\n\n\n<li>Excellent career opportunities<\/li>\n\n\n\n<li>Powerful Android development support<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These benefits make Java one of the most valuable programming languages to learn.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Writing your first Java program is the foundation of your programming journey. By understanding classes, methods, syntax, and program execution, you develop the skills needed to build more advanced applications. Consistent practice with simple Java programs will strengthen your coding abilities and prepare you for Android development, software engineering, and other exciting career opportunities in technology.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javaapp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Java Fundamentals (Beginner Level) > Introduction to Java > Writing First Java Program<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><\/div>\n","protected":false},"menu_order":5,"template":"","class_list":["post-62","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Writing First Java Program - Learn Java used for Apps with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Writing First Java Program - Learn Java used for Apps with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Java used for Apps with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-05T06:00:09+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javaapp\\\/?lesson=writing-first-java-program\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Writing First Java Program - Learn Java used for Apps with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javaapp\\\/#website\"},\"datePublished\":\"2026-06-02T07:56:26+00:00\",\"dateModified\":\"2026-06-05T06:00:09+00:00\",\"description\":\"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javaapp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Fundamentals (Beginner Level) > Introduction to Java > Writing First Java Program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javaapp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javaapp\\\/\",\"name\":\"Learn Java used for Apps with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javaapp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Writing First Java Program - Learn Java used for Apps with GiGz.PK","description":"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.","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:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Writing First Java Program - Learn Java used for Apps with GiGz.PK","og_description":"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn Java used for Apps with GiGz.PK","article_modified_time":"2026-06-05T06:00:09+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javaapp\/?lesson=writing-first-java-program","url":"https:\/\/gigz.pk\/","name":"Writing First Java Program - Learn Java used for Apps with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javaapp\/#website"},"datePublished":"2026-06-02T07:56:26+00:00","dateModified":"2026-06-05T06:00:09+00:00","description":"Learn how to write your first Java program with simple steps, code structure explained, and tips to avoid common beginner mistakes.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javaapp"},{"@type":"ListItem","position":2,"name":"Java Fundamentals (Beginner Level) > Introduction to Java > Writing First Java Program"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javaapp\/#website","url":"https:\/\/gigz.pk\/javaapp\/","name":"Learn Java used for Apps with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javaapp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javaapp\/index.php?rest_route=\/wp\/v2\/lesson\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javaapp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javaapp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javaapp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}