Math and Wrapper Classes Notes.docx - Math and Wrapper Classes There are other classes that have useful methods in them that we don\u2019t have to write

Math and Wrapper Classes Notes.docx - Math and Wrapper...

This preview shows page 1 - 2 out of 3 pages.

Math and Wrapper Classes There are other classes that have useful methods in them that we don’t have to write. This is referred to as procedural abstraction. We are going to look at two wrapper classes and the Math class. These are classes that the AP would like you to know. All three classes are part of the java.lang package so the programmer does not need to import them unlike Scanner. Create a file called Example06 and write the following: import static java.lang.System.*; public class Example06 { public static void main(String args []) { Integer k = new Integer(82); Integer x ; int y , z ; x = 22; //autoboxing y = k .intValue(); z = x ; //unboxing out .println( "k = " + k ); out .println( "x = " + x ); out .println( "y = " + y ); out .println( "z = " + z ); out .println( "Smallest Integer = " +Integer. MIN_VALUE ); out .println( "Largest Integer = " +Integer. MAX_VALUE ); } } The output should look like this: k = 82 x = 22 y = 82 z = 22 Smallest Integer = -2147483648 Largest Integer = 2147483647 The Integer wrapper class is a way to hold the int primitive data type as an object. The wonderful thing about the Integer class is that they use autoboxing and unboxing . Autoboxing is the automatic conversion of a data type to a corresponding wrapper class. Autoboxing occurs when a primitive value is
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 3 pages?

  • Fall '20

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture