Learn Java: Variables

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";



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


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

Folder Icon

Take this course for free

Already have an account?