int
◈ int is a primitive data type. Primitive data types are basic data types used by the programmers to create variables in their programs.
◈ Primitive data types start with small letters.
◈ int can never be null. Int data type used to store integer binary values only.
◈ We can not change its value or syntax.
Integer
◈ Integer is a wrapper class. Wrapper class encapsulates or wraps primitive data types (eg. int, char, byte, etc.,).
◈ Wrapper classes start with a capital letter even all the predefined classes in java start with a capital letter.
◈ Integer can be null i.e. we can assign a reference variable of Integer to null. It can throw NullPointerException if you are performing auto-boxing to convert Integer to int or vice-versa.
◈ Since Integer is a wrapper class, it can call several in-built methods defined in the class.
◈ Integer class helps us to convert int data object and to convert the object into int as per programmers requirement.
◈ By using Integer class, we can perform several operations like reverse(), rotateLeft(), rotateRight().
In java, every primitive type has an equivalent wrapper class. These are as follows:
Primitive data type | Wrapper class |
int | Integer |
char | Character |
float | Float |
byte | Byte |
short | Short |
long | Long |
double | Double |
boolean | Boolean |
No comments:
Post a Comment