Variables and Data Types

In the VolcanoRobot application you created during Day 2, "Object-Oriented Programming," you used variables to keep track of information.

Variables are a place where information can be stored while a program is running. The value can be changed at any point in the program—hence the name.

To create a variable, you must give it a name and identify what type of information it will store. You also can give a variable an initial value at the same time you create it.

There are three kinds of variables in Java: instance variables, class variables, and local variables.

Instance variables, as you learned yesterday, are used to define an object's attributes. Class variables define the attributes of an entire class of objects, ...

Get Sams Teach Yourself Java 2 in 21 Days, Second 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.