CPSC 124, Fall 2017: Sample Answers to Quiz #1

These are sample answers only. Often, answers that are less
detailed than the ones given here can still receive full credit.

Question 1. What is the purpose of a CPU (Central Processing Unit) in a computer?

Answer. The CPU is the "brain" of the computer that actually executes programs. It fetches machine language instructions from main memory, one-by-one, and executes them.

Question 2. What is meant by the syntax of a programming language? In your answer, include a specific example of syntax as it applies to Java.

Answer. Syntax, or grammar, determines what can be in a legal program. A syntactically correct program can be compiled without error. For example, there is a syntax rule that an assignment statement must end with a semicolon. If the semicolon is missing, you will get an error when you try to compile the program. (Another example is the rule that a variable must be declared before it can be used in a program.)

Question 3. What does the computer do when it executes the following Java statement?

cost = area * costPerSquareYard;

Answer. This is an assignment statement. Its purpose is to compute a value and store it into a variable. In this case, the computer will get the values of the variables cost and costPerSquareYard from memory. It will multiply those values and store the answer into the variable named cost.

Question 4. What is the purpose of a compiler?

Answer. A compiler translates programs written in a high-level programming language (such as Java) into machine language, so that it can be executed by a computer.

Question 5. Name three different primitive data types in Java. (Just list them.)

Answer. The answer can be any three of the following:

        double                 float
        int                    long
        char                   short
        boolean                byte

(These are the only primitive types in Java. Other types are "object types" whose values are objects.)

[Note that String is not a primitive type. It is an object type.]