{"id":242,"date":"2017-12-05T02:50:00","date_gmt":"2017-12-05T02:50:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2017\/12\/05\/java-for-beginners-lesson-3-structure-of-a-java-program\/"},"modified":"2020-11-05T12:55:24","modified_gmt":"2020-11-05T11:55:24","slug":"java-for-beginners-lesson-3-structure-of-a-java-program","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/java-for-beginners-lesson-3-structure-of-a-java-program\/","title":{"rendered":"Java For Beginners Lesson 3: Structure of a Java Program"},"content":{"rendered":"<div style=\"color: #555555; font-size: 18px; line-height: 30px;\">\n<div style=\"font-family: 'segoe ui';\">\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-pBkd0Z_a4go\/WiYJDR8m-EI\/AAAAAAAAAVc\/GD8XpjMPRN86uea7BAkuvLj8b5wVTjgeACLcBGAs\/s1600\/Lesson-3-Java-For-Beginners.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-pBkd0Z_a4go\/WiYJDR8m-EI\/AAAAAAAAAVc\/GD8XpjMPRN86uea7BAkuvLj8b5wVTjgeACLcBGAs\/s400\/Lesson-3-Java-For-Beginners.jpg\" width=\"400\" height=\"291\" border=\"0\" data-original-height=\"1104\" data-original-width=\"1516\" \/><\/a><\/div>\n<div style=\"text-align: justify;\">This lesson follows from the <a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-2-write-your-first-java-program\/\" target=\"_blank\" rel=\"noopener noreferrer\">Lesson 2<\/a> of the Java Programming Tutorial for Beginners. So if you have not gone through <a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-1-introduction-to-java-and-intallation-of-netbeans\/\" target=\"_blank\" rel=\"noopener noreferrer\">Lesson 1<\/a> and<a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-2-write-your-first-java-program\/\" target=\"_blank\" rel=\"noopener noreferrer\"> Lesson 2<\/a>, you need to take them before you continue on Lesson 3.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">In <a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-2-write-your-first-java-program\/\">Lesson 2<\/a>, you wrote your first Java program which is <i>MyFirstProgram.java<\/i>. So, let us examine this program more closely to help you get a better knowledge of how a java program is arranged.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-6eTAMJBMwSo\/WiLB339dC3I\/AAAAAAAAATw\/62KeNOi-h5Ub_W3xkw5rr5FhL6x9FkvmACLcBGAs\/s1600\/Structure-of-a-Java-Program.JPG\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-6eTAMJBMwSo\/WiLB339dC3I\/AAAAAAAAATw\/62KeNOi-h5Ub_W3xkw5rr5FhL6x9FkvmACLcBGAs\/s640\/Structure-of-a-Java-Program.JPG\" width=\"640\" height=\"406\" border=\"0\" data-original-height=\"411\" data-original-width=\"645\" \/><\/a><\/div>\n<div style=\"text-align: justify;\">Notice that Netbeans gives different colors to various part of the program. This is called Syntax Coloration.<\/div>\n<div style=\"text-align: justify;\">You also need to know about the word, Compiler. In simple terms, it is an application used to run computer programs. For instance Netbeans.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><b>Comments in Java<\/b><\/div>\n<div style=\"text-align: justify;\">Comments are text added to a program to provide more information about the program. Comments have no effect on the running of the program and are ignored by the compiler(know what a compiler is, right? An application used for running computer programs).<\/div>\n<p>Comments can be single-line or multi-line<br \/>\nSingle line comments begin with \/\/ and only takes one line<br \/>\nMultiline comments begin with \/* and end with *\/ and can span more than one line<br \/>\nCan you identify the comments in the program above?<\/p>\n<p><b>The line: package myfirstprogram<\/b><br \/>\nThis line simply means that a collection of similar programs are placed inside the folder myfirstprogram. You will not have to write this. The system automatically writes it when you create your first program in NetBeans<\/p>\n<div style=\"text-align: justify;\"><b>The line: public class myFirstProgram<\/b><\/div>\n<div style=\"text-align: justify;\">This actually the beginning of the program.<\/div>\n<div style=\"text-align: justify;\">The word public is known as a keyword and for now just know that each program begins this way<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><b>The line: public static void main(&#8230;<\/b><\/div>\n<div style=\"text-align: justify;\">This is the beginning of the function called main. This function main, has to be in all java programs.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">The word Static means that the function main(or any other function or variable after the word static) is shared between all instances of the class.(don&#8217;t worry about this for now, you&#8217;ll get a clearer understanding at a later lesson)<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><b>System.out.println(&#8220;Welcome to Java for Beginners&#8221;);<\/b><\/div>\n<div style=\"text-align: justify;\">This is a function that prints out a text to the output. This is an inbuilt function in java just as there are many others. Inbuilt functions can be used to perform different tasks. With time you will learn about more inbuilt functions.<\/div>\n<p><b>The Semicolon (;)<\/b><br \/>\nAlso note that the line of code we wrote ends in semicolon. All lines of code written in Java is terminated in semicolon.<\/p>\n<p>So we stop here for now because we need to keep it simple and easygoing. Try to do the exercise below.<\/p>\n<p><b>Exercise:<\/b><\/p>\n<ol>\n<li>Remove the semicolon that ends the program and try to run the program again. What is your observation. Write in the comment box below.<\/li>\n<li>Count how many curly braces { in the program. Give your answer in the comment box.<\/li>\n<\/ol>\n<p>Now get ready for Lesson 3: Your Second Java Program<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This lesson follows from the Lesson 2 of the Java Programming Tutorial for Beginners. So if you have not gone through Lesson 1 and Lesson &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[85],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/242"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":4,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":1686,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/242\/revisions\/1686"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}