{"appState":{"pageLoadApiCallsStatus":true},"categoryState":{"relatedCategories":{"headers":{"timestamp":"2025-04-17T16:01:07+00:00"},"categoryId":33602,"data":{"title":"Java","slug":"java","image":{"src":null,"width":0,"height":0},"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"parentCategory":{"categoryId":33592,"title":"Programming & Web Design","slug":"programming-web-design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"}},"childCategories":[],"description":"Java powers much of the online world and tons of apps and programs. You can read all about it right here. (Perhaps over a cup of java?)","relatedArticles":{"self":"https://dummies-api.dummies.com/v2/articles?category=33602&offset=0&size=5"},"hasArticle":true,"hasBook":true,"articleCount":122,"bookCount":7},"_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"relatedCategoriesLoadedStatus":"success"},"listState":{"list":{"count":10,"total":122,"items":[{"headers":{"creationTime":"2017-05-03T13:14:52+00:00","modifiedTime":"2024-10-28T17:51:19+00:00","timestamp":"2024-10-28T18:01:09+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"The Atoms: Java’s Primitive Types","strippedTitle":"the atoms: java’s primitive types","slug":"atoms-javas-primitive-types","canonicalUrl":"","seo":{"metaDescription":"The words int and double are examples of primitive types (also known as simple types) in Java. The Java language has exactly eight primitive types. As a newcome","noIndex":0,"noFollow":0},"content":"The words <em>int</em> and <em>double</em> are examples of <em>primitive types</em> (also known as <em>simple</em> types) in Java. The Java language has exactly eight primitive types. As a newcomer to Java, you can pretty much ignore all but four of these types. (As programming languages go, Java is nice and compact that way.)\r\n\r\nThe types that you shouldn’t ignore are <code>int</code>, <code>double</code>, <code>char</code>, and <code>boolean</code>.\r\n<h2 id=\"tab1\" >The char type</h2>\r\nSeveral decades ago, people thought computers existed only for doing big number-crunching calculations. Nowadays, nobody thinks that way. So, if you haven’t been in a cryogenic freezing chamber for the past 20 years, you know that computers store letters, punctuation symbols, and other characters.\r\n\r\nThe Java type that’s used to store characters is called <em>char.</em> The code below has a simple program that uses the <code>char</code> type. This image shows the output of the program in the code below.\r\n\r\n[caption id=\"attachment_239304\" align=\"aligncenter\" width=\"163\"]<a href=\"https://www.dummies.com/wp-content/uploads/java-7e-char-type.jpg\"><img class=\"wp-image-239304 size-full\" src=\"https://www.dummies.com/wp-content/uploads/java-7e-char-type.jpg\" alt=\"java char type\" width=\"163\" height=\"122\" /></a> An exciting run of the program of below as it appears in the Eclipse Console view.[/caption]\r\n\r\n<code>public class CharDemo {</code>\r\n\r\n \r\n\r\n<code>public static void main(String args[]) {</code>\r\n\r\n<code>char myLittleChar = 'b';</code>\r\n\r\n<code>char myBigChar = Character.toUpperCase(myLittleChar);</code>\r\n\r\n<code>System.out.println(myBigChar);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nIn this code, the first initialization stores the letter <em>b</em> in the variable <code>myLittleChar</code>. In the initialization, notice how <em>b</em> is surrounded by single quote marks. In Java, every <code>char</code> literally starts and ends with a single quote mark.\r\n<p class=\"article-tips remember\">In a Java program, single quote marks surround the letter in a <code>char</code> literal.</p>\r\n<em>Character.toUpperCase.</em> The <code>Character.toUpperCase</code> method does just what its name suggests — the method produces the uppercase equivalent of the letter <em>b.</em> This uppercase equivalent (the letter <em>B</em>) is assigned to the <code>myBigChar</code> variable, and the <em>B</em> that’s in <code>myBigChar</code> prints onscreen.\r\n\r\nIf you’re tempted to write the following statement,\r\n\r\n<code>char myLittleChars = &apos;barry&apos;; //Don&apos;t do this</code>\r\n\r\nplease resist the temptation. You can’t store more than one letter at a time in a <code>char</code> variable, and you can’t put more than one letter between a pair of single quotes. If you’re trying to store words or sentences (not just single letters), you need to use something called a String.\r\n<p class=\"article-tips warning\">If you’re used to writing programs in other languages, you may be aware of something called ASCII character encoding. Most languages use ASCII; Java uses Unicode. In the old ASCII representation, each character takes up only 8 bits, but in Unicode, each character takes up 8, 16, or 32 bits. Whereas ASCII stores the letters of the Roman (English) alphabet, Unicode has room for characters from most of the world’s commonly spoken languages.</p>\r\nThe only problem is that some of the Java API methods are geared specially toward 16-bit Unicode. Occasionally, this bites you in the back (or it bytes you in the back, as the case may be). If you’re using a method to write <code>Hello</code> on the screen and <code>H e l l o</code> shows up instead, check the method’s documentation for mention of Unicode characters.\r\n\r\nIt’s worth noticing that the two methods, <code>Character.toUpperCase</code> and <code>System.out.println</code>, are used quite differently in the code above. The method <code>Character.toUpperCase</code> is called as part of an initialization or an assignment statement, but the method <code>System.out.println</code> is called on its own.\r\n<h2 id=\"tab2\" >The boolean type</h2>\r\nA variable of type <code>boolean</code> stores one of two values: <code>true</code> or <code>false</code>. The code below demonstrates the use of a <code>boolean</code> variable.\r\n\r\n<code>public class ElevatorFitter2 {</code>\r\n\r\n \r\n\r\n<code>public static void main(String args[]) {</code>\r\n\r\n<code>System.out.println(\"True or False?\");</code>\r\n\r\n<code>System.out.println(\"You can fit all ten of the\");</code>\r\n\r\n<code>System.out.println(\"Brickenchicker dectuplets\");</code>\r\n\r\n<code>System.out.println(\"on the elevator:\");</code>\r\n\r\n<code>System.out.println();</code>\r\n\r\n \r\n\r\n<code>int weightOfAPerson = 150;</code>\r\n\r\n<code>int elevatorWeightLimit = 1400;</code>\r\n\r\n<code>int numberOfPeople = elevatorWeightLimit / weightOfAPerson;</code>\r\n\r\n \r\n\r\n<code>&lt;strong&gt; boolean allTenOkay = numberOfPeople &gt;= 10;&lt;/strong&gt;</code>\r\n\r\n \r\n\r\n<code>System.out.println(allTenOkay);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nIn this code, the <code>allTenOkay</code> variable is of type <code>boolean</code>. To find a value for the <code>allTenOkay</code> variable, the program checks to see whether <code>numberOfPeople</code> is greater than or equal to ten. (The symbols >= stand for <em>greater than or equal to.</em>)\r\n\r\nAt this point, it pays to be fussy about terminology. Any part of a Java program that has a value is an <em>expression.</em> If you write\r\n\r\n<code>weightOfAPerson = 150;</code>\r\n\r\nthen <code>150 ,</code>is an expression (an expression whose value is the quantity <code>150</code>). If you write\r\n\r\n<code>numberOfEggs = 2 + 2;</code>\r\n\r\nthen 2 + 2 is an expression (because <code>2 + 2</code> has the value <code>4</code>). If you write\r\n\r\n<code>int numberOfPeople = elevatorWeightLimit / weightOfAPerson;</code>\r\n\r\nthen <code>elevatorWeightLimit / weightOfAPerson</code> is an expression. (The value of the expression <code>elevatorWeightLimit / weightOfAPerson</code> depends on whatever values the variables <code>elevatorWeightLimit</code> and <code>weightOfAPerson</code> have when the code containing the expression is executed.)\r\n<p class=\"article-tips remember\">Any part of a Java program that has a value is an expression.</p>\r\nIn the second set of code, <code>numberOfPeople &gt;= 10</code> is an expression. The expression’s value depends on the value stored in the <code>numberOfPeople</code> variable. But, as you know from seeing the strawberry shortcake at the Brickenchicker family’s catered lunch, the value of <code>numberOfPeople</code> isn’t greater than or equal to ten. As a result, the value of <code>numberOfPeople &gt;= 10</code> is <code>false</code>. So, in the statement in the second set of code, in which <code>allTenOkay</code> is assigned a value, the <code>allTenOkay</code> variable is assigned a <code>false</code> value.\r\n<p class=\"article-tips tip\">In the second set of code, <code>System.out.println()</code> is called with nothing inside the parentheses. When you do this, Java adds a line break to the program’s output. In the second set of code, <code>System.out.println()</code> tells the program to display a blank line.</p>","description":"The words <em>int</em> and <em>double</em> are examples of <em>primitive types</em> (also known as <em>simple</em> types) in Java. The Java language has exactly eight primitive types. As a newcomer to Java, you can pretty much ignore all but four of these types. (As programming languages go, Java is nice and compact that way.)\r\n\r\nThe types that you shouldn’t ignore are <code>int</code>, <code>double</code>, <code>char</code>, and <code>boolean</code>.\r\n<h2 id=\"tab1\" >The char type</h2>\r\nSeveral decades ago, people thought computers existed only for doing big number-crunching calculations. Nowadays, nobody thinks that way. So, if you haven’t been in a cryogenic freezing chamber for the past 20 years, you know that computers store letters, punctuation symbols, and other characters.\r\n\r\nThe Java type that’s used to store characters is called <em>char.</em> The code below has a simple program that uses the <code>char</code> type. This image shows the output of the program in the code below.\r\n\r\n[caption id=\"attachment_239304\" align=\"aligncenter\" width=\"163\"]<a href=\"https://www.dummies.com/wp-content/uploads/java-7e-char-type.jpg\"><img class=\"wp-image-239304 size-full\" src=\"https://www.dummies.com/wp-content/uploads/java-7e-char-type.jpg\" alt=\"java char type\" width=\"163\" height=\"122\" /></a> An exciting run of the program of below as it appears in the Eclipse Console view.[/caption]\r\n\r\n<code>public class CharDemo {</code>\r\n\r\n \r\n\r\n<code>public static void main(String args[]) {</code>\r\n\r\n<code>char myLittleChar = 'b';</code>\r\n\r\n<code>char myBigChar = Character.toUpperCase(myLittleChar);</code>\r\n\r\n<code>System.out.println(myBigChar);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nIn this code, the first initialization stores the letter <em>b</em> in the variable <code>myLittleChar</code>. In the initialization, notice how <em>b</em> is surrounded by single quote marks. In Java, every <code>char</code> literally starts and ends with a single quote mark.\r\n<p class=\"article-tips remember\">In a Java program, single quote marks surround the letter in a <code>char</code> literal.</p>\r\n<em>Character.toUpperCase.</em> The <code>Character.toUpperCase</code> method does just what its name suggests — the method produces the uppercase equivalent of the letter <em>b.</em> This uppercase equivalent (the letter <em>B</em>) is assigned to the <code>myBigChar</code> variable, and the <em>B</em> that’s in <code>myBigChar</code> prints onscreen.\r\n\r\nIf you’re tempted to write the following statement,\r\n\r\n<code>char myLittleChars = &apos;barry&apos;; //Don&apos;t do this</code>\r\n\r\nplease resist the temptation. You can’t store more than one letter at a time in a <code>char</code> variable, and you can’t put more than one letter between a pair of single quotes. If you’re trying to store words or sentences (not just single letters), you need to use something called a String.\r\n<p class=\"article-tips warning\">If you’re used to writing programs in other languages, you may be aware of something called ASCII character encoding. Most languages use ASCII; Java uses Unicode. In the old ASCII representation, each character takes up only 8 bits, but in Unicode, each character takes up 8, 16, or 32 bits. Whereas ASCII stores the letters of the Roman (English) alphabet, Unicode has room for characters from most of the world’s commonly spoken languages.</p>\r\nThe only problem is that some of the Java API methods are geared specially toward 16-bit Unicode. Occasionally, this bites you in the back (or it bytes you in the back, as the case may be). If you’re using a method to write <code>Hello</code> on the screen and <code>H e l l o</code> shows up instead, check the method’s documentation for mention of Unicode characters.\r\n\r\nIt’s worth noticing that the two methods, <code>Character.toUpperCase</code> and <code>System.out.println</code>, are used quite differently in the code above. The method <code>Character.toUpperCase</code> is called as part of an initialization or an assignment statement, but the method <code>System.out.println</code> is called on its own.\r\n<h2 id=\"tab2\" >The boolean type</h2>\r\nA variable of type <code>boolean</code> stores one of two values: <code>true</code> or <code>false</code>. The code below demonstrates the use of a <code>boolean</code> variable.\r\n\r\n<code>public class ElevatorFitter2 {</code>\r\n\r\n \r\n\r\n<code>public static void main(String args[]) {</code>\r\n\r\n<code>System.out.println(\"True or False?\");</code>\r\n\r\n<code>System.out.println(\"You can fit all ten of the\");</code>\r\n\r\n<code>System.out.println(\"Brickenchicker dectuplets\");</code>\r\n\r\n<code>System.out.println(\"on the elevator:\");</code>\r\n\r\n<code>System.out.println();</code>\r\n\r\n \r\n\r\n<code>int weightOfAPerson = 150;</code>\r\n\r\n<code>int elevatorWeightLimit = 1400;</code>\r\n\r\n<code>int numberOfPeople = elevatorWeightLimit / weightOfAPerson;</code>\r\n\r\n \r\n\r\n<code>&lt;strong&gt; boolean allTenOkay = numberOfPeople &gt;= 10;&lt;/strong&gt;</code>\r\n\r\n \r\n\r\n<code>System.out.println(allTenOkay);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nIn this code, the <code>allTenOkay</code> variable is of type <code>boolean</code>. To find a value for the <code>allTenOkay</code> variable, the program checks to see whether <code>numberOfPeople</code> is greater than or equal to ten. (The symbols >= stand for <em>greater than or equal to.</em>)\r\n\r\nAt this point, it pays to be fussy about terminology. Any part of a Java program that has a value is an <em>expression.</em> If you write\r\n\r\n<code>weightOfAPerson = 150;</code>\r\n\r\nthen <code>150 ,</code>is an expression (an expression whose value is the quantity <code>150</code>). If you write\r\n\r\n<code>numberOfEggs = 2 + 2;</code>\r\n\r\nthen 2 + 2 is an expression (because <code>2 + 2</code> has the value <code>4</code>). If you write\r\n\r\n<code>int numberOfPeople = elevatorWeightLimit / weightOfAPerson;</code>\r\n\r\nthen <code>elevatorWeightLimit / weightOfAPerson</code> is an expression. (The value of the expression <code>elevatorWeightLimit / weightOfAPerson</code> depends on whatever values the variables <code>elevatorWeightLimit</code> and <code>weightOfAPerson</code> have when the code containing the expression is executed.)\r\n<p class=\"article-tips remember\">Any part of a Java program that has a value is an expression.</p>\r\nIn the second set of code, <code>numberOfPeople &gt;= 10</code> is an expression. The expression’s value depends on the value stored in the <code>numberOfPeople</code> variable. But, as you know from seeing the strawberry shortcake at the Brickenchicker family’s catered lunch, the value of <code>numberOfPeople</code> isn’t greater than or equal to ten. As a result, the value of <code>numberOfPeople &gt;= 10</code> is <code>false</code>. So, in the statement in the second set of code, in which <code>allTenOkay</code> is assigned a value, the <code>allTenOkay</code> variable is assigned a <code>false</code> value.\r\n<p class=\"article-tips tip\">In the second set of code, <code>System.out.println()</code> is called with nothing inside the parentheses. When you do this, Java adds a line break to the program’s output. In the second set of code, <code>System.out.println()</code> tells the program to display a blank line.</p>","blurb":"","authors":[{"authorId":11028,"name":"Barry A. Burd","slug":"barry-a-burd","description":"","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/11028"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"The char type","target":"#tab1"},{"label":"The boolean type","target":"#tab2"}],"relatedArticles":{"fromBook":[{"articleId":239553,"title":"Using Streams and Lambda Expressions in Java","slug":"using-streams-lambda-expressions-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239553"}},{"articleId":239544,"title":"Command Line Arguments in Java","slug":"command-line-arguments-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239544"}},{"articleId":239529,"title":"How to Add Searching Capability with Java","slug":"add-searching-capability-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239529"}},{"articleId":239524,"title":"How to Use Subclasses in Java","slug":"use-subclasses-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239524"}},{"articleId":239520,"title":"Defining a Class in Java (What It Means to Be an Account)","slug":"defining-class-java-means-account","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239520"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281748,"slug":"java-for-dummies-2","isbn":"9781119861645","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119861640-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/9781119861645-203x255.jpg","width":203,"height":255},"title":"Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119861645&quot;]}]\" id=\"du-slot-671fd1658c809\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119861645&quot;]}]\" id=\"du-slot-671fd1658d3f6\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2024-10-28T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":239303},{"headers":{"creationTime":"2016-03-27T16:48:10+00:00","modifiedTime":"2023-01-11T15:40:51+00:00","timestamp":"2023-01-11T18:01:03+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Java All-in-One For Dummies Cheat Sheet","strippedTitle":"java all-in-one for dummies cheat sheet","slug":"java-all-in-one-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"Learn about writing Java statements and classes, the different kinds of Java data types, and the operations for operands.","noIndex":0,"noFollow":0},"content":"Writing Java statements (like <code>for </code>and <code>if</code>) and classes (like <code>Math</code> and <code>NumberFormat</code>) help you start and build strong programs. Variables hold different kinds of <a href=\"https://www.dummies.com/programming/java/the-eight-data-types-of-java/\" target=\"_blank\" rel=\"noopener\">Java data types</a>: numbers, characters, and true/false numbers. You designate Java operations that can be performed on operands, including arithmetic operators, relational operators (or binary) and logical operators (or Boolean).\r\n\r\n[caption id=\"attachment_272791\" align=\"alignnone\" width=\"556\"]<img class=\"size-full wp-image-272791\" src=\"https://www.dummies.com/wp-content/uploads/Java-concept.jpg\" alt=\"Java concept image\" width=\"556\" height=\"489\" /> © DeymosHR/Shutterstock.com[/caption]","description":"Writing Java statements (like <code>for </code>and <code>if</code>) and classes (like <code>Math</code> and <code>NumberFormat</code>) help you start and build strong programs. Variables hold different kinds of <a href=\"https://www.dummies.com/programming/java/the-eight-data-types-of-java/\" target=\"_blank\" rel=\"noopener\">Java data types</a>: numbers, characters, and true/false numbers. You designate Java operations that can be performed on operands, including arithmetic operators, relational operators (or binary) and logical operators (or Boolean).\r\n\r\n[caption id=\"attachment_272791\" align=\"alignnone\" width=\"556\"]<img class=\"size-full wp-image-272791\" src=\"https://www.dummies.com/wp-content/uploads/Java-concept.jpg\" alt=\"Java concept image\" width=\"556\" height=\"489\" /> © DeymosHR/Shutterstock.com[/caption]","blurb":"","authors":[{"authorId":8946,"name":"Doug Lowe","slug":"doug-lowe","description":" <p><b>Doug Lowe </b>is the information technology director at Blair, Church & Flynn Consulting Engineers, a civil engineering firm. He has written more than 50 <i>For Dummies</i> books on topics ranging from Java to electronics to PowerPoint.</p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/8946"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281747,"slug":"java-all-in-one-for-dummies-6th-edition","isbn":"9781119986645","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119986648/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119986648/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119986648-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119986648/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119986648/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/java-all-in-one-for-dummies-7th-edition-cover-9781119986645-203x255.jpg","width":203,"height":255},"title":"Java All-in-One For Dummies, 7th Edition","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"8946\">Doug Lowe</b> </b>is the information technology director at Blair, Church & Flynn Consulting Engineers, a civil engineering firm. He has written more than 50 <i>For Dummies</i> books on topics ranging from Java to electronics to PowerPoint.</p>","authors":[{"authorId":8946,"name":"Doug Lowe","slug":"doug-lowe","description":" <p><b>Doug Lowe </b>is the information technology director at Blair, Church & Flynn Consulting Engineers, a civil engineering firm. He has written more than 50 <i>For Dummies</i> books on topics ranging from Java to electronics to PowerPoint.</p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/8946"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119986645&quot;]}]\" id=\"du-slot-63bef95f2b3be\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119986645&quot;]}]\" id=\"du-slot-63bef95f2bc1c\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":154428,"title":"Common Java Statements","slug":"common-java-statements","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/154428"}},{"articleId":154427,"title":"Primitive Data Types","slug":"primitive-data-types","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/154427"}},{"articleId":154429,"title":"Math and NumberFormat Classes","slug":"math-and-numberformat-classes","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/154429"}},{"articleId":154426,"title":"Java Operators","slug":"java-operators","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/154426"}}],"content":[{"title":"Common Java statements","thumb":null,"image":null,"content":"<p>Java statements build programs. Every Java class must have a body, which is made up of one or more statements. You can write different kinds of statements, including declaration and expression.</p>\n<h3>The <i>break</i> statement</h3>\n<pre class=\"code\">break;</pre>\n<h3>The <i>continue</i> statement</h3>\n<pre class=\"code\">continue;</pre>\n<h3>The <i>do</i> statement</h3>\n<pre class=\"code\">do\r\n {<i>statements</i>...}\r\nwhile (<i>expression</i>);</pre>\n<h3>The <i>for</i> statement</h3>\n<pre class=\"code\">for (<i>init</i>; <i>test</i>; count)\r\n {<i>statements</i>...}</pre>\n<h3>The enhanced <i>for</i> statement</h3>\n<pre class=\"code\">for (type variable : array-or-\r\n collection)\r\n {statements...}</pre>\n<h3>The <i>if</i> statement</h3>\n<pre class=\"code\">if (<i>expression</i>)\r\n {<i>statements</i>...}\r\nelse\r\n {<i>statements</i>...}</pre>\n<h3>The <i>throw</i> statement</h3>\n<pre class=\"code\">throw (<i>exception</i>)</pre>\n<h3>The <i>switch</i> statement</h3>\n<pre class=\"code\"><i>switch (expression)</i>\r\n{\r\n case <i>constant</i>:\r\n <i>statements</i>;\r\n break;\r\n default:\r\n <i>statements</i>;\r\n break; \r\n}</pre>\n<h3>The <i>while</i> statement</h3>\n<pre class=\"code\">while (<i>expression</i>)\r\n {<i>statements</i>...}</pre>\n<h3>The <i>try</i> statement</h3>\n<pre class=\"code\">try\r\n {<i>statements</i>...}\r\ncatch (<i>exception</i><i>-class</i> e)\r\n {<i>statements</i>...}...\r\nfinally\r\n {<i>statements</i>...}\r\ntry\r\n {<i>statements</i>...}\r\nfinally\r\n {<i>statements</i>...}</pre>\n"},{"title":"Primitive data types","thumb":null,"image":null,"content":"<p><i>Java data types </i>are the kind of data you can store in a variable. <i>Primitive data types</i> are defined by the language itself. Java defines a total of eight primitive types. Of the eight primitive data types, six are for numbers, one is for characters, and one is for true/false values. Of the six number types, four are types of integers, and two are types of floating-point numbers.</p>\n<table>\n<tbody>\n<tr>\n<th>Type</th>\n<th>Wrapper Class</th>\n<th>Parse Method of Wrapper Class</th>\n</tr>\n<tr>\n<td><span class=\"code\"><code>int</code></span></td>\n<td><span class=\"code\"><code>Integer</code></span></td>\n<td><span class=\"code\"><code>int parseInt(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>short</code></span></td>\n<td><span class=\"code\"><code>Short</code></span></td>\n<td><span class=\"code\"><code>short parseShort(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>long</code></span></td>\n<td><span class=\"code\"><code>Long&lt;</code>/span&gt;</span></td>\n<td><span class=\"code\"><code>long parseLong(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>byte</code></span></td>\n<td><span class=\"code\"><code>Byte</code></span></td>\n<td><span class=\"code\"><code>byte parseByte(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>float</code></span></td>\n<td><span class=\"code\"><code>Float</code></span></td>\n<td><span class=\"code\"><code>float parseFloat(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>double</code></span></td>\n<td><span class=\"code\"><code>Double</code></span></td>\n<td><span class=\"code\"><code>double parseDouble(String s)</code></span></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>char</code></span></td>\n<td><span class=\"code\"><code>Character</code></span></td>\n<td>(none)</td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>boolean</code></span></td>\n<td><span class=\"code\"><code>Boolean</code></span></td>\n<td><span class=\"code\"><code>boolean parseBoolean(String s)</code></span></td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Math and NumberFormat classes","thumb":null,"image":null,"content":"<p>Java classes lay the foundation for your programs. The Java <span class=\"code\"><code>Math</code></span> and <span class=\"code\"><code>NumberFormat</code></span> classes let you program number values, as well as format numbers and currencies.</p>\n<table>\n<caption><strong>The <i>Math</i> Class</strong></caption>\n<tbody>\n<tr>\n<th>Method</th>\n<th>Description</th>\n</tr>\n<tr>\n<td><span class=\"code\"><code>num abs(num y);</code></span></td>\n<td>Absolute value of <em><span class=\"code\">y</span></em> (<span class=\"code\">num</span> can be any numeric data type)</td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>num max(num y, num z);</code></span></td>\n<td>Maximum of <em><span class=\"code\">y</span></em> and <em><span class=\"code\">z</span></em></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>num min(num y, num z);</code></span></td>\n<td>Minimum of <em><span class=\"code\">y</span></em> and <em><span class=\"code\">z</span></em></td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>double = Math. random();</code></span></td>\n<td>Random number, such that 0.0 &lt; <em>x</em> &lt;= 1.0</td>\n</tr>\n</tbody>\n</table>\n<table>\n<caption><strong>The <em>NumberFormat</em> Class</strong></caption>\n<tbody>\n<tr>\n<th>Method</th>\n<th>Description</th>\n</tr>\n<tr>\n<td><span class=\"code\"><code>NumberFormat<br />\ngetNumberInstance();</code></span></td>\n<td>Gets an instance that formats numbers.</td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>NumberFormat</code></span></td>\n<td>Gets an instance that formats currency.</td>\n</tr>\n<tr>\n<td><span class=\"code\"><code>String format(x);</code></span></td>\n<td>Formats the specified number.</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Java operators","thumb":null,"image":null,"content":"<p>An <i>operator </i>designates a mathematical operation or some other type of operation that can be performed on <i>operands.</i> Java has <i>arithmetic operators, relational operators </i>(also known as <i>binary operators</i>) and <i>logical operators </i>(also known as <i>B</i><i>oolean</i><i> operators)</i>.</p>\n<table>\n<caption><strong>Arithmetic</strong></caption>\n<tbody>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n</tr>\n<tr>\n<td><span class=\"code\">+</span></td>\n<td>Addition</td>\n</tr>\n<tr>\n<td><span class=\"code\">&#8211;</span></td>\n<td>Subtraction</td>\n</tr>\n<tr>\n<td><span class=\"code\">*</span></td>\n<td>Multiplication</td>\n</tr>\n<tr>\n<td><span class=\"code\">/</span></td>\n<td>Division</td>\n</tr>\n<tr>\n<td><span class=\"code\">%</span></td>\n<td>Remainder</td>\n</tr>\n<tr>\n<td><span class=\"code\">++</span></td>\n<td>Increment</td>\n</tr>\n<tr>\n<td><span class=\"code\">—</span></td>\n<td>Decrement</td>\n</tr>\n<tr>\n<td><span class=\"code\">+=</span></td>\n<td>Addition and assignment</td>\n</tr>\n<tr>\n<td><span class=\"code\">-=</span></td>\n<td>Subtraction and assignment</td>\n</tr>\n<tr>\n<td><span class=\"code\">*=</span></td>\n<td>Multiplication and assignment</td>\n</tr>\n<tr>\n<td><span class=\"code\">/=</span></td>\n<td>Division and assignment</td>\n</tr>\n<tr>\n<td><span class=\"code\">%=</span></td>\n<td>Remainder and assignment</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<table>\n<caption><strong>Relational</strong></caption>\n<tbody>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n</tr>\n<tr>\n<td><span class=\"code\">==</span></td>\n<td>Equal</td>\n</tr>\n<tr>\n<td><span class=\"code\">!=</span></td>\n<td>Not equal</td>\n</tr>\n<tr>\n<td><span class=\"code\">&lt;</span></td>\n<td>Less than</td>\n</tr>\n<tr>\n<td><span class=\"code\">&lt;=</span></td>\n<td>Less than or equal to</td>\n</tr>\n<tr>\n<td><span class=\"code\">&gt;</span></td>\n<td>Greater than</td>\n</tr>\n<tr>\n<td><span class=\"code\">&gt;=</span></td>\n<td>Greater than or equal to</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<table>\n<caption><strong>Logical</strong></caption>\n<tbody>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n</tr>\n<tr>\n<td><span class=\"code\">!</span></td>\n<td>Not</td>\n</tr>\n<tr>\n<td><span class=\"code\">&amp;</span></td>\n<td>And</td>\n</tr>\n<tr>\n<td><span class=\"code\">&amp;&amp;</span></td>\n<td>Conditional and</td>\n</tr>\n<tr>\n<td><span class=\"code\">|</span></td>\n<td>Or</td>\n</tr>\n<tr>\n<td><span class=\"code\">||</span></td>\n<td>Conditional or</td>\n</tr>\n<tr>\n<td><span class=\"code\">^</span></td>\n<td>xor</td>\n</tr>\n</tbody>\n</table>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2023-01-11T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":207712},{"headers":{"creationTime":"2016-03-27T16:48:00+00:00","modifiedTime":"2022-02-25T17:45:58+00:00","timestamp":"2022-09-14T18:19:16+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Java For Dummies Cheat Sheet","strippedTitle":"java for dummies cheat sheet","slug":"java-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"To program in Java, you need to know the Java keywords, literal words, restricted keywords, and identifiers.","noIndex":0,"noFollow":0},"content":"When doing anything with Java, you need to know your Java words — those programming words, phrases, and nonsense terms that have specific meaning in the Java language, and get it to do its thing.\r\n\r\nThis Cheat Sheet tells you all about Java's categories of words.","description":"When doing anything with Java, you need to know your Java words — those programming words, phrases, and nonsense terms that have specific meaning in the Java language, and get it to do its thing.\r\n\r\nThis Cheat Sheet tells you all about Java's categories of words.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":239553,"title":"Using Streams and Lambda Expressions in Java","slug":"using-streams-lambda-expressions-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239553"}},{"articleId":239544,"title":"Command Line Arguments in Java","slug":"command-line-arguments-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239544"}},{"articleId":239529,"title":"How to Add Searching Capability with Java","slug":"add-searching-capability-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239529"}},{"articleId":239524,"title":"How to Use Subclasses in Java","slug":"use-subclasses-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239524"}},{"articleId":239520,"title":"Defining a Class in Java (What It Means to Be an Account)","slug":"defining-class-java-means-account","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239520"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281748,"slug":"java-for-dummies-2","isbn":"9781119861645","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119861640-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119861640/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/9781119861645-203x255.jpg","width":203,"height":255},"title":"Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119861645&quot;]}]\" id=\"du-slot-63221b24d6b52\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119861645&quot;]}]\" id=\"du-slot-63221b24d74fb\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":235909,"title":"The Words in a Java Program","slug":"words-java-program","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/235909"}}],"content":[{"title":"Java's 51 keywords","thumb":null,"image":null,"content":"<p>The Java programming language has 50 <em>keywords</em>. Each keyword has a specific meaning in the language. You can&#8217;t use a keyword for anything other than its pre-assigned meaning.</p>\n<p>The following table lists Java&#8217;s keywords.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"315\"><strong>Keyword</strong></td>\n<td width=\"263\"><strong>What It Does</strong></td>\n</tr>\n<tr>\n<td width=\"315\">abstract</td>\n<td width=\"263\">Indicates that the details of a class, a method, or an interface are given elsewhere in the code.</td>\n</tr>\n<tr>\n<td width=\"315\">assert</td>\n<td width=\"263\">Tests the truth of a condition that the programmer believes is true.</td>\n</tr>\n<tr>\n<td width=\"315\">boolean</td>\n<td width=\"263\">Indicates that a value is either true or false.</td>\n</tr>\n<tr>\n<td width=\"315\">break</td>\n<td width=\"263\">Jumps out of a loop or switch.</td>\n</tr>\n<tr>\n<td width=\"315\">byte</td>\n<td width=\"263\">Indicates that a value is an 8-bit whole number.</td>\n</tr>\n<tr>\n<td width=\"315\">case</td>\n<td width=\"263\">Introduces one of several possible paths of execution in a switch statement.</td>\n</tr>\n<tr>\n<td width=\"315\">catch</td>\n<td width=\"263\">Introduces statements that are executed when something interrupts the flow of execution in a try clause.</td>\n</tr>\n<tr>\n<td width=\"315\">char</td>\n<td width=\"263\">Indicates that a value is a character (a single letter, digit, punctuation symbol, and so on) stored in 16 bits of memory.</td>\n</tr>\n<tr>\n<td width=\"315\">class</td>\n<td width=\"263\">Introduces a class — a blueprint for an object.</td>\n</tr>\n<tr>\n<td width=\"315\">const</td>\n<td width=\"263\">You can’t use this word in a Java program. The word has no meaning but, because it’s a keyword, you can’t create a variable named const.</td>\n</tr>\n<tr>\n<td width=\"315\">continue</td>\n<td width=\"263\">Forces the abrupt end of the current loop iteration and begins another iteration.</td>\n</tr>\n<tr>\n<td width=\"315\">default</td>\n<td width=\"263\">Introduces a path of execution to take when no case is a match in a switch statement.</td>\n</tr>\n<tr>\n<td width=\"315\">do</td>\n<td width=\"263\">Causes the computer to repeat some statements over and over again (for instance, as long as the computer keeps getting unacceptable results).</td>\n</tr>\n<tr>\n<td width=\"315\">double</td>\n<td width=\"263\">Indicates that a value is a 64-bit number with one or more digits after the decimal point.</td>\n</tr>\n<tr>\n<td width=\"315\">else</td>\n<td width=\"263\">Introduces statements that are executed when the condition in an if statement isn’t true.</td>\n</tr>\n<tr>\n<td width=\"315\">enum</td>\n<td width=\"263\">Creates a newly defined type — a group of values that a variable can have.</td>\n</tr>\n<tr>\n<td width=\"315\">extends</td>\n<td width=\"263\">Creates a subclass @@md a class that reuses functionality from a previously defined class.</td>\n</tr>\n<tr>\n<td width=\"315\">final</td>\n<td width=\"263\">Indicates that a variable’s value cannot be changed, that a class’s functionality cannot be extended, or that a method cannot be overridden.</td>\n</tr>\n<tr>\n<td width=\"315\">finally</td>\n<td width=\"263\">Introduces the last will and testament of the statements in a try clause.</td>\n</tr>\n<tr>\n<td width=\"315\">float</td>\n<td width=\"263\">Indicates that a value is a 32-bit number with one or more digits after the decimal point.</td>\n</tr>\n<tr>\n<td width=\"315\">for</td>\n<td width=\"263\">Gets the computer to repeat some statements over and over again (for instance, a certain number of times).</td>\n</tr>\n<tr>\n<td width=\"315\">goto</td>\n<td width=\"263\">You can’t use this word in a Java program. The word has no meaning. Because it’s a keyword, you can’t create a variable named goto.</td>\n</tr>\n<tr>\n<td width=\"315\">if</td>\n<td width=\"263\">Tests to see whether a condition is true. If it’s true, the computer executes certain statements; otherwise, the computer executes other statements.</td>\n</tr>\n<tr>\n<td width=\"315\">implements</td>\n<td width=\"263\">Indicates that a class provides bodies for methods whose headers are declared in an interface.</td>\n</tr>\n<tr>\n<td width=\"315\">import</td>\n<td width=\"263\">Enables the programmer to abbreviate the names of classes defined in a package.</td>\n</tr>\n<tr>\n<td width=\"315\">instanceof</td>\n<td width=\"263\">Tests to see whether a certain object comes from a certain class.</td>\n</tr>\n<tr>\n<td width=\"315\">int</td>\n<td width=\"263\">Indicates that a value is a 32-bit whole number.</td>\n</tr>\n<tr>\n<td width=\"315\">interface</td>\n<td width=\"263\">Introduces an interface. An interface is like a class but, for the most part, an interface’s methods have no bodies.</td>\n</tr>\n<tr>\n<td width=\"315\">long</td>\n<td width=\"263\">Indicates that a value is a 64-bit whole number.</td>\n</tr>\n<tr>\n<td width=\"315\">native</td>\n<td width=\"263\">Enables the programmer to use code that was written in a language other than Java.</td>\n</tr>\n<tr>\n<td width=\"315\">new</td>\n<td width=\"263\">Creates an object from an existing class.</td>\n</tr>\n<tr>\n<td width=\"315\">package</td>\n<td width=\"263\">Puts the code into a package — a collection of logically related definitions.</td>\n</tr>\n<tr>\n<td width=\"315\">private</td>\n<td width=\"263\">Indicates that a variable or method can be used only within a certain class.</td>\n</tr>\n<tr>\n<td width=\"315\">protected</td>\n<td width=\"263\">Indicates that a variable or method can be used in subclasses from another package.</td>\n</tr>\n<tr>\n<td width=\"315\">public</td>\n<td width=\"263\">Indicates that a variable, class, or method can be used by any other Java code.</td>\n</tr>\n<tr>\n<td width=\"315\">return</td>\n<td width=\"263\">Ends execution of a method and possibly returns a value to the calling code.</td>\n</tr>\n<tr>\n<td width=\"315\">short</td>\n<td width=\"263\">Indicates that a value is a 16-bit whole number.</td>\n</tr>\n<tr>\n<td width=\"315\">static</td>\n<td width=\"263\">Indicates that a variable or method belongs to a class, rather than to any object created from the class.</td>\n</tr>\n<tr>\n<td width=\"315\">strictfp</td>\n<td width=\"263\">Limits the computer’s ability to represent extra large or extra small numbers when the computer does intermediate calculations on float and double values.</td>\n</tr>\n<tr>\n<td width=\"315\">super</td>\n<td width=\"263\">Refers to the superclass of the code in which the word super appears.</td>\n</tr>\n<tr>\n<td width=\"315\">switch</td>\n<td width=\"263\">Tells the computer to follow one of many possible paths of execution (one of many possible cases), depending on the value of an expression.</td>\n</tr>\n<tr>\n<td width=\"315\">synchronized</td>\n<td width=\"263\">Keeps two threads from interfering with one another.</td>\n</tr>\n<tr>\n<td width=\"315\">this</td>\n<td width=\"263\">A self-reference — refers to the object in which the word this appears.</td>\n</tr>\n<tr>\n<td width=\"315\">throw</td>\n<td width=\"263\">Creates a new exception object and indicates that an exceptional situation (usually something unwanted) has occurred.</td>\n</tr>\n<tr>\n<td width=\"315\">throws</td>\n<td width=\"263\">Indicates that a method or constructor may pass the buck when an exception is thrown.</td>\n</tr>\n<tr>\n<td width=\"315\">transient</td>\n<td width=\"263\">Indicates that, if and when an object is serialized, a variable’s value doesn’t need to be stored.</td>\n</tr>\n<tr>\n<td width=\"315\">try</td>\n<td width=\"263\">Introduces statements that are watched (during runtime) for things that can go wrong.</td>\n</tr>\n<tr>\n<td width=\"315\">void</td>\n<td width=\"263\">Indicates that a method doesn’t return a value.</td>\n</tr>\n<tr>\n<td width=\"315\">volatile</td>\n<td width=\"263\">Imposes strict rules on the use of a variable by more than one thread at a time.</td>\n</tr>\n<tr>\n<td width=\"315\">while</td>\n<td width=\"263\">Repeats some statements over and over again (as long as a condition is still true).</td>\n</tr>\n<tr>\n<td width=\"315\">_ (a single underscore)</td>\n<td width=\"263\">You can’t use this word in a Java 17 program. The word might have a meaning in later versions of Java. Because it’s a keyword, you can’t create a variable named _.</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Java's literal words","thumb":null,"image":null,"content":"<p>In addition to its keywords, three of the words you use in a Java program are called <em>literals</em>. Each literal has a specific meaning in the language. You can&#8217;t use a literal for anything other than its pre-assigned meaning.</p>\n<p>The following table lists Java&#8217;s literal words.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"195\"><strong>Literal</strong></td>\n<td width=\"383\"><strong>What It Does</strong></td>\n</tr>\n<tr>\n<td width=\"195\">false</td>\n<td width=\"383\">One of the two values that a boolean expression can possibly have.</td>\n</tr>\n<tr>\n<td width=\"195\">null</td>\n<td width=\"383\">The &#8220;nothing&#8221; value. If you intend to have an expression refer to an object of some kind, but the expression doesn&#8217;t refer to any object, the expression&#8217;s value is <span style=\"text-decoration: line-through;\">null</span>.</td>\n</tr>\n<tr>\n<td width=\"195\">true</td>\n<td width=\"383\">One of the two values that a boolean expression can possibly have.</td>\n</tr>\n</tbody>\n</table>\n<p>The keywords and literal words are all called <em>reserved</em> words because each of these words is reserved for special use in the Java programming language.</p>\n"},{"title":"Restricted keywords in Java","thumb":null,"image":null,"content":"<p>A <em>restricted keyword</em> has a specific meaning in the language, but only if you use that word in a specific way. For example, if you write</p>\n<p><code>requires other.stuff;<br />\n</code><br />\nyou tell Java that your program won&#8217;t run unless it has access to some other code (the code contained in <code>other.stuff</code>). But if you write</p>\n<p><code>int requires = 10;<br />\n</code><br />\nthen <code>requires </code>is an ordinary <code>int </code>variable.</p>\n<p>The following table lists the restricted keywords in Java 17.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"143\"><strong>Restricted Keyword</strong></td>\n<td width=\"435\"><strong>What It Does</strong></td>\n</tr>\n<tr>\n<td width=\"143\">exports</td>\n<td width=\"435\">Indicates that the code in a particular package is available for use by code in other modules.</td>\n</tr>\n<tr>\n<td width=\"143\">module</td>\n<td width=\"435\">A bunch of packages.</td>\n</tr>\n<tr>\n<td width=\"143\">non-sealed</td>\n<td width=\"435\">Removes the restriction that only certain other classes may extend this class.</td>\n</tr>\n<tr>\n<td width=\"143\">open</td>\n<td width=\"435\">Indicates that all the packages in a module are, in a certain way, available for use by code in other modules.</td>\n</tr>\n<tr>\n<td width=\"143\">opens</td>\n<td width=\"435\">Gets access to all the code in another module. This access uses Java reflection (which tends to be messy).</td>\n</tr>\n<tr>\n<td width=\"143\">permits</td>\n<td width=\"435\">Names the classes that can extend a sealed class.</td>\n</tr>\n<tr>\n<td width=\"143\">provides</td>\n<td width=\"435\">Indicates that a module makes a service available.</td>\n</tr>\n<tr>\n<td width=\"143\">record</td>\n<td width=\"435\">Introduces a class with some commonly-used methods defined by default.</td>\n</tr>\n<tr>\n<td width=\"143\">requires</td>\n<td width=\"435\">Indicates that the program won’t run unless it has access to some other code.</td>\n</tr>\n<tr>\n<td width=\"143\">sealed</td>\n<td width=\"435\">Indicates that only certain other classes may extend this class.</td>\n</tr>\n<tr>\n<td width=\"143\">to</td>\n<td width=\"435\">Names the code that has permission to use a particular piece of code.</td>\n</tr>\n<tr>\n<td width=\"143\">transitive</td>\n<td width=\"435\">When my code requires use of the A code, and the Z code requires use of my code, the word transitive means that Z code automatically requires A code.</td>\n</tr>\n<tr>\n<td width=\"143\">uses</td>\n<td width=\"435\">Indicates that a module uses a service.</td>\n</tr>\n<tr>\n<td width=\"143\">var</td>\n<td width=\"435\">Leaves Java to infer a variable’s type.</td>\n</tr>\n<tr>\n<td width=\"143\">with</td>\n<td width=\"435\">Specifies a particular way of using a service.</td>\n</tr>\n<tr>\n<td width=\"143\">yield</td>\n<td width=\"435\">Marks the value of a case clause in a switch expression.</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Identifiers in the Java API","thumb":null,"image":null,"content":"<p>The Java application programming interface (API) has thousands of identifiers. Each identifier is the name of something (a class, an object, a method, or something like that). These identifiers include System, out, println, String, toString, JFrame, File, Scanner, next, nextInt, Exception, close, ArrayList, stream, JTextField, Math, Random, MenuItem, Month, parseInt, Query, Rectangle, Color, Oval, paint, Robot, SQLData, Stack, Queue, TimeZone, URL, and so many others.</p>\n<p>You can reuse any of these names for any purpose in your code. But if you do, you might have trouble using a name with its normal meaning from the Java API. For example, you can write</p>\n<p>int System = 7;</p>\n<p>java.lang.System.out.println(System);</p>\n<p>But you can’t write</p>\n<p>int System = 7;</p>\n<p>System.out.println(System);</p>\n"},{"title":"Identifiers that you (the programmer) declare","thumb":null,"image":null,"content":"<p>In your own Java program, you can make up names to your heart&#8217;s delight. For example, in the code</p>\n<p><code>double multiplyByTwo(double myValue) {<br />\n</code><br />\n<code>return myValue * 2;<br />\n</code><br />\n<code>}</code></p>\n<p>the names <code>multiplyByTwo</code> and <code>myValue</code> are your very own identifiers.</p>\n<p>When you create a new name, you can use letters, digits, underscores (_), and dollar signs ($). But don&#8217;t start the name with a digit. If you try to start a name with a digit, Java replies with a &#8220;Please don&#8217;t do that&#8221; message.</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-02-08T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":207676},{"headers":{"creationTime":"2016-03-26T22:54:38+00:00","modifiedTime":"2022-01-13T23:52:54+00:00","timestamp":"2022-09-14T18:19:01+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Java Programming: Telling the Computer to Do Something","strippedTitle":"java programming: telling the computer to do something","slug":"java-programming-telling-the-computer-to-do-something","canonicalUrl":"","seo":{"metaDescription":"In Listing 1, below, you get a blast of Java code. Like all novice programmers, you're expected to gawk humbly at the code. But don't be intimidated. When you g","noIndex":0,"noFollow":0},"content":"In Listing 1, below, you get a blast of Java code. Like all novice programmers, you're expected to gawk humbly at the code. But don't be intimidated. When you get the hang of it, programming is pretty easy. Yes, it's fun, too.\r\n\r\n<b>Listing 1: A Simple Java Program</b>\r\n<pre class=\"code\">/*\r\n* A program to list the good things in life\r\n* Author: Barry Burd, [email protected]\r\n* February 10, 2021\r\n*/\r\npublic class ThingsILike \r\n{\r\n public static void main (String[] args)\r\n{\r\n System.out.println(\"Chocolate, royalties, sleep\");\r\n } \r\n}</pre>\r\nBuried deep in the heart of Listing 1 is the single line that actually issues a direct instruction to the computer. The line\r\n<pre class=\"code\">System.out.println(\"Chocolate, royalties, sleep\");</pre>\r\ntells the computer to display the words <tt>Chocolate, royalties, sleep</tt> in the command prompt window. This line can be described in at least two different ways:\r\n<ul>\r\n \t<li><b>It's a statement: </b> In Java, a direct instruction that tells the computer to do something is called a <i>statement</i>. The statement in Listing 1 tells the computer to display some text. The statements in other programs may tell the computer to put 7 in certain memory location, or make a window appear on the screen. The statements in computer programs do all kinds of things.</li>\r\n</ul>\r\n<ul>\r\n \t<li><b>It's a method call: </b> A method call is a separate piece of code (in a different part of the Java program) that tells the computer to call the method into action.The statement</li>\r\n</ul>\r\n<pre class=\"code\">&lt;tt&gt;FixTheAlternator(junkyOldFord);&lt;/tt&gt;</pre>\r\n<ul>is an example of a method call, and so is</ul>\r\n<pre class=\"code\">&lt;tt&gt;System.out.println(\"Chocolate, royalties, sleep\");&lt;/tt&gt;</pre>\r\n<ul>Java has many different kinds of statements. A method call is just one kind.</ul>\r\n<h2 id=\"tab1\" >Ending a statement with a semicolon</h2>\r\nIn Java, each statement ends with a semicolon. The code in Listing 1 has only one statement in it, so only one line in Listing 1 ends with a semicolon.\r\n\r\nTake any other line in Listing 1, like the method header, for instance. The method header (the line with the word main in it) doesn't directly tell the computer to do anything. Instead, the method header describes some action for future reference. The header announces \"Just in case someone ever calls the main method, the next few lines of code tell you what to do in response to that call.\"\r\n<p class=\"Remember\">Every complete Java statement ends with a semicolon. A method call is a statement, so it ends with a semicolon, but neither a method header nor a method declaration is a statement.</p>\r\n\r\n<h2 id=\"tab2\" >The method named System.out.println</h2>\r\nThe statement in the middle of Listing 1 calls a method named <i>System.out.println</i>. This method is defined in the Java API. Whenever you call the System.out.println method, the computer displays text on its screen.\r\n\r\nThink about the name Pauline Ott, for example. Believe it or not, I know two people named Pauline Ott. One of them is a nun; the other is physicist. Of course, there are plenty of Paulines in the English-speaking world, just as there are several things named println in the Java API. So to distinguish the physicist Pauline Ott from the film critic Pauline Kael, write the full name \"Pauline Ott.\" And, to distinguish the nun from the physicist, write \"Sister Pauline Ott.\" In the same way, write either System.out.println or DriverManager.println. The first writes text on the computer's screen. The second writes to a database log file.\r\n\r\nJust as Pauline and Ott are names in their own right, so System, out, and println are names in the Java API. But to use println, you must write the method's full name. You never write println alone. It's always System.out.println or some other combination of API names.\r\n<p class=\"Warning\">The Java programming language is case-sensitive. If you change a lowercase letter to an uppercase letter (or vice versa), you change a word's meaning. You can't replace System.out.println with system.out.Println<i>.</i> If you do, your program won't work.</p>\r\n\r\n<h2 id=\"tab3\" >The Java class</h2>\r\nYou may have heard the term <i>object-oriented programming </i>(also known as <i>OOP</i>). OOP is a way of thinking about computer programming problems — a way that's supported by several different programming languages. OOP started in the 1960s with a language called Simula. It was reinforced in the 1970s with another language named Smalltalk. In the 1980s, OOP took off big time with the language C++.\r\n\r\nSome people want to change the acronym, and call it COP, class-oriented programming. That's because object-oriented programming begins with something called a <i>class</i>. In Java, everything starts with classes, everything is enclosed in classes, and everything is based on classes.\r\n\r\nIn Java, your main method has to be inside a class. The code in Listing 1 starts with the words class ThingsILike. Take another look at Listing 1, and notice what happens after the line class ThingsILike. The rest of the code is enclosed in curly braces. These braces mark all the stuff inside the class. Without these braces, you'd know where the declaration of the ThingsILike class starts, but you wouldn't know where the declaration ends.\r\n\r\nIt's as if the stuff inside the ThingsILike class is in a box. To box off a chunk of code, you do two things:\r\n<ul>\r\n \t<li><b>You use curly braces: </b> These curly braces tell the compiler where a chunk of code begins and ends.</li>\r\n</ul>\r\n<ul>\r\n \t<li><b>You indent code: </b> Indentation tells your human eye (and the eyes of other programmers) where a chunk of code begins and ends.</li>\r\n</ul>\r\nDon't forget. You have to do both.","description":"In Listing 1, below, you get a blast of Java code. Like all novice programmers, you're expected to gawk humbly at the code. But don't be intimidated. When you get the hang of it, programming is pretty easy. Yes, it's fun, too.\r\n\r\n<b>Listing 1: A Simple Java Program</b>\r\n<pre class=\"code\">/*\r\n* A program to list the good things in life\r\n* Author: Barry Burd, [email protected]\r\n* February 10, 2021\r\n*/\r\npublic class ThingsILike \r\n{\r\n public static void main (String[] args)\r\n{\r\n System.out.println(\"Chocolate, royalties, sleep\");\r\n } \r\n}</pre>\r\nBuried deep in the heart of Listing 1 is the single line that actually issues a direct instruction to the computer. The line\r\n<pre class=\"code\">System.out.println(\"Chocolate, royalties, sleep\");</pre>\r\ntells the computer to display the words <tt>Chocolate, royalties, sleep</tt> in the command prompt window. This line can be described in at least two different ways:\r\n<ul>\r\n \t<li><b>It's a statement: </b> In Java, a direct instruction that tells the computer to do something is called a <i>statement</i>. The statement in Listing 1 tells the computer to display some text. The statements in other programs may tell the computer to put 7 in certain memory location, or make a window appear on the screen. The statements in computer programs do all kinds of things.</li>\r\n</ul>\r\n<ul>\r\n \t<li><b>It's a method call: </b> A method call is a separate piece of code (in a different part of the Java program) that tells the computer to call the method into action.The statement</li>\r\n</ul>\r\n<pre class=\"code\">&lt;tt&gt;FixTheAlternator(junkyOldFord);&lt;/tt&gt;</pre>\r\n<ul>is an example of a method call, and so is</ul>\r\n<pre class=\"code\">&lt;tt&gt;System.out.println(\"Chocolate, royalties, sleep\");&lt;/tt&gt;</pre>\r\n<ul>Java has many different kinds of statements. A method call is just one kind.</ul>\r\n<h2 id=\"tab1\" >Ending a statement with a semicolon</h2>\r\nIn Java, each statement ends with a semicolon. The code in Listing 1 has only one statement in it, so only one line in Listing 1 ends with a semicolon.\r\n\r\nTake any other line in Listing 1, like the method header, for instance. The method header (the line with the word main in it) doesn't directly tell the computer to do anything. Instead, the method header describes some action for future reference. The header announces \"Just in case someone ever calls the main method, the next few lines of code tell you what to do in response to that call.\"\r\n<p class=\"Remember\">Every complete Java statement ends with a semicolon. A method call is a statement, so it ends with a semicolon, but neither a method header nor a method declaration is a statement.</p>\r\n\r\n<h2 id=\"tab2\" >The method named System.out.println</h2>\r\nThe statement in the middle of Listing 1 calls a method named <i>System.out.println</i>. This method is defined in the Java API. Whenever you call the System.out.println method, the computer displays text on its screen.\r\n\r\nThink about the name Pauline Ott, for example. Believe it or not, I know two people named Pauline Ott. One of them is a nun; the other is physicist. Of course, there are plenty of Paulines in the English-speaking world, just as there are several things named println in the Java API. So to distinguish the physicist Pauline Ott from the film critic Pauline Kael, write the full name \"Pauline Ott.\" And, to distinguish the nun from the physicist, write \"Sister Pauline Ott.\" In the same way, write either System.out.println or DriverManager.println. The first writes text on the computer's screen. The second writes to a database log file.\r\n\r\nJust as Pauline and Ott are names in their own right, so System, out, and println are names in the Java API. But to use println, you must write the method's full name. You never write println alone. It's always System.out.println or some other combination of API names.\r\n<p class=\"Warning\">The Java programming language is case-sensitive. If you change a lowercase letter to an uppercase letter (or vice versa), you change a word's meaning. You can't replace System.out.println with system.out.Println<i>.</i> If you do, your program won't work.</p>\r\n\r\n<h2 id=\"tab3\" >The Java class</h2>\r\nYou may have heard the term <i>object-oriented programming </i>(also known as <i>OOP</i>). OOP is a way of thinking about computer programming problems — a way that's supported by several different programming languages. OOP started in the 1960s with a language called Simula. It was reinforced in the 1970s with another language named Smalltalk. In the 1980s, OOP took off big time with the language C++.\r\n\r\nSome people want to change the acronym, and call it COP, class-oriented programming. That's because object-oriented programming begins with something called a <i>class</i>. In Java, everything starts with classes, everything is enclosed in classes, and everything is based on classes.\r\n\r\nIn Java, your main method has to be inside a class. The code in Listing 1 starts with the words class ThingsILike. Take another look at Listing 1, and notice what happens after the line class ThingsILike. The rest of the code is enclosed in curly braces. These braces mark all the stuff inside the class. Without these braces, you'd know where the declaration of the ThingsILike class starts, but you wouldn't know where the declaration ends.\r\n\r\nIt's as if the stuff inside the ThingsILike class is in a box. To box off a chunk of code, you do two things:\r\n<ul>\r\n \t<li><b>You use curly braces: </b> These curly braces tell the compiler where a chunk of code begins and ends.</li>\r\n</ul>\r\n<ul>\r\n \t<li><b>You indent code: </b> Indentation tells your human eye (and the eyes of other programmers) where a chunk of code begins and ends.</li>\r\n</ul>\r\nDon't forget. You have to do both.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Ending a statement with a semicolon","target":"#tab1"},{"label":"The method named System.out.println","target":"#tab2"},{"label":"The Java class","target":"#tab3"}],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1549940\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b154a3d2\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":201122},{"headers":{"creationTime":"2016-03-26T22:46:46+00:00","modifiedTime":"2022-01-13T23:06:18+00:00","timestamp":"2022-09-14T18:19:01+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Getting Started with Java Programming","strippedTitle":"getting started with java programming","slug":"getting-started-with-java-programming","canonicalUrl":"","seo":{"metaDescription":"Learn some basic terminology, useful tips and necessary first steps to get started on your Java programming journey.","noIndex":0,"noFollow":0},"content":"The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language's founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet. Since 1995, this library has grown to include more than 4,000 programs. This library is called the <i>Application Programming Interface (API).</i>\r\n\r\nEvery Java program, even the simplest one, calls on code in the Java API. This Java API is both useful and formidable. It's useful because of all the things you can do with the API's programs. It's formidable because the API is so extensive. No one memorizes all the features made available by the Java API. Programmers remember the features that they use often, and look up the features that they need in a pinch.\r\n<h2 id=\"tab1\" >So many ways to write computer programs</h2>\r\nTo write Java programs, you need four tools:\r\n<ul>\r\n \t<li><b>A Java compiler</b></li>\r\n</ul>\r\n<ul>\r\n \t<li><b>A Java Virtual Machine. </b></li>\r\n</ul>\r\n<ul>\r\n \t<li><b>The Java API.</b></li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>The Java API documentation.</strong></li>\r\n</ul>\r\n<h2 id=\"tab2\" >The Java smorgasbord</h2>\r\nThis section explains some of the terminology you might see as you travel through the Java ecosystem.\r\n<h3>Medium Java, little Java, and gigantic Java</h3>\r\nAt some point, you may see mention of Java SE, Java ME, or Java EE. Here’s the lowdown on these three kinds of “Java E”:\r\n<ul>\r\n \t<li><strong>Java Standard Edition (Java SE):</strong> This is the only edition you should think about (for now, anyway). Java SE includes all the code you need in order to create general-purpose applications on a typical computer. Nowadays, when you hear the word Java, it almost always refers to Java SE.</li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>Java Micro Edition (Java ME):</strong> The Micro Edition contains code for programming special-purpose devices such as television sets, printers, and other gadgets.</li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>Java Enterprise Edition (Java EE):</strong> In 1999, the stewards of Java released an edition that was tailored for the needs of big companies. The starring role in this edition was a framework called Enterprise JavaBeans — a way of managing data storage across connected computers. In 2017, Oracle walked away from Java EE, handing it over to the Eclipse Foundation, which renamed it Jakarta EE.</li>\r\n</ul>\r\nThe rest of this book deals exclusively with Java Standard Edition.\r\n<h2 id=\"tab3\" >How do you type this stuff?</h2>\r\nA computer program is a big piece of text. So to write a computer program, you need a <i>text editor</i> — a tool for creating text documents. A text editor is a lot like Microsoft Word, or like any other word processing program. The big difference is that the documents that you create with a text editor have no formatting whatsoever. They have no bold, no italic, no distinctions among fonts. They have nothing except plain old letters, numbers, and other familiar keyboard characters. That's good, because computer programs aren't supposed to have any formatting.\r\n\r\nA document with no formatting is called a <i>plain text</i> document.\r\n\r\nDocuments without formatting are fairly simple things, so a typical text editor is easier to use than a word processing program. (Text editors are a lot cheaper than word processing programs, and they're lightning fast. Even better, text editors take very little space on your hard drive.)\r\n<p class=\"Warning\">You can use a word processor, like Microsoft Word, to create program files. But, by default, word processors insert formatting into your document. This formatting makes it impossible for a Java compiler to do its job. Using word processors to write Java programs isn't recommended. But, if you must use a word processor, be sure to save your source files with the .java extension. (Call a file <i>SomeName</i>.java.) Remember, also, to use the Save As command to save with the plain text file type.</p>\r\n\r\n<h2 id=\"tab4\" >Using a customized editor</h2>\r\nEven if you don't use an integrated development environment, you can use other tools to make your programming life easy. Think, for a moment, about an ordinary text editor — an editor like Windows Notepad. With Notepad you can\r\n<ul>\r\n \t<li>Create a document that has no formatting</li>\r\n</ul>\r\n<ul>\r\n \t<li>Find and replace characters, words, and other strings</li>\r\n</ul>\r\n<ul>\r\n \t<li>Copy, cut, and paste</li>\r\n</ul>\r\n<ul>\r\n \t<li>Print</li>\r\n</ul>\r\n<ul>\r\n \t<li>Not much else</li>\r\n</ul>\r\nNotepad is fine for writing computer programs. But if you plan to do a lot of programming, you may want to try a customized editor. These editors do more than Windows Notepad.\r\n\r\nThey have\r\n<ul>\r\n \t<li>Syntax highlighting</li>\r\n</ul>\r\n<ul>\r\n \t<li>Shortcuts for compiling and running programs</li>\r\n</ul>\r\n<ul>\r\n \t<li>Explorer-like views of your works in progress</li>\r\n</ul>\r\n<ul>\r\n \t<li>Code completion</li>\r\n</ul>\r\n<ul>\r\n \t<li>Other cool stuff</li>\r\n</ul>\r\nWhen it comes to choosing a custom editor, one favorite is IntelliJ IDEA. IntelliJ Idea comes in two different editions: Ultimate Edition or Community Edition. The Community Edition is free. To download the IntelliJ IDEA Community Edition, visit <a href=\"http://www.jetbrains.com/idea/download\" target=\"_blank\" rel=\"noopener\">www.jetbrains.com/idea/download</a>.","description":"The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language's founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet. Since 1995, this library has grown to include more than 4,000 programs. This library is called the <i>Application Programming Interface (API).</i>\r\n\r\nEvery Java program, even the simplest one, calls on code in the Java API. This Java API is both useful and formidable. It's useful because of all the things you can do with the API's programs. It's formidable because the API is so extensive. No one memorizes all the features made available by the Java API. Programmers remember the features that they use often, and look up the features that they need in a pinch.\r\n<h2 id=\"tab1\" >So many ways to write computer programs</h2>\r\nTo write Java programs, you need four tools:\r\n<ul>\r\n \t<li><b>A Java compiler</b></li>\r\n</ul>\r\n<ul>\r\n \t<li><b>A Java Virtual Machine. </b></li>\r\n</ul>\r\n<ul>\r\n \t<li><b>The Java API.</b></li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>The Java API documentation.</strong></li>\r\n</ul>\r\n<h2 id=\"tab2\" >The Java smorgasbord</h2>\r\nThis section explains some of the terminology you might see as you travel through the Java ecosystem.\r\n<h3>Medium Java, little Java, and gigantic Java</h3>\r\nAt some point, you may see mention of Java SE, Java ME, or Java EE. Here’s the lowdown on these three kinds of “Java E”:\r\n<ul>\r\n \t<li><strong>Java Standard Edition (Java SE):</strong> This is the only edition you should think about (for now, anyway). Java SE includes all the code you need in order to create general-purpose applications on a typical computer. Nowadays, when you hear the word Java, it almost always refers to Java SE.</li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>Java Micro Edition (Java ME):</strong> The Micro Edition contains code for programming special-purpose devices such as television sets, printers, and other gadgets.</li>\r\n</ul>\r\n<ul>\r\n \t<li><strong>Java Enterprise Edition (Java EE):</strong> In 1999, the stewards of Java released an edition that was tailored for the needs of big companies. The starring role in this edition was a framework called Enterprise JavaBeans — a way of managing data storage across connected computers. In 2017, Oracle walked away from Java EE, handing it over to the Eclipse Foundation, which renamed it Jakarta EE.</li>\r\n</ul>\r\nThe rest of this book deals exclusively with Java Standard Edition.\r\n<h2 id=\"tab3\" >How do you type this stuff?</h2>\r\nA computer program is a big piece of text. So to write a computer program, you need a <i>text editor</i> — a tool for creating text documents. A text editor is a lot like Microsoft Word, or like any other word processing program. The big difference is that the documents that you create with a text editor have no formatting whatsoever. They have no bold, no italic, no distinctions among fonts. They have nothing except plain old letters, numbers, and other familiar keyboard characters. That's good, because computer programs aren't supposed to have any formatting.\r\n\r\nA document with no formatting is called a <i>plain text</i> document.\r\n\r\nDocuments without formatting are fairly simple things, so a typical text editor is easier to use than a word processing program. (Text editors are a lot cheaper than word processing programs, and they're lightning fast. Even better, text editors take very little space on your hard drive.)\r\n<p class=\"Warning\">You can use a word processor, like Microsoft Word, to create program files. But, by default, word processors insert formatting into your document. This formatting makes it impossible for a Java compiler to do its job. Using word processors to write Java programs isn't recommended. But, if you must use a word processor, be sure to save your source files with the .java extension. (Call a file <i>SomeName</i>.java.) Remember, also, to use the Save As command to save with the plain text file type.</p>\r\n\r\n<h2 id=\"tab4\" >Using a customized editor</h2>\r\nEven if you don't use an integrated development environment, you can use other tools to make your programming life easy. Think, for a moment, about an ordinary text editor — an editor like Windows Notepad. With Notepad you can\r\n<ul>\r\n \t<li>Create a document that has no formatting</li>\r\n</ul>\r\n<ul>\r\n \t<li>Find and replace characters, words, and other strings</li>\r\n</ul>\r\n<ul>\r\n \t<li>Copy, cut, and paste</li>\r\n</ul>\r\n<ul>\r\n \t<li>Print</li>\r\n</ul>\r\n<ul>\r\n \t<li>Not much else</li>\r\n</ul>\r\nNotepad is fine for writing computer programs. But if you plan to do a lot of programming, you may want to try a customized editor. These editors do more than Windows Notepad.\r\n\r\nThey have\r\n<ul>\r\n \t<li>Syntax highlighting</li>\r\n</ul>\r\n<ul>\r\n \t<li>Shortcuts for compiling and running programs</li>\r\n</ul>\r\n<ul>\r\n \t<li>Explorer-like views of your works in progress</li>\r\n</ul>\r\n<ul>\r\n \t<li>Code completion</li>\r\n</ul>\r\n<ul>\r\n \t<li>Other cool stuff</li>\r\n</ul>\r\nWhen it comes to choosing a custom editor, one favorite is IntelliJ IDEA. IntelliJ Idea comes in two different editions: Ultimate Edition or Community Edition. The Community Edition is free. To download the IntelliJ IDEA Community Edition, visit <a href=\"http://www.jetbrains.com/idea/download\" target=\"_blank\" rel=\"noopener\">www.jetbrains.com/idea/download</a>.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"So many ways to write computer programs","target":"#tab1"},{"label":"The Java smorgasbord","target":"#tab2"},{"label":"How do you type this stuff?","target":"#tab3"},{"label":"Using a customized editor","target":"#tab4"}],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1541583\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1541ff6\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":200023},{"headers":{"creationTime":"2016-03-26T22:40:59+00:00","modifiedTime":"2022-01-13T22:40:56+00:00","timestamp":"2022-09-14T18:19:01+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Tackling Error Messages in Java Programming","strippedTitle":"tackling error messages in java programming","slug":"tackling-error-messages-in-java-programming","canonicalUrl":"","seo":{"metaDescription":"Sometimes, error messages can strike fear into the heart of even the bravest programmer. Fortunately some helpful, calming advice is here!","noIndex":0,"noFollow":0},"content":"Sometimes, error messages can strike fear into the heart of even the bravest programmer. Fortunately some helpful, calming advice is here — advice to help you solve the problem when you see one of these messages.\r\n<h2 id=\"tab1\" >NoClassDefFoundError</h2>\r\nYou get this error when you're trying to run your code. So first ask yourself, did you attempt to compile the code? If so, did you see any error messages when you compiled? If you saw error messages, look for things you can fix in your <tt>.java</tt> file. Try to fix these things, and then compile the <tt>.java</tt> file again.\r\n\r\nIf you normally keep code in the <tt>JavaPrograms</tt> directory, make sure that you're still working in this <tt>JavaPrograms</tt> directory. (In Windows, make sure that the command prompt says <tt>JavaPrograms</tt>.)\r\n\r\nMake sure you have an appropriately named <tt>.class</tt> file in your working directory. For instance, if you're trying to run a program named <tt>MyGreatProg</tt>, look for a file named <tt>MyGreatProg.class</tt> in your working directory.\r\n\r\nCheck your classpath to make sure that it contains the <tt>.class</tt> file that you need. For example, if all your Java code is in your working directory, make sure that the classpath includes a dot.\r\n<h2 id=\"tab2\" >NoSuchMethodError</h2>\r\nWhen you encounter this error message, check for the misspelling or inconsistent capitalization of a method name. Check the capitalization of <tt>main</tt> (not <tt>Main</tt>).\r\n\r\nWhen you issue the <tt>java</tt> command (or do whatever you normally do to run a program in your environment), does the class that you're trying to run contain its own <tt>main</tt> method? If not, then find the class with the <tt>main</tt> method and run that class instead.\r\n<h2 id=\"tab3\" >Cannot Resolve Symbol</h2>\r\nIf you get an error message that includes <tt>cannot resolve symbol</tt>, check the spelling and capitalization of all identifiers and keywords. Then check again.\r\n\r\nIf the unresolved symbol is a variable, make sure that this variable's declaration is in the right place. For instance, if the variable is declared in a <tt>for</tt> loop's initialization, are you trying to use that variable outside the <tt>for</tt> loop? If the variable is declared inside a block (a pair of curly braces), are you trying to use that variable outside of the block?\r\n\r\nFinally, look for errors in the variable's declaration. If the compiler finds errors in a variable's declaration, then the compiler can't resolve that variable name in the remainder of the code.\r\n<h2 id=\"tab4\" >Expected ';' (Or Expected Something Else)</h2>\r\nWhen you see an error message that says <tt>';' expected</tt>, go through your code and make sure that each statement and each declaration ends with a semicolon. If so, then maybe the compiler's guess about a missing semicolon is incorrect. Fixing another (seemingly unrelated) error and recompiling your code may get rid of a bogus <tt>';' expected</tt> message.\r\n\r\nFor a missing parenthesis, check the conditions of <tt>if</tt> statements and loops. Make sure each condition is enclosed in parentheses. Also, make sure that a parameter list (enclosed in parentheses) follows the name of each method.\r\n\r\nFor an <tt><identifier> expected</tt> message, check your assignment statements. Make sure that each assignment statement is inside a method. (Remember, a declaration with an initialization can be outside of a method, but each plain old assignment statement must be inside a method.)\r\n\r\nFor the <tt>'class' or 'interface' expected</tt> message, make sure you've spelled the word <tt>class</tt> correctly. If your code has an <tt>import</tt> declaration, check the spelling and capitalization of the word <tt>import</tt>.\r\n<h2 id=\"tab5\" >Missing Method Body or Declare Abstract</h2>\r\nYou get a <tt>missing method body or declare abstract</tt> message when the compiler sees a method header, but the compiler can't find the method's body. Look at the end of the method's header. If you ended the header with a semicolon, then try removing the semicolon.\r\n\r\nIf the header doesn't end with a semicolon, then check the code immediately following the header. The code immediately following the header should start with an open curly brace (the beginning of a method body). If some code comes between the header and the body's open curly brace, consider moving that code somewhere else.\r\n<h2 id=\"tab6\" >An 'else' without an 'if'</h2>\r\nCompare the number of <tt>if</tt> clauses with the number of <tt>else</tt> clauses. An <tt>if</tt> clause doesn't need to have an <tt>else</tt> clause, but each <tt>else</tt> clause must belong to an <tt>if</tt> clause.\r\n\r\nRemember, you enclose an <tt>if</tt> condition in parentheses, but you don't put a semicolon after the condition. Did you mistakenly end an <tt>if</tt> condition with a semicolon?\r\n\r\nLook at all the lines between an <tt>if</tt> and its <tt>else</tt>. When you find more than one statement between an <tt>if</tt> and its <tt>else</tt>, look for curly braces. If the statements between the <tt>if</tt> and its <tt>else</tt> aren't surrounded by curly braces, you may have found the culprit.\r\n<h2 id=\"tab7\" >Non-static Variable Cannot Be Referenced from a Static Context</h2>\r\nLots of things can give you a <tt>non-static variable cannot be referenced from a static context</tt> error message. But for beginning programmers, the most common cause is having a variable that's declared outside of the <tt>main</tt> method. It's no sin to declare such a variable, but because the <tt>main</tt> method is always <tt>static</tt>, you need some special help to make the <tt>main</tt> method refer to a variable that's declared outside the <tt>main</tt> method.\r\n\r\nThe quickest solution is to put the word <tt>static</tt> in front of the variable's declaration. But first, ask yourself why this variable's declaration isn't inside the <tt>main</tt> method. If there's no good reason, then move the variable's declaration so that it's inside the <tt>main</tt> method.\r\n<h2 id=\"tab8\" >FileNotFoundException (The System Cannot Find the File Specified) or EOFException</h2>\r\nIf you encounter a <tt>FileNotFoundException</tt> message, check that the file named in your code actually exists. (Look for the file using your system's explorer or using the command prompt window.) Double-check the spelling in your code against the name of the file on your hard drive.\r\n\r\nIf you've found a correctly named file on your hard drive, make sure that the file is in the correct directory. (For a program running in your working directory, a typical data file is in the working directory also.)\r\n\r\nIf you're a Windows user, make sure that the system didn't add an extra <tt>.txt</tt> extension when you created the file. (Use the command prompt window to check the file's name. Windows Explorer can hide the <tt>.txt</tt> extension, and that always leads to confusion.)\r\n\r\nFor an <tt>EOFException</tt>, you're probably trying to read more data than you have in the file. Very often, a small logic error makes your program do this. So do a careful review of all the steps in your program's execution. Look for subtle things, like improperly primed loops or the reading of array values past the array's largest index. Look for conditions that use <tt><=</tt> when they should use <tt><</tt>. Conditions like these can often be troublesome.","description":"Sometimes, error messages can strike fear into the heart of even the bravest programmer. Fortunately some helpful, calming advice is here — advice to help you solve the problem when you see one of these messages.\r\n<h2 id=\"tab1\" >NoClassDefFoundError</h2>\r\nYou get this error when you're trying to run your code. So first ask yourself, did you attempt to compile the code? If so, did you see any error messages when you compiled? If you saw error messages, look for things you can fix in your <tt>.java</tt> file. Try to fix these things, and then compile the <tt>.java</tt> file again.\r\n\r\nIf you normally keep code in the <tt>JavaPrograms</tt> directory, make sure that you're still working in this <tt>JavaPrograms</tt> directory. (In Windows, make sure that the command prompt says <tt>JavaPrograms</tt>.)\r\n\r\nMake sure you have an appropriately named <tt>.class</tt> file in your working directory. For instance, if you're trying to run a program named <tt>MyGreatProg</tt>, look for a file named <tt>MyGreatProg.class</tt> in your working directory.\r\n\r\nCheck your classpath to make sure that it contains the <tt>.class</tt> file that you need. For example, if all your Java code is in your working directory, make sure that the classpath includes a dot.\r\n<h2 id=\"tab2\" >NoSuchMethodError</h2>\r\nWhen you encounter this error message, check for the misspelling or inconsistent capitalization of a method name. Check the capitalization of <tt>main</tt> (not <tt>Main</tt>).\r\n\r\nWhen you issue the <tt>java</tt> command (or do whatever you normally do to run a program in your environment), does the class that you're trying to run contain its own <tt>main</tt> method? If not, then find the class with the <tt>main</tt> method and run that class instead.\r\n<h2 id=\"tab3\" >Cannot Resolve Symbol</h2>\r\nIf you get an error message that includes <tt>cannot resolve symbol</tt>, check the spelling and capitalization of all identifiers and keywords. Then check again.\r\n\r\nIf the unresolved symbol is a variable, make sure that this variable's declaration is in the right place. For instance, if the variable is declared in a <tt>for</tt> loop's initialization, are you trying to use that variable outside the <tt>for</tt> loop? If the variable is declared inside a block (a pair of curly braces), are you trying to use that variable outside of the block?\r\n\r\nFinally, look for errors in the variable's declaration. If the compiler finds errors in a variable's declaration, then the compiler can't resolve that variable name in the remainder of the code.\r\n<h2 id=\"tab4\" >Expected ';' (Or Expected Something Else)</h2>\r\nWhen you see an error message that says <tt>';' expected</tt>, go through your code and make sure that each statement and each declaration ends with a semicolon. If so, then maybe the compiler's guess about a missing semicolon is incorrect. Fixing another (seemingly unrelated) error and recompiling your code may get rid of a bogus <tt>';' expected</tt> message.\r\n\r\nFor a missing parenthesis, check the conditions of <tt>if</tt> statements and loops. Make sure each condition is enclosed in parentheses. Also, make sure that a parameter list (enclosed in parentheses) follows the name of each method.\r\n\r\nFor an <tt><identifier> expected</tt> message, check your assignment statements. Make sure that each assignment statement is inside a method. (Remember, a declaration with an initialization can be outside of a method, but each plain old assignment statement must be inside a method.)\r\n\r\nFor the <tt>'class' or 'interface' expected</tt> message, make sure you've spelled the word <tt>class</tt> correctly. If your code has an <tt>import</tt> declaration, check the spelling and capitalization of the word <tt>import</tt>.\r\n<h2 id=\"tab5\" >Missing Method Body or Declare Abstract</h2>\r\nYou get a <tt>missing method body or declare abstract</tt> message when the compiler sees a method header, but the compiler can't find the method's body. Look at the end of the method's header. If you ended the header with a semicolon, then try removing the semicolon.\r\n\r\nIf the header doesn't end with a semicolon, then check the code immediately following the header. The code immediately following the header should start with an open curly brace (the beginning of a method body). If some code comes between the header and the body's open curly brace, consider moving that code somewhere else.\r\n<h2 id=\"tab6\" >An 'else' without an 'if'</h2>\r\nCompare the number of <tt>if</tt> clauses with the number of <tt>else</tt> clauses. An <tt>if</tt> clause doesn't need to have an <tt>else</tt> clause, but each <tt>else</tt> clause must belong to an <tt>if</tt> clause.\r\n\r\nRemember, you enclose an <tt>if</tt> condition in parentheses, but you don't put a semicolon after the condition. Did you mistakenly end an <tt>if</tt> condition with a semicolon?\r\n\r\nLook at all the lines between an <tt>if</tt> and its <tt>else</tt>. When you find more than one statement between an <tt>if</tt> and its <tt>else</tt>, look for curly braces. If the statements between the <tt>if</tt> and its <tt>else</tt> aren't surrounded by curly braces, you may have found the culprit.\r\n<h2 id=\"tab7\" >Non-static Variable Cannot Be Referenced from a Static Context</h2>\r\nLots of things can give you a <tt>non-static variable cannot be referenced from a static context</tt> error message. But for beginning programmers, the most common cause is having a variable that's declared outside of the <tt>main</tt> method. It's no sin to declare such a variable, but because the <tt>main</tt> method is always <tt>static</tt>, you need some special help to make the <tt>main</tt> method refer to a variable that's declared outside the <tt>main</tt> method.\r\n\r\nThe quickest solution is to put the word <tt>static</tt> in front of the variable's declaration. But first, ask yourself why this variable's declaration isn't inside the <tt>main</tt> method. If there's no good reason, then move the variable's declaration so that it's inside the <tt>main</tt> method.\r\n<h2 id=\"tab8\" >FileNotFoundException (The System Cannot Find the File Specified) or EOFException</h2>\r\nIf you encounter a <tt>FileNotFoundException</tt> message, check that the file named in your code actually exists. (Look for the file using your system's explorer or using the command prompt window.) Double-check the spelling in your code against the name of the file on your hard drive.\r\n\r\nIf you've found a correctly named file on your hard drive, make sure that the file is in the correct directory. (For a program running in your working directory, a typical data file is in the working directory also.)\r\n\r\nIf you're a Windows user, make sure that the system didn't add an extra <tt>.txt</tt> extension when you created the file. (Use the command prompt window to check the file's name. Windows Explorer can hide the <tt>.txt</tt> extension, and that always leads to confusion.)\r\n\r\nFor an <tt>EOFException</tt>, you're probably trying to read more data than you have in the file. Very often, a small logic error makes your program do this. So do a careful review of all the steps in your program's execution. Look for subtle things, like improperly primed loops or the reading of array values past the array's largest index. Look for conditions that use <tt><=</tt> when they should use <tt><</tt>. Conditions like these can often be troublesome.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"NoClassDefFoundError","target":"#tab1"},{"label":"NoSuchMethodError","target":"#tab2"},{"label":"Cannot Resolve Symbol","target":"#tab3"},{"label":"Expected ';' (Or Expected Something Else)","target":"#tab4"},{"label":"Missing Method Body or Declare Abstract","target":"#tab5"},{"label":"An 'else' without an 'if'","target":"#tab6"},{"label":"Non-static Variable Cannot Be Referenced from a Static Context","target":"#tab7"},{"label":"FileNotFoundException (The System Cannot Find the File Specified) or EOFException","target":"#tab8"}],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b153839a\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1538e27\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":199123},{"headers":{"creationTime":"2016-03-26T11:09:18+00:00","modifiedTime":"2022-01-13T22:12:08+00:00","timestamp":"2022-09-14T18:19:01+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"How to Generate Words Randomly in Java","strippedTitle":"how to generate words randomly in java","slug":"how-to-generate-words-randomly-in-java","canonicalUrl":"","seo":{"metaDescription":"Most Java programs don’t work correctly the first time you run them, and some programs don’t work without extensive trial and error on your part. This code is a","noIndex":0,"noFollow":0},"content":"Most Java programs don’t work correctly the first time you run them, and some programs don’t work without extensive trial and error on your part. This code is a case in point.\r\n\r\nTo write this code, you need a way to generate three-letter words randomly. This code would give you the desired result:\r\n<pre class=\"code\">anAccount.lastName = \" +\r\n (char) (myRandom.nextInt(26) + 'A') +\r\n (char) (myRandom.nextInt(26) + 'a') +\r\n (char) (myRandom.nextInt(26) + 'a');</pre>\r\nHere’s how the code works:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">Each call to the <span class=\"code\">Random.nextInt(26) </span>generates a number from 0 to 25.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Adding <span class=\"code\">'A' </span>gives you a number from 65 to 90.</p>\r\n<p class=\"child-para\">To store a letter <span class=\"code\">'A'</span>, the computer puts the number 65 in its memory. That’s why adding <span class=\"code\">'A'</span> to 0 gives you 65 and why adding <span class=\"code\">'A'</span> to 25 gives you 90.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Applying <span class=\"code\">(char) </span>to a number turns the number into a <span class=\"code\">char </span>value.</p>\r\n<p class=\"child-para\">To store the letters <span class=\"code\">'A'</span> through <span class=\"code\">'Z'</span>, the computer puts the numbers 65 through 90 in its memory. So applying <span class=\"code\">(char)</span> to a number from 65 to 90 turns the number into an uppercase letter.</p>\r\n</li>\r\n</ul>\r\nPause for a brief summary. The expression <span class=\"code\">(char) (myRandom.nextInt(26) + 'A')</span> represents a randomly generated uppercase letter. In a similar way, <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> represents a randomly generated lowercase letter.\r\n\r\nWatch out! The next couple of steps can be tricky.\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">Java doesn’t allow you to assign a <span class=\"code\">char </span>value to a string variable.</p>\r\n<p class=\"child-para\">The following statement would lead to a compiler error:</p>\r\n\r\n<pre class=\"code\">//Bad statement:\r\nanAccount.lastName = (char) (myRandom.nextInt(26) + 'A');</pre>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">In Java, you can use a plus sign to add a <span class=\"code\">char </span>value to a string. When you do, the result is a string.</p>\r\n<p class=\"child-para\">So <span class=\"code\">\"\" + (char) (myRandom.nextInt(26) + 'A')</span> is a string containing one randomly generated uppercase character. And when you add <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> onto the end of that string, you get another string — a string containing two randomly generated characters</p>\r\n<p class=\"child-para\">Finally, when you add another <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> onto the end of that string, you get a string containing three randomly generated characters. So you can assign that big string to <span class=\"code\">anAccount.lastName</span>. That’s how the statement works.</p>\r\n</li>\r\n</ul>\r\nWhen you write a program, you have to be very careful with numbers, <span class=\"code\">char</span> values, and strings. This isn’t the kind of programming you do every day of the week, but it is a lesson that you need to be persistent in your Java programming.","description":"Most Java programs don’t work correctly the first time you run them, and some programs don’t work without extensive trial and error on your part. This code is a case in point.\r\n\r\nTo write this code, you need a way to generate three-letter words randomly. This code would give you the desired result:\r\n<pre class=\"code\">anAccount.lastName = \" +\r\n (char) (myRandom.nextInt(26) + 'A') +\r\n (char) (myRandom.nextInt(26) + 'a') +\r\n (char) (myRandom.nextInt(26) + 'a');</pre>\r\nHere’s how the code works:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">Each call to the <span class=\"code\">Random.nextInt(26) </span>generates a number from 0 to 25.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Adding <span class=\"code\">'A' </span>gives you a number from 65 to 90.</p>\r\n<p class=\"child-para\">To store a letter <span class=\"code\">'A'</span>, the computer puts the number 65 in its memory. That’s why adding <span class=\"code\">'A'</span> to 0 gives you 65 and why adding <span class=\"code\">'A'</span> to 25 gives you 90.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Applying <span class=\"code\">(char) </span>to a number turns the number into a <span class=\"code\">char </span>value.</p>\r\n<p class=\"child-para\">To store the letters <span class=\"code\">'A'</span> through <span class=\"code\">'Z'</span>, the computer puts the numbers 65 through 90 in its memory. So applying <span class=\"code\">(char)</span> to a number from 65 to 90 turns the number into an uppercase letter.</p>\r\n</li>\r\n</ul>\r\nPause for a brief summary. The expression <span class=\"code\">(char) (myRandom.nextInt(26) + 'A')</span> represents a randomly generated uppercase letter. In a similar way, <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> represents a randomly generated lowercase letter.\r\n\r\nWatch out! The next couple of steps can be tricky.\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">Java doesn’t allow you to assign a <span class=\"code\">char </span>value to a string variable.</p>\r\n<p class=\"child-para\">The following statement would lead to a compiler error:</p>\r\n\r\n<pre class=\"code\">//Bad statement:\r\nanAccount.lastName = (char) (myRandom.nextInt(26) + 'A');</pre>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">In Java, you can use a plus sign to add a <span class=\"code\">char </span>value to a string. When you do, the result is a string.</p>\r\n<p class=\"child-para\">So <span class=\"code\">\"\" + (char) (myRandom.nextInt(26) + 'A')</span> is a string containing one randomly generated uppercase character. And when you add <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> onto the end of that string, you get another string — a string containing two randomly generated characters</p>\r\n<p class=\"child-para\">Finally, when you add another <span class=\"code\">(char) (myRandom.nextInt(26) + 'a')</span> onto the end of that string, you get a string containing three randomly generated characters. So you can assign that big string to <span class=\"code\">anAccount.lastName</span>. That’s how the statement works.</p>\r\n</li>\r\n</ul>\r\nWhen you write a program, you have to be very careful with numbers, <span class=\"code\">char</span> values, and strings. This isn’t the kind of programming you do every day of the week, but it is a lesson that you need to be persistent in your Java programming.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b152f027\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b152f908\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":150866},{"headers":{"creationTime":"2016-03-26T11:08:24+00:00","modifiedTime":"2022-01-13T19:00:45+00:00","timestamp":"2022-09-14T18:19:01+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"How to Write Java Code to Show an Image on the Screen","strippedTitle":"how to write java code to show an image on the screen","slug":"how-to-write-java-code-to-show-an-image-on-the-screen","canonicalUrl":"","seo":{"metaDescription":"Java code to add an image may seem to have very little logic of its own, but don't worry. Follow this simple guide to help you.","noIndex":0,"noFollow":0},"content":"You will probably find times when programming with Java that you need to display a window on your computer screen. This code has very little logic of its own. Instead, this code pulls together a bunch of classes from the Java API.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434454.image0.jpg\" alt=\"image0.jpg\" width=\"303\" height=\"400\" />\r\n<pre class=\"code\">import javax.swing.JFrame;\r\nimport javax.swing.ImageIcon;\r\nimport javax.swing.JLabel;\r\nclass ShowPicture {\r\n public static void main(String args[]) {\r\n var frame = new JFrame();\r\n var icon = new ImageIcon(\"androidBook.jpg\");\r\n var label = new JLabel(icon);\r\n frame.add(label);\r\n frame.setDefaultCloseOperation\r\n (JFrame.EXIT_ON_CLOSE);\r\n frame.pack();\r\n frame.setVisible(true);\r\n }\r\n}</pre>\r\nYou can create an instance of the <span class=\"code\">Purchase</span> class with the line\r\n<pre class=\"code\">var purchase1 = new Purchase();</pre>\r\nSo in the code, you can do the same kind of thing. You can create instances of the <span class=\"code\">JFrame</span>, <span class=\"code\">ImageIcon</span>, and <span class=\"code\">JLabel</span> classes with the following lines:\r\n<pre class=\"code\">var frame = new JFrame();\r\nvar icon = new ImageIcon(\"androidBook.jpg\");\r\nvar label = new JLabel(icon);</pre>\r\nHere’s some gossip about each of these lines:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">A <span class=\"code\">JFrame</span> is like a window (except that it’s called a <span class=\"code\">JFrame</span>, not a “window”). The line</p>\r\n\r\n<pre class=\"code\">var frame = new JFrame();</pre>\r\n<p class=\"child-para\">creates a <span class=\"code\">JFrame</span> object, but this line doesn’t display the <span class=\"code\">JFrame</span> object anywhere. (The displaying comes later in the code.)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">An <span class=\"code\">ImageIcon</span> object is a picture. At the root of the program's project directory, there is a file named <span class=\"code\">androidBook.jpg</span>. That file contains the picture. The line</p>\r\n\r\n<pre class=\"code\">var icon = new ImageIcon(\"androidBook.jpg\");</pre>\r\n<p class=\"child-para\">creates an <span class=\"code\">ImageIcon</span> object — an icon containing the <span class=\"code\">androidBook.jpg</span> picture.</p>\r\n<p class=\"child-para Remember\">You can use almost any <span class=\"code\">.gif</span>, <span class=\"code\">.jpg</span>, or <span class=\"code\">.png</span> file in place of the (lovely) Android book cover image. To do so, drag your own image file to Eclipse's Package Explorer. (Drag it to the root of this example's project folder.) Then, in Eclipse's editor, change the name <span class=\"code\">androidBook.jpg</span> to your own image file's name. That's it!</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">You need a place to put the icon. You can put it on something called a <span class=\"code\">JLabel</span>. The line</p>\r\n\r\n<pre class=\"code\">var label = new JLabel(icon);</pre>\r\n<p class=\"child-para\">creates a <span class=\"code\">JLabel</span> object and puts the <span class=\"code\">androidBook.jpg</span> icon on the new label’s face.</p>\r\n</li>\r\n</ul>\r\nIf you read the previous bullets, you may get a false impression. The wording may suggest that the use of each component (<span class=\"code\">JFrame</span>, <span class=\"code\">ImageIcon</span>, <span class=\"code\">JLabel</span>, and so on) is a logical extension of what you already know. “Where do you put an <span class=\"code\">ImageIcon</span>?\r\n\r\nWell of course, you put it on a <span class=\"code\">JLabel</span>.” When you’ve worked long and hard with Java’s Swing components, all these things become natural to you. But until then, you look everything up in Java's API documentation.\r\n<p class=\"Remember\">You never need to memorize the names or features of Java’s API classes. Instead, you keep Java’s API documentation handy. When you need to know about a class, you look it up in the documentation. If you need a certain class often enough, you’ll remember its features. For classes that you don’t use often, you always have the docs.</p>","description":"You will probably find times when programming with Java that you need to display a window on your computer screen. This code has very little logic of its own. Instead, this code pulls together a bunch of classes from the Java API.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434454.image0.jpg\" alt=\"image0.jpg\" width=\"303\" height=\"400\" />\r\n<pre class=\"code\">import javax.swing.JFrame;\r\nimport javax.swing.ImageIcon;\r\nimport javax.swing.JLabel;\r\nclass ShowPicture {\r\n public static void main(String args[]) {\r\n var frame = new JFrame();\r\n var icon = new ImageIcon(\"androidBook.jpg\");\r\n var label = new JLabel(icon);\r\n frame.add(label);\r\n frame.setDefaultCloseOperation\r\n (JFrame.EXIT_ON_CLOSE);\r\n frame.pack();\r\n frame.setVisible(true);\r\n }\r\n}</pre>\r\nYou can create an instance of the <span class=\"code\">Purchase</span> class with the line\r\n<pre class=\"code\">var purchase1 = new Purchase();</pre>\r\nSo in the code, you can do the same kind of thing. You can create instances of the <span class=\"code\">JFrame</span>, <span class=\"code\">ImageIcon</span>, and <span class=\"code\">JLabel</span> classes with the following lines:\r\n<pre class=\"code\">var frame = new JFrame();\r\nvar icon = new ImageIcon(\"androidBook.jpg\");\r\nvar label = new JLabel(icon);</pre>\r\nHere’s some gossip about each of these lines:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">A <span class=\"code\">JFrame</span> is like a window (except that it’s called a <span class=\"code\">JFrame</span>, not a “window”). The line</p>\r\n\r\n<pre class=\"code\">var frame = new JFrame();</pre>\r\n<p class=\"child-para\">creates a <span class=\"code\">JFrame</span> object, but this line doesn’t display the <span class=\"code\">JFrame</span> object anywhere. (The displaying comes later in the code.)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">An <span class=\"code\">ImageIcon</span> object is a picture. At the root of the program's project directory, there is a file named <span class=\"code\">androidBook.jpg</span>. That file contains the picture. The line</p>\r\n\r\n<pre class=\"code\">var icon = new ImageIcon(\"androidBook.jpg\");</pre>\r\n<p class=\"child-para\">creates an <span class=\"code\">ImageIcon</span> object — an icon containing the <span class=\"code\">androidBook.jpg</span> picture.</p>\r\n<p class=\"child-para Remember\">You can use almost any <span class=\"code\">.gif</span>, <span class=\"code\">.jpg</span>, or <span class=\"code\">.png</span> file in place of the (lovely) Android book cover image. To do so, drag your own image file to Eclipse's Package Explorer. (Drag it to the root of this example's project folder.) Then, in Eclipse's editor, change the name <span class=\"code\">androidBook.jpg</span> to your own image file's name. That's it!</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">You need a place to put the icon. You can put it on something called a <span class=\"code\">JLabel</span>. The line</p>\r\n\r\n<pre class=\"code\">var label = new JLabel(icon);</pre>\r\n<p class=\"child-para\">creates a <span class=\"code\">JLabel</span> object and puts the <span class=\"code\">androidBook.jpg</span> icon on the new label’s face.</p>\r\n</li>\r\n</ul>\r\nIf you read the previous bullets, you may get a false impression. The wording may suggest that the use of each component (<span class=\"code\">JFrame</span>, <span class=\"code\">ImageIcon</span>, <span class=\"code\">JLabel</span>, and so on) is a logical extension of what you already know. “Where do you put an <span class=\"code\">ImageIcon</span>?\r\n\r\nWell of course, you put it on a <span class=\"code\">JLabel</span>.” When you’ve worked long and hard with Java’s Swing components, all these things become natural to you. But until then, you look everything up in Java's API documentation.\r\n<p class=\"Remember\">You never need to memorize the names or features of Java’s API classes. Instead, you keep Java’s API documentation handy. When you need to know about a class, you look it up in the documentation. If you need a certain class often enough, you’ll remember its features. For classes that you don’t use often, you always have the docs.</p>","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1527320\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1527d8d\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":150767},{"headers":{"creationTime":"2016-03-26T11:08:16+00:00","modifiedTime":"2022-01-05T19:33:10+00:00","timestamp":"2022-09-14T18:18:59+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"How to Store Values in an Array in Java","strippedTitle":"how to store values in an array in java","slug":"how-to-store-values-in-an-array-in-java","canonicalUrl":"","seo":{"metaDescription":"After you’ve created an array in Java, follow this simple guide to put values into the array’s components.","noIndex":0,"noFollow":0},"content":"After you’ve created an array in Java, you can put values into the array’s components. For example, imagine you are the owner of a motel. The guests in Room 6 are fed up with all those mint candies that you put on peoples’ beds. They check out, and Room 6 becomes vacant. You should put the value 0 into the 6 component. You can do it with this assignment statement:\r\n<pre class=\"code\">guestsIn[6] = 0;</pre>\r\nOn one weekday, business is awful. No one’s staying at the motel. But then you get a lucky break. A big bus pulls up to the motel. The side of the bus has a sign that says “Loners’ Convention.” Out of the bus come 25 people, each walking to the motel’s small office, none paying attention to the others who were on the bus. Each person wants a private room.\r\n\r\nOnly 10 of them can stay at the Java Motel, but that’s okay, because you can send the other 15 loners down the road to the old C-Side Resort and Motor Lodge.\r\n\r\nAnyway, to register ten of the loners into the Java Motel, you put one guest in each of your ten rooms. Having created an array, you can take advantage of the array’s indexing and write a <span class=\"code\">for</span> loop, like this:\r\n<pre class=\"code\">for (int roomNum = 0; roomNum &lt; 10; roomNum++) {\r\n guestsIn[roomNum] = 1;\r\n}</pre>\r\nThis loop takes the place of ten assignment statements because the computer executes the statement <span class=\"code\">guestsIn[roomNum] = 1</span> ten times. The first time around, the value of <span class=\"code\">roomNum</span> is 0, so in effect, the computer executes\r\n<pre class=\"code\">guestsIn[&lt;b&gt;0&lt;/b&gt;] = 1;</pre>\r\nIn the next loop iteration, the value of <span class=\"code\">roomNum</span> is 1, so the computer executes the equivalent of the following statement:\r\n<pre class=\"code\">guestsIn[&lt;b&gt;1&lt;/b&gt;] = 1;</pre>\r\nDuring the next iteration, the computer behaves as if it’s executing\r\n<pre class=\"code\">guestsIn[&lt;b&gt;2&lt;/b&gt;] = 1;</pre>\r\nAnd so on. When <span class=\"code\">roomNum</span> gets to be 9, the computer executes the equivalent of the following statement:\r\n<pre class=\"code\">guestsIn[&lt;b&gt;9&lt;/b&gt;] = 1;</pre>\r\nNotice that the loop’s counter goes from 0 to 9. Remember that the indices of an array go from 0 to one fewer than the number of components in the array. Looping with room numbers from 0 to 9 covers all the rooms in the Java Motel.\r\n<p class=\"Remember\">When you work with an array, and you step through the array’s components using a <span class=\"code\">for</span> loop, you normally start the loop’s counter variable at 0. To form the condition that tests for another iteration, you often write an expression like <span class=\"code\">roomNum < </span><span class=\"code\"><i>arraySize</i></span>, where <span class=\"code\"><i>arraySize</i></span> is the number of components in the array.</p>","description":"After you’ve created an array in Java, you can put values into the array’s components. For example, imagine you are the owner of a motel. The guests in Room 6 are fed up with all those mint candies that you put on peoples’ beds. They check out, and Room 6 becomes vacant. You should put the value 0 into the 6 component. You can do it with this assignment statement:\r\n<pre class=\"code\">guestsIn[6] = 0;</pre>\r\nOn one weekday, business is awful. No one’s staying at the motel. But then you get a lucky break. A big bus pulls up to the motel. The side of the bus has a sign that says “Loners’ Convention.” Out of the bus come 25 people, each walking to the motel’s small office, none paying attention to the others who were on the bus. Each person wants a private room.\r\n\r\nOnly 10 of them can stay at the Java Motel, but that’s okay, because you can send the other 15 loners down the road to the old C-Side Resort and Motor Lodge.\r\n\r\nAnyway, to register ten of the loners into the Java Motel, you put one guest in each of your ten rooms. Having created an array, you can take advantage of the array’s indexing and write a <span class=\"code\">for</span> loop, like this:\r\n<pre class=\"code\">for (int roomNum = 0; roomNum &lt; 10; roomNum++) {\r\n guestsIn[roomNum] = 1;\r\n}</pre>\r\nThis loop takes the place of ten assignment statements because the computer executes the statement <span class=\"code\">guestsIn[roomNum] = 1</span> ten times. The first time around, the value of <span class=\"code\">roomNum</span> is 0, so in effect, the computer executes\r\n<pre class=\"code\">guestsIn[&lt;b&gt;0&lt;/b&gt;] = 1;</pre>\r\nIn the next loop iteration, the value of <span class=\"code\">roomNum</span> is 1, so the computer executes the equivalent of the following statement:\r\n<pre class=\"code\">guestsIn[&lt;b&gt;1&lt;/b&gt;] = 1;</pre>\r\nDuring the next iteration, the computer behaves as if it’s executing\r\n<pre class=\"code\">guestsIn[&lt;b&gt;2&lt;/b&gt;] = 1;</pre>\r\nAnd so on. When <span class=\"code\">roomNum</span> gets to be 9, the computer executes the equivalent of the following statement:\r\n<pre class=\"code\">guestsIn[&lt;b&gt;9&lt;/b&gt;] = 1;</pre>\r\nNotice that the loop’s counter goes from 0 to 9. Remember that the indices of an array go from 0 to one fewer than the number of components in the array. Looping with room numbers from 0 to 9 covers all the rooms in the Java Motel.\r\n<p class=\"Remember\">When you work with an array, and you step through the array’s components using a <span class=\"code\">for</span> loop, you normally start the loop’s counter variable at 0. To form the condition that tests for another iteration, you often write an expression like <span class=\"code\">roomNum < </span><span class=\"code\"><i>arraySize</i></span>, where <span class=\"code\"><i>arraySize</i></span> is the number of components in the array.</p>","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b138fb21\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b139039d\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-05T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":150754},{"headers":{"creationTime":"2016-03-26T11:08:11+00:00","modifiedTime":"2022-01-05T19:27:37+00:00","timestamp":"2022-09-14T18:18:59+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"Java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"},"slug":"java","categoryId":33602}],"title":"Tips for Beginning Java Programmers: Variables and Recycling","strippedTitle":"tips for beginning java programmers: variables and recycling","slug":"tips-for-beginning-java-programmers-variables-and-recycling","canonicalUrl":"","seo":{"metaDescription":"These are just a few things beginning Java programmers should know about variables and recycling before getting started.","noIndex":0,"noFollow":0},"content":"There are a few things beginning Java programmers should know about variables and recycling. When you assign a new value to <span class=\"code\">smallLetter</span>, the old value of <span class=\"code\">smallLetter</span> gets obliterated. <span class=\"code\">smallLetter</span> is used twice, and <span class=\"code\">bigLetter</span> is used twice. That’s why they call these things <i>variables.</i>\r\n\r\nFirst, the value of <span class=\"code\">smallLetter</span> is <span class=\"code\">R</span>. Later, the value of <span class=\"code\">smallLetter</span> is varied so that the value of <span class=\"code\">smallLetter</span> becomes <span class=\"code\">3</span><span class=\"code\">. </span>When the computer executes this second assignment statement, the old value <span class=\"code\">R</span> is gone.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434439.image0.jpg\" alt=\"Two results for the variable SmallLetter in a Java code.\" width=\"535\" height=\"244\" />\r\n\r\nIs that okay? Can you afford to forget the value that <span class=\"code\">smallLetter</span> once had? Yes, sometimes, it’s okay. After you’ve assigned a value to <span class=\"code\">bigLetter</span> with the statement\r\n<pre class=\"code\">bigLetter = Character.toUpperCase(smallLetter);</pre>\r\nyou can forget all about the existing <span class=\"code\">smallLetter</span> value. You don’t need to do this:\r\n<pre class=\"code\">&lt;b&gt;// This code is cumbersome.&lt;/b&gt;\r\n&lt;b&gt;// The extra variables are unnecessary.&lt;/b&gt;\r\nchar &lt;b&gt;smallLetter1&lt;/b&gt;, bigLetter1;\r\nchar &lt;b&gt;smallLetter2&lt;/b&gt;, bigLetter2;\r\n&lt;b&gt;smallLetter1&lt;/b&gt; = 'R';\r\nbigLetter1 = Character.toUpperCase(smallLetter1);\r\nSystem.out.println(bigLetter1);\r\n&lt;b&gt;smallLetter2&lt;/b&gt; = '3';\r\nbigLetter2 = Character.toUpperCase(smallLetter2);\r\nSystem.out.println(bigLetter2);</pre>\r\nYou don’t need to store the old and new values in separate variables. Instead, you can reuse the variables <span class=\"code\">smallLetter</span> and <span class=\"code\">bigLetter</span>.\r\n\r\nThis reuse of variables doesn’t save you from a lot of extra typing. It doesn’t save much memory space, either. But reusing variables keeps the program uncluttered. Sometimes, you can see at a glance that the code has two parts, and you see that both parts do roughly the same thing.\r\n\r\nIn such a small program, simplicity and manageability don’t matter very much. But in a large program, it helps to think carefully about the use of each variable.","description":"There are a few things beginning Java programmers should know about variables and recycling. When you assign a new value to <span class=\"code\">smallLetter</span>, the old value of <span class=\"code\">smallLetter</span> gets obliterated. <span class=\"code\">smallLetter</span> is used twice, and <span class=\"code\">bigLetter</span> is used twice. That’s why they call these things <i>variables.</i>\r\n\r\nFirst, the value of <span class=\"code\">smallLetter</span> is <span class=\"code\">R</span>. Later, the value of <span class=\"code\">smallLetter</span> is varied so that the value of <span class=\"code\">smallLetter</span> becomes <span class=\"code\">3</span><span class=\"code\">. </span>When the computer executes this second assignment statement, the old value <span class=\"code\">R</span> is gone.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434439.image0.jpg\" alt=\"Two results for the variable SmallLetter in a Java code.\" width=\"535\" height=\"244\" />\r\n\r\nIs that okay? Can you afford to forget the value that <span class=\"code\">smallLetter</span> once had? Yes, sometimes, it’s okay. After you’ve assigned a value to <span class=\"code\">bigLetter</span> with the statement\r\n<pre class=\"code\">bigLetter = Character.toUpperCase(smallLetter);</pre>\r\nyou can forget all about the existing <span class=\"code\">smallLetter</span> value. You don’t need to do this:\r\n<pre class=\"code\">&lt;b&gt;// This code is cumbersome.&lt;/b&gt;\r\n&lt;b&gt;// The extra variables are unnecessary.&lt;/b&gt;\r\nchar &lt;b&gt;smallLetter1&lt;/b&gt;, bigLetter1;\r\nchar &lt;b&gt;smallLetter2&lt;/b&gt;, bigLetter2;\r\n&lt;b&gt;smallLetter1&lt;/b&gt; = 'R';\r\nbigLetter1 = Character.toUpperCase(smallLetter1);\r\nSystem.out.println(bigLetter1);\r\n&lt;b&gt;smallLetter2&lt;/b&gt; = '3';\r\nbigLetter2 = Character.toUpperCase(smallLetter2);\r\nSystem.out.println(bigLetter2);</pre>\r\nYou don’t need to store the old and new values in separate variables. Instead, you can reuse the variables <span class=\"code\">smallLetter</span> and <span class=\"code\">bigLetter</span>.\r\n\r\nThis reuse of variables doesn’t save you from a lot of extra typing. It doesn’t save much memory space, either. But reusing variables keeps the program uncluttered. Sometimes, you can see at a glance that the code has two parts, and you see that both parts do roughly the same thing.\r\n\r\nIn such a small program, simplicity and manageability don’t matter very much. But in a large program, it helps to think carefully about the use of each variable.","blurb":"","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"primaryCategoryTaxonomy":{"categoryId":33602,"title":"Java","slug":"java","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":290326,"title":"Firing up IntelliJ IDEA","slug":"firing-up-intellij-idea","categoryList":["technology"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290326"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}},{"articleId":245138,"title":"Let the Objects Do the Work in Java","slug":"let-objects-work-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245138"}}],"fromCategory":[{"articleId":275099,"title":"How to Download and Install TextPad","slug":"how-to-download-and-install-textpad","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275099"}},{"articleId":275089,"title":"Important Features of the Java Language","slug":"important-features-of-the-java-language","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/275089"}},{"articleId":245151,"title":"How to Install JavaFX and Scene Builder","slug":"install-javafx-scene-builder","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245151"}},{"articleId":245148,"title":"A Few Things about Java GUIs","slug":"things-java-guis","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245148"}},{"articleId":245141,"title":"Getting a Value from a Method in Java","slug":"getting-value-method-java","categoryList":["technology","programming-web-design","java"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/245141"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281636,"slug":"beginning-programming-with-java-for-dummies","isbn":"9781119806912","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119806917-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119806917/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-programming-with-java-for-dummies-6th-edition-cover-9781119806912-203x255.jpg","width":203,"height":255},"title":"Beginning Programming with Java For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b>Dr. <b data-author-id=\"9069\">Barry Burd</b></b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p>","authors":[{"authorId":9069,"name":"Barry Burd","slug":"barry-burd","description":" <p><b>Dr. Barry Burd</b> holds an M.S. in Computer Science from Rutgers University and a Ph.D. in Mathematics from the University of Illinois. Barry is also the author of <i>Beginning Programming with Java For Dummies, Java for Android For Dummies,</i> and <i>Flutter For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9069"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1387f67\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;java&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119806912&quot;]}]\" id=\"du-slot-63221b1388950\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-05T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":150748}],"_links":{"self":{"self":"https://dummies-api.dummies.com/v2/categories/33602/categoryArticles?sortField=time&sortOrder=1&size=10&offset=0"},"next":{"self":"https://dummies-api.dummies.com/v2/categories/33602/categoryArticles?sortField=time&sortOrder=1&size=10&offset=10"},"last":{"self":"https://dummies-api.dummies.com/v2/categories/33602/categoryArticles?sortField=time&sortOrder=1&size=10&offset=112"}}},"objectTitle":"","status":"success","pageType":"article-category","objectId":"33602","page":1,"sortField":"time","sortOrder":1,"categoriesIds":[],"articleTypes":[],"filterData":{"categoriesFilter":[{"itemId":0,"itemName":"All Categories","count":122}],"articleTypeFilter":[{"articleType":"All Types","count":122},{"articleType":"Articles","count":118},{"articleType":"Cheat Sheet","count":4}]},"filterDataLoadedStatus":"success","pageSize":10},"adsState":{"pageScripts":{"headers":{"timestamp":"2025-04-17T15:50:01+00:00"},"adsId":0,"data":{"scripts":[{"pages":["all"],"location":"header","script":"<!--Optimizely Script-->\r\n<script src=\"https://cdn.optimizely.com/js/10563184655.js\"></script>","enabled":false},{"pages":["all"],"location":"header","script":"<!-- comScore Tag -->\r\n<script>var _comscore = _comscore || [];_comscore.push({ c1: \"2\", c2: \"15097263\" });(function() {var s = document.createElement(\"script\"), el = document.getElementsByTagName(\"script\")[0]; s.async = true;s.src = (document.location.protocol == \"https:\" ? \"https://sb\" : \"http://b\") + \".scorecardresearch.com/beacon.js\";el.parentNode.insertBefore(s, el);})();</script><noscript><img src=\"https://sb.scorecardresearch.com/p?c1=2&c2=15097263&cv=2.0&cj=1\" /></noscript>\r\n<!-- / comScore Tag -->","enabled":true},{"pages":["all"],"location":"footer","script":"<!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->\r\n<script type='text/javascript'>\r\n(function(){var g=function(e,h,f,g){\r\nthis.get=function(a){for(var a=a+\"=\",c=document.cookie.split(\";\"),b=0,e=c.length;b<e;b++){for(var d=c[b];\" \"==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};\r\nthis.set=function(a,c){var b=\"\",b=new Date;b.setTime(b.getTime()+6048E5);b=\"; expires=\"+b.toGMTString();document.cookie=a+\"=\"+c+b+\"; path=/; \"};\r\nthis.check=function(){var a=this.get(f);if(a)a=a.split(\":\");else if(100!=e)\"v\"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(\":\"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case \"v\":return!1;case \"r\":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(\":\")),!c}return!0};\r\nthis.go=function(){if(this.check()){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.src=g;document.body&&document.body.appendChild(a)}};\r\nthis.start=function(){var t=this;\"complete\"!==document.readyState?window.addEventListener?window.addEventListener(\"load\",function(){t.go()},!1):window.attachEvent&&window.attachEvent(\"onload\",function(){t.go()}):t.go()};};\r\ntry{(new g(100,\"r\",\"QSI_S_ZN_5o5yqpvMVjgDOuN\",\"https://zn5o5yqpvmvjgdoun-wiley.siteintercept.qualtrics.com/SIE/?Q_ZID=ZN_5o5yqpvMVjgDOuN\")).start()}catch(i){}})();\r\n</script><div id='ZN_5o5yqpvMVjgDOuN'><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>\r\n<!--END WEBSITE FEEDBACK SNIPPET-->","enabled":false},{"pages":["all"],"location":"header","script":"<!-- Hotjar Tracking Code for http://www.dummies.com -->\r\n<script>\r\n (function(h,o,t,j,a,r){\r\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\r\n h._hjSettings={hjid:257151,hjsv:6};\r\n a=o.getElementsByTagName('head')[0];\r\n r=o.createElement('script');r.async=1;\r\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\r\n a.appendChild(r);\r\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\r\n</script>","enabled":false},{"pages":["article"],"location":"header","script":"<!-- //Connect Container: dummies --> <script src=\"//get.s-onetag.com/bffe21a1-6bb8-4928-9449-7beadb468dae/tag.min.js\" async defer></script>","enabled":true},{"pages":["homepage"],"location":"header","script":"<meta name=\"facebook-domain-verification\" content=\"irk8y0irxf718trg3uwwuexg6xpva0\" />","enabled":true},{"pages":["homepage","article","category","search"],"location":"footer","script":"<!-- Facebook Pixel Code -->\r\n<noscript>\r\n<img height=\"1\" width=\"1\" src=\"https://www.facebook.com/tr?id=256338321977984&ev=PageView&noscript=1\"/>\r\n</noscript>\r\n<!-- End Facebook Pixel Code -->","enabled":true}]}},"pageScriptsLoadedStatus":"success"},"navigationState":{"navigationCollections":[{"collectionId":287568,"title":"BYOB (Be Your Own Boss)","hasSubCategories":false,"url":"/collection/for-the-entry-level-entrepreneur-287568"},{"collectionId":293237,"title":"Be a Rad Dad","hasSubCategories":false,"url":"/collection/be-the-best-dad-293237"},{"collectionId":295890,"title":"Career Shifting","hasSubCategories":false,"url":"/collection/career-shifting-295890"},{"collectionId":294090,"title":"Contemplating the Cosmos","hasSubCategories":false,"url":"/collection/theres-something-about-space-294090"},{"collectionId":287563,"title":"For Those Seeking Peace of Mind","hasSubCategories":false,"url":"/collection/for-those-seeking-peace-of-mind-287563"},{"collectionId":287570,"title":"For the Aspiring Aficionado","hasSubCategories":false,"url":"/collection/for-the-bougielicious-287570"},{"collectionId":291903,"title":"For the Budding Cannabis Enthusiast","hasSubCategories":false,"url":"/collection/for-the-budding-cannabis-enthusiast-291903"},{"collectionId":299891,"title":"For the College Bound","hasSubCategories":false,"url":"/collection/for-the-college-bound-299891"},{"collectionId":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":301547,"title":"For the Game Day Prepper","hasSubCategories":false,"url":"/collection/big-game-day-prep-made-easy-301547"}],"navigationCollectionsLoadedStatus":"success","navigationCategories":{"books":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/books/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/books/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/books/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/books/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/books/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/books/level-0-category-0"}},"articles":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/articles/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/articles/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/articles/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/articles/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/articles/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/articles/level-0-category-0"}}},"navigationCategoriesLoadedStatus":"success"},"searchState":{"searchList":[],"searchStatus":"initial","relatedArticlesList":[],"relatedArticlesStatus":"initial"},"routeState":{"name":"ArticleCategory","path":"/category/articles/java-33602/","hash":"","query":{},"params":{"category":"java-33602"},"fullPath":"/category/articles/java-33602/","meta":{"routeType":"category","breadcrumbInfo":{"suffix":"Articles","baseRoute":"/category/articles"},"prerenderWithAsyncData":true},"from":{"name":null,"path":"/","hash":"","query":{},"params":{},"fullPath":"/","meta":{}}},"profileState":{"auth":{},"userOptions":{},"status":"success"}}
Logo
  • Articles Open Article Categories
  • Books Open Book Categories
  • Collections Open Collections list
  • Custom Solutions

Article Categories

Book Categories

Collections

Explore all collections
BYOB (Be Your Own Boss)
Be a Rad Dad
Career Shifting
Contemplating the Cosmos
For Those Seeking Peace of Mind
For the Aspiring Aficionado
For the Budding Cannabis Enthusiast
For the College Bound
For the Exam-Season Crammer
For the Game Day Prepper
Log In
  • Home
  • Technology Articles
  • Programming & Web Design Articles
  • Java Articles

Java Articles

Java powers much of the online world and tons of apps and programs. You can read all about it right here. (Perhaps over a cup of java?)

Articles From Java

page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10
page 11
page 12
page 13

Filter Results

122 results
122 results
Java The Atoms: Java’s Primitive Types

Article / Updated 10-28-2024

The words int and double are examples of primitive types (also known as simple types) in Java. The Java language has exactly eight primitive types. As a newcomer to Java, you can pretty much ignore all but four of these types. (As programming languages go, Java is nice and compact that way.) The types that you shouldn’t ignore are int, double, char, and boolean. The char type Several decades ago, people thought computers existed only for doing big number-crunching calculations. Nowadays, nobody thinks that way. So, if you haven’t been in a cryogenic freezing chamber for the past 20 years, you know that computers store letters, punctuation symbols, and other characters. The Java type that’s used to store characters is called char. The code below has a simple program that uses the char type. This image shows the output of the program in the code below. public class CharDemo { public static void main(String args[]) { char myLittleChar = 'b'; char myBigChar = Character.toUpperCase(myLittleChar); System.out.println(myBigChar); } } In this code, the first initialization stores the letter b in the variable myLittleChar. In the initialization, notice how b is surrounded by single quote marks. In Java, every char literally starts and ends with a single quote mark. In a Java program, single quote marks surround the letter in a char literal. Character.toUpperCase. The Character.toUpperCase method does just what its name suggests — the method produces the uppercase equivalent of the letter b. This uppercase equivalent (the letter B) is assigned to the myBigChar variable, and the B that’s in myBigChar prints onscreen. If you’re tempted to write the following statement, char myLittleChars = 'barry'; //Don't do this please resist the temptation. You can’t store more than one letter at a time in a char variable, and you can’t put more than one letter between a pair of single quotes. If you’re trying to store words or sentences (not just single letters), you need to use something called a String. If you’re used to writing programs in other languages, you may be aware of something called ASCII character encoding. Most languages use ASCII; Java uses Unicode. In the old ASCII representation, each character takes up only 8 bits, but in Unicode, each character takes up 8, 16, or 32 bits. Whereas ASCII stores the letters of the Roman (English) alphabet, Unicode has room for characters from most of the world’s commonly spoken languages. The only problem is that some of the Java API methods are geared specially toward 16-bit Unicode. Occasionally, this bites you in the back (or it bytes you in the back, as the case may be). If you’re using a method to write Hello on the screen and H e l l o shows up instead, check the method’s documentation for mention of Unicode characters. It’s worth noticing that the two methods, Character.toUpperCase and System.out.println, are used quite differently in the code above. The method Character.toUpperCase is called as part of an initialization or an assignment statement, but the method System.out.println is called on its own. The boolean type A variable of type boolean stores one of two values: true or false. The code below demonstrates the use of a boolean variable. public class ElevatorFitter2 { public static void main(String args[]) { System.out.println("True or False?"); System.out.println("You can fit all ten of the"); System.out.println("Brickenchicker dectuplets"); System.out.println("on the elevator:"); System.out.println(); int weightOfAPerson = 150; int elevatorWeightLimit = 1400; int numberOfPeople = elevatorWeightLimit / weightOfAPerson; <strong> boolean allTenOkay = numberOfPeople >= 10;</strong> System.out.println(allTenOkay); } } In this code, the allTenOkay variable is of type boolean. To find a value for the allTenOkay variable, the program checks to see whether numberOfPeople is greater than or equal to ten. (The symbols >= stand for greater than or equal to.) At this point, it pays to be fussy about terminology. Any part of a Java program that has a value is an expression. If you write weightOfAPerson = 150; then 150 ,is an expression (an expression whose value is the quantity 150). If you write numberOfEggs = 2 + 2; then 2 + 2 is an expression (because 2 + 2 has the value 4). If you write int numberOfPeople = elevatorWeightLimit / weightOfAPerson; then elevatorWeightLimit / weightOfAPerson is an expression. (The value of the expression elevatorWeightLimit / weightOfAPerson depends on whatever values the variables elevatorWeightLimit and weightOfAPerson have when the code containing the expression is executed.) Any part of a Java program that has a value is an expression. In the second set of code, numberOfPeople >= 10 is an expression. The expression’s value depends on the value stored in the numberOfPeople variable. But, as you know from seeing the strawberry shortcake at the Brickenchicker family’s catered lunch, the value of numberOfPeople isn’t greater than or equal to ten. As a result, the value of numberOfPeople >= 10 is false. So, in the statement in the second set of code, in which allTenOkay is assigned a value, the allTenOkay variable is assigned a false value. In the second set of code, System.out.println() is called with nothing inside the parentheses. When you do this, Java adds a line break to the program’s output. In the second set of code, System.out.println() tells the program to display a blank line.

View Article
Java Java All-in-One For Dummies Cheat Sheet

Cheat Sheet / Updated 01-11-2023

Writing Java statements (like for and if) and classes (like Math and NumberFormat) help you start and build strong programs. Variables hold different kinds of Java data types: numbers, characters, and true/false numbers. You designate Java operations that can be performed on operands, including arithmetic operators, relational operators (or binary) and logical operators (or Boolean).

View Cheat Sheet
Java Java For Dummies Cheat Sheet

Cheat Sheet / Updated 02-25-2022

When doing anything with Java, you need to know your Java words — those programming words, phrases, and nonsense terms that have specific meaning in the Java language, and get it to do its thing. This Cheat Sheet tells you all about Java's categories of words.

View Cheat Sheet
Java Java Programming: Telling the Computer to Do Something

Article / Updated 01-13-2022

In Listing 1, below, you get a blast of Java code. Like all novice programmers, you're expected to gawk humbly at the code. But don't be intimidated. When you get the hang of it, programming is pretty easy. Yes, it's fun, too. Listing 1: A Simple Java Program /* * A program to list the good things in life * Author: Barry Burd, [email protected] * February 10, 2021 */ public class ThingsILike { public static void main (String[] args) { System.out.println("Chocolate, royalties, sleep"); } } Buried deep in the heart of Listing 1 is the single line that actually issues a direct instruction to the computer. The line System.out.println("Chocolate, royalties, sleep"); tells the computer to display the words Chocolate, royalties, sleep in the command prompt window. This line can be described in at least two different ways: It's a statement: In Java, a direct instruction that tells the computer to do something is called a statement. The statement in Listing 1 tells the computer to display some text. The statements in other programs may tell the computer to put 7 in certain memory location, or make a window appear on the screen. The statements in computer programs do all kinds of things. It's a method call: A method call is a separate piece of code (in a different part of the Java program) that tells the computer to call the method into action.The statement <tt>FixTheAlternator(junkyOldFord);</tt> is an example of a method call, and so is <tt>System.out.println("Chocolate, royalties, sleep");</tt> Java has many different kinds of statements. A method call is just one kind. Ending a statement with a semicolon In Java, each statement ends with a semicolon. The code in Listing 1 has only one statement in it, so only one line in Listing 1 ends with a semicolon. Take any other line in Listing 1, like the method header, for instance. The method header (the line with the word main in it) doesn't directly tell the computer to do anything. Instead, the method header describes some action for future reference. The header announces "Just in case someone ever calls the main method, the next few lines of code tell you what to do in response to that call." Every complete Java statement ends with a semicolon. A method call is a statement, so it ends with a semicolon, but neither a method header nor a method declaration is a statement. The method named System.out.println The statement in the middle of Listing 1 calls a method named System.out.println. This method is defined in the Java API. Whenever you call the System.out.println method, the computer displays text on its screen. Think about the name Pauline Ott, for example. Believe it or not, I know two people named Pauline Ott. One of them is a nun; the other is physicist. Of course, there are plenty of Paulines in the English-speaking world, just as there are several things named println in the Java API. So to distinguish the physicist Pauline Ott from the film critic Pauline Kael, write the full name "Pauline Ott." And, to distinguish the nun from the physicist, write "Sister Pauline Ott." In the same way, write either System.out.println or DriverManager.println. The first writes text on the computer's screen. The second writes to a database log file. Just as Pauline and Ott are names in their own right, so System, out, and println are names in the Java API. But to use println, you must write the method's full name. You never write println alone. It's always System.out.println or some other combination of API names. The Java programming language is case-sensitive. If you change a lowercase letter to an uppercase letter (or vice versa), you change a word's meaning. You can't replace System.out.println with system.out.Println. If you do, your program won't work. The Java class You may have heard the term object-oriented programming (also known as OOP). OOP is a way of thinking about computer programming problems — a way that's supported by several different programming languages. OOP started in the 1960s with a language called Simula. It was reinforced in the 1970s with another language named Smalltalk. In the 1980s, OOP took off big time with the language C++. Some people want to change the acronym, and call it COP, class-oriented programming. That's because object-oriented programming begins with something called a class. In Java, everything starts with classes, everything is enclosed in classes, and everything is based on classes. In Java, your main method has to be inside a class. The code in Listing 1 starts with the words class ThingsILike. Take another look at Listing 1, and notice what happens after the line class ThingsILike. The rest of the code is enclosed in curly braces. These braces mark all the stuff inside the class. Without these braces, you'd know where the declaration of the ThingsILike class starts, but you wouldn't know where the declaration ends. It's as if the stuff inside the ThingsILike class is in a box. To box off a chunk of code, you do two things: You use curly braces: These curly braces tell the compiler where a chunk of code begins and ends. You indent code: Indentation tells your human eye (and the eyes of other programmers) where a chunk of code begins and ends. Don't forget. You have to do both.

View Article
Java Getting Started with Java Programming

Article / Updated 01-13-2022

The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language's founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet. Since 1995, this library has grown to include more than 4,000 programs. This library is called the Application Programming Interface (API). Every Java program, even the simplest one, calls on code in the Java API. This Java API is both useful and formidable. It's useful because of all the things you can do with the API's programs. It's formidable because the API is so extensive. No one memorizes all the features made available by the Java API. Programmers remember the features that they use often, and look up the features that they need in a pinch. So many ways to write computer programs To write Java programs, you need four tools: A Java compiler A Java Virtual Machine. The Java API. The Java API documentation. The Java smorgasbord This section explains some of the terminology you might see as you travel through the Java ecosystem. Medium Java, little Java, and gigantic Java At some point, you may see mention of Java SE, Java ME, or Java EE. Here’s the lowdown on these three kinds of “Java E”: Java Standard Edition (Java SE): This is the only edition you should think about (for now, anyway). Java SE includes all the code you need in order to create general-purpose applications on a typical computer. Nowadays, when you hear the word Java, it almost always refers to Java SE. Java Micro Edition (Java ME): The Micro Edition contains code for programming special-purpose devices such as television sets, printers, and other gadgets. Java Enterprise Edition (Java EE): In 1999, the stewards of Java released an edition that was tailored for the needs of big companies. The starring role in this edition was a framework called Enterprise JavaBeans — a way of managing data storage across connected computers. In 2017, Oracle walked away from Java EE, handing it over to the Eclipse Foundation, which renamed it Jakarta EE. The rest of this book deals exclusively with Java Standard Edition. How do you type this stuff? A computer program is a big piece of text. So to write a computer program, you need a text editor — a tool for creating text documents. A text editor is a lot like Microsoft Word, or like any other word processing program. The big difference is that the documents that you create with a text editor have no formatting whatsoever. They have no bold, no italic, no distinctions among fonts. They have nothing except plain old letters, numbers, and other familiar keyboard characters. That's good, because computer programs aren't supposed to have any formatting. A document with no formatting is called a plain text document. Documents without formatting are fairly simple things, so a typical text editor is easier to use than a word processing program. (Text editors are a lot cheaper than word processing programs, and they're lightning fast. Even better, text editors take very little space on your hard drive.) You can use a word processor, like Microsoft Word, to create program files. But, by default, word processors insert formatting into your document. This formatting makes it impossible for a Java compiler to do its job. Using word processors to write Java programs isn't recommended. But, if you must use a word processor, be sure to save your source files with the .java extension. (Call a file SomeName.java.) Remember, also, to use the Save As command to save with the plain text file type. Using a customized editor Even if you don't use an integrated development environment, you can use other tools to make your programming life easy. Think, for a moment, about an ordinary text editor — an editor like Windows Notepad. With Notepad you can Create a document that has no formatting Find and replace characters, words, and other strings Copy, cut, and paste Print Not much else Notepad is fine for writing computer programs. But if you plan to do a lot of programming, you may want to try a customized editor. These editors do more than Windows Notepad. They have Syntax highlighting Shortcuts for compiling and running programs Explorer-like views of your works in progress Code completion Other cool stuff When it comes to choosing a custom editor, one favorite is IntelliJ IDEA. IntelliJ Idea comes in two different editions: Ultimate Edition or Community Edition. The Community Edition is free. To download the IntelliJ IDEA Community Edition, visit www.jetbrains.com/idea/download.

View Article
Java Tackling Error Messages in Java Programming

Article / Updated 01-13-2022

Sometimes, error messages can strike fear into the heart of even the bravest programmer. Fortunately some helpful, calming advice is here — advice to help you solve the problem when you see one of these messages. NoClassDefFoundError You get this error when you're trying to run your code. So first ask yourself, did you attempt to compile the code? If so, did you see any error messages when you compiled? If you saw error messages, look for things you can fix in your .java file. Try to fix these things, and then compile the .java file again. If you normally keep code in the JavaPrograms directory, make sure that you're still working in this JavaPrograms directory. (In Windows, make sure that the command prompt says JavaPrograms.) Make sure you have an appropriately named .class file in your working directory. For instance, if you're trying to run a program named MyGreatProg, look for a file named MyGreatProg.class in your working directory. Check your classpath to make sure that it contains the .class file that you need. For example, if all your Java code is in your working directory, make sure that the classpath includes a dot. NoSuchMethodError When you encounter this error message, check for the misspelling or inconsistent capitalization of a method name. Check the capitalization of main (not Main). When you issue the java command (or do whatever you normally do to run a program in your environment), does the class that you're trying to run contain its own main method? If not, then find the class with the main method and run that class instead. Cannot Resolve Symbol If you get an error message that includes cannot resolve symbol, check the spelling and capitalization of all identifiers and keywords. Then check again. If the unresolved symbol is a variable, make sure that this variable's declaration is in the right place. For instance, if the variable is declared in a for loop's initialization, are you trying to use that variable outside the for loop? If the variable is declared inside a block (a pair of curly braces), are you trying to use that variable outside of the block? Finally, look for errors in the variable's declaration. If the compiler finds errors in a variable's declaration, then the compiler can't resolve that variable name in the remainder of the code. Expected ';' (Or Expected Something Else) When you see an error message that says ';' expected, go through your code and make sure that each statement and each declaration ends with a semicolon. If so, then maybe the compiler's guess about a missing semicolon is incorrect. Fixing another (seemingly unrelated) error and recompiling your code may get rid of a bogus ';' expected message. For a missing parenthesis, check the conditions of if statements and loops. Make sure each condition is enclosed in parentheses. Also, make sure that a parameter list (enclosed in parentheses) follows the name of each method. For an expected message, check your assignment statements. Make sure that each assignment statement is inside a method. (Remember, a declaration with an initialization can be outside of a method, but each plain old assignment statement must be inside a method.) For the 'class' or 'interface' expected message, make sure you've spelled the word class correctly. If your code has an import declaration, check the spelling and capitalization of the word import. Missing Method Body or Declare Abstract You get a missing method body or declare abstract message when the compiler sees a method header, but the compiler can't find the method's body. Look at the end of the method's header. If you ended the header with a semicolon, then try removing the semicolon. If the header doesn't end with a semicolon, then check the code immediately following the header. The code immediately following the header should start with an open curly brace (the beginning of a method body). If some code comes between the header and the body's open curly brace, consider moving that code somewhere else. An 'else' without an 'if' Compare the number of if clauses with the number of else clauses. An if clause doesn't need to have an else clause, but each else clause must belong to an if clause. Remember, you enclose an if condition in parentheses, but you don't put a semicolon after the condition. Did you mistakenly end an if condition with a semicolon? Look at all the lines between an if and its else. When you find more than one statement between an if and its else, look for curly braces. If the statements between the if and its else aren't surrounded by curly braces, you may have found the culprit. Non-static Variable Cannot Be Referenced from a Static Context Lots of things can give you a non-static variable cannot be referenced from a static context error message. But for beginning programmers, the most common cause is having a variable that's declared outside of the main method. It's no sin to declare such a variable, but because the main method is always static, you need some special help to make the main method refer to a variable that's declared outside the main method. The quickest solution is to put the word static in front of the variable's declaration. But first, ask yourself why this variable's declaration isn't inside the main method. If there's no good reason, then move the variable's declaration so that it's inside the main method. FileNotFoundException (The System Cannot Find the File Specified) or EOFException If you encounter a FileNotFoundException message, check that the file named in your code actually exists. (Look for the file using your system's explorer or using the command prompt window.) Double-check the spelling in your code against the name of the file on your hard drive. If you've found a correctly named file on your hard drive, make sure that the file is in the correct directory. (For a program running in your working directory, a typical data file is in the working directory also.) If you're a Windows user, make sure that the system didn't add an extra .txt extension when you created the file. (Use the command prompt window to check the file's name. Windows Explorer can hide the .txt extension, and that always leads to confusion.) For an EOFException, you're probably trying to read more data than you have in the file. Very often, a small logic error makes your program do this. So do a careful review of all the steps in your program's execution. Look for subtle things, like improperly primed loops or the reading of array values past the array's largest index. Look for conditions that use <= when they should use <. Conditions like these can often be troublesome.

View Article
Java How to Generate Words Randomly in Java

Article / Updated 01-13-2022

Most Java programs don’t work correctly the first time you run them, and some programs don’t work without extensive trial and error on your part. This code is a case in point. To write this code, you need a way to generate three-letter words randomly. This code would give you the desired result: anAccount.lastName = " + (char) (myRandom.nextInt(26) + 'A') + (char) (myRandom.nextInt(26) + 'a') + (char) (myRandom.nextInt(26) + 'a'); Here’s how the code works: Each call to the Random.nextInt(26) generates a number from 0 to 25. Adding 'A' gives you a number from 65 to 90. To store a letter 'A', the computer puts the number 65 in its memory. That’s why adding 'A' to 0 gives you 65 and why adding 'A' to 25 gives you 90. Applying (char) to a number turns the number into a char value. To store the letters 'A' through 'Z', the computer puts the numbers 65 through 90 in its memory. So applying (char) to a number from 65 to 90 turns the number into an uppercase letter. Pause for a brief summary. The expression (char) (myRandom.nextInt(26) + 'A') represents a randomly generated uppercase letter. In a similar way, (char) (myRandom.nextInt(26) + 'a') represents a randomly generated lowercase letter. Watch out! The next couple of steps can be tricky. Java doesn’t allow you to assign a char value to a string variable. The following statement would lead to a compiler error: //Bad statement: anAccount.lastName = (char) (myRandom.nextInt(26) + 'A'); In Java, you can use a plus sign to add a char value to a string. When you do, the result is a string. So "" + (char) (myRandom.nextInt(26) + 'A') is a string containing one randomly generated uppercase character. And when you add (char) (myRandom.nextInt(26) + 'a') onto the end of that string, you get another string — a string containing two randomly generated characters Finally, when you add another (char) (myRandom.nextInt(26) + 'a') onto the end of that string, you get a string containing three randomly generated characters. So you can assign that big string to anAccount.lastName. That’s how the statement works. When you write a program, you have to be very careful with numbers, char values, and strings. This isn’t the kind of programming you do every day of the week, but it is a lesson that you need to be persistent in your Java programming.

View Article
Java How to Write Java Code to Show an Image on the Screen

Article / Updated 01-13-2022

You will probably find times when programming with Java that you need to display a window on your computer screen. This code has very little logic of its own. Instead, this code pulls together a bunch of classes from the Java API. import javax.swing.JFrame; import javax.swing.ImageIcon; import javax.swing.JLabel; class ShowPicture { public static void main(String args[]) { var frame = new JFrame(); var icon = new ImageIcon("androidBook.jpg"); var label = new JLabel(icon); frame.add(label); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } You can create an instance of the Purchase class with the line var purchase1 = new Purchase(); So in the code, you can do the same kind of thing. You can create instances of the JFrame, ImageIcon, and JLabel classes with the following lines: var frame = new JFrame(); var icon = new ImageIcon("androidBook.jpg"); var label = new JLabel(icon); Here’s some gossip about each of these lines: A JFrame is like a window (except that it’s called a JFrame, not a “window”). The line var frame = new JFrame(); creates a JFrame object, but this line doesn’t display the JFrame object anywhere. (The displaying comes later in the code.) An ImageIcon object is a picture. At the root of the program's project directory, there is a file named androidBook.jpg. That file contains the picture. The line var icon = new ImageIcon("androidBook.jpg"); creates an ImageIcon object — an icon containing the androidBook.jpg picture. You can use almost any .gif, .jpg, or .png file in place of the (lovely) Android book cover image. To do so, drag your own image file to Eclipse's Package Explorer. (Drag it to the root of this example's project folder.) Then, in Eclipse's editor, change the name androidBook.jpg to your own image file's name. That's it! You need a place to put the icon. You can put it on something called a JLabel. The line var label = new JLabel(icon); creates a JLabel object and puts the androidBook.jpg icon on the new label’s face. If you read the previous bullets, you may get a false impression. The wording may suggest that the use of each component (JFrame, ImageIcon, JLabel, and so on) is a logical extension of what you already know. “Where do you put an ImageIcon? Well of course, you put it on a JLabel.” When you’ve worked long and hard with Java’s Swing components, all these things become natural to you. But until then, you look everything up in Java's API documentation. You never need to memorize the names or features of Java’s API classes. Instead, you keep Java’s API documentation handy. When you need to know about a class, you look it up in the documentation. If you need a certain class often enough, you’ll remember its features. For classes that you don’t use often, you always have the docs.

View Article
Java How to Store Values in an Array in Java

Article / Updated 01-05-2022

After you’ve created an array in Java, you can put values into the array’s components. For example, imagine you are the owner of a motel. The guests in Room 6 are fed up with all those mint candies that you put on peoples’ beds. They check out, and Room 6 becomes vacant. You should put the value 0 into the 6 component. You can do it with this assignment statement: guestsIn[6] = 0; On one weekday, business is awful. No one’s staying at the motel. But then you get a lucky break. A big bus pulls up to the motel. The side of the bus has a sign that says “Loners’ Convention.” Out of the bus come 25 people, each walking to the motel’s small office, none paying attention to the others who were on the bus. Each person wants a private room. Only 10 of them can stay at the Java Motel, but that’s okay, because you can send the other 15 loners down the road to the old C-Side Resort and Motor Lodge. Anyway, to register ten of the loners into the Java Motel, you put one guest in each of your ten rooms. Having created an array, you can take advantage of the array’s indexing and write a for loop, like this: for (int roomNum = 0; roomNum < 10; roomNum++) { guestsIn[roomNum] = 1; } This loop takes the place of ten assignment statements because the computer executes the statement guestsIn[roomNum] = 1 ten times. The first time around, the value of roomNum is 0, so in effect, the computer executes guestsIn[<b>0</b>] = 1; In the next loop iteration, the value of roomNum is 1, so the computer executes the equivalent of the following statement: guestsIn[<b>1</b>] = 1; During the next iteration, the computer behaves as if it’s executing guestsIn[<b>2</b>] = 1; And so on. When roomNum gets to be 9, the computer executes the equivalent of the following statement: guestsIn[<b>9</b>] = 1; Notice that the loop’s counter goes from 0 to 9. Remember that the indices of an array go from 0 to one fewer than the number of components in the array. Looping with room numbers from 0 to 9 covers all the rooms in the Java Motel. When you work with an array, and you step through the array’s components using a for loop, you normally start the loop’s counter variable at 0. To form the condition that tests for another iteration, you often write an expression like roomNum < arraySize, where arraySize is the number of components in the array.

View Article
Java Tips for Beginning Java Programmers: Variables and Recycling

Article / Updated 01-05-2022

There are a few things beginning Java programmers should know about variables and recycling. When you assign a new value to smallLetter, the old value of smallLetter gets obliterated. smallLetter is used twice, and bigLetter is used twice. That’s why they call these things variables. First, the value of smallLetter is R. Later, the value of smallLetter is varied so that the value of smallLetter becomes 3. When the computer executes this second assignment statement, the old value R is gone. Is that okay? Can you afford to forget the value that smallLetter once had? Yes, sometimes, it’s okay. After you’ve assigned a value to bigLetter with the statement bigLetter = Character.toUpperCase(smallLetter); you can forget all about the existing smallLetter value. You don’t need to do this: <b>// This code is cumbersome.</b> <b>// The extra variables are unnecessary.</b> char <b>smallLetter1</b>, bigLetter1; char <b>smallLetter2</b>, bigLetter2; <b>smallLetter1</b> = 'R'; bigLetter1 = Character.toUpperCase(smallLetter1); System.out.println(bigLetter1); <b>smallLetter2</b> = '3'; bigLetter2 = Character.toUpperCase(smallLetter2); System.out.println(bigLetter2); You don’t need to store the old and new values in separate variables. Instead, you can reuse the variables smallLetter and bigLetter. This reuse of variables doesn’t save you from a lot of extra typing. It doesn’t save much memory space, either. But reusing variables keeps the program uncluttered. Sometimes, you can see at a glance that the code has two parts, and you see that both parts do roughly the same thing. In such a small program, simplicity and manageability don’t matter very much. But in a large program, it helps to think carefully about the use of each variable.

View Article
page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10
page 11
page 12
page 13

Quick Links

  • About For Dummies
  • Contact Us
  • Activate Online Content

Connect

About Dummies

Dummies has always stood for taking on complex concepts and making them easy to understand. Dummies helps everyone be more knowledgeable and confident in applying what they know. Whether it's to pass that big test, qualify for that big promotion or even master that cooking technique; people who rely on dummies, rely on it to learn the critical skills and relevant information necessary for success.

Copyright @ 2000-2024 by John Wiley & Sons, Inc., or related companies. All rights reserved, including rights for text and data mining and training of artificial technologies or similar technologies.

Terms of Use
Privacy Policy
Cookies Settings
Do Not Sell My Personal Info - CA Only