Java Language Fundamentals
Data Types - continued
The range of values stored by each type is always the same, regardless of what kind of computer you’re using. Therefore your program will execute in the same way on computers that may be quite different. In contrast the format and size of primitive data types of other languages may depend on the platform on which a program is running.
Declaring a variable is exactly same as it is in C. For example:
int value; long bigValue;
float value; double bigValue;
char letter; boolean check;
You can also initialize them at the same time you declare them. For example:
int value = 10; long bigValue = 99999999L;
float value = 1.28E12F; double bigValue = 1.56E-35;
char letter = ‘a’; boolean check = true;
Note: All integer values of type long must have an L appended to them to differentiate them from other integer constants. Same with the float variables, they must have F or a D appended to them.
Booleans
Booleans have two states – true and false. In other languages, a boolean can also have the value of 0 or 1 to signify true or false, but in Java, the only valid values are the literals “true” and “false”. For example:
// declares the variable truth as a boolean and assigns a value
boolean truth = true;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment