Chapter 2 Flashcards

1
Q

Briefly explain what is meant by the syntax and the semantics of a programming language. Give an example to illustrate the difference between a syntax error and a semantics error.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the computer do when it executes a variable declaration statement. Give an example.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a type, as this term relates to programming?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

One of the primitive types in Java is boolean. What is the boolean type? Where are boolean values used? What are its possible values?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give the meaning of each of the following Java operators:

a) ++
b) &&
c) !=

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain what is meant by an assignment statement, and give an example. What are assignment statements used for?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is meant by precedence of operators?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a literal?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In Java, classes have two fundamentally different purposes. What are they?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between the statement “x = TextIO.getDouble();” and the statement “x = TextIO.getlnDouble();”

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain why the value of the expression 2 + 3 + “test” is the string “5test” while the value of the expression “test” + 2 + 3 is the string “test23”. What is the value of “test” + 2 * 3 ?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Integrated Development Environments such as Eclipse often use syntax coloring, which assigns various colors to the characters in a program to reflect the syntax of the language. A student notices that Eclipse colors the word String differently from int, double, and boolean. The student asks why String should be a different color, since all these words are names of types. What’s the answer to the student’s question?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of an import directive, such as import textio.TextIO or import java.util.Scanner?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write a complete program that asks the user to enter the number of “widgets” they want to buy and the cost per widget. The program should then output the total cost for all the widgets. Use System.out.printf to print the cost, with two digits after the decimal point. You do not need to include any comments in the program.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly