Archive for December, 2007

110 Part II: Writing Your Own Java Programs (Php web hosting)

Friday, December 21st, 2007

110 Part II: Writing Your Own Java Programs You can use all Java s comparison operators to compare numbers and characters. When you compare numbers, things go pretty much the way you think they should go. But when you compare characters, things are a little strange. Comparing uppercase letters with one another is no problem. Because the letter B comes alphabetically before H, the condition B < H is true. Comparing lowercase letters with one another is also okay. What s strange is that when you compare an uppercase letter with a lowercase letter, the uppercase letter is always smaller. So, even though Z < A is false, Z < a is true. Under the hood, the letters A through Z are stored with numeric codes 65 through 90. The letters a through z are stored with codes 97 through 122. That s why each uppercase letter is smaller than each lowercase letter. Be careful when you compare two numbers for equality (with ==) or inequality (with !=). After doing some calculations and obtaining two doublevalues or two floatvalues, the values that you have are seldom dead-on equal to one another. (The problem comes from those pesky digits beyond the decimal point.) For instance, the Fahrenheit equivalent of 21 degrees Celsius is 69.8, and when you calculate 9.0 / 5 * 21 + 32by hand, you get 69.8. But the condition 9.0 / 5 * 21 + 32 == 69.8turns out to be false. That s because, when the computer calculates 9.0 / 5 * 21 + 32, it gets 69.80000000000001, not 69.8. Comparing objects When you start working with objects, you find that you can use ==and !=to compare objects with one another. For instance, a button that you see on the computer screen is an object. You can ask whether the thing that was just mouse-clicked is a particular button on your screen. You do this with Java s equality operator. if (e.getSource() == bCopy) { clipboard.setText(which.getText()); To find out more about responding to button clicks, read Chapter 16 on this book s CD-ROM. The big gotcha with Java s comparison scheme comes when you compare two strings. (For a word or two about Java s Stringtype, see the section about reference types in Chapter 4.) When you compare two strings with one another, you don t want to use the double equal sign. Using the double equal sign would ask, Is this string stored in exactly the same place in memory as that other string? That s usually not what you want to ask. Instead, you usually want to ask, Does this string have the same characters in it as that other
CGI is used because it is far better and more physical than other ways , such as constructing miniatures for effects shots or hiring a cheap deal of extras for crowd scenes, and because it allows the creation of images that would not be feasible using any other technology.Check fore more details under our cgi web hosting section.

Chapter 5: Controlling Program Flow with Decision-Making Statements (Web hosting service)

Thursday, December 20th, 2007

Chapter 5: Controlling Program Flow with Decision-Making Statements 109 Figure 5-3: Two runs of the game in Listing 5-2. Listing 5-2 illustrates another new idea. With an importdeclaration for System.in, I can reduce new Scanner(System.in)to the shorter new Scanner(in). Adding this importdeclaration is hardly worth the effort. In fact, I do more typing with the importdeclaration than without it. Nevertheless, the code in Listing 5-2 demonstrates that it s possible to import System.in. Forming Conditions with Comparisons and Logical Operators The Java programming language has plenty of little squiggles and doodads for your various condition-forming needs. This section tells you all about them. Comparing numbers; comparing characters Table 5-1 shows you the operators that you can use to compare one thing with another. Table 5-1 Comparison Operators Operator Symbol Meaning Example == is equal to numberOfCows == 5 != is not equal to buttonClicked != panicButton < is less than numberOfCows < 5 > is greater than myInitial > B <= is less than or equal to numberOfCows <= 5 >= is greater than or equal to myInitial >= B
The European settlement at Melbourne was founded in 1835 by settlers coming from Tasmania (then known as Van Die men’s Land), where they had difficulty finding available land.We provides affordable, discount and cheapest Melbourne web hosting, free domain name, unlimited data transfer, unlimited emails, PHP, ASP, and database hosting,check Web Hosting Melbourne services.

108 Part II: Writing Your Own Java Programs (Cheap web hosting)

Wednesday, December 19th, 2007

108 Part II: Writing Your Own Java Programs When you write ifstatements, you may be tempted to chuck all the rules about curly braces out the window and just rely on indentation. Unfortunately, this seldom works. If you indent three statements after the word else and forget to enclose those statements in curly braces, the computer thinks that the else part includes only the first of the three statements. What s worse, the indentation misleads you into believing that the elsepart includes all three statements. This makes it more difficult for you to figure out why your code isn t behaving the way you think it should behave. So watch those braces! Elseless in Ifrica Okay, so the title of this section is contrived. Big deal! The idea is that you can create an ifstatement without the elsepart. Take, for instance, the code in Listing 5-1. Maybe you d rather not rub it in whenever the user loses the game. The modified code in Listing 5-2 shows you how to do this (and Figure 5-3 shows you the result). Listing 5-2: A Kinder, Gentler Guessing Game import static java.lang.System.in; import static java.lang.System.out; import java.util.Scanner; import java.util.Random; class DontTellThemTheyLost { public static void main(String args[]) { Scanner myScanner = new Scanner(in); out.print( Enter an int from 1 to 10: ); int inputNumber = myScanner.nextInt(); int randomNumber = new Random().nextInt(10) + 1; if (inputNumber == randomNumber) { out.println( *You win.* ); } out.println( That was a very good guess :-) ); out.print( The random number was ); out.println(randomNumber + . ); out.println( Thank you for playing. ); } } The ifstatement in Listing 5-2 has no elsepart. When inputNumberis the same as randomNumber, the computer prints You win.When inputNumber is different from randomNumber, the computer doesn t print You win.
If you need complete web hosting solution you come to right place,try mac web hosting services.

Chapter 5: Controlling Program Flow with Decision-Making Statements (Make web site)

Wednesday, December 19th, 2007

Chapter 5: Controlling Program Flow with Decision-Making Statements 107 Brace yourself The ifstatement in Listing 5-1 has two halves a top half and a bottom half. I have names for these two parts of an ifstatement. I call them the if part (the top half) and the else part (the bottom half). The ifpart in Listing 5-1 seems to have more than one statement in it. I make this happen by enclosing the three statements of the ifpart in a pair of curly braces. When I do this, I form a block. A block is a bunch of statements scrunched together by a pair of curly braces. With this block, three calls to printlnare tucked away safely inside the if part. With the curly braces, the rows of asterisks and the words You winare displayed only when the user s guess is correct. This business with blocks and curly braces applies to the elsepart as well. In Listing 5-1, whenever inputNumberdoesn t equal randomNumber, the computer executes three print/printlncalls. To convince the computer that all three of these calls are inside the elseclause, I put these calls into a block. That is, I enclose these three calls in a pair of curly braces. Strictly speaking, Listing 5-1 has only one statement between the ifand the elsestatements and only one statement after the elsestatement. The trick is that when you place a bunch of statements inside curly braces, you get a block; and a block behaves, in all respects, like a single statement. In fact, the official Java documentation lists blocks as one of the many kinds of statements. So, in Listing 5-1, the block that prints You winand asterisks is a single statement. It s a statement that has, within it, three smaller statements. Indenting if statements in your code Notice how, in Listing 5-1, the printand printlncalls inside the ifstatement are indented. (This includes both the You winand You losestatements. The printand printlncalls that come after the word else are still part of the ifstatement.) Strictly speaking, you don t have to indent the statements that are inside an ifstatement. For all the compiler cares, you can write your whole program on a single line or place all your statements in an artful, misshapen zigzag. The problem is that if you don t indent your statements in some logical fashion, neither you nor anyone else can make sense of your code. In Listing 5-1, the indenting of the printand println statements helps your eye (and brain) see quickly that these statements are subordinate to the overall if/elseflow. In a small program, unindented or poorly indented code is barely tolerable. But in a complicated program, indentation that doesn t follow a neat, logical pattern is a big, ugly nightmare.
Need a managed web hosting provider to help maintain your website? Our web hosting service is the preferred choice of thousands of demanding customers.

106 Part II: Writing Your Own Java Programs (Simple web server)

Tuesday, December 18th, 2007

106 Part II: Writing Your Own Java Programs Figure 5-2: An if statement is like a fork in the road. Does inputNumber equal randomNumber? ********** *You win.* ********** You lose. The random number was… Thank you for playing. yes no Sometimes, when I m writing about a condition that s being tested, I slip into using the word expression instead of condition. That s okay, because every condition is an expression. An expression is something that has a value and, sure enough, every condition has a value. The condition s value is either trueor false. (For revealing information about expressions and values like trueand false, see Chapter 4.) The double equal sign In Listing 5-1, in the ifstatement s condition, notice the use of the double equal sign. Comparing two numbers to see whether they re the same isn t the same as setting something equal to something else. That s why the symbol to compare for equality isn t the same as the symbol that s used in an assignment or an initialization. In an ifstatement s condition, you can t replace the double equal sign with a single equal sign. If you do, your program just won t work. (You almost always get an error message when you try to compile your code.) On the other hand, if you never make the mistake of using a single equal sign in a condition, you re not normal. Not long ago, while I was teaching an introductory Java course, I promised that I d swallow my laser pointer if no one made the single equal sign mistake during any of the lab sessions. This wasn t an idle promise. I knew I d never have to keep it. As it turned out, even if I had ignored the first ten times anybody made the single equal sign mistake during those lab sessions, I would still be laser-pointer free. Everybody mistakenly uses the single equal sign several times in his or her programming career. The trick is not to avoid making the mistake; the trick is to catch the mistake whenever you make it.
Would you like to be a member of headache free web site owner’s community. Now you can. We focus in IX Web Hosting, go go go!

Chapter 5: Controlling Program Flow with Decision-Making Statements (Web hosting java)

Monday, December 17th, 2007

Chapter 5: Controlling Program Flow with Decision-Making Statements 105 Computers aren t much better than coins and human thumbs. A computer mimics the generation of random sequences but, in the end, the computer just does what it s told and does all this in a purely deterministic fashion. So in Listing 5-1, when the computer executes import java.util.Random; int randomNumber = new Random().nextInt(10) + 1; the computer appears to give us a randomly generated number a whole number between 1 and 10. But it s all a fake. The computer just follows instructions. It s not really random, but without bending a computer over backwards, it s the best that anyone can do. Once again, I ask you to take this code on blind faith. Don t worry about what new Random().nextIntmeans until you have more experience with Java. Just copy this code into your own programs and have fun with it. And if the numbers from 1 to 10 aren t in your flight plans, don t fret. To roll an imaginary die, write the statement int rollEmBaby = new Random().nextInt(6) + 1; With the execution of this statement, the variable rollEmBabygets a value from 1to 6. The if statement At the core of Listing 5-1 is a Java ifstatement. This ifstatement represents a fork in the road. (See Figure 5-2.) The computer follows one of two prongs the prong that prints You winor the prong that prints You lose. The computer decides which prong to take by testing the truth or falsehood of a condition. In Listing 5-1, the condition being tested is inputNumber == randomNumber Does the value of inputNumberequal the value of randomNumber? When the condition is true, the computer does the stuff between the condition and the word else. When the condition turns out to be false, the computer does the stuff after the word else. Either way, the computer goes on to execute the last printlncall, which displays Thank you for playing. The condition in an ifstatement must be enclosed in parentheses. However, a line like if (inputNumber == randomNumber)is not a complete statement (just as If I had a hammer isn t a complete sentence). So this line if (inputNumber == randomNumber)shouldn t end with a semicolon.
Here java web hosting you will find professional-grade java web hosting at affordable prices.

Tomcat web hosting - 104 Part II: Writing Your Own Java Programs

Saturday, December 15th, 2007

104 Part II: Writing Your Own Java Programs I can also beef up my program s importdeclarations, as I do in Listings 5-2 and 5-3. Other than that, I have very little leeway. As you read on in this book, you ll start recognizing the patterns behind these three lines of code, so I don t clutter up this section with all the details. For now, you can just copy these three lines and keep the following in mind: When you import java.util.Scanner, you don t use the word static. Importing Scanneris different from importing System.out. When you import java.lang.System.out, you use the word static. (See Listing 5-1.) For the real story on the word static, see Chapter 10. The name System.in stands for the keyboard. To get characters from someplace other than the keyboard, you can type something other than System.ininside the parentheses. What else can you put inside the parentheses? For some ideas, see Chapter 8. When you expect the user to type an int value (a whole number of some kind), use nextInt(). If you expect the user to type a doublevalue (a number containing a decimal point), use nextDouble(). If you expect the user to type true or false, use nextBoolean(). If you expect the user to type a word (a word like Barry, Java, or Hello), use next(). For an example in which the user types a word, see Listing 5-3. For an example in which the user types a single character, see Listing 6-4 in Chapter 6. For an example in which a program reads an entire line of text (all in one big gulp), see Chapter 8. You can get several values from the keyboard, one after another. To do this, use the myScanner.nextInt()code several times. To see a program that reads more than one value from the keyboard, go to Listing 5-4. Creating randomness Achieving real randomness is surprisingly difficult. Mathematician Persi Diaconis says that if you flip a coin several times, always starting with the head side up, you re likely to toss heads more often than tails. If you toss several more times, always starting with the tail side up, you re likely to toss tails more often than heads. In other words, coin tossing isn t really fair.* * Diaconis, Persi. The Search for Randomness. American Association for the Advancement of Science annual meeting. Seattle. 14 Feb. 2004.
As web cam capabilities have been added to instant messaging text chat services such as Yahoo Messenger, AOL Instant Messenger (AIM), MSN Messenger and Skype, one-to-one live video communication over the internet has now reached millions of mainstream PC users worldwide.You can see details on web cam web hosting section.

Chapter 5: Controlling Program Flow with Decision-Making Statements (Php hosting)

Friday, December 14th, 2007

Chapter 5: Controlling Program Flow with Decision-Making Statements 103 Figure 5-1: Two runs of the guessing game. The program in Listing 5-1 plays a guessing game with the user. The program gets a number (a guess) from the user and then generates a random number between 1 and 10. If the number that the user entered is the same as the random number, the user wins. Otherwise, the user loses. In either case, the program tells the user what the random number was. She controlled keystrokes from the keyboard Taken together, the lines import java.util.Scanner; Scanner myScanner = new Scanner(System.in); int inputNumber = myScanner.nextInt(); in Listing 5-1 get whatever number the user types on the keyboard. The last of the three lines puts this number into a variable named inputNumber. If these lines look complicated, don t worry. You can copy these lines almost word for word whenever you want to read from the keyboard. Include the first two lines (the importand Scannerlines) just once in your program. Later in your program, wherever the user types an intvalue, include a line with a call to nextInt(as in the last of the preceding three lines of code). Of all the names in these three lines of code, the only two names that I coined myself are inputNumber and myScanner. All the other names are part of Java. So, if I want to be creative, I can write the lines this way: import java.util.Scanner; Scanner readingThingie = new Scanner(System.in); int valueTypedIn = readingThingie.nextInt();
Our Colorado hosting facilities are located in Little Rock, Colorado. Colorado web hosting datacenter which we have is linked on five major US backbones which gives you assurance that your site will be online 24/7 a day. More details you can find out in Web Hosting Colorado part.

102 Part II: Writing Your Own Java Programs (Paypal hosting)

Thursday, December 13th, 2007

102 Part II: Writing Your Own Java Programs Making Decisions (Java if Statements) When you re writing computer programs, you re constantly hitting forks in roads. Did the user correctly type his or her password? If yes, let the user work; if no, kick the bum out. So the Java programming language needs a way of making a program branch in one of two directions. Fortunately, the language has a way. It s called an if statement. Guess the number The use of an ifstatement is illustrated in Listing 5-1. Two runs of the program in Listing 5-1 are shown in Figure 5-1. Listing 5-1: A Guessing Game import static java.lang.System.out; import java.util.Scanner; import java.util.Random; class GuessingGame { public static void main(String args[]) { Scanner myScanner = new Scanner(System.in); out.print( Enter an int from 1 to 10: ); int inputNumber = myScanner.nextInt(); int randomNumber = new Random().nextInt(10) + 1; if (inputNumber == randomNumber) { out.println( ********** ); out.println( *You win.* ); out.println( ********** ); } else { out.println( You lose. ); out.print( The random number was ); out.println(randomNumber + . ); } out.println( Thank you for playing. ); } }
If you are looking quality, fast, secure and reliable web hosting with PHP service at an affordable price, check php5 hosting services.

Chapter 5 Controlling Program Flow with Decision-Making Statements

Wednesday, December 12th, 2007

Chapter 5 Controlling Program Flow with Decision-Making Statements In This Chapter Writing statements that choose between alternatives Putting statements inside one another Choosing among many alternatives The TV show Dennis the Menace aired on CBS from 1959 to 1963. I remember one episode in which Mr. Wilson was having trouble making an important decision. I think it was something about changing jobs or moving to a new town. Anyway, I can still see that shot of Mr. Wilson sitting in his yard, sipping lemonade, and staring into nowhere for the whole afternoon. Of course, the annoying character Dennis was constantly interrupting Mr. Wilson s peace and quiet. That s what made this situation funny. What impressed me about this episode (the reason why I remember it so clearly even now) was Mr. Wilson s dogged intent in making the decision. This guy wasn t going about his everyday business, roaming around the neighborhood, while thoughts about the decision wandered in and out of his mind. He was sitting quietly in his yard, making marks carefully and logically on his mental balance sheet. How many people actually make decisions this way? At that time, I was still pretty young. I d never faced the responsibility of having to make a big decision that affected my family and me. But I wondered what such a decision-making process would be like. Would it help to sit there like a stump for hours on end? Would I make my decisions by the careful weighing and tallying of options? Or would I shoot in the dark, take risks, and act on impulse? Only time would tell.
Every our account comes with web mail client, free virus scanner, free anti-spam tool, free web templates and much more. For complete list of all our virtual web hosting features check our Virtual Web Hosting section.