This document discusses data types and type conversion in Java. It describes primitive and non-primitive data types, including their storage sizes and value ranges. It explains widening and narrowing type conversion, and how coercion can occur in expressions. Relational and boolean expressions are also summarized, including logical operators that can combine boolean expressions.
4. TYPE STORAGE SIZE VALUE RANGE
boolean NA NA
byte 1 byte -128 to 127
short 2 bytes -32,768 to 32,767
char 2 bytes 0 to 65,535
int 4 bytes -2
31
to 2
31
-1
long 8 bytes -2
63
to 2
63
-1
float 4 bytes -3.4e38 to 3.4e83
double 8 bytes -1.7e308 to 1.7e308
12. TO SUM UP:
Widening Conversion (Implicit)
byte short int long float double
Narrowing Conversion (Explicitly done)
byte short int long float double
Type Conversion
16. TO SUM UP (PART II):
Widening Conversion
int counter = 10; float num = counter;
Narrowing Conversion
float id = 10.5f; int sid = id;
Casting
float temp = 10.1234f; int count = (int)temp;
Type Conversion
17. TO
FROM boolean byte short char int long float double
boolean - N N N N N N N
byte N - Y C Y Y Y Y
short N C - C Y Y Y Y
char N C C - Y Y Y Y
int N C C C - Y Y* Y*
long N C C C C - Y* Y*
float N C C C C C - Y
double N C C C C C C -
21. OPERATION Pascal Ada C Fortran77
Equal = = == .EQ.
Not Equal <> /= != .NE.
Greater than > > > .GT.
Less than < < < .LT.
Greater than or equal >= >= >= .GE.
Less than or equal <= <= <= .LE.
22. Rational Expression
Example:
int a = 10, b = 20;
System.out.println(“a == b = ” +(a==b));
System.out.println(“a <= b = ” +(a<=b));
Output:
a == b = false
a <= b = true
Relational & Boolean Expressions
23. Relational & Boolean Expressions
compares data of any type as long as both
parts of the expression have the same basic
data type.
Boolean Expressions
24. Relational & Boolean Expressions
can create more complex boolean expression by
joining these 3-part expressions with logical
operators.
Arithmetic Expressions Relational Expressions
Relational Expressions Boolean Expressions
Boolean Expressions
25. Logical Operator Use Operation
& opt1 & opt2 bitwise AND
| opt1 | opt2 bitwise OR
^ opt1 ^ opt2 bitwise xor
~ ~opt1 bitwise complement
26. Boolean Expression
Example:
int a = 1, b = 0;
System.out.println(“a & b = ” +(a&b));
System.out.println(“a | b = ” +(a|b));
Output:
a & b = 0
a | b = 1
Relational & Boolean Expressions