Professional Documents
Culture Documents
with Java
Java Type Manipulation
ImanLHakim
Agenda
• What is Data
• How Computer Stores Data
• Java Data Type
• Primitive Type
• Primitive Data Conversion (Casting)
• Arithmetic of Primitive Data
• Wrapper Class of Primitive Data Type
• Reference Type
• Reference Type Casting
• Object Class as Parents of all Java Classes
• Immutable String and Mutable String
• Basics String Operation and Regular Expression
What is Data
• The term data refers to qualitative or
quantitative attributes of a variable
or set of variables. Data (plural of
"datum") are typically the results of
measurements and can be the basis
of graphs, images, or observations of
a set of variables. Data are often
viewed as the lowest level of
abstraction from which information
and then knowledge are derived.
Raw data, i.e. unprocessed data,
refers to a collection of numbers,
characters, images or other outputs
from devices that collect information
to convert physical quantities into
symbols. Wikipedia
• We use Computer to process data.
How Computer Stores Data
• Data stored in computer
memory or storage in
binary format.
• Computer only recognize
binary type of data.
• It is Computer
Programming Language
and other programs that
help us classified data
into varieties type
Java Data Types
Class
Reference Interface
Array
float (signed)
Type
Floating Point
double (signed)
byte (signed)
Numeric
short (signed)
Primitive Boolean
long (signed)
char (unsigned)
Integral Data Type
Default
Data Type Value Size Range
Value
Unicode
Char \u0000 16 bits \u0000 to \uFFFF
character
Byte Signed integer 0 8 bits -128 to 127
Short Signed integer 0 16 bits -32768 to 32767
-2147483648 to
Int Signed integer 0 32 bits
2147483647
-9223372036854775808
long Signed integer 0 64 bits to
9223372036854775807
Integral Literal
IntegerLiteral:
DecimalIntegerLiteral
HexIntegerLiteral
OctalIntegerLiteral
DecimalIntegerLiteral:
DecimalNumeral IntegerTypeSuffixopt
HexIntegerLiteral:
HexNumeral IntegerTypeSuffixopt
OctalIntegerLiteral:
OctalNumeral IntegerTypeSuffixopt
IntegerTypeSuffix: one of
l L
DecimalNumeral:
0
NonZeroDigit Digitsopt
Digits:
Digit
Digits Digit
Digit:
0
NonZeroDigit
NonZeroDigit: one of
1 2 3 4 5 6 7 8 9
HexNumeral:
0 x HexDigits
0 X HexDigits
HexDigits:
HexDigit
HexDigit HexDigits
HexDigit: one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
OctalNumeral:
0 OctalDigits
OctalDigits:
OctalDigit
OctalDigit OctalDigits
OctalDigit: one of
0 1 2 3 4 5 6 7
Sample byte Literals
byte b1 = 015; byte b2 = 15; byte b3 = 0x15;
byte b4 = 0X15; byte b5 = -015; byte b6 = -15;
byte b7 = -0x15; byte b8 = -0X15;byte b9 = 127;
byte b10 = -128;
// byte b11 = 128;
//Type mismatch: cannot convert from int to byte
// byte b12 = -129;
//Type mismatch: cannot convert from int to byte
byte b13 = (byte) 128; // konversi tipe eksplisit
byte b14 = (byte) -129; // konversi tipe eksplisit
Sample short Literals
short s1 = 015; short s2 = 15; short s3 = 0x15;
short s4 = 0X15; short s5 = -015; short s6 = -15;
short s7 = -0x15; short s8 = -0X15; short s9 = 32767;
short s10 = -32768;
// short s11 = 32768; //Type mismatch: cannot
// convert from int to short
// short s12 = -32769; //Type mismatch: cannot
// convert from int to short
short s13 = (short) 32768; // konversi tipe eksplisit
short s14 = (short) -32768;// konversi tipe eksplisit
Sample int Literals
int i1 = 0555; int i2 = 555; int i3 = 0xFAfa; int i4 = 2147483647;
s1 s2
s2 name = “Angust”
age = 14
Type Casting
• Let an object with type X acts as object with Type Y.
• Java understands two types of casting
– Implicit or up casting , done automatically
– Explicit or down casting, done manually