| | |
Boolean class
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2009
Posts: 115
Reputation:
Solved Threads: 3
0
#2 Nov 6th, 2009
•
•
•
•
Public final static Boolean FALSE=new Boolean(false);
Public final static Boolean TRUE=new Boolean(true);
what is the meaning of above two statements?
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:
java Syntax (Toggle Plain Text)
private boolean isWindows; if (isWindows == true) // do something only a windows os can do else // 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
•
•
Join Date: Apr 2008
Posts: 1,004
Reputation:
Solved Threads: 149
0
#3 Nov 6th, 2009
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:
is a dumb way of saying
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) •
•
Join Date: Apr 2009
Posts: 115
Reputation:
Solved Threads: 3
0
#4 Nov 6th, 2009
Last edited by KirkPatrick; Nov 6th, 2009 at 2:11 pm.
0
#6 Nov 6th, 2009
++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.
Java Syntax (Toggle Plain Text)
if (isComplete) {...
Last edited by Ezzaral; Nov 6th, 2009 at 5:00 pm.
0
#7 Nov 7th, 2009
•
•
•
•
++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.Java Syntax (Toggle Plain Text)
if (isComplete) {...
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 :
Java Syntax (Toggle Plain Text)
if(state == false)
Java Syntax (Toggle Plain Text)
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.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
![]() |
Similar Threads
- JDBC not recognizing ResultSet assingment (?) (Java)
- Explain toString() and constructors, and their use? (Java)
- urgently need help (Java)
- cannot explain the arrayIndexOutofBoundsException (Java)
- HELP!!! I cant figure this out!! (Java)
- JTable Reloading/Refreshing/Updating/Whatever. (Java)
- Class & method Boolean (Java)
- I need help in C++ (C++)
Other Threads in the Java Forum
- Previous Thread: Algorithm for creating a linked list that is sorted as nodes are inserted
- Next Thread: Need Project Suggestion
| Thread Tools | Search this Thread |
Tag cloud for Java
@param android animated api appinventor apple applet application arguments array arrays automation binary bluetooth c++ chat chatprogramusingobjects class classes client code codesnippet compare compiler component coordinates database doctype draw eclipse editor error event exception file fractal freeze game givemetehcodez graphics gui guidancer health helpwithhomework html ide image input int integer j2me java javaprojects jmf jni jpanel jtable julia linux list login loop map method methods mobile netbeans newbie nonstatic number oracle page plazmic print problem program programming project recursion scanner screen sell server set sharepoint size sms socket sort sourcelabs sql string swing system test testautomation threads time tree windows







