Storing Information in a Variable

In the programs you write, one thing that's often needed is a place to store information for a brief period of time. You can do this by using a variable, a storage place that can hold information such as integers, floating-point numbers, true-false values, characters, and lines of text. The information stored in a variable can change, which is where the name “variable” comes from.

Load the Saluton.java file into your word processor (if it's not already loaded) and replace Line 3 with the following:

String greeting = "Saluton mondo!";

This statement tells the computer to store the line of text “Saluton mondo!” into a variable called greeting.

In a Java program, you must tell the computer what type of information ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.