{"id":244,"date":"2017-12-02T03:10:00","date_gmt":"2017-12-02T03:10:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2017\/12\/02\/java-progamming-for-beginners-lesson-2-write-your-first-java-program\/"},"modified":"2020-11-05T12:56:08","modified_gmt":"2020-11-05T11:56:08","slug":"java-progamming-for-beginners-lesson-2-write-your-first-java-program","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-2-write-your-first-java-program\/","title":{"rendered":"Java Progamming For Beginners Lesson 2: Write Your First Java Program"},"content":{"rendered":"<div style=\"color: #555555; font-size: 18px; line-height: 30px;\">\n<div style=\"font-family: 'segoe ui';\">This is Lesson 2 of the Java Programming Tutorials for Beginners, and in this Lesson, you would write your first Java Program. This lesson follows from the Lesson 1 which is <a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-1-introduction-to-java-and-intallation-of-netbeans\/\">Introduction to Java and Installation of Netbeans<\/a>. So If you have not taken Lesson 1, please take the lesson before you continue. You can find in the link:<br \/><a href=\"https:\/\/kindsonthegenius.com\/blog\/java-progamming-for-beginners-lesson-1-introduction-to-java-and-intallation-of-netbeans\/\">Java Programming Tutorials for Beginners, Lesson 1: Introduction to Java<\/a><\/p>\n<p>So lets get started!<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-h_wTk1IIN_s\/WiH5yOWj0PI\/AAAAAAAAASM\/b_HsoFrtdw0_hB4wskyUpP3mlT7A77UHQCLcBGAs\/s1600\/Java-Programming-For-Beginners-Lesson-2.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"929\" data-original-width=\"1516\" height=\"196\" src=\"https:\/\/2.bp.blogspot.com\/-h_wTk1IIN_s\/WiH5yOWj0PI\/AAAAAAAAASM\/b_HsoFrtdw0_hB4wskyUpP3mlT7A77UHQCLcBGAs\/s320\/Java-Programming-For-Beginners-Lesson-2.jpg\" width=\"320\" \/><\/a><\/div>\n<p><b>Step 1: <\/b>Open Netbeans (This is actually the last step of Lesson 1)<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-left: auto; margin-right: auto; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-u6ntLx87D0c\/WiFKpfpF_LI\/AAAAAAAAAR0\/NAJE6ijm_8sM7gCFYwbGBJI5rBScVIPFACPcBGAYYCw\/s1600\/Netbeans-IDE-Window.JPG\" style=\"margin-left: auto; margin-right: auto;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"728\" data-original-width=\"1370\" height=\"340\" src=\"https:\/\/1.bp.blogspot.com\/-u6ntLx87D0c\/WiFKpfpF_LI\/AAAAAAAAAR0\/NAJE6ijm_8sM7gCFYwbGBJI5rBScVIPFACPcBGAYYCw\/s640\/Netbeans-IDE-Window.JPG\" width=\"640\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">The Netbeans Window<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Step 2: Click on File and Select &#8220;New Project&#8221;. You would see the window below<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/4.bp.blogspot.com\/-U3r1UNsMm2o\/WiH7AJa1wGI\/AAAAAAAAASY\/nw7glH8H6f4gwsSurm4CPyv9_jxpw9N1ACLcBGAs\/s1600\/New-Java-Project.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"496\" data-original-width=\"729\" height=\"434\" src=\"https:\/\/4.bp.blogspot.com\/-U3r1UNsMm2o\/WiH7AJa1wGI\/AAAAAAAAASY\/nw7glH8H6f4gwsSurm4CPyv9_jxpw9N1ACLcBGAs\/s640\/New-Java-Project.JPG\" width=\"640\" \/><\/a><\/div>\n<p>Under Categories, make sure Java is selected and under Projects: make sure Java Application is selected exactly as is shown.<\/p>\n<p>Step 3:&nbsp; Click on Next. The window below appears<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-Cx9U8HOPYyU\/WiH7zL-2eUI\/AAAAAAAAASg\/WIt7giEY-A4XAmSvzYKRbdMCIiN7lnhMgCLcBGAs\/s1600\/New-Java-Project-Name.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"496\" data-original-width=\"729\" height=\"434\" src=\"https:\/\/1.bp.blogspot.com\/-Cx9U8HOPYyU\/WiH7zL-2eUI\/AAAAAAAAASg\/WIt7giEY-A4XAmSvzYKRbdMCIiN7lnhMgCLcBGAs\/s640\/New-Java-Project-Name.JPG\" width=\"640\" \/><\/a><\/div>\n<p><b>Step 4: <\/b>In the Project Name box, delete what is there and write: MyFirstProgram (don&#8217;t give spaces). Then you can click on Finish<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/3.bp.blogspot.com\/-PTYcHev4Lnk\/WiH8i4KW7mI\/AAAAAAAAASo\/HmbmfnHcmnY_9xiKN9NAn0n2vtU0ze4eQCLcBGAs\/s1600\/New-Java-Project-Name-Finish.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"496\" data-original-width=\"729\" height=\"434\" src=\"https:\/\/3.bp.blogspot.com\/-PTYcHev4Lnk\/WiH8i4KW7mI\/AAAAAAAAASo\/HmbmfnHcmnY_9xiKN9NAn0n2vtU0ze4eQCLcBGAs\/s640\/New-Java-Project-Name-Finish.JPG\" width=\"640\" \/><\/a><\/div>\n<p>If you have done everything correctly, the Java File opens where you can start writing programs. This is shown below.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/4.bp.blogspot.com\/-hQUJ60AA26o\/WiH9tLXWvFI\/AAAAAAAAAS0\/u8iUJxu172kmpAT2qKF_7EfHdzUyl6tRACLcBGAs\/s1600\/Java-Window.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"651\" data-original-width=\"1229\" height=\"338\" src=\"https:\/\/4.bp.blogspot.com\/-hQUJ60AA26o\/WiH9tLXWvFI\/AAAAAAAAAS0\/u8iUJxu172kmpAT2qKF_7EfHdzUyl6tRACLcBGAs\/s640\/Java-Window.JPG\" width=\"640\" \/><\/a><\/div>\n<p><b>Step 5:<\/b> Take some time to observe the parts I labelled 1 &#8211; 6 as you can see in the screen below.<\/p>\n<p><a href=\"https:\/\/3.bp.blogspot.com\/-mvrkgiO7Je8\/WiH_MJ1bf0I\/AAAAAAAAATA\/UWjKmoOtPK02bxaHItERIMrwFb1Wyu43wCLcBGAs\/s1600\/Java-Window2.JPG\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"651\" data-original-width=\"1280\" height=\"323\" src=\"https:\/\/3.bp.blogspot.com\/-mvrkgiO7Je8\/WiH_MJ1bf0I\/AAAAAAAAATA\/UWjKmoOtPK02bxaHItERIMrwFb1Wyu43wCLcBGAs\/s640\/Java-Window2.JPG\" width=\"640\" \/><\/a><br \/>1. <i>MyFirstProgram.java<\/i> &#8211; This is the name of the file that you are currently looking at. Remember that Java file have the extension of .java.&lt;\/div&gt;<\/p>\n<p>2. File Tab &#8211; Where you can see two folders. The Second folder is yours, Netbeans keeps all your file in this folder. Later, we would discuss the content.<\/p>\n<p>3. Navigator Tab &#8211; Shows you the classes and functions in your program(don&#8217;t worry about these, we would discuss them later)<\/p>\n<p>4. This section is where you actually write your program. So we would start writting program under the text that begins with \/\/ TODO&#8230;<\/p>\n<p>5. The name of the package. This is same name as the folder name in the Files tab. The package contains all your files.<\/p>\n<p>6. The name of the Function. Every java program <i>must <\/i>have this Function called main.<\/p>\n<p>Now on to Step 6.<\/p>\n<p><b>Step 6:<\/b> In Section 6 under the part that says \/\/TODO&#8230;.<br \/>Type the following line of code(don&#8217;t copy and paste, type it)<br \/><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;This is my First Program&#8221;);<\/i><br \/>As you are typing, some pop-ups may appear, ignore them and just type exactly as you see here<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/3.bp.blogspot.com\/-ndgqsLOyYKE\/WiID0CHJqmI\/AAAAAAAAATY\/t3IAqQ2qieEWbOsG88d5oqhXedjs8m0CACLcBGAs\/s1600\/java-window-first-prog.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"651\" data-original-width=\"1229\" height=\"338\" src=\"https:\/\/3.bp.blogspot.com\/-ndgqsLOyYKE\/WiID0CHJqmI\/AAAAAAAAATY\/t3IAqQ2qieEWbOsG88d5oqhXedjs8m0CACLcBGAs\/s640\/java-window-first-prog.JPG\" width=\"640\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><b>Step 7:<\/b> Run The Program by clicking on the Run button. The Run Button is highlighted in Red. It it a green play button.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Step 8: <\/b>Wait for a few seconds and if you did everything correctly, the output of your program is shown as given below:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-4uTaCgd5X30\/WiIEm2th-fI\/AAAAAAAAATg\/VPT1ocyNLJsvZheAhCrEZafQAxC1jXYBwCLcBGAs\/s1600\/Run-Java-Program.JPG\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"651\" data-original-width=\"1229\" height=\"337\" src=\"https:\/\/2.bp.blogspot.com\/-4uTaCgd5X30\/WiIEm2th-fI\/AAAAAAAAATg\/VPT1ocyNLJsvZheAhCrEZafQAxC1jXYBwCLcBGAs\/s640\/Run-Java-Program.JPG\" width=\"640\" \/><\/a><\/div>\n<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">If you have come this far, you have successfully completed Lesson 2 of the Java Programming Tutorials for Beginners.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">Congratulations!!If you have some issues, let me know in the comment box below, before I publish lesson 3.<\/div>\n<p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This is Lesson 2 of the Java Programming Tutorials for Beginners, and in this Lesson, you would write your first Java Program. This lesson follows &hellip; <\/p>\n","protected":false},"author":2,"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,414],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/244"}],"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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":1687,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/244\/revisions\/1687"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}