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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access