0% found this document useful (0 votes)
2 views

Data Types

Uploaded by

Phuc Hoang
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Types

Uploaded by

Phuc Hoang
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data types are divided into two groups:

Primitive data types:

byte -128 to 127

short -32,768 to 32,767

int -2,147,483,648 to 2,147,483,647

long 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float 6 to 7 decimal digits

double 15 to 16 decimal digits

boolean

char single character/letter or ASCII values

Non-primitive data types: String, Arrays and Classes

Numbers:

Integer types: byte, short, int and long

Floating point types: float and double

Boolean Types: YES / NO, ON / OFF, TRUE / FALSE

Type Casting:

Widening Casting (automatically) - converting a smaller type to a larger type


size

byte -> short -> char -> int -> long -> float -> double

Narrowing Casting (manually) - converting a larger type to a smaller size


type

double -> float -> long -> int -> char -> short -> byte

Operators: + - * / % ++ --

Assignment Operators:

= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3

Comparison Operators:

== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

Logical Operators:

&& Logical and x < 5 && x < 10


|| Logical or x < 5 || x < 4
! Logical not !(x < 5 && x < 10)

You might also like