Data Types in Java
Today let's see what the data types in Java are. Generally, we consider two types of data types: Primitive Data Types and Reference Data Types.
Since Java is a statically-typed language, variables must be declared before use. Declaring means you have to give the data type and name of the variable.
ex: int num ;
Initializing the variable...
Since the data type of the above variable is int ,the value it contains should be an int.
ex: int num = 10 ;
There are 8 Primitive Data Types in Java.
Since Java is a statically-typed language, variables must be declared before use. Declaring means you have to give the data type and name of the variable.
ex: int num ;
Initializing the variable...
Since the data type of the above variable is int ,the value it contains should be an int.
ex: int num = 10 ;
There are 8 Primitive Data Types in Java.
- byte
- short
- int
- long
- float
- double
- boolean
- char
In addition to these primitive data types Java also supports String type which contains character strings. Strings are represented within double quotation marks ( " " ).
ex: String s = "string example";
When we declare a String, then an object will be created for it automatically in String Constant Pool of Heap. Once created the value of a String object will not be changed. (immutable)
String s1 = "ABC";
String s2 = "xyz";
s1 = s1 + "DE";
Comments
Post a Comment