Java, the boolean type: the Base of Computer Logic


Is a Boolean data type that allows only two values, true or false.

Java, programming, computing, two binary values ​​...?

Yes, it has to do with something more complex, Boolean Algebra (binary numbers and logic), which is the basis of all Electrical Engineering, Electronics and Telecommunications, for example.



But you do not need to go so deep on this to learn to Java (good!) .

As I said before, everything in computer is number, is bit.
This is true or false for humans and Java developers more easily create code (Java programmer is not human, is Paladino Arts Computing, is a stage above).

And where we use 'true' and 'false'? Everywhere.

"I have read and agree with the terms of conditions'.
If not selected, this option is set to 'false' and you can not install that illegal software on your Windows (anyone ever read any term of condition in life?).
When you chek, it is set to 'true' and you can proceed.

If a form asks for a date in the form: m/dd/yyyy
While it is not filled out correctly, the form is set to 'false', and is not possible continue.
Is only set to true if completed correctly. So if you put: jan/5/90
will not set to true, never.

That is, we use Boolean types in Java when we want to make sure that some condition is true or false.
Sometimes (ie, always), we will do THIS just if we know that THAT happened. Got?
If A, do B.
If C, do D.
To check if A or C happened, we look if they are true or false.

In a more mathematical language, boolean types are associated with the logical operators AND and OR, we'll see then.

Declaration

boolean name_bool  = true;
boolean name_bool2 = false;

While we can make an analogy with the binary system, unlike other languages, we can not make the conversion to integers for true = 1 and false = 0.
Ie boolean is boolean and integer is an integer in Java, nor cast vai.

In others languages, eg 'false' can be represented by 0, empty string, pointer pointing to 'null' or something empty and 'true' by any other value.
In SQL (language to work with the database), the boolean can be true, false, unknown or null.

For now, we do not have much to show. We will use the Boolean VERY in control conditions and loops, plus front and throughout our course.

George Boole, his work is the basis of the whole system of the digital world

http://en.wikipedia.org/wiki/Boolean_data_type

No comments: