File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why(boolean b3=true;)(Boolean b4=true;)is both right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why(boolean b3=true;)(Boolean b4=true;)is both right?" Watch "why(boolean b3=true;)(Boolean b4=true;)is both right?" New topic
Author

why(boolean b3=true;)(Boolean b4=true;)is both right?

Jianfeng Qian
Ranch Hand

Joined: Jan 25, 2005
Posts: 83
shoud'nt be
Boolean=new Boolean(true);
or
Boolean=new Boolean("true");


Jianfeng Qian<br />SCJP 1.4, SCBCD 5.0(beta)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

I am assuming that you are using Java 1.5, which is why "Boolean b4 = true" works. Java 1.5 introduced an autoboxing feature which converts between primative types and their object counterparts automatically.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Liang Anmian
Ranch Hand

Joined: Jun 25, 2004
Posts: 119
Hey there, when you study for the exam, and wish to try out codes, please make sure you are using the 1.4 compiler. As mentioned, Boolean something = false works because version 1.5 introduces an autoboxing feature. But in 1.4, this is a compilation error. So please pay special attention to this, else you may study the wrong thing.


Current Status:<br /> <br />SCJP 1.4<br />SCJD (in progress)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Hey there, when you study for the exam, and wish to try out codes, please make sure you are using the 1.4 compiler.

Unless, of course, you're studying for the 1.5 exam. The general rule is: know what exam you're preparing for, and make sure you are using the correct JDK for that exam.


"I'm not back." - Bill Harding, Twister
Jianfeng Qian
Ranch Hand

Joined: Jan 25, 2005
Posts: 83
Thank you .
Yes,I am using 1.5.
I will install 1.4 tomorrow
 
Consider Paul's rocket mass heater.
 
subject: why(boolean b3=true;)(Boolean b4=true;)is both right?