Looks like no one added any tags here yet for you.
Which of the following lines is a properly formatted comment?
a.
// This is a comment
b.
/ This is a comment //
c.
/*
this is a comment
*/
d.
both a and b
e.
a, b and c
e. a, b, c
The Java compiler translates Java source code into _____________ .
a.
assembly code
b.
C++
c.
Java bytecode
d.
an object-oriented language
e.
machine code
c. Java bytecode
Classes can be created from other classes by using _______________ .
a.
machine code
b.
attributes
c.
polymorphism
d.
encapsulation
e.
inheritance
e. inheritance
Which of the following is not a valid Java identifier?
a.
thirdNumber
b.
answer_7
c.
2ndlevel
d.
highest$
e.
anExtremelyLongIdentifierIfYouAskMe
c. 2ndlevel
Which of the following might be included in an IDE?
a.
a compiler
b.
an editor
c.
a debugger
d.
all of the above
e.
none of the above
d. all of the above
Which of the following describes the act of ensuring that a program solves the intended problem in all cases?
a.
implementing the design
b.
creating a design
c.
establishing the requirements
d.
testing
e.
preliminary practice coding
d. testing
Write a statement that prints Hello, world to the screen.
a.
System.out.println("Hello, world")
b.
system.out.println("Hello, world");
c.
System.out.println("Hello, world");
d.
System.out.println('Hello, world');
c. System.out.println("Hello, world");
What can be included in a comment?
a.
reserved words
b.
special characters
c.
user output
d.
all of the above
d. all of the above
Which of the following is a valid comment?
a.
int age; /the age of the user /
b.
int age; /// the age of the user ///
c.
int age; / the age of the user /
d.
int age; // the age of the user //
a. int age; / the age of the user /
Which of the following is not a reserved word?
a.
static
b.
this
c.
public
d.
main
d. main
_____________ consists of specific words and symbols to express a problem solution.
a.
An application
b.
A computer
c.
Hardware
d.
Software
e.
A programming language
e. A programming language
Which of the following is a valid Java identifier?
a.
Fourth_&_goal
b.
2_%_2
c.
Studio#54
d.
_____________
d. _____________
Java is _____________________.
a.
a spoken-language
b.
a functional language
c.
an object-oriented language
d.
a fourth-generation language
e.
a procedural language
c. an object-oriented language
In Java, an identifier that is made up by the programmer can consist of ___________________.
a.
only numbers
b.
numbers, letters, the underscore ( _ ), and the dollar sign ( $ )
c.
only letters
d.
any characters
e.
only letters, the underscore ( _ ), and the dollar sign ( $ )
b. numbers, letters, the underscore ( _ ), and the dollar sign ( $ )
In order for a program to run on a computer, it must be expressed in ______________________.
a.
a high-level language
b.
an object-oriented language
c.
an assembly language
d.
a machine language
e.
a fourth generation language
d. a machine language
A syntax error is a _____________________.
a.
a run-time error
b.
a bug
c.
a compile-time error
d.
an exception
e.
a logical error
c. a compile-time error
Which of the following is not one of the four basic software development activities?
a.
implementing the design
b.
establishing the requirements
c.
preliminary practice coding
d.
testing
e.
creating a design
c. preliminary practice coding
Software requirements specify ____________________.
a.
a programming schedule
b.
how a solution should be implemented
c.
what a program should accomplish
d.
which programming language the developer should use
e.
how objects should be encapsulated
c. what a program should accomplish
The _____________ of an object define it define its potential behaviors.
a.
methods
b.
attributes
c.
name
d.
white spaces
e.
variables
a. methods
Which of the following is considered a logical error?
a.
typing a curly bracket when you should have typed a parenthesis
b.
dividing by zero
c.
multiplying two numbers when you meant to add them
d.
misspelling an identifier
e.
forgetting a semicolon at the end of a programming statement
c. multiplying two numbers when you meant to add them
An object should never be encapsulated.
True
False
False
Java is case-sensitive.
True
False
True
Comments affect the run-time execution of a program.
True
False
False
A reserved word can be used to name a method.
True
False
False
An identifier can begin with a digit.
True
False
False
In Java, total, ToTal and TOTAL are all different identifiers.
True
False
True
Identifiers can be of any length.
True
False
True
These two snippets of code are identical from the point of view of the compiler:
//snippet 1
public static void main(String [] args) {
System.out.println("Hi!");
}
//snippet 2
public static void main(String [] args){System.out.println("Hi!");}
True
False
True
An interpreter is a program that translates code that is written in one language into equivalent code in another language.
True
False
False
Syntax rules dictate the form of a program. Semantics dictate the meaning of the program statements.
True
False
True
A _______________ is a list of characters in a particular order. Examples include ASCII and Unicode.
a.
character literal
b.
character set
c.
char data type
d.
control character
e.
none of the above
b. character set
Consider the expression:
result = 15 % 4;
What value stored in result after this line is executed?
a.
0
b.
1
c.
2
d.
3
e.
4
d. 3
Which of the following lines allows a programmer to use the Scanner class in a Java program?
a.
import java.util.Scanner;
b.
using Scanner;
c.
include Scanner;
d.
include java.util.Scanner;
e.
any of the above will allow the programmer to use the Scanner class
a. import java.util.Scanner;
Consider the following snippet of code:
System.out.println("30 plus 25 is " + 30 + 25);
What is printed by this line?
a.
30 plus 25 is 55
b.
30 plus 25 is 3025
c.
30 plus 25 is 30
d.
30 plus 25 is 25
e.
this snippet of code will result in a compiler error
b. 30 plus 25 is 3025
Consider the following snippet of code:
int firstNum = 25;
int seconNum = 3;
double result = 25/3;
System.out.println(result);
What is output by this code?
a.
8.3
b.
8.333333333
c.
This snippet of code will result in a compiler error
d.
8
e.
8.0
e. 8.0
Information is most likely to be lost in what kind of data conversion?
a.
A widening conversion
b.
A narrowing conversion
c.
promotion
d.
assignment conversion
e.
no information will be lost in any of the conversions listed above
b. A narrowing conversion
Write a String constant consisting of exactly one character - A.
a.
System.out.print("");
b.
System.out.print( );
c.
System.out.print('');
d.
none of the above
a. System.out.print("");
Write a String constant that is the empty string .
a.
System.out.print("");
b.
System.out.print( );
c.
System.out.print('');
d.
none of the above
a. System.out.print("");
The character escape sequence to force the cursor to advance forward to the next tab setting is:
a.
\t
b.
\tab
c.
\T
d.
\\t
a. \t
Declare an integer constant, DAYS_IN_MAY , whose value is 31.
a.
final int DAYS_IN_MAY = 31;
b.
final String DAYS_IN_MAY = "31";
c.
final int DAYS_IN_YEAR = 31;
d.
final INT DAYS_IN_MAY = 31;
a. final int DAYS_IN_MAY = 31;
Which of the following are examples of invalid string literals?
a.
"Hello World!"
b.
"4 score and 7 years ago, our forefathers brought forth..."
c.
"z"
d.
""
e.
none of the above
e. none of the above
Writing a floating point literal corresponding to the value of 0.
a.
0f
b.
0.0
c.
0.0f
d.
all of the above
d. all of the above
A(n) ________________ is a piece of data that we send to a method.
a.
service
b.
expression
c.
escape sequence
d.
object
e.
parameter
e. parameter
Which of the following is an example of an invalid assignment or declaration statement?
a.
int age = 30;
b.
int money, dollars = 0, cents = 0;
c.
int years = 1; months = 12; days = 365;
d.
int length, meters, centimeters, millimeters;
e.
none of the above
c. int years = 1; months = 12; days = 365;
Java has two basic kinds of numeric values: _____________, which have no fractional part, and ___________________ which do.
a.
shorts, longs
b.
characters, bytes
c.
integers, floating points
d.
doubles, floating points
e.
integers, longs
c. integers, floating points
Consider the expression:
result = 12 + 5 / 2;
What value stored in result after this line is executed?
a.
8.5
b.
14
c.
14.5
d.
this will result in a compiler error
e.
9
b. 14
Which of the following is not an arithmetic operation in Java?
a.
+
b.
-
c.
*
d.
%
e.
These are all arithmetic operations in Java
e. These are all arithmetic operations in Java
In order to make a variable a constant which modifier must be included in its declaration?
a.
public
b.
private
c.
void
d.
final
e.
static
d. final
Which of the following data types only allows one of two possible values to be assigned?
a.
long
b.
char
c.
int
d.
boolean
e.
float
d. boolean
Which of the following is an example of an invalid expression in Java?
a.
result = firstNum % secondNum;
b.
result = firstNum / secondNum % thirdNum;
c.
result = a + b;
d.
result = (14 + 9) * 5;
e.
result = ((19 + 4) - 5;
e. result = ((19 + 4) - 5;
The Scanner class must be imported using the import statement before it can be used in a program.
True
False
True
The print and the println methods are identical and can be used interchangeably.
True
False
False
In order for a string literal may span multiple lines in the program code.
True
False
False
Java is a strongly-typed language.
True
False
True
Variables declared with the final modifier cannot have new values assigned to them.
True
False
True
The byte type can be assigned a larger range of numbers than the int type.
True
False
False
Java uses the ASCII character set to represent character data.
True
False
False
In Java, all floating point literals are assumed to be of type float.
True
False
False
The type of result produced by a mathematical expression depends on the types of the operands.
True
False
True
Promotion is a widening data conversion that is explicitly requested by the programmer.
True
False
False
____________________ is the automatic conversion between a primitive value and a corresponding wrapper object.
a.
Number formatting
b.
Autoboxing
c.
Aliasing
d.
Generating
e.
Static invocation
b. Autoboxing
Which of the following best describes what happens when an object no longer has any references pointing to it?
a.
The object is marked as garbage and its associated memory is freed when the garbage collector runs.
b.
The object is immediately deleted from memory.
c.
The object stays in memory for the remainder of the programs execution.
d.
The object is overwritten the next time the new operator is called.
e.
The object is overwritten the next time the new operator is called using the same class.
a. The object is marked as garbage and its associated memory is freed when the garbage collector runs.
When an object variable is declared but it is not assigned a value, it is called a ______________________.
a.
null reference
b.
static reference
c.
zero reference
d.
void reference
e.
empty reference
a. null reference
Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?
a.
String prefix = listing.front(5);
b.
String prefix = listing.front(6);
c.
String prefix = listing.substring(1,5);
d.
String prefix = listing.substring(0,5);
e.
String prefix = listing.firstChars(5);
d. String prefix = listing.substring(0,5);
When two references point to the same object, ________________________________ .
a.
a run-time error will occur.
b.
a compiler error will occur.
c.
the references are called aliases of each other.
d.
the object will be marked for garbage collection.
e.
the references are called null references.
c. the references are called aliases of each other.
The String class _______________________________ .
a.
is part of the java.lang package.
b.
is part of the java.util.package.
c.
is a wrapper class.
d.
none of the above.
e.
all of the above.
a. is part of the java.lang package.
Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off, and checking if the air conditioner is on or off. The following methods provide this behavior: turnOn and turnOff , setTemp , and isOn , which accepts no argument and returns a boolean indicating whether the air conditioner is on or off. Assume there is a reference variable myAC to an object of this class, which has already been created.
a.
status = myAC.isOn
b.
status = myAC.isOn( );
c.
myAC.status();
d.
myAC.isOn()
b. status = myAC.isOn( );
Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off, and setting the desired temperature. The following methods provide this behavior: turnOn and turnOff , and setTemp , which accepts an int argument and returns no value. Assume there is a reference variable myAC to an object of this class, which has already been created. Use the reference variable, to invoke a method that tells the object to set the air conditioner to 72 degrees.
a.
myAC.turnOn(72);
b.
myAC.setTemp( 72 );
c.
myAC.turnOn();
myAC.setTemp(72);
d.
myAc.setTemp(72);
b. myAC.setTemp( 72 );
Assume that dateManager is a reference to an object that has a method named printTodaysDate , that accepts no arguments and returns no value. Write a statement that calls printTodaysDate .
a.
dateManager.printTodaysDate( );
b.
printTodaysDate();
c.
dateManager.printTodaysDate;
d.
dataManager.printTodaysDate();
a. dateManager.printTodaysDate( );
Assume that logger is a reference to an object that has a method named printErrorDescription , that accepts one int argument and returns no value. Write a statement that invokes the method printErrorDescription , passing it the value 14 .
a.
printErrorDescription(14);
b.
printErrorDescription.logger(14);
c.
logger.printErrorDescription(14);
d.
printErrorDescription(14);
c. logger.printErrorDescription(14);
The ________________ operator is used to instantiate an object.
a.
static
b.
new
c.
+
d.
-
e.
none of the above
b. new
Assume that dataTransmitter is a variable that refers to an object that provides a method, sendSignal that takes no arguments. Write the code for invoking this method.
a.
dataTransmitter.sendSignal();
b.
dataTransmitter.sendSignal;
c.
sendSignal.dataTransmitter();
d.
dateTransmitter.sendSignal();
a. dataTransmitter.sendSignal();
A special method that is invoked to set up an object during instantiation is called a ___________________.
a.
destructor
b.
creator
c.
dot operator
d.
constructor
e.
new method
d. constructor
Which of the following is an invalid way to instantiate a String object?
a.
String title = new String("Java Software Solutions");
b.
String name = "John Lewis";
c.
String empty = "";
d.
String alsoEmpty = new String("");
e.
all of the above are valid
e. all of the above are valid
Assume that we have a Random object referenced by a variable called generator. Which of the following lines will generate a random number in the range 5-20 and store it in the int variable randNum?
a.
randNum = generator.nextInt(15) + 5;
b.
randNum = generator.nextInt(15) + 6;
c.
randNum = generator.nextInt(16) + 5;
d.
randNum = generator.nextInt(16) + 6;
e.
none of the above
c. randNum = generator.nextInt(16) + 5;
Which of the following classes include the getCurrencyInstance() method?
a.
String
b.
NumberFormat
c.
DecimalFormat
d.
Math
e.
none of the above
b. NumberFormat
Which of the following expressions correctly compute 5 + 2^6?
a.
result = 5 + 2^6;
b.
result = 5 + 2*exponent(6);
c.
result = 5 + 2*Math.exponent(6);
d.
result = 5 + Math.pow(2, 6);
e.
none of the above
d. result = 5 + Math.pow(2, 6);
Consider the following snippet of code:
Random generator = new Random();
int randNum = generator.nextInt(20) + 1;
Which of the following will be true after these lines are executed?
a.
randNum will hold a number between 1 and 20 inclusive.
b.
randNum will hold a number between 0 and 20 inclusive.
c.
randNum will hold a number between 1 and 21 inclusive.
d.
these lines will not be executed because a compiler error will result.
e.
none of the above
a. randNum will hold a number between 1 and 20 inclusive.
Which of the following represents the proper way to create a NumberFormat object that formats numbers as percentages?
a.
NumberFormat fmt = new NumberFormat(%);
b.
NumberFormat fmt = new NumberFormat("%");
c.
NumberFormat fmt = NumberFormat.getPercentInstance();
d.
NumberFormat fmt = new PercentNumberFormat();
e.
none of the above
c. NumberFormat fmt = NumberFormat.getPercentInstance();
Which of the following is a correct declaration of enumerated type for the suits of a deck of cards?
a.
enumerated type Suit = {hearts, spades, diamonds, clubs };
b.
enum Suit {hearts, spades, diamonds, clubs };
c.
enumerated type Suit = { hearts, spades, diamonds, clubs };
d.
enum Suit {hearts, spades, diamonds, clubs }
e.
enum Suit = { hearts, spades, diamonds, clubs }
d. enum Suit {hearts, spades, diamonds, clubs }
The System.out.printf() method is an alternative way to output information in Java.
True
False
True
Multiple reference variables can refer to the same object.
True
False
True
The new operator is used to access an objects methods.
True
False
False
A variable that is declared as a primitive type stores the actual value of the associated data. A variable that is declared as an object type stores a pointer to the associated object.
True
False
True
When there are no references to an object, the object is marked as garbage and is automatically removed from memory using Java's automatic garbage collection feature.
True
False
True
String objects can be changed after instantiation.
True
False
False
All of the classes contained in the java.util package are automatically included in every Java program.
True
False
False
When called with integer parameter n, the nextInt() method of the Random class will return a randomly generated integer between 0 and n.
True
False
False
The Math class is part of the java.lang package.
True
False
True
Enumerated types allow a programmer to treat primitive data as objects.
True
False
False
Which of the following statements best describes the flow of control in the main method of a Java program that has no conditionals or loops?
Program statements are executed linearly, with earlier statements being executed first
Which of the following best describes this code snippet?
if (count != 400)
System.out.println("Hello World!");
If the variable count is not equal to 400, "Hello World" will be printed.
Which of the following is not a valid relational operator in Java
<>
Let a and b be valid boolean expressions. Which of the following best describes the result of the expression a || b?
It will evaluate to false if a evaluates to false and b evaluates to false. It will evaluate to true otherwise
Which of the following expressions best represents the condition "if the grade is between 70 and 100"
if (75 < grade && grade < 100)
Which of the following logical operators has the highest precedence?
!
Suppose we wanted to process a text file called "input.txt" using the Scanner object. Which of the following lines of code correctly creates the necessary Scanner object?
Scanner inputFile = new Scanner(new File("input.txt"));
A _______________ loop always executes its loop body at least once.
do
What happens if a case in a switch statement does not end with a break statement?
The switch statement will execute the next case statement as well.
Suppose we want to condition an if statement on whether two String objects, referenced by stringOne and stringTwo, are the same. Which of the following is the correct way to achieve this?
if(stringOne.equals(stringTwo))