Archive for November, 2007

My web site - Chapter 3: Using the Basic Building Blocks 57

Thursday, November 1st, 2007

Chapter 3: Using the Basic Building Blocks 57 Curly braces Long ago, or maybe not so long ago, your schoolteachers told you how useful outlines are. With an outline, you can organize thoughts and ideas, help people see forests instead of trees, and generally show that you re a member of the Tidy Persons Club. Well, a Java program is like an outline. The program in Listing 3-1 starts with a big header line that says, Here comes a class named Displayer. After that first big header is a subheader that announces, Here comes a method named main. Now, if a Java program is like an outline, why doesn t a program look like an outline? What takes the place of the Roman numerals, capital letters, and other things? The answer is twofold: In a Java program, curly braces enclose meaningful units of code. You, the programmer, can (and should) indent lines so that other programmers can see the outline form of your code at a glance. In an outline, everything is subordinate to the item in Roman numeral I. In a Java program, everything is subordinate to the top line the line with the word classin it. To indicate that everything else in the code is subordinate to this classline, you use curly braces. Everything else in the code goes inside these curly braces. (See Listing 3-4.) Listing 3-4: Curly Braces for a Java Class class Displayer { public static void main(String args[]) { System.out.println( You ll love Java! ); } } In an outline, some stuff is subordinate to a capital letter A item. In a Java program, some lines are subordinate to the method header. To indicate that something is subordinate to a method header, you use curly braces. (See Listing 3-5.) Listing 3-5: Curly Braces for a Java Method class Displayer { public static void main(String args[]) { System.out.println( You ll love Java! ); } }
Are you tired of finding web hosting providers listed as inexpensive?Just check our Inexpensive Web Hosting services.