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!”, a message in Esperanto. The computer needed to remember that text a little later, 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
To see the different types of variables and how they are created, load the word processor you're using to write programs and set it up to start a new file. You will be creating a program called Variable.
Give your new file the name Variable.java and start writing the program by ...
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