Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

boolean & Boolean - interchanable (where & where not)?

Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above code compiles & gives output "true".
The API says public static boolean parseBoolean(String s)

I understand that because of Autoboxing feature, the code works fine.

Now can I say "We can use boolean and Boolean interchangably"? (Correct me if I am wrong)

What are exceptional case?
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja,

Good question.
Small problem...

class BooleanTest{
Boolean b;

public void display(boolean b) { //Here null can't be converted to boolean
System.out.println("Boolean b value:"+b);
public static void main(String... a) {
new BooleanTest.display(b);

The above gives a NullPointerException bec'ze the Booleab b is initialized to null. and when we try to convert it into primitive boolean throws NPException.

Hope this example will help you.
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic