CPSC 124, Fall 1998

Quiz Number 1


This is the first quiz given in CPSC 124: Introductory Programming, Fall 1998. See the information page for that course for more information.

The answers given here are sample answers that would receive full credit. However, they are not necessarily the only correct answers. In some cases, I give more detailed answers here than would be necessary to get full credit.


Question 1: What is meant by the fetch-and-execute cycle?

Answer: The fetch-and-execute cycle is what the Central Processing Unit does to execute machine language programs. A machine language program is stored in the computer's main memory. The CPU fetches one machine language instruction from memory, and executes that instruction. Then it fetches the next instruction from memory and executes it. And so on.


Question 2: Explain the difference between high-level languages and machine language.

Answer: Programs written in the machine language of a given type of computer can be directly executed by the CPU of that type of computer. High-level language programs must be translated into machine language before they can be executed. (Machine language instructions are encoded as binary numbers that are meant to be used by a machine, not read or written by people. High-level languages use a syntax that is closer to human language.)


Question 3: If you have the source code for a Java program, and you want to run that program, you will need both a compiler and an interpreter. What does the Java compiler do, and what does the Java interpreter do?

Answer: The Java compiler translates Java programs into a language called Java bytecode. Although bytecode is similar to machine language, it is not the machine language of any actual computer. A Java interpreter is used to run the compiled Java bytecode program. (Each type of computer needs its own Java bytecode interpreter, but all these interpreters interpret the same bytecode language.)


Question 4: What is a subroutine?

Answer: A subroutine is a set of instructions for performing some task that have been grouped together and given a name. Later, when that task needs to be performed, it is only necessary to call the subroutine by giving its name, rather than repeating the whole sequence of instructions.


Question 5: Java is an object-oriented programming language. What is an object?

Answer: An object consists of some data together with a set of subroutines that manipulate that data. (An object is a kind of "module," or self-contained entity that communicates with the rest of the world through a well-defined interface. An object should represent some coherent concept or real-world object.)


David Eck, 19 September 1998