Java Reviewer Updated

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

HOTSPOT

You need to evaluate the following code segment. Line numbers are included for reference only.

Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:

You have the following code segment. Line numbers are included for reference only.

What is the output of line 07?

• A. -44
• B. -40.0
• C. 40.0
• D. 44.0
HOTSPOT -
You are interviewing for a job as a Java developer.
You are presented with the following code. Line numbers are included for reference only.

You need to evaluate what happens when the code runs.


Use the drop-down menus to select the answer choice that answers each question based
on the information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:

HOTSPOT -
You need to evaluate the following Java program. Line numbers are included for reference only.
Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:

You need to analyze the following code segment. Line numbers are included for reference only.
printInt addOne

What is the output of line 12 when you run printInt()?

• A. 0
• B. 1
• C. 2
• D. 3

HOTSPOT -
You write the following code:

You need to determine the values of the data1, data2, data3, and data4 variables.
Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:
HOTSPOT -
You are creating a Java console application.
You need to read a birthdate entered by the user.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:
DRAG DROP -
You need to evaluate the following Java program. Line numbers are included for reference only.
JavaProgram1

Which three values will be displayed in sequence? To answer, move the appropriate values from
the list of values to the answer area and arrange them in the correct order.
NOTE: Each correct selection is worth one point.
Select and Place:

DRAG DROP -
You are interviewing for a job at Adventure Works, Inc. The hiring manager asks you to create a
single console program.
The program takes multiple arguments from the command line and writes them to the screen in
the same order as they were typed on the command line.
Which three code segments should you use to develop the solution? To answer, move the
appropriate code segments from the list of code segments to the answer area and arrange them
in the correct order.
Select and Place:

HOTSPOT -
You need to evaluate the following code. Line numbers are included for reference only.

Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:
DRAG DROP -
You have the following code:

You need to create an int array named numbers initialized with num1, num2, and num3.
How should you complete the code? To answer, drag the appropriate code segment to the
correct position. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:
HOTSPOT -
You are creating a method that processes invoices. The invoices are contained in an ArrayList
instance. After each invoice is processed, the method must remove the invoice from the
ArrayList instance.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

HOTSPOT -
You are writing a Java method.
The method accepts a two-dimensional String array and prints the content of each array
element.
The size of each dimension of the array might be different.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:
HOTSPOT -
You are developing a Java program to play Tic-Tac-Toe. You define the following array to store
the state of the board:

Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:
HOTSPOT -
You are writing a Java program.
The program must meet the following requirements:
-> Truncate firstName to its first five characters
-> Set output to a string that contains the firstName and the number of characters in firstName
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

DRAG DROP -
You are writing a Java program that collects patient information and stores it in a database.
You need to ensure that the program stores data using the least amount of memory.
Which data type should you use to complete each variable declaration? To answer, drag the
appropriate data type from the column on the left to its code segment on the right. Each data
may be used once, more than once, or not at all. You may need to drag the split bar between
panes or scroll to view content.
Select and Place:

DRAG DROP -
You are writing a Java method that evaluates an arithmetic formula.
The method accepts an int value named number, raises the value to the second power, and
returns the negative value of the result.
How should you complete the code? To answer, drag the appropriate code segment to the
correct position. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:
HOTSPOT -
You are creating a method that converts a string representation of a number into an actual
number.
The numbers passed into the method include whole numbers and fractional numbers.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

DRAG DROP -
You attend an interview for a job as a Java programmer.
You need to declare a two by three array of the double type with initial values.
How should you complete the code? To answer, drag the appropriate code segment to the
correct location. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:
HOTSPOT -
You are interviewing for a job as a Java developer. You need to evaluate the following code. Line
numbers are included for reference only. Hello World

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:

The question requires that you evaluate the underlined text to determine if it is correct.
You should use an int data type to store the numeric value 3,000,000,000 (3 billion) so that the
least amount of memory is used.
Review the underlined text. If it makes the statement correct, select "No change is needed." If
the statement is incorrect, select the answer choice that makes the statement correct.

• A. No change is needed.
• B. a short
• C. a byte
• D. a long
You need to evaluate the following code segment:

What happens when the code segment is run?

• A. iNum has a value of 0.


• B. An exception is thrown.
• C. iNum has a value of 2.
• D. iNum has a value of 3.

DRAG DROP -
You are writing a Java method.
The program must meet the following requirements:
-> Accept a String parameter firstName
-> Display a welcome message that contains firstName
-> Ensure that the first letter of the name is capitalized, and the remaining letters are in
lowercase
How should you complete the code? To answer, drag the appropriate code segment to the
correct position. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:

ANSWER:
substring, toUpperCase
substring, toLowerCase
You work as a Java programmer.
You need to convert a numeric String to a primitive double value.
What code segment should you use?

• A. Double.valueOf(numberString);
• B. double.parseDouble(numberString);
• C. String.parseDouble(numberString);
• D. Double.parseDouble(numberString);

DRAG DROP -
Your instructor asks you to evaluate four arithmetic code segments.
What is the value of each code segment? To answer, drag the appropriate value from the
column on the left to its code segment on the right. Each data may be used once, more than
once, or not at all. You may need to drag the split bar between panes or scroll to view content.
Select and Place:
QUESTION 26
HOTSPOT
You are writing a Java console program. The program accepts command line arguments.
You need to ensure that the main method parses and handles each command line argument.
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:
You work as an intern Java programmer at Adventure Works. Your team lead asks you to create a
method.
The method must meet the following requirements:
Accept an int array
Check for duplicate values in the array
Stop the outer loop as soon as a duplicate value has been detected and return true
Return false if all values in the array are unique
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:
You are interviewing for a job as a Java developer. You need to demonstrate your understanding of
switch
statements.
For each of the following code segments, select Yes if the code segment can be changed to a switch
statement with up to three case statements. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:
You are writing a Java method.
The method must meet the following requirements:
Accept a String array named entries
Iterate through entries
Stop the iteration and return false if any element has more than 10 characters
Otherwise, return true
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:
Traders hires you to write a Java program to manage account openings.
To open a new accunt, a user must meet one the following requirements:
be over 65 years old and have a minimum annual income of 10,000
be at least 21 and have an annual income greater than 25,000
How should you complete the code? To answer, drag the appropriate operator to the correct position.
Each
operator may be used once, more than once, or not at all. You may need to drag the split bar between
panes
or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:

You are writing a Java method named countdown.


The method must meet the following requirements:
Accept an int parameter named start
Display all numbers from start to zero in decrements of one
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:
You work as a Java programmer. A member of the team creates the following program. Line numbers are
included for reference only.

int timer = 60

The program is supposed to display a message to the console while it counts down from 60. The method
does
not work as intended.
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
You are writing a Java console program.
The program must meet the following requirements:
Read a line of text entered by the user
Print each word in the text to the console on a separate line
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.

Hot Area:
You need to evaluate the following code. Line numbers are included for reference only.

public static void main anum

Use the drop-down menus to select the answer choice that answers each question based on the
information
presented in the code.
NOTE: Each correct selection is worth one point.
Hot Area:
Correct Answer:
You work for Woodgrove Bank as a Java programmer.
You need to evaluate the following class. Line numbers are included for reference only.

public class Account

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:
You have the following code segment. Line numbers are included for reference only.

Customer id = 3

The code does not compile.


For each of the following statements, select Yes if the action is required to resolve the compilation error.
Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:
You have a Java class named InsurancePolicy.
You need to define a constant data member named RATE. The data member must be accessible by any
class
without instantiating the InsurancePolicy class.

How should you complete the code? To answer, drag the appropriate code segment to the correct
position.
Each code segment may be used once, more than once, or not at all. You may need to drag the split bar
between panes or scroll to view content.
NOTE: Each correct selection is worth one point.
Select and Place:

You work on a team that develops e-commerce applications. A member of the team creates a class
named DB
that connects to a database. The class contains a method named query.
You need to initiate the DB class and invoke the query method.
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:

You are writing a Java class named SavingsAccount.


The class must meet the following requirements:
Inherit from an existing class named Account
Include a constructor that uses the base class constructor to initialize the starting balance
Include a substitute toString() method
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area:
Correct Answer:
The question requires that you evaluate the underlined text to determine if it is correct.
You have the following class definition:

The logError method can be invoked by code in all classes in the same package as the Logger class.
Review the underlined text. If it makes the statement correct, select “No change is needed.” If the
statement is
incorrect, select the answer choice that makes the statement correct.
A. No change is needed
B. only by the Logger class
C. only by the Logger class and classes in the same package that inherit from it
D. by all classes in all packages

You write the following Java program for Munson’s Pickles and Preserves Farm. Line numbers are
included for reference only.

You encounter error messages when you attempt to compile the program.
You need to ensure the program compiles successfully.
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
NOTE: Each correct selection is worth one point.
Hot Area: Class Pickle preserved
You need to evaluate the output of the following code segment. Line numbers are included
for reference only. Try arithmeticexception “finally” try catch catch

For each of the following outputs, select Yes if the output is displayed. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:

You work as a Java programmer Your colleague creates the following class Line numbers are included
for reference only

You need to write code to test the Rectangle class

Complete the code by selecting the correct code segment from each drop down
new Rectangle(20,40)
You are writing a Java program that uses the calculatePrice function to calculate the admission fee (price)
for a museum The standard ticket price is $1000 A membership costs $4000. The program must
implement the following rules

Members receive a 70% discount on the standard ticket price

Members over the age of 86 receive free admission.

Non-members can pay the standard ticket price or purchase a membership and a discounted ticket in one
transaction (buy Membership

The isMember Variable specifies whether a person is a member

Complete the cook by selecting the correct code segment from each drop down list
Review the following code segment

Char[][] chArray = { {‘A’,’B’,’C’}, {‘D’, ‘E’, ‘F’}, {‘G’, ‘H’, ‘I’}};

chArry.length

What is output to the console window after the loops finish executing?

Review the following code

Public class DivisionManager

What type of error occurs when you run the code?


Review the following code segment

Int[][] iArray = { {4, 10, 25}, {16, 8, 32}, {50, 1, 17} };

iArray.length

Review the following code

public class Logger {

What is the output when you run the program?


You are writing a Java Method. The method must perform the following tasks

Accept a double array

Return the largest value in the array

Keyword: findMax

double[] maxArray
double max = max Array
[0]
maxArray.length
max < maxArray [i]
max = maxArray [i]

You are creating a class named Oven that simulated an oven

Keyword: oven maxTemperature

CLASS
PRIVATE
FINAL
You program uses a Student class to create objects of type Student. Each data member has accessor
and mutator (getter and setter) methods

Keyword: Student millerS

Keywords: int x=5 y=5


Keywords: double value1 = 255.255 value2 value3

225

-1

Keyword: entries 10 characters


Keyword: countdown decrements of one

Keywords: Account displayTerms addAccount


Keyword: 19 26 1 2.5

Keyword: ScopeTester test()

this.x = 5

Y=10
Keywords: displayMenu makeNewTransaction

} while (makeNewTransaction());

Keywords: data members public accessor author title year isbn


Keywords: value1 = 127 value1++ byte

Keywords: Sunset Web signature

Keywords: sum is greater than or equal to num cnt is smaller than num
Keywords: main method parameter args

Keyword: school Bob student


Keywords: ArrayManipulation throws fraction

Keywords: RaceCar race car


Keywords: senior adult youth 65 20 classification

Keywords: gpa calculateAward

15000
15000
30000
Keywords: Box

Keywords: final value of x x=50


Keywords: stringvalue boolean

Keywords: change the score 0 to 50

1 2
Keywords: score player game
1.
public class RaceCar{
private int speed,
protected String color

2.
What happens when line 01 and 02 are run? - the letter ‘A’ is displayed
What happens when line 04 and 05 are run? - the number 65 is displayed
What happens when line 07 and 08 are run? - the number -65 is displayed
What happens when line 10 and 11 are run? - An exception is thrown

3.
age switch expressions
- age >= 25 - no
- grade == "A" - yes
- gpa == 4.0 - no

If 4 choices
Yes
Yes
No
yes

4.
Output of line 11 is - x=10
Output of line 12 - this x = 5
Output of line 13 - y = 10
Output of line 14 - ScopeTester y = 5

5.
for ( int I = start; i>=0 --i ) {

6.
public void traverse
String[][]
board.length
board[x].length
board[x][x]

7.
if (age> 65) {
else {
if (buyMembership) {
else {

8.

The Account class has a single constructor - no


Other classes can inherit the Account class - yes
Line 07 is equivalent to this.balance = amount - yes

9.
double [][] maxArray = {{ 0.77,3.4,55}, { 2.2,.045,2 }};

10.
private bool islnMovie(String actor) {
return true
return false

11.
Change the access modifier of the id variable to public - No
Change the access modifier of the showld method to public - No
On lines 07 and 08 - Yes

12.
Which annotation should you use at line 5 - Override

13.
while (timer >= 0)
if (timer == 0)
timer--

14.
public class Account {
public
static
protected

15.
chArray -
CBAFEDIHG
16.
if age > 65 && income >= 10000 || age >= 21 && income > 25000) {

17.
3 billion
long

18.
import java.util.Scanner
Scanner sc= new Scanner(System. in)
String birthdate = sc.next ()
sc.close ()

19.
Sunset Web
public static void , String args []

20.
ArrayManipulation -
Exception due to: java.lang.ArithmeticException/ by zero

21.
Output line 04 - 60
line 05 - 16

22.
Value bonus line 04 - true
true value extra line 05 - false
value score line 07 - true
value score line 14 - false

23.
Student millerS = new Student():
Private
display (millerS)

24.
if num <= sum && int <

25.
Rectangle rect= new Rectangle (20,40)
areaNum = rect.area();
rect.getWidth(),
rect.getLength ()

26.
Double Array largest value
double[] maxArray
double max = max Array [0]
maxArray.length
max < maxArray [i]
max = maxArray [i]

27.
The value of value 2 is 255
The value of value 3 is -1

28.
try - no
catch arithmetic - yes
catch exception - no
finally - yes

29.
output line 03 - -128
line 04 - 0.3333333333333
line 05 - 0.33333334

30.
Christopher firstName
substring(0,5);
%s
%d
length ()

31.
class Oven
private int temperature
final int max temperature

32.
ValidateEntries -
for
:
break;

33.
main method parameter - true
can only accept one argument - false
must be static - true

34.
StringageClassification
if (age >= 65)
else if (age >= 20)
else

35.
if ( num <= sum && int < num)

36.
iArray
16 50

37.
Logger
ArrayIndexOutofBounds Exception

38.
Line 06 - x + y = 57
Line 08 - x + y = 12

39.
DivisionManager
Logical Error

40.
do
} while (makeNewTransaction());

41.
If (age >= 25) {
Yes
Yes
No
Yes

42.
Four arithmetic code segments
(2+3) *4-1 = 19
4*4+2*5 = 26
8*2%3 = 1
5/2-4%2 = 2

43.
What is the output of line 03 - 3.142
What is the output of line 04 - 3
What is the output of line 05 - 03.141593

44.
What is the output of line 04- 6
What is the output of line 06 - 16

45.
What is the output of line 07- -40.0

46.
What is the output of line 12 when you run printInt()?
0

47.
The value of data1 is - 1
The value of data2 is - Excellent
The value of data3 is - 2
The value of data4 is - Good 3 Fair 4 Poor

48.
JavaProgram1 Values - 1
100
25

49.
Adventure Works
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}

50.
What is the return value when model has a value of ‘A’? - 50
What is the return value when model has a value of ‘T’? - 5
What is the return value when model has a value of ‘C’? - 5
What is the return value when model has any other value? - 100

51.
Process(ArrayList<String> invoices)
0
size()
)

52.
class Exam {
static
protected

53.
Tic-Tac-Toe
Which array element contains an “x”?
grid[0][2]
Which array element contains an “o”?
grid[2][1]

54.
Patient information
Short birthYear = 1974;
Boolean exempt = false;
Char initial = ‘D’;
Float salary = 22123.5f;

55.
Public static int negativeSquare(int number) {
-
Number
*
Number

56.
convertStringToNumber
double
Double
parseDouble

57.
s1 and s2 refer to the same object in memory. - No
s2 and s3 refer to the same object in memory - Yes
A different string can be assigned to s1 on line 04 - Yes
A different string can be assigned to s2 on line 05 - Yes

58.
Double dNum, iNum
iNum has a value of 2.

59.
showGreeting, String parameter firstName, welcome message
substring
toUpperCase
substring
toLowerCase

60.
You need to convert a numeric String to a primitive double value.
Double.parseDouble(numberString);

61. Public static void main


String[]
for int(
args.length
handleArgument
args[i]

62. Public static boolean duplicate(int[] array) {


int x = 0;
x < array.length -1;
y++
break;

63.
Read a line of text entered by the user
Print each word in the text to the console on a separate line
util.Scanner
util.Scanner
System.in
hasNext()
System.out.println
next()

64.
public static void main anum
Line 05 - When cnt is 9, the value of anum is 55.
Line 11 - When cnt is 7, the value of anum is 55.
Line 06 - the variable cnt is out of scope.

65.
public class InsurancePolicy
public
static
final

66.
DB db =
new DB()
db.query()

67.
Public class SavingsAccount
extends
super
@Override

68.
logError Method
No change is needed.

69.
Pickle
Pickle pickle = new Pickle();
pickle.isCreated = true;
pickle.preserve();

You might also like