Data types in Java
What do you mean by Data types used in Java?
Data Types in Java is used to define the type of data that can be accepted by the identifier. For example, just try to run the below code:
public class Sample { publc static void main(String args[]) { int a = 200; char b = 200;//You will get error on compilation as b //is declared as a character type but //you are trying to assign a integer value to it. } }
Data types declare the different sizes and types of values that can be assigned in the variable. There are two types of data types in Java:
- Primitive data types: The primitive data types include int, char, float, boolean, byte, short, long, and double.
- Non-primitive data types: The non-primitive data types include String, Class, Interface, and Array.