What Is String?
Swipe to show menu
Now that you've covered primitive data types, you can move on to another important type that Java uses to work with text: String.
In Java, text is not stored using primitive types. Instead, it is handled using a special data type called String. A string is simply text stored in a variable.
You've already been using strings without even focusing on them, for example when printing messages:
System.out.println("Hello World");
Anything written inside double quotation marks is treated as a string in Java. Text can be stored in a variable like this:
String coffeeName = "Cappuccino";
String Is Not a Primitive Type
One important thing to understand is that String is not a primitive data type. Instead, it is a reference type, which means:
- it does not store the value directly
- it stores a reference to where the text is stored in memory
We will have an entire module dedicated to Strings where we'll go into more detail — for now just remember that Strings work a bit differently than numbers.
Strings Must Always Use Double Quotes
Correct:
String drink = "Latte";
Incorrect:
String drink = Latte;
Without quotes, Java thinks you are referring to a variable, not text.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
What Is String?
Now that you've covered primitive data types, you can move on to another important type that Java uses to work with text: String.
In Java, text is not stored using primitive types. Instead, it is handled using a special data type called String. A string is simply text stored in a variable.
You've already been using strings without even focusing on them, for example when printing messages:
System.out.println("Hello World");
Anything written inside double quotation marks is treated as a string in Java. Text can be stored in a variable like this:
String coffeeName = "Cappuccino";
String Is Not a Primitive Type
One important thing to understand is that String is not a primitive data type. Instead, it is a reference type, which means:
- it does not store the value directly
- it stores a reference to where the text is stored in memory
We will have an entire module dedicated to Strings where we'll go into more detail — for now just remember that Strings work a bit differently than numbers.
Strings Must Always Use Double Quotes
Correct:
String drink = "Latte";
Incorrect:
String drink = Latte;
Without quotes, Java thinks you are referring to a variable, not text.
Thanks for your feedback!