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 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.