80 Part II: Writing Your Own Java Programs (Business web site)
80 Part II: Writing Your Own Java Programs In Listing 4-2, you announce in the introduction (in the import declaration) that you re using System.outin your Java class. You clarify what you mean by Systemwith the full name java.lang.System. (Hey! Didn t the first lecturer clarify with the full name Lionel Herbert Blythe Barrymore? ) After having announced your intentions in the import declaration, you can use the abbreviated name out in your Java class code. The details of this import stuff can be pretty nasty. So for now, just paste the import declaration in Listing 4-2 at the top of your Java programs. (Don t bother pasting this import declaration into a program that doesn t use System.out. It probably wouldn t hurt anything, but it would look very strange to a veteran Java programmer.) No single section in this book can present the entire story about import declarations. To begin untangling some of the import declaration s subtleties, see Chapters 5, 9, and 10. Displaying Text The last three statements in Listing 4-2 use a neat formatting trick. You want to display several different things on a single line on the screen. You put these things in separate statements. All but the last of the statements are calls to out.print. (The last statement is a call to out.println.) Calls to out.printdisplay text on part of a line and then leave the cursor at the end of the current line. After executing out.print, the cursor is still at the end of the same line, so the next out.whatevercan continue printing on that same line. With several calls to print capped off by a single call to println, the result is just one nice-looking line of output. (Refer to Figure 4-3.) A call to out.printwrites some things and leaves the cursor sitting at the end of the line of output. A call to out.printlnwrites things and then finishes the job by moving the cursor to the start of a brand new line of output. Numbers without Decimal Points In 1995, the average family had 2.3 children. At this point, a wise guy always remarks that no real family has exactly 2.3 children. Clearly, whole numbers have a role in this world. So, in Java, you can declare a variable to store nothing but whole numbers. Listing 4-3 shows a program that uses whole number variables.
Our stuff is composed of devoted and highly-tainted professionals, creating a mix of powerful and high-quality web hosting perl services, check web hosting perl.