This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wrapper object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wrapper object" Watch "wrapper object" New topic

wrapper object

saran bala

Joined: Oct 17, 2007
Posts: 8
can you please explain the reason?

public class Test12{
public static void main(String a[]){
byte b = 100;
Byte b1= new Byte(100);
Byte b2 = new Byte(b);
System.out.println(b1 == b2);
What is output?

Answer:Complier error
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14991

Try compiling it yourself. What error does the compiler give you exactly? Read the error message carefully and try to understand what it means.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Yogesh Baraskar
Ranch Hand

Joined: Oct 07, 2007
Posts: 33
Byte b1= new Byte(100);
literals like 100 are of integer type by default.

To create a Byte object using new you should pass a byte

Try this
Byte b1= new Byte((byte)(100));
I agree. Here's the link:
subject: wrapper object
It's not a secret anymore!