Archive for December, 2007

90 Part II: Writing Your Own Java Programs (Yahoo web space)

Monday, December 3rd, 2007

90 Part II: Writing Your Own Java Programs Every Java class is a reference type. If you declare a variable to have some type that s not a primitive type, the variable s type is (most of the time) the name of a Java class. Now, when you declare a variable to have type int, you can visualize what that declaration means in a fairly straightforward way. It means that, somewhere inside the computer s memory, a storage location is reserved for that variable s value. In that storage location is a bunch of bits. The arrangement of the bits assures that a certain whole number is represented. That explanation is fine for primitive types like intor double, but what does it mean when you declare a variable to have a reference type? What does it mean to declare variable myFrameto be of type JFrame? Well, what does it mean to declare i thank You God to be an E. E. Cummings poem? What would it mean to write the following declaration? EECummingsPoem ithankYouGod; It means that a class of things is EECummingsPoem, and ithankYouGod refers to an instance of that class. In other words, ithankYouGodis an object belonging to the EECummingsPoemclass. Because JFrameis a class, you can create objects from that class. (See Chapter 1.) Each such object (each instance of the JFrameclass) is an actual frame a window that appears on the screen when you run the code in Listing 4-6. By declaring the variable myFrameto be of type JFrame, you re reserving the use of the name myFrame. This reservation tells the computer that myFramecan refer to an actual JFrame-type object. In other words, myFramecan become a nickname for one of the windows that appears on the computer screen. The situation is illustrated in Figure 4-8. When you declare ClassName variableName;, you re saying that a certain variable can refer to an instance of a particular class. In Listing 4-6, the phrase JFrame myFramereserves the use of the name myFrame. On that same line of code, the phrase new JFrame()creates a new object (an instance of the JFrameclass). Finally, that line s equal sign makes myFramerefer to the new object. Knowing that the two words new JFrame()create an object can be very important. For a more thorough explanation of objects, see Chapter 7.
Don’t want to have just any web hosting, but web hosting provider who will share the same beliefs? You have found them. Our Church Web Hosting company will treat in you in appropriate way, the one you are accustomed to.

Chapter 4: Making the Most of Variables and (Business web hosting)

Sunday, December 2nd, 2007

Chapter 4: Making the Most of Variables and Their Values 89 The program in Listing 4-6 uses two references types. Both these types are defined in the Java API. One of the types (the one that you ll use all the time) is called String. The other type (the one that you can use to create GUIs) is called JFrame. A Stringis a bunch of characters. It s like having several charvalues in a row. So, with the myTitlevariable declared to be of type String, assigning Blank Frame to the myTitlevariable makes sense in Listing 4-6. The Stringclass is declared in the Java API. In a Java program, double quote marks surround the letters in a Stringliteral. A Java JFrame is a lot like a window. (The only difference is that you call it a JFrame instead of a window.) To keep Listing 4-6 short and sweet, I decided not to put anything in my frame no buttons, no fields, nothing. Even with a completely empty frame, Listing 4-6 uses tricks that I don t describe until later in this book. So don t try reading and interpreting every word of Listing 4-6. The big thing to get from Listing 4-6 is that the program has two variable declarations. In writing the program, I made up two variable names myTitleand myFrame. According to the declarations, myTitleis of type String, and myFrameis of type JFrame. You can look up Stringand JFramein Java s API documentation. But, even before you do, I can tell you what you ll find. You ll find that Stringand JFrameare the names of Java classes. So, that s the big news. Every class is the name of a reference type. You can reserve amountInAccountfor doublevalues by writing double amountInAccount; or by writing double amountInAccount = 50.22; You can also reserve myFramefor a JFramevalue by writing JFrame myFrame; or by writing JFrame myFrame = new JFrame(); To review the notion of a Java class, see the sections on object-oriented programming (OOP) in Chapter 1.
We are dedicated to offering you a reliable, fast, and scalable unlimited web hosting home for your business, and personal web sites.Go and see our shared web hosting services.

Hp web site - 88 Part II: Writing Your Own Java Programs

Saturday, December 1st, 2007

88 Part II: Writing Your Own Java Programs In Listing 4-5, I call out.println()with nothing inside the parentheses. When I do this, Java adds a line break to the program s output. In Listing 4-5, out.println()tells the program to display a blank line. The Molecules and Compounds: Reference Types By combining simple things, you get more complicated things. That s the way it always goes. Take some of Java s primitive types, whip them together to make a primitive type stew, and what do you get? A more complicated type called a reference type. The program in Listing 4-6 uses reference types. Figure 4-7 shows you what happens when you run the program in Listing 4-6. Listing 4-6: Using Reference Types import javax.swing.JFrame; class ShowAFrame { public static void main(String args[]) { JFrame myFrame = new JFrame(); String myTitle = Blank Frame ; myFrame.setTitle(myTitle); myFrame.setSize(200, 200); myFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); myFrame.setVisible(true); } } Figure 4-7: An empty frame.
We will hook you up with a JSP web hosting at the great rate, check our jsp web hosting, and join us today!!!