Java Software Solutions, 8e, Global Edition (Lewis/Loftus)
Chapter 1 Introduction
1.1 Multiple-Choice Questions
1) A Java program is best classified as
A) hardware
B) software
C) storage
D) processor
E) input
2) 6 bits can be used to represent ________ distinct items or values
A) 6
B) 20
C) 24
D) 32
E) 64
3) When executing a program, the processor reads each program instruction from
A) secondary memory (storage)
B) the Internet
C) registers stored in the processor
D) main memory
E) could be any of these
4) Which memory capacity is the largest?
A) 1,500,000,000,000 bytes
B) 100 gigabytes
C) 3,500,000 kilobytes
D) 10 terabyte
E) 12,000,000 megabytes
5) Binary numbers are composed entirely of
A) 0s
B) 1s
C) 0s and 1s
D) 0s, 1s and 2s
E) any digits between 0 and 9
6) Volatility is a property of
A) RAM
B) ROM
C) disk
D) software
E) computer networks
7) The ability to directly obtain a stored item by referencing its address is known as
A) random access
B) sequential access
C) read-only access
D) fetch access
E) volatility
8) Which phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic
unit?
A) fetch
B) decode
C) execute
D) during fetch or execute, but not decode
E) could be used in fetch, decode or execute phase
9) In order for a computer to be accessible over a computer network, the computer needs its own
A) MODEM
B) communication line
C) network address
D) packet
E) router
10) For a computer to communicate over the Internet, it must use
A) the TCP protocol
B) the IP protocol
C) the combined TCP/IP protocol
D) the Ethernet protocol
E) the ARPANET protocol
11) A URL (Universal Resource Locator) specifies the address of
A) a computer on any network
B) a computer on the Internet
C) a local area network (LAN) on the Internet
D) a document or other type of file on the Internet
E) a Java program on the Internet
12) It is important to dissect a problem into manageable pieces before trying to solve the problem
because
A) most problems are too complex to be solved as a single, large activity
B) most problems are solved by multiple people and it is easy to assign each piece to a separate
person
C) it is easier to integrate small pieces of a program into one program than it is to integrate one
big chunk of code into one program
D) our first solution may not solve the problem correctly
E) all of the above
13) Once we have implemented the solution, we are not done with the problem because
A) the solution may not be the best (most efficient)
B) the solution may have errors and need testing and fixing before we are done
C) the solution may, at a later date, need revising to handle new specifications
D) the solution may, at a later date, need revising because of new programming language
features
E) all of the above
14) Java is an example of a(n)
A) machine language
B) assembly language
C) high-level language
D) fourth generation language
E) both C and D
15) In the following list, which statement is not true regarding Java as a programming language?
A) It is a relatively recent language, having been introduced in 1995
B) It is a language whose programs do not require translating into machine language before they
are executed
C) It is an object-oriented programming language
D) It is a language that embraces the idea of writing programs to be executed using the World
Wide Web
E) All of the above are true
16) Comments should
A) rephrase the code it explains in English
B) be insightful and explain what the instruction’s intention is
C) only be included in code that is difficult to understand
D) be used to define variables whose names are not easy to understand
E) all of the above
17) The main method for a Java program is defined by
A) public static main( )
B) public static main(String[ ] args);
C) public static main(String[ ] args)
D) private static main(String[ ] args)
E) the main method could be defined as in A, C or D but not B
18) The line of Java code “// System.out.println(“Hello”);” will
A) do nothing
B) cause “Hello” to be output
C) cause a syntax error
D) cause “(Hello)” to be output
E) there is no way to know without executing this line of code
19) The instruction: System.out.println(“Hello World”); might best be commented as
A) // prints “Hello World” to the screen
B) // prints a message
C) // used to demonstrate an output message
D) //
E) // meaningless instruction
20) Which character below is not allowed in an identifier?
A) $
B) _
C) 0 (zero)
D) q
E) ^
21) Which of the following is not syntactically legal in Java?
A) public class Foo
B) System.out.println(“Hi”);
C) { }
D) s t a t i c main(String[ ] args)
E) only B is legally valid, all of the rest are illegal
22) Which of the following is a legal Java identifier?
A) i
B) class
C) ilikeclass!
D) idon’tlikeclass
E) i-like-class
23) A unique aspect of Java that allows code compiled on one machine to be executed on a
machine of a different hardware platform is Java‘s
A) bytecodes
B) syntax
C) use of objects
D) use of exception handling
E) all of the above
24) Java is similar in syntax to what other high level language?
A) Pascal
B) Ada
C) C++
D) FORTRAN
E) BASIC
25) An error in a program that results in the program outputting $100 instead of the correct
answer, $250 is
A) a programmer error
B) a syntax error
C) a run-time error
D) a logical error
E) a snafu
26) Which of the following is true regarding Java syntax and semantics?
A) a Java compiler can determine if you have followed proper syntax but not proper semantics
B) a Java compiler can determine if you have followed proper semantics but not proper syntax
C) a Java compiler can determine if you have followed both proper syntax and semantics
D) a Java compiler cannot determine if you have followed either proper syntax or semantics
E) a Java compiler can determine if you have followed proper syntax and can determine if you
have followed proper semantics if you follow the Java naming convention rules
27) Following Java naming convention, which of the following would be the best name for a
class about store customers?
A) StoreCustomer
B) Store Customer
C) storeCustomer
D) STORE_CUSTOMER
E) Store-Customer
28) Which of the following would be a good variable name for the current value of a stock?
A) curstoval
B) theCurrentValueOfThisStockIs
C) currentStockVal
D) csv
E) current
29) Which of the following is a legal Java identifier?
A) 1ForAll
B) oneForAll
C) one/4/all
D) 1_4_all
E) 1forall
30) A color image is broken down into individual pixels (points), each of which is represented by
A) a 1 for white and a 0 for black
B) 3 values denoting the intensity of red, green, and blue in the image
C) a single number indicating the intensity of color between white and black
D) two numbers, a value that denotes where between white and black the color is, and a
brightness
E) none of the above, it is not possible to represent a color image
31) Which of the following characters does not need to have an associated “closing” character in
a Java program?
A) {
B) (
C) [
D) <
E) all of these require closing characters
32) Mistyping “println” as “printn” will result in
A) a syntax error
B) a run-time error
C) a logical error
D) no error at all
E) converting the statement into a comment
1.2 True/False Questions
1) All information is stored in the computer using binary numbers.
2) Java is an object-oriented programming language.
3) System.out.print is used in a program to denote that a documentation comment follows.
4) Java byte codes are directly executable whereas Java source code is not.
5) The Java compiler is able to find all programmer errors.
6) Java is a case-sensitive language meaning that Current, current and CURRENT will all
reference the same identifier.
7) Code placed inside of comments will not be compiled and therefore will not execute.
8) The word “Public” is a reserved word.
9) Reserved words in Java can be redefined by the programmer to mean something other than
their original intentions.
10) In a Java program, dividing by 0 is a syntax error.
11) During translation, the compiler puts its output (the compiled Java program) into ROM.
12) Objects are defined by a class that describes the characteristics common to all instances of
the class.
13) Inheritance is a form of software reuse.
14) Polymorphism is the idea that we can refer to multiple types of related objects in consistent
ways.
15) In Java, identifiers may be of any length up to a limit determined by the compiler.
1.3 Free-Form Questions
1) What is wrong with the following class definition?
public class Program1
{
public static void main(String[ ] args)
{
System.out.println(“My first Java program”)
}
}
2) What is wrong with the following class definition?
public class Program2
public static void main(String[ ] args)
{
System.out.println(“My second Java program”);
}
3) Given the following class definition, what are the reserved words and what are the identifiers?
public class Program3
{
public static void main(String[ ] args)
{
System.out.println(“My third Java program”);
}
}
4) Provide a brief explanation of the role of main memory, the control unit, the arithmetic logic
unit, and registers. (see figure 1.13)
5) What is the output of the following when the main method is executed?
public class Question4
{
public static void main(String[ ] args)
{
System.out.println(“hi there”);
System.out.println(” “);
System.out.println(“how are you doing today? “);
}
}
6) What is wrong with the following println statement?
System.out.println(“My fourth Java Program);
7) Provide identifier names that would be used to represent a person’s social security number,
income tax withheld, and net pay.
8) There are a number of reserved words in Java that have no current meaning (denoted with an *
in figure 1.18). Why?
9) Rewrite the following comment so that it can appear over multiple lines.
// This is one really enormously long comment that might run off the page
10) Examine figure 1.7 before answering this question. What 8-bit value comes immediately
before and what 8-bit value comes immediately after 10010111?
11) Rewrite the following program with better formatting to make it easier to read.
public
class
MyProgram
{ public static void
main(
String[ ]
args)
{ System.out.println(
“Wow, this is messed up!”
);
} }
}
}
12) A document of text is 15 pages long. Each page contains approximately 200 words and the
average length of each word is 5 characters. Also assume one blank space between each word
and no punctuation. How many bytes will it take to store this document in memory or on disk
using ASCII?
13) Provide a brief description of the roles of the following hardware elements (that is, what each
is used for):
a) CPU
b) Main memory
c) Secondary memory devices
d) Input/Output devices
14) Considering that the Pentium IV processor runs at a clock speed of about 850 MHz. What
clock speed might we expect from a Pentium chip that would be released in 3 years?
15) Write a Java program that will output on two separate lines the names of the authors of this
textbook.
16) Correct all the syntax errors in the following program.
Public Class Program \\ A problem program
(
Public static voided main[Strings( ) args]
{
system.out.println(‘This program’); \* oh, my… *\
system.out.println(‘has several syntax errors’); \* lots of errors *\
}
)
}
}
17) Name five of the fundamental terms which encompass object-oriented programming.
18) Write a Java program that will display the following three lines when it is run:
*
* * *
* * * * *