Learn
Learn Java: Variables
String

So far, we have learned primitive data types, which are the simplest types of data with no built-in behavior. Our programs will also use Strings, which are objects, instead of primitives. Objects have built-in behavior.

Strings hold sequences of characters. We’ve already seen instances of a String, for example when you printed out "Hello World".

Just like with a primitive, we declare the variable by specifying the type first:

String greeting = "Hello World";

Instructions

1.

Create a variable called openingLyrics that holds "Yesterday, all my troubles seemed so far away".

2.

Call System.out.println() to print out openingLyrics.

Folder Icon

Take this course for free

Already have an account?