1. | Label the parts of the following Java program: |
|
2. | What is the definition of the term variable? |
|
3. | What is the difference between a class and an instance variable? |
|
4. | What is the definition of the term constant? How do you declare a constant? |
|
5. | List and describe the two Java type categories. Discuss the primary differences between each type category. |
|
6. | What are the four requirements for formulating identifier names? |
|
7. | What is the function of the new operator? |
|
8. | What is the purpose of the Java garbage collector? |
|
9. | How do you determine an object’s memory location value? |
|
10. | What are the primitive type wrapper classes and what functionality do they provide? |
|
Answers
1. |
1 public class QuestionOne { // class definition 2 private int int_i; // instance variable declaration 3 private static int int_j; // class variable declaration 4 public static final int INT_K = 25; // class constant definition 5 6 public static void main(String[] args){ // main method definition 7 System.out.println(int_j); // statement using System.out object 8 System.out.println(INT_K); // statement using System.out object 9 10 QuestionOne q1 = new QuestionOne(); // local variable declaration and initialization 11 12 System.out.println(q1.int_i); // statement using System.out object 13 } // end main() method 14 } // end class definition |
2. | - a named location in memory whose contents value can change during program execution |
3. | - A class (static) variable is shared by all instances of a particular class; all objects have their very own copy of an instance variable. |
4. | - A constant’s value cannot be changed once defined. By using the final keyword. |
5. | - primitive types and reference types. Reference type objects must be created with the new operator. |
6. | - must begin with a valid Java letter; first letter can be followed by valid letters or digits; identifier cannot spell the name of a reserved keyword; identifier cannot spell true, false, or null |
7. | - to dynamically create reference type objects in the heap |
8. | - to free up memory occupied by unreferenced objects |
9. | - You cannot directly determine an object’s memory location in Java |
10. | - There is a wrapper class for each primitive type: Boolean, Character, Byte, Integer, Float, Double. (A description of their functionality is left to the student.) |