Data Types
Data Types
DATA TYPES :
There are two main categories of data types:
1. Primitive data types.
2. Non-Primitive data types.
- Strings
- Arrays
- Classes
- Interfaces
- Enumerations
Primitive data types are more efficient for basic data operations,
while non-primitive types are objects, offering more flexibility and
methods.
DATA TYPES AND CASTING IN JAVA
CASTING
Typecasting in Java is the process of converting one data type into another. It
can be classified into two types.
Types of Casting :
Type casting is when you assign a value of one primitive data type to another type.
Widening Casting :
Widening casting is done automatically when passing a smaller size type to a
larger size type:
Example -
public class Main {
int myInt = 9;
System.out.println(myInt); // Outputs 9
}
DATA TYPES AND CASTING IN JAVA
Narrowing Casting :
Narrowing casting must be done manually by placing the type in
parentheses () in front of the value:
Example -
public class Main {
System.out.println(myInt); // Outputs 9