Variables and Data Types in Java

Java has two categories of variables and four kinds of named data types. Variables can either contain primitive values or refer to objects. Reference variables refer to objects—you can think of the variable as containing a handle to the object. Naturally, the internal workings of the JVM deal with real pointers to memory, but these details are all concealed from you as a programmer. The four kinds of data types are primitives, classes, interfaces, and arrays, all of which are discussed throughout this chapter.

Instance Variables, Local Variables, and Static Variables

When a class is used to create an object, we say that the object is an instance of the class. Variables associated with the object are instance

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) 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.