Chaper 7


Chapter 6

1. 

Label the parts of the following Java program:

image from book

2. 

What is the definition of the term variable?

 - a named location in memory whose contents value can change during program execution

3. 

What is the difference between a class and an instance variable?

image from book

4. 

What is the definition of the term constant? How do you declare a constant?

 - a constant s value cannot be changed once defined. by using the final keyword.

5. 

List and describe the two Java type categories. Discuss the primary differences between each type category.

image from book

6. 

What are the four requirements for formulating identifier names?

image from book

7. 

What is the function of the new operator?

 - to dynamically create reference type objects in the heap

8. 

What is the purpose of the Java garbage collector?

 - to free up memory occupied by unreferenced objects

9. 

How do you determine an object’s memory location value?

 - you cannot directly determine an object s memory location in java

10. 

What are the primitive type wrapper classes and what functionality do they provide?

image from book

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.)




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net