JavaBeat
calling cards | international calling cards | phone card
JAVABEAT
home
articles
tips
QnA
forums
QNA TOPICS
All api java
java 6.0 java 7.0 jdbc
jsp servlet ejb
jndi jms ejb 3.0
j2ee jee 5.0 jee 6.0
jsf struts spring
Hibernate ajax JBoss Seam
netbeans eclipse ant
xml maven dojo
junit javafx j2me
log4j ESB JBoss
Apache Quartz scjp
mysql oracle gwt
openjpa jmx yui
google-guice android JBoss
scwcd 5.0 scjp 1.5 scjp 1.6
scja scbcd 5.0
JavaBeat Feeds JavaBeat RSS Feeds for Articles and Tips
JavaBeat Articles
JavaBeat QnA

JavaBeat Tips

Links for Developers

About Wrapper class in Java

Here no boxing or unboxing need to happen so it doens't happen. Generally when you compare objects using '==' it checks for reference equality rather its value equality(done through equals() method of object). But then how i==j returns true ? As String pool even Integer has its own pool or cache.

static final Integer cache[] = new Integer[-(-128) + 127 + 1];

static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Integer(i - 128);
}

From -128 to 127, values available in the the pool already, it takes from the pool. And for the values above/below it will create new object in the heap. Do the same operation for any value above 127 you will get false as the result.

Try the below snippet.

public class IntegerValueCheck {

public static void main(String[
] args) {
Integer i = 127;
Integer j = 127;
System.out.println("i==j >> "+ (i==j));

Integer a = 127;
Integer b = new Integer(127);

System.out.println("a==b >> "+ (a==b));

Integer k = 128;
Integer l = 128;
System.out.println("k==l >> "+ (k==l));


}

}

i==j >> true
a==b >> false
k==l >> false

Favorites
AffiliatedAds.com
Buy movies
Access Control
Busby seo challenge contest
Sohbet
Chat
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Sohbet
chat
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Website (2004-2008), India
javabeat | about us | planetoss
Copyright (2004 - 2008), JavaBeat