Download the JDK
Search the Tutorials
Trail: Learning the Java Language
Lesson: Language Basics
Home Page > Learning the Java Language > Language Basics
« Previous • TOC
Answers to Questions and Exercises: Variables

> ### Answers to Questions

> > 1. The term "instance variable" is another name for non-static field.

> > 2. The term "class variable" is another name for static field.

> > 3. A local variable sores temporary state; it is declared inside a method.

> > 4. A variable declared within the opening and closing parenthesis of a method is called a parameter.

> > 5. What are the eight primitive data types supported by the Java programming language? byte, short, int, long, float, double, boolean, char

> > 6. Character strings are represented by the class java.lang.String.

> > 7. An array is a container object that holds a fixed number of values of a single type.

> ### Answers to Exercises

> > 1. Create a small program that defines some fields. Try creating some illegal field names and see what kind of error the compiler produces. Use the naming rules and conventions as a guide.

> >    There is no single correct answer here. Your results will vary depending on your code.

> > 2. In the program you created in Exercise 1, try leaving the fields uninitialized and print out their values. Try the same with a local variable and see what kind of compiler errors you can produce. Becoming familiar with common compiler errors will make it easier to recognize bugs in your code.

> >    Again, there is no single correct answer for this exercise. Your results will vary depending on your code.

Previous page: Questions and Exercises: Variables