90 Part II: Writing Your Own Java Programs (Yahoo web space)
Monday, December 3rd, 200790 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.