tailieunhanh - Sams Teach Yourself Java 6 in 21 Days 5th phần 3

Như bạn đã học được, Java cung cấp lớp wrapper như Integer và Float cho mỗi của các loại nguyên thủy. Bằng cách sử dụng phương pháp lớp được định nghĩa trong những lớp học, bạn có thể chuyển các đối tượng các loại nguyên thủy và chuyển đổi các loại nguyên thủy cho các đối tượng. | 124 SimpoEPDF Mergeand Split Unregistered Version - http As you have learned Java supplies wrapper classes such as Integer and Float for each of the primitive types. By using class methods defined in those classes you can convert objects to primitive types and convert primitive types to objects. For example the parseInt class method in the Integer class can be used with a string argument returning an int representation of that string. The following statement shows how the parseInt method can be used int count 42 In the preceding statement the String value 42 is returned by parseInt as an integer with a value of 42 and this is stored in the count variable. The lack of a static keyword in front of a method name makes it an instance method. Instance methods operate in a particular object rather than a class of objects. On Day 1 Getting Started with Java you created an instance method called checkTemperature that checked the temperature in the robot s environment. TIP Most methods that affect a particular object should be defined as instance methods. Methods that provide some general capability but do not directly affect an instance of the class should be declared as class methods. Creating Java Applications Now that you know how to create classes objects class and instance variables and class and instance methods you can put it all together in a Java program. To refresh your memory applications are Java classes that can be run on their own. NOTE Applications are different from applets which are run by a Java-enabled browser as part of a web page. You can find out how to develop applets in Writing Java Applets a bonus chapter included on this book s CD. A Java application consists of one or more classes and can be as large or as small as you want it to be. Although all the applications you ve created up to this point do nothing but output some characters to the screen you also can create Java applications that use windows graphics and

TỪ KHÓA LIÊN QUAN