Test Bank For Absolute Java 6th Edition
Test Bank For Absolute Java 6th Edition
Test Bank for Absolute Java 6th Edition by Walter Savitch Kenrick
Mock
Chapter 1
Getting Started
Multiple Choice
1) Java is an object-oriented programming language. An object-oriented language
(a) Uses structured programming.
(b) Views a program as consisting of objects which communicate through interactions.
(c) Functionally breaks down problems into smaller, more manageable problems.
(d) All of the above.
Answer: B
double quantity = 5;
double amountDue = 0;
(a) 12
(b) 12.25
(c) 12.5
(d) 13
Answer: C
13) What is the value of the variable c in the statements that follow?
char c = phrase.charAt(10);
(a) w
(b) h
(c) i
(d) None of the above
Answer: B
14) The escape sequence the represents the new-line character is:
(a) \r
(b) \t
(c) \n
(d) \\
Answer: C
15) The syntax that declares a Java named constant named SALES_TAX is:
(a) double SALES_TAX = 7.50;
(b) public double SALES_TAX = 7.50;
(c) public static double SALES_TAX = 7.50;
(d) public static final double SALES_TAX = 7.50;
Answer: D
17) To mark a block comment for inclusion in the Javadoc documentation, the block must be delimited
by:
(a) /** */
(b) */* */
(c) **/ /*
(d) **/ */
Answer: A
True/False
1) Java began as a language for home appliances.
Answer: True
3) The Java programming language allows you to concatenate two strings using the plus sign.
Answer: True
5) Java does not require that a variable be declared before it is used within a program.
Answer: False
9) Objects of type String are strings of characters that are written within single quotes.
Answer: False
10) In Java, Strings are immutable objects. Immutable objects can be changed.
Answer: False
11) An advantage of using the Unicode character set is that it easily handles languages other than
English.
Answer: True
Short Answer/Essay
1) Define high-level languages, machine language and low-level language. Explain how the languages
correspond to one another.
Answer: High-level programming languages were designed to be easy for humans to read and use.
High-level languages consist of English like statements. Machine language or low-level
language is the language that the computer understands directly.
The source code created with Java, a high-level language, is compiled or translated into the machine
language, or object code. The object code is the program that executes on the computer.
2) Two kinds of Java programs are applications and applets. Define and discuss each.
Answer: An application is just a regular program that runs on your computer. An applet is a little
Java program that runs in a Web browser. Applets and applications are almost identical. The
difference is that applications are meant to be run on your computer like any other program, whereas
an applet is meant to be run from a Web browser. An applet can be sent to another location on the
Internet and run there.
5) What steps must the programmer take to create an executable Java program?
Answer: First, the programmer must create the source code. The programmer creates a Java class
that is contained in a file with the same name as the class. The source code file ends with
the .java extension. Next, the programmer uses a tool called a compiler to translate the
source code into Java byte-code. If the source code is syntactically correct, a file
containing the byte-code is created. This file has the same name as the source code file
with one exception, the byte-code file ends in the .class extension.
Once the .class is generated, it may be executed on any computer that has the Java Virtual Machine
(JVM) installed on it.
6) List the primitive data types Java supports. Indicate the kind of values each type can store.
Answer: boolean , true or false
char, single Unicode character
byte, integer (8 bits)
short, integer (16 bits)
int, integer (32 bits)
long, integer (64 bits)
float, floating-point number (32 bit IEEE 754)
double, floating-point number (64 bit IEEE 754)
7) How is the % (modulus) operator used? What is the common use of the modulus operator?
Answer: The modulus operator is used to return the remainder in integer division. For example, the
modulus operator is commonly used to determine if a number is an even or an odd value.
8) What are the values of the variables a, b, c, and d after the execution of the following expressions?
int a = 3;
int b = 12;
int c = 6;
int d = 1;
d = d * a;
c = c + 2 * a;
d = d - b / c;
c = c * b % c;
b = b / 2;
Answer:
a: 3
b: 6
c: 0
d: 2
9) Explain the difference between an implicit type cast and an explicit type cast.
Answer: A type cast takes a value of one type and produces a value of another type. Java supports
two kinds of type casts: explicit and implicit. Java performs an implicit type cast
automatically. This can be seen in the declaration of a variable of type double that is
assigned an integer value.
The integer value assigned to the variable castExample is automatically converted to a floating point
number. The number assigned to castExample is converted to 72.0.
An explicit type cast occurs when the programmer explicitly forces a value of one type into a value
of another type. In the example that follows, the value 72.5 is explicitly cast into an integer value.
int castExample = (int) 72.5;
int value1 = 3;
int value2 = 4;
int result = 0;
Answer:
Post increment/decrement: 12
Pre increment/decrement: 10
11) Define the terms class, object, method and method call.
Answer: Objects are entities that store data and can take actions. A class is the name for a type
whose values are objects. Methods are defined as the actions that an object can take. A
method call is invoked with the dot operator by the calling object, usually a variable of
some type. Any information, called arguments, needed by the called method is passed in
parenthesis. Objects have a collection of methods.
12) What does the String method trim() do? Give an example of its use.
Answer: The string method trim removes leading and trailing white space, as well as the tab and
new-line character from String objects. For example, the following is an invocation of
trim():
String s = userInput.trim();
where s represents the new String with no white space, tab or new-line characters.
System.out.println(str.equals("Java Programming!"));
System.out.println(str.toLowerCase());
Copyright © 2016 Pearson Education, Inc., Hoboken NJ
Chapter 1 Getting Started 9
System.out.println(str.toUpperCase());
System.out.println(str.substring(5,8));
System.out.println(str.lastIndexOf("m"));
Answer:
true
java programming!
JAVA PROGRAMMING!
Pro
12
14) Write a Java statement to access the 7th character in the String variable myString and place it in the
char variable c.
Answer:
c = myString.charAt(6);
15) Write a Java statement to determine the length of a string variable called input. Store the result in an
integer variable called strLength.
Answer: int strLength = input.length();
A block comment is included as documentation to users of the class. Users of the class are usually
other programmers. A block comment begins with /* and ends with */. A block comment my span
many lines. Any text between the beginning /* and the ending */ is part of the block comment. A
special block comment can be used with Javadoc, a documentation tool included in Java’s SDK, to
create documentation for users of the class.