Different Data Types used in Java
Data type defines a set of permitted values on which the legal operations can be performed.
There are two data types available in Java:
- Primitive Data Types
- Reference/Object Data Types
Primitive Data Types
Primitive Data Types defines 8 simple types of data: byte, short, int, long, char, float, double, and boolean. These can be put in four groups.
Integer:
This groups include byte, short, int, and long which are for whole valued signed number.Floating:
This group includes float and double, which represents numbers with fractional precision.Characters:
This group includes char, which respresents symbls in a character set like letters and numbers.Boolean:
This group includes boolean, which is a special type for representing true/false.Data Type | Default Value (for fields) | Size (in bits) | Minimum Range | Maximum Range |
byte | 0 | 8 bits | -128 | +127 |
short | 0 | 16 bits | -32768 | +32767 |
int | 0 | 32 bits | -2147483648 | +2147483647 |
long | 0L | 64 bits | -9223372036854775808 | +9223372036854775807 |
float | 0.0f | 32-bit | 1.40129846432481707e-45 | 3.40282346638528860e+38 |
double | 0.0d | 64-bit | 4.94065645841246544e-324d | 1.79769313486231570e+308d |
char | '\u0000' | 16-bit | 0 to 65,535 | |
boolean | false | 1- bit | NA | NA |
Reference Data Types
Reference variables are created using defined constructors of the classes. They are used to access objects. Class objects, and various type of array variables come under reference data type. Default value of any reference variable is null. These non-primitive types are often called "reference types" because they are handled "by reference"--in other words, the address of the object or array is stored in a variable, passed to methods, and so on. By comparison, primitive types are handled "by value"--the actual primitive values are stored in variables and passed to methods. The reference data types are arrays, classes and interfaces that are made and handle according to a programmer in a java program which can hold the three kind of values as:
nice post
ReplyDelete