Boolean class

Reply

Join Date: Oct 2009
Posts: 5
Reputation: sridhar123 is an unknown quantity at this point 
Solved Threads: 0
sridhar123 sridhar123 is offline Offline
Newbie Poster

Boolean class

 
0
  #1
16 Days Ago
Public final static Boolean FALSE=new Boolean(false);
Public final static Boolean TRUE=new Boolean(true);
what is the meaning of above two statements?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 114
Reputation: KirkPatrick is an unknown quantity at this point 
Solved Threads: 3
KirkPatrick KirkPatrick is offline Offline
Junior Poster
 
0
  #2
16 Days Ago
Originally Posted by sridhar123 View Post
Public final static Boolean FALSE=new Boolean(false);
Public final static Boolean TRUE=new Boolean(true);
what is the meaning of above two statements?
There should be more code to go with this, otherwise it's pretty hard to tell what you are trying to accomplish.

I'm also not quite sure why someone would want to create a true/false when the point of a boolean is to determine whether it is true or false.

For example:

  1. private boolean isWindows;
  2.  
  3. if (isWindows == true)
  4. // do something only a windows os can do
  5. else
  6. // do something only a unix os can do

Obviously there are more operating system's than those two but that shows how a boolean would work. Or at least how I use my booleans instead of creating true false
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 971
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark
 
0
  #3
16 Days Ago
These two statements create two constants TRUE and FALSE (Java constants are captialised by convention). These constants are members of the Boolean class, with values true and false respectively.
Back in the old days befor Java 1.5 the compiler would not convert automatically between Boolean (the class) members and boolean (primitive) values, so it was useful to have constants for the class members. Now Java will autobox true and false into Boolean class members automatically this is no longer of any great use.

ps sridhar123:

if (isWindows == true)
is a dumb way of saying
if (isWindows)
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 114
Reputation: KirkPatrick is an unknown quantity at this point 
Solved Threads: 3
KirkPatrick KirkPatrick is offline Offline
Junior Poster
 
0
  #4
16 Days Ago
Originally Posted by JamesCherrill View Post

if (isWindows == true)
is a dumb way of saying
if (isWindows)
haha agreed, unless for some reason it's set to false above

thanks for the insight as well, i wasn't aware that was the reason for creating TRUE and FALSE
Last edited by KirkPatrick; 16 Days Ago at 2:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 971
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark
 
0
  #5
16 Days Ago
Originally Posted by KirkPatrick View Post
haha agreed, unless for some reason it's set to false above
No, the two statements are equivalent for both boolean values.
(This is a little obsession of mine. I guess I see
if (booleanExpression == true)
once a week or so, and it always makes me wince).
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster
 
0
  #6
16 Days Ago
Originally Posted by JamesCherrill View Post
... and it always makes me wince).
++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.
  1. if (isComplete) {...
Last edited by Ezzaral; 16 Days Ago at 5:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,076
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 140
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Veteran Poster
 
0
  #7
15 Days Ago
Originally Posted by Ezzaral View Post
++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.
  1. if (isComplete) {...
Yea, sometimes, but IMO not all the times. It depends on the variable
name. When giving a variable name, if giving it isBlah doesn't
necessarily make sense, for example, suppose you have a state flag
the in that case I would rather do this :
  1. if(state == false)
than
  1. if(!state)

I am not sure which one would be faster, but I guess it depends on
many things, but I assume it would be the same in a decent
compiler.
I give up! 
1) What word becomes shorter if you add a letter to it?
2) What does this equal :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster
 
0
  #8
15 Days Ago
Your example is only a case of poor variable naming. Why would you name a boolean "state"? What would "state equals true" mean in a logical description of the program flow? If it is truly a boolean state then you can easily assign a name that accurately reflects that binary nature.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC