File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring 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: 15038

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));
It is sorta covered in the JavaRanch Style Guide.
subject: wrapper object
It's not a secret anymore!