CPSC 124, Spring 2006
Answers to Quiz #1


Question 1: Explain the difference between a high-level programming language and machine language.

Answer: In a high-level programming language, instructions are written in a form that is human-readable, because it is something like ordinary human language. In machine language, instructions are coded as binary numbers. A computer cannot understand high-level programming languages directly -- they must be translated into machine language before they can be executed. The computer can directly execute a program that is written in its machine language.


Question 2: One of the two major components of a computer is the RAM. What is the function of the RAM?

Answer: The RAM, or Random Access Memory, holds the machine language instructions that make up programs and data for use by those programs. The CPU reads the instructions from RAM and executes them, and it reads any data needed by those instructions from RAM and stores its answers back into RAM.


Question 3: When you compile a Java source code file (such as Measures.java) with the javac command, you get a class file (such as Measures.class). What sort of information is contained in the class file?

Answer: The "javac" command translates the Java source code into Java "bytecode" instructions, which are stored in the class file. Java bytecode is the machine language for the "Java Virtual Machine," a computer that doesn't actually exist. The program can be executed by running the class file under the "java" command, which is an interpretor for Java bytecode.


Question 4: The main subroutine of a program begins with the line

            public static void main(String[] args)
What does the word "public" mean here, and why is it necessary?

Answer: The word "public" means that the main routine is visible or accessible from outside the class in which it is defined. It is necessary since main will be called from outside the class (by the system) when the program is executed.


Question 5: What is a variable?

Answer: A variable is a named memory location that can be used to store data. The variable's name can be used in a program to refer to the memory location or to the data that it contains. For example, "int n;" creates a variable named n that can hold an integer.


Question 6: What does it mean to say that classes can be arranged in a class hierarchy, and why might it be useful to do this?

Answer: A class can be a subclass of another class. The subclass inherits the properties of the main class, and can then build on what it inherits. This organizes the classes conceptually and makes it easy to build on previous work. A "class hierarchy" shows a collection of related classes, with lines showing the connnections between each class and its subclasses.


Question 7: What is the relationship between classes and objects?

Answer: Objects are specific entities. A class represents the common properties of a group of related entities. In the real world, objects (such as specific individual dogs) exist, and a class (such as DOG) is an abstract idea that is created to group the objects together conceptually. In programming, the class is created first and is then used as a "factory" for producing objects.


David Eck, 23 January 2006