O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assigning Variable Types

Variables are the main way that a computer remembers something as it runs a program. The Saluton program in Hour 2 used the greeting variable to hold “Saluton mondo!”. The computer needed to remember that text so that the message could be displayed.

In a Java program, variables are created with a statement that must include two things:

• The name of the variable

• The type of information the variable will store

Variables also can include the value of the information being stored.

To see the different types of variables and how they are created, run NetBeans and create a new empty Java file with the class name Variable.

Start writing the program by entering the following lines:

class Variable {    public static void main ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required