Java Data Types:
Java is a strongly typed language. It means all the variables must be declared before using them. Java data types of are of two types.
1. Primitive data type
2. Non-primitive data type
1. Primitive Data Types:
These are predefined by the language and is named by a reserved keyword.
Example: int, float, double etc.
Below is the list of primitive data types in java. Totally there are 8 primitive java data types.
i. Integer data types:
- byte (1 byte)
- short (2 bytes)
- int (4 bytes)
- long (8 bytes)
ii. Floating type:
- float (4 bytes)
- double (8 bytes)
- char (2 bytes)
- boolean (1 byte) (true / false)
Points to be noted:
1. All numeric data types are signed.
2. The size of the data types remains the same on all platforms.
3. char data type in java is 2 bytes because it uses UNICODE character set.
4. UNICODE is a character set which covers all known scripts and languages in the world.
2. Non-Primitive Data Types:
These are also referred as reference data types. They are called as reference data types because, they are handled by reference. In other words, the address of the object or array is stored in a variable of reference data type and not the value directly. To the contrary, primitive data types are handled by value.
Example: Objects and Arrays
Points to be noted:
1. Objects and Arrays are accessed using reference variables in Java.
2. A reference variable is similar to pointer (stores memory address of an object).
3. Java doesn’t support the explicit use of addresses like other languages.
4. Pointer manipulation is not allowed in Java.
5. A reference type cannot be cast to primitive type.
6. We can assign a null to the reference type to show that it is not referring to any object.
* ‘null‘ is a keyword in Java
Note: If you like selenium99.com and want to contribute any articles, then please send your articles to firstname.lastname@example.org.
If you want to improve this article or find any mistake in the article, then please use comment box to share your feedback.
Tags: Java Data Types