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 ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth 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.