Java Data Types (Strings)

String Type (Non-Primitive)

 

Unlike numbers, a String is not a primitive data type; it is a Reference type (an object).

 

Definition: A String is a sequence of characters (e.g., "Hello World").

 

Immutability: Once a String object is created, its value cannot be changed. Any "modification" actually creates a brand-new String object.

 

Syntax: Must be enclosed in double quotes.

 

Utility: Because it is a class, it comes with built-in methods like .length(),

 

It is a class from the Java standard library:

 

java.lang.String

 

String stores text (sequence of characters).

Example:

String name = "David";

String course = "Programming 1";

Key Differences: Number vs String

 


Important Concept for Students
int x = 10;
String y = "10";
These
are NOT the same:
x + 5
15 (math)
y + 5
"105" (text concatenation)