Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn What Is String? | Variables and Data Types
Introduction to Java

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.

question mark

Which of the following is the correct way to create a String in Java?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7

Ask AI

expand

Ask AI

ChatGPT

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.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7
some-alt