1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Monday's Programming Question

Monday December 8, 2008

This week it's the turn of wrapper classes to take the spotlight. Every primitive data type has a corresponding class. These classes are handy if you want to make the primitive data type into an object. For example, the data type int has a corresponding wrapper class called Integer.

It's important to remember that the wrapper classes are not the same as primitive data types and will act differently in certain circumstances. In the following lines of code I've been playing with wrapper classes. The question is can you figure out what the values of the wrapper objects will be?

Boolean eminem = new Boolean("yes");

Boolean lLCoolJ = new Boolean("true");

Integer mosDef = new Integer(Integer.MAX_VALUE+1);

Long queenLatifah = new Long(Integer.MAX_VALUE+1);

Long iceCube = new Long((long)Integer.MAX_VALUE + 1);

Long jayZ = new Long(iceCube++);

Long kanyeWest = new Long(++iceCube);

Character snoopDogg = new Character("c".replace("c", "d").toCharArray()[0]);

Double theGame = new Double(Double.POSITIVE_INFINITY);

Double common = new Double (Math.round(Double.POSITIVE_INFINITY));

Integer nas = 10444;
Integer trickTrick = 10444;
Boolean lilWayne = (nas == trickTrick);

Boolean bowWow = (nas.equals(trickTrick));
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.