{"appState":{"pageLoadApiCallsStatus":true},"categoryState":{"relatedCategories":{"headers":{"timestamp":"2022-10-18T16:01:25+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":6},"_links":{"self":"https://dummies-api.dummies.com/v2/categories/33602"}},"relatedCategoriesLoadedStatus":"success"},"listState":{"list":{"count":10,"total":122,"items":[{"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":null,"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-27T16:48:10+00:00","modifiedTime":"2022-02-24T18:59:09+00:00","timestamp":"2022-09-14T18:19:13+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, about the different kinds of Java data types, and about the operations that can be performed on 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 bestselling author of more than 40 <i>For Dummies</i> books. He's covered everything from Microsoft Office to creating web pages to technologies such as Java and ASP.NET, and has written several editions of both <i>PowerPoint For Dummies</i> and <i>Networking For Dummies.</i></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":null,"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":"9781119680451","categoryList":["technology","programming-web-design","java"],"amazon":{"default":"https://www.amazon.com/gp/product/111968045X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111968045X/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/111968045X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111968045X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111968045X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/java-all-in-one-for-dummies-6th-edition-cover-9781119680451-203x255.jpg","width":203,"height":255},"title":"Java All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"8946\">Doug Lowe</b></b> is the bestselling author of more than 40 <i>For Dummies</i> books. He's covered everything from Microsoft Office to creating web pages to technologies such as Java and ASP.NET, and has written several editions of both <i>PowerPoint For Dummies</i> and <i>Networking For Dummies.</i></p>","authors":[{"authorId":8946,"name":"Doug Lowe","slug":"doug-lowe","description":" <p><b>Doug Lowe</b> is the bestselling author of more than 40 <i>For Dummies</i> books. He's covered everything from Microsoft Office to creating web pages to technologies such as Java and ASP.NET, and has written several editions of both <i>PowerPoint For Dummies</i> and <i>Networking For Dummies.</i></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;9781119680451&quot;]}]\" id=\"du-slot-63221b21ecc12\"></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;9781119680451&quot;]}]\" id=\"du-slot-63221b21ed6e7\"></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":"2022-02-24T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":207712},{"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":null,"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":null,"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":null,"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":null,"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":null,"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":null,"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":null,"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},{"headers":{"creationTime":"2016-03-26T11:08:30+00:00","modifiedTime":"2021-11-23T18:43:47+00:00","timestamp":"2022-09-14T18:18:48+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 Configure Java in Eclipse","strippedTitle":"how to configure java in eclipse","slug":"how-to-configure-java-in-eclipse","canonicalUrl":"","seo":{"metaDescription":"Eclipse normally looks on your computer for Java installations and selects an installed version of Java to use for running your Java programs. Your computer may","noIndex":0,"noFollow":0},"content":"Eclipse normally looks on your computer for Java installations and selects an installed version of Java to use for running your Java programs. Your computer may have more than one version of Java, so you may want to double-check Eclipse's choice of the Java version. The following steps show you how:\r\n<ol class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">On Windows or Linux: In Eclipse's main menu, select Window→Preferences. On a Mac: In Eclipse's main menu, select Eclipse→Preferences.</p>\r\n<p class=\"child-para\">As a result, Eclipse's Preferences dialog appears.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434477.image0.jpg\" alt=\"image0.jpg\" width=\"501\" height=\"400\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the tree on the left side of the Preferences dialog, expand the Java branch.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Within the Java branch, select the Installed JREs sub-branch.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Look at the list of Java versions (Installed JREs) in the main body of the Preferences dialog.</p>\r\n<p class=\"child-para\">In the list, each version of Java has a check box. Eclipse uses the version whose box is checked. If the checked version isn't your preferred version (for example, if the checked version isn't version 8 or higher), you can make some changes.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">If your preferred version of Java appears in the Installed JREs list, put a check mark in that version's check box.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">If your preferred version of Java doesn't appear in the Installed JREs list, click the Add button.</p>\r\n<p class=\"child-para\">When you click the Add button, a JRE Type dialog appears.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434478.image1.jpg\" alt=\"image1.jpg\" width=\"535\" height=\"373\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the JRE Type dialog, double-click Standard VM.</p>\r\n<p class=\"child-para\">As a result, a JRE Definition dialog appears. What you do next depends on a few different things.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Fill in the dialog's JRE Home field.</p>\r\n<p class=\"child-para\">How you do this depends on your operating system.</p>\r\n\r\n<ul class=\"level-two\">\r\n \t<li>\r\n<p class=\"first-para\">On Windows, browse to the directory in which you've installed your preferred Java version. On your Windows computers, that directory is either <span class=\"code\">C:Program FilesJavajre8</span>, <span class=\"code\">C:Program FilesJavajdk1.8.0</span>, <span class=\"code\">C:Program Files (x86)Javajre8</span>, or something of that sort.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">On a Mac, use the Finder to browse to the directory in which you've installed your preferred Java version. Type the name of the directory in the dialog's JRE Home field.</p>\r\n<p class=\"child-para\">My Mac has one Java directory named <span class=\"code\">/System/Library/Java/Java Virtual Machines/1.6.0.jdk/Contents/Home</span> and another Java directory named <span class=\"code\">/Library/Java/JavaVirtualMachines/jdk 1.8.0.jdk/Contents/Home</span>. (The first is for Apple's old version of Java; the second is for Oracle's new Java version.) You might also find Oracle's Java in the <span class=\"code\">/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home</span> directory.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434479.image2.jpg\" alt=\"image2.jpg\" width=\"389\" height=\"400\" />\r\nDirectories like <span class=\"code\">/System</span> and <span class=\"code\">/Library</span> don't normally appear in the Finder window. To browse to one of these directories (to the <span class=\"code\">/Library</span> directory, for example), choose Go→Go to Folder in the Finder's menu bar. In the resulting dialog, type <span class=\"code\">/Library</span> and then press Go.\r\n\r\nAs you navigate to the directory containing your preferred Java version, you may encounter a <span class=\"code\">JDK 1.8.0.jdk</span> icon or some other item whose extension is <span class=\"code\">.jdk</span>. To see the contents of this item, control-click the item's icon and then select Show Package Contents.</li>\r\n \t<li>\r\n<p class=\"first-para\">On Linux, browse to the directory in which you've installed your preferred Java version. When in doubt, search for a directory whose name starts with <span class=\"code\">jre</span> or <span class=\"code\">jdk</span>.</p>\r\n</li>\r\n</ul>\r\n<p class=\"child-para\">You might have one more thing to do back in the JRE Definition dialog.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Look at the JRE Definition dialog's JRE Name field; if Eclipse hasn't filled in a name automatically, type a name (almost any text) in the JRE Name field.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Dismiss the JRE Definition dialog by clicking Finish.</p>\r\n<p class=\"child-para\">Eclipse's Preferences dialog returns to the foreground. The box's Installed JREs list contains your newly added version of Java.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Put a check mark in the check box next to your newly added version of Java.</p>\r\n<p class=\"child-para\">You’re almost done. (You have a few more steps to follow.)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Within the Java branch on the left side of the Preferences dialog, select the Compiler sub-branch.</p>\r\n<p class=\"child-para\">In the main body of the Preferences dialog, you see a Compiler Compliance Level drop-down list.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434480.image3.jpg\" alt=\"image3.jpg\" width=\"417\" height=\"400\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the Compiler Compliance Level drop-down list, select a number that matches your preferred Java version.</p>\r\n<p class=\"child-para\">For Java 7, you select compliance level 1.7. For Java 8, you select compliance level 1.8.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Whew! Click the Preferences dialog's OK button to return to the Eclipse workbench.</p>\r\n</li>\r\n</ol>","description":"Eclipse normally looks on your computer for Java installations and selects an installed version of Java to use for running your Java programs. Your computer may have more than one version of Java, so you may want to double-check Eclipse's choice of the Java version. The following steps show you how:\r\n<ol class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">On Windows or Linux: In Eclipse's main menu, select Window→Preferences. On a Mac: In Eclipse's main menu, select Eclipse→Preferences.</p>\r\n<p class=\"child-para\">As a result, Eclipse's Preferences dialog appears.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434477.image0.jpg\" alt=\"image0.jpg\" width=\"501\" height=\"400\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the tree on the left side of the Preferences dialog, expand the Java branch.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Within the Java branch, select the Installed JREs sub-branch.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Look at the list of Java versions (Installed JREs) in the main body of the Preferences dialog.</p>\r\n<p class=\"child-para\">In the list, each version of Java has a check box. Eclipse uses the version whose box is checked. If the checked version isn't your preferred version (for example, if the checked version isn't version 8 or higher), you can make some changes.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">If your preferred version of Java appears in the Installed JREs list, put a check mark in that version's check box.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">If your preferred version of Java doesn't appear in the Installed JREs list, click the Add button.</p>\r\n<p class=\"child-para\">When you click the Add button, a JRE Type dialog appears.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434478.image1.jpg\" alt=\"image1.jpg\" width=\"535\" height=\"373\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the JRE Type dialog, double-click Standard VM.</p>\r\n<p class=\"child-para\">As a result, a JRE Definition dialog appears. What you do next depends on a few different things.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Fill in the dialog's JRE Home field.</p>\r\n<p class=\"child-para\">How you do this depends on your operating system.</p>\r\n\r\n<ul class=\"level-two\">\r\n \t<li>\r\n<p class=\"first-para\">On Windows, browse to the directory in which you've installed your preferred Java version. On your Windows computers, that directory is either <span class=\"code\">C:Program FilesJavajre8</span>, <span class=\"code\">C:Program FilesJavajdk1.8.0</span>, <span class=\"code\">C:Program Files (x86)Javajre8</span>, or something of that sort.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">On a Mac, use the Finder to browse to the directory in which you've installed your preferred Java version. Type the name of the directory in the dialog's JRE Home field.</p>\r\n<p class=\"child-para\">My Mac has one Java directory named <span class=\"code\">/System/Library/Java/Java Virtual Machines/1.6.0.jdk/Contents/Home</span> and another Java directory named <span class=\"code\">/Library/Java/JavaVirtualMachines/jdk 1.8.0.jdk/Contents/Home</span>. (The first is for Apple's old version of Java; the second is for Oracle's new Java version.) You might also find Oracle's Java in the <span class=\"code\">/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home</span> directory.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434479.image2.jpg\" alt=\"image2.jpg\" width=\"389\" height=\"400\" />\r\nDirectories like <span class=\"code\">/System</span> and <span class=\"code\">/Library</span> don't normally appear in the Finder window. To browse to one of these directories (to the <span class=\"code\">/Library</span> directory, for example), choose Go→Go to Folder in the Finder's menu bar. In the resulting dialog, type <span class=\"code\">/Library</span> and then press Go.\r\n\r\nAs you navigate to the directory containing your preferred Java version, you may encounter a <span class=\"code\">JDK 1.8.0.jdk</span> icon or some other item whose extension is <span class=\"code\">.jdk</span>. To see the contents of this item, control-click the item's icon and then select Show Package Contents.</li>\r\n \t<li>\r\n<p class=\"first-para\">On Linux, browse to the directory in which you've installed your preferred Java version. When in doubt, search for a directory whose name starts with <span class=\"code\">jre</span> or <span class=\"code\">jdk</span>.</p>\r\n</li>\r\n</ul>\r\n<p class=\"child-para\">You might have one more thing to do back in the JRE Definition dialog.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Look at the JRE Definition dialog's JRE Name field; if Eclipse hasn't filled in a name automatically, type a name (almost any text) in the JRE Name field.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Dismiss the JRE Definition dialog by clicking Finish.</p>\r\n<p class=\"child-para\">Eclipse's Preferences dialog returns to the foreground. The box's Installed JREs list contains your newly added version of Java.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Put a check mark in the check box next to your newly added version of Java.</p>\r\n<p class=\"child-para\">You’re almost done. (You have a few more steps to follow.)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Within the Java branch on the left side of the Preferences dialog, select the Compiler sub-branch.</p>\r\n<p class=\"child-para\">In the main body of the Preferences dialog, you see a Compiler Compliance Level drop-down list.</p>\r\n<img src=\"https://www.dummies.com/wp-content/uploads/434480.image3.jpg\" alt=\"image3.jpg\" width=\"417\" height=\"400\" /></li>\r\n \t<li>\r\n<p class=\"first-para\">In the Compiler Compliance Level drop-down list, select a number that matches your preferred Java version.</p>\r\n<p class=\"child-para\">For Java 7, you select compliance level 1.7. For Java 8, you select compliance level 1.8.</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Whew! Click the Preferences dialog's OK button to return to the Eclipse workbench.</p>\r\n</li>\r\n</ol>","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":null,"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":0,"slug":null,"isbn":null,"categoryList":null,"amazon":null,"image":null,"title":null,"testBankPinActivationLink":null,"bookOutOfPrint":false,"authorsInfo":null,"authors":null,"_links":null},"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;:[null]}]\" id=\"du-slot-63221b08e8109\"></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;:[null]}]\" id=\"du-slot-63221b08e8e8f\"></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":"One year","lifeExpectancySetFrom":"2021-11-23T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":150777}],"_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":"2022-10-18T10: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":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":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":287569,"title":"For the Hopeless Romantic","hasSubCategories":false,"url":"/collection/for-the-hopeless-romantic-287569"},{"collectionId":287567,"title":"For the Unabashed Hippie","hasSubCategories":false,"url":"/collection/for-the-unabashed-hippie-287567"},{"collectionId":292186,"title":"Just DIY It","hasSubCategories":false,"url":"/collection/just-diy-it-292186"}],"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":{}}},"sfmcState":{"status":"initial"},"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
Contemplating the Cosmos
For Those Seeking Peace of Mind
For the Aspiring Aficionado
For the Budding Cannabis Enthusiast
For the Exam-Season Crammer
For the Hopeless Romantic
For the Unabashed Hippie
Just DIY It
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 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 All-in-One For Dummies Cheat Sheet

Cheat Sheet / Updated 02-24-2022

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 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
Java How to Configure Java in Eclipse

Article / Updated 11-23-2021

Eclipse normally looks on your computer for Java installations and selects an installed version of Java to use for running your Java programs. Your computer may have more than one version of Java, so you may want to double-check Eclipse's choice of the Java version. The following steps show you how: On Windows or Linux: In Eclipse's main menu, select Window→Preferences. On a Mac: In Eclipse's main menu, select Eclipse→Preferences. As a result, Eclipse's Preferences dialog appears. In the tree on the left side of the Preferences dialog, expand the Java branch. Within the Java branch, select the Installed JREs sub-branch. Look at the list of Java versions (Installed JREs) in the main body of the Preferences dialog. In the list, each version of Java has a check box. Eclipse uses the version whose box is checked. If the checked version isn't your preferred version (for example, if the checked version isn't version 8 or higher), you can make some changes. If your preferred version of Java appears in the Installed JREs list, put a check mark in that version's check box. If your preferred version of Java doesn't appear in the Installed JREs list, click the Add button. When you click the Add button, a JRE Type dialog appears. In the JRE Type dialog, double-click Standard VM. As a result, a JRE Definition dialog appears. What you do next depends on a few different things. Fill in the dialog's JRE Home field. How you do this depends on your operating system. On Windows, browse to the directory in which you've installed your preferred Java version. On your Windows computers, that directory is either C:Program FilesJavajre8, C:Program FilesJavajdk1.8.0, C:Program Files (x86)Javajre8, or something of that sort. On a Mac, use the Finder to browse to the directory in which you've installed your preferred Java version. Type the name of the directory in the dialog's JRE Home field. My Mac has one Java directory named /System/Library/Java/Java Virtual Machines/1.6.0.jdk/Contents/Home and another Java directory named /Library/Java/JavaVirtualMachines/jdk 1.8.0.jdk/Contents/Home. (The first is for Apple's old version of Java; the second is for Oracle's new Java version.) You might also find Oracle's Java in the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home directory. Directories like /System and /Library don't normally appear in the Finder window. To browse to one of these directories (to the /Library directory, for example), choose Go→Go to Folder in the Finder's menu bar. In the resulting dialog, type /Library and then press Go. As you navigate to the directory containing your preferred Java version, you may encounter a JDK 1.8.0.jdk icon or some other item whose extension is .jdk. To see the contents of this item, control-click the item's icon and then select Show Package Contents. On Linux, browse to the directory in which you've installed your preferred Java version. When in doubt, search for a directory whose name starts with jre or jdk. You might have one more thing to do back in the JRE Definition dialog. Look at the JRE Definition dialog's JRE Name field; if Eclipse hasn't filled in a name automatically, type a name (almost any text) in the JRE Name field. Dismiss the JRE Definition dialog by clicking Finish. Eclipse's Preferences dialog returns to the foreground. The box's Installed JREs list contains your newly added version of Java. Put a check mark in the check box next to your newly added version of Java. You’re almost done. (You have a few more steps to follow.) Within the Java branch on the left side of the Preferences dialog, select the Compiler sub-branch. In the main body of the Preferences dialog, you see a Compiler Compliance Level drop-down list. In the Compiler Compliance Level drop-down list, select a number that matches your preferred Java version. For Java 7, you select compliance level 1.7. For Java 8, you select compliance level 1.8. Whew! Click the Preferences dialog's OK button to return to the Eclipse workbench.

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 A Book Pin

Connect

Opt in to our newsletter!

By entering your email address and clicking the “Submit” button, you agree to the Terms of Use and Privacy Policy & to receive electronic communications from Dummies.com, which may include marketing promotions, news and updates.

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.

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