CS 1401, Quiz #2

Date: Tuesday, January 31, 2006
Class section (9 am or 10:30 am): ______________________
Name: ______________________________________________________________________

1. For each item on the first list, find the description from the second list that is most appropriate.
(a) metalanguage
(b) object-oriented language
(c) machine language
(e) high-level programming language

(1) a language that includes constructs to associate data with the code for operating on the data.
(2) a programming language that is close to a natural language.
(3) a language that is used to describe another language.
(4) a language where instructions are in binary code for a specific machine.


(a)-(3) (b)-(1) (c)-(4) (e)-(2)

2. For each string, write down whether this string is a valid name for an identifier in Java; if not, explain why.


january 31    no: blank spaces are not allowed inside a Java name

january_31    yes

31january     no: Java name cannot start with a digit

$10           yes, but it is not recommended to use names with $ inside

January31     yes

char          no: reserved word of Java

String        no: reserved word of Java

String7       yes

3. Write a Java code that defines a new variable month of type String and assigns, to this variable, a new value January.


String month = "January";

Alternative answer:

String month;
month = "January";

4. In order to print a string, one must use Java method System.out. Write down a Java command that would print the following string:
"The month is over," said the bird.


System.out.println("\"The month is over,\" said the bird");