The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Language Basics

Questions and Exercises: Variables

Questions

  1. Which of the following are valid variable names?
    int
    anInt
    i
    i1
    1
    thing1
    1thing
    ONE-HUNDRED
    ONE_HUNDRED
    something2do
    
  2. Answer the following questions about the BasicsDemo(in a .java source file) program.
    1. What is the name of each variable declared in the program? Remember that method parameters are also variables.
    2. What is the data type of each variable?
    3. What is the scope of each variable?

Exercises

  1. Modify the MaxVariablesDemo(in a .java source file) program so that aBoolean has a different value.
  2. Rewrite the MaxVariablesDemo program to display the minimum value of each integer data type. You can guess what the names of these variables are or you can look them up in the API documentation.
  3. Can you guess the name of a method in the Character(in the API reference documentation) class that you can use instead of isUpperCase to determine the capitalization of a character? Modify the MaxVariablesDemo program to use that method instead of isUpperCase.
Check your answers.(in the Learning the Java Language trail)

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form