Data Types (Cont.)
Primitive Data Types (Cont.)
Other comments related to primitive data types include:
- Java uses two bytes (16 bits) for a character because it uses Unicode system, instead of ASCII code system (8 bits).
- Java is a statically-typed programming language.
It means that all variables must be declared before they are used.
That is why we need to declare variable’s type and name.
- The
String
data type is used to store a sequence of characters (text).
String values must be surrounded by double quotes.
It is so much used and integrated in Java, and it is actually a non-primitive data type, because it refers to an object that has methods that are used to perform certain operations on strings.
Concatenate.java (string concatenation)
|
Using the ‘+’ operator is the most common way to concatenate two strings in Java.
The operator ‘+’ normally acts as an arithmetic operator unless one of its operands is a
String
.
If so, it converts the other operand to a
String
before joining the second operand to the end of the first operand.
Rome was not built in one day.
|