Primitive Data Types
Java’s most basic data types are known as primitive data types and are in the system by default.
The available types are as follows:
null is another, but it can only ever store the value null.
int age = 28;char grade = 'A';boolean late = true;byte b = 20;long num1 = 1234567;short no = 10;float k = (float)12.5;double pi = 3.14;
In Java, the type of variable is checked at compile time. This is known as static typing. It has the advantage of catching the errors at compile time rather than at execution time.
Variables must be declared with the appropriate data type or the program will not compile.
int i = 10; // Type is intchar ch = 'a'; // Type is charj = 20; // Won't compile, no type is givenchar name = "Sonny"; // Won't compile, wrong data type
- Anonymous contributors
Learn Java on Codecademy
- Anonymous contributorsAnonymous contributors