Public final static Boolean FALSE=new Boolean(false);
Public final static Boolean TRUE=new Boolean(true);
what is the meaning of above two statements?

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:

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

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)

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

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).

... and it always makes me wince).

++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.

if (isComplete) {...

++
Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.

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 :

if(state == false)

than

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.