You are on page 1of 55

1. What is the output?

Mark for Review


char grade = 'A'; (1) Points
switch (grade) {
case 'A':
System.out.println("Congratulations!"); case
'B':
System.out.println("Good work");
case 'C':
System.out.println("Average");
case 'D':
System.out.println("Barely passing");
case 'F':
System.out.println("Failed");
}

Congratulations!

Failed

Congratulations! Good Work


Average Barely Passing Failed (*)

Incorrect.
Refer to
Section 5
Lesson 3.

2. Which two of the following data types


can be used in a switch statement? Mark for Review
(1) Points

(Choose all correct answers)

boolean

float
String (*)

int (*)

Incorrect.
Refer to
Section 5
Lesson 3.

3. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants");
}
}

Compilation error

Vowels

Consonants (*)

Vowels

Correct

4. The switch statement is a more


efficient way to write code when Mark for Review
dealing with a large range of unknown (1) Points
values.

True

False (*)

Incorrect.
Refer to
Section 5
Lesson 3.

5. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

No output

Bob is 43 Bob is 50

Bob is 43 (*)

Correct
6. An if/else
statement is Mark for Review
used when you (1) Points
need to choose
between two
alternatives.

True (*)
False
Correct

7. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
String name = "Java";
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

False

JavaProgramming

Java Programming

True (*)

Incorrect. Refer to Section 5 Lesson 1.

8. Which are used in a boolean expression?


Mark for Review
(1) Points

(Choose all correct answers)

Loops

Errors

Operators (*)

Variables (*)

Correct

9. How should Strings be compared?


Mark for Review
(1) Points

~=

==

The equals() method (*)

Incorrect. Refer to Section 5 Lesson 1.

10. Which operator is used to test if both sides of a boolean expression


are equal? Mark for Review
(1) Points

== (*)
<=

>=

Incorrect. Refer to Section 5 Lesson 1.

11. The equal


sign (=) is Mark for Review
used to make (1) Points
an
assignment,
whereas the
== sign
merely
makes a
comparison
and returns a
boolean.

True (*)

False

Correct

12. In a boolean expression which uses the && operator, what would
make this expression evaluate to true? Mark for Review
(1) Points
boolean x = (firstCondition && secondCondition);

If both the first condition and second condition are true (*)

If the first condition is false, but the second condition is true

If both the first condition and second condition are false

If the first condition is true, but the second condition is false

Incorrect. Refer to Section 5 Lesson 2.

13. In Java, an if statement can be nested inside another if statement.


Mark for Review
(1) Points

True (*)

False

Correct

14. An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print? Mark for Review
(1) Points
int rating;
int experience;
if (rating > 1 && experience == 5) {
System.out.println (“Eligible for a bonus”);
}

5 experience and 2 or more rating (*)

5 rating and 1 experience

5 experience and 1 rating

Less than 5 experience and 1 rating.

Incorrect. Refer to Section 5 Lesson 2.

15. What is the result?


Mark for Review
public static void main(String[] args) { (1) Points
int point = 10;
String s = (point == 1 ? "point" : "points");
System.out.println("I scored " +point +" " +s );
}

Compilation error

I scored 1 point 10 points

I scored 10 points (*)

I scored 1 point

Incorrect. Refer to Section 5 Lesson 2.


6. A break
statement Mark for Review
causes control (1) Points
to transfer to
the end of the
switch
statement.

True (*)

False

Correct

7. Which two statements are true about the default statement?

(Choose all correct answers)

A default statement is required in every switch statement.

A default statement is executed by default when the program is


executed.
The default statement is optional in switch statement. (*)

When the input does not match any of the cases, the default
statement is executed. (*)

Incorrect. Refer to Section 5 Lesson 3.


8. What is the output?

public static void main(String args[]) {


char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants");
}
}

Consonants (*)

Vowels

Vowels

Compilation error

Correct

9. What is the output?

public static void main(String[] args) {


int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

Bob is 43 (*)

Bob is 43 Bob is 50

No output

Incorrect. Refer to Section 5 Lesson 1.

10. Which operator is used to test if both sides of a boolean expression are
equal?

<=

== (*)

>=

Incorrect. Refer to Section 5 Lesson 1.


1. A String
comparison with Mark for Review
== compares (1) Points
the Strings’
locations in
memory and
not the content
of the String.

True (*)

False

Correct

2. What is the output?

public static void main(String[] args) {


int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

Bob is 43 Bob is 50

No output

Bob is 43 (*)

Incorrect. Refer to Section 5 Lesson 1.

3. What is the output?

public static void main(String[] args) {


String name = "Java";
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

True (*)

JavaProgramming

False

Java Programming

Incorrect. Refer to Section 5 Lesson 1.

4. Which are used in a boolean expression?


(Choose all correct answers)

Errors

Loops

Operators (*)

Variables (*)

Incorrect. Refer to Section 5 Lesson 1.

5. What are the possible values of a boolean data type in Java?

good/bad

true/false (*)

yes/no

0/1

Incorrect. Refer to Section 5 Lesson 1.


6. Which three are
conditional Mark for Review
statements? (1) Points

(Choose all correct answers)

switch statement (*)

if statement (*)

for loop

do while loop

if/else statement (*)

Correct

7. The equal sign (=) is used to make an assignment, whereas the == sign
merely makes a comparison and returns a boolean.

True (*)

False

Correct

8. In the AND (&&) test, if the first expression on the left hand side is false,
then there is no need to evaluate the second statement.

True (*)

False
Correct

9. In a boolean expression which uses the && operator, what would make
this expression evaluate to true?

boolean x = (firstCondition && secondCondition);

If both the first condition and second condition are false

If the first condition is false, but the second condition is true

If the first condition is true, but the second condition is false

If both the first condition and second condition are true (*)

Incorrect. Refer to Section 5 Lesson 2.

10. Which two are not logical operators?

(Choose all correct answers)

||

&&

% (*)

+ (*)

Correct
6. Which three are
conditional Mark for Review
statements? (1) Points

(Choose all correct answers)

switch statement (*)

if statement (*)

for loop

do while loop

if/else statement (*)

Correct

7. The equal sign (=) is used to make an assignment, whereas the == sign
merely makes a comparison and returns a boolean.

True (*)

False

Correct
8. In the AND (&&) test, if the first expression on the left hand side is false,
then there is no need to evaluate the second statement.

True (*)

False

Correct

9. In a boolean expression which uses the && operator, what would make
this expression evaluate to true?

boolean x = (firstCondition && secondCondition);

If both the first condition and second condition are false

If the first condition is false, but the second condition is true

If the first condition is true, but the second condition is false

If both the first condition and second condition are true (*)

Incorrect. Refer to Section 5 Lesson 2.

10. Which two are not logical operators?

(Choose all correct answers)

||

&&

% (*)

+ (*)

1. In object
oriented Mark for Review
programming, an (1) Points
object comprises
of properties and
behaviors where
properties
represented as
fields of the
object and
behavior is
represented as
method.

True (*)

False

Correct
2. An object may interact with another object by invoking methods.
Mark for Review
(1) Points

True (*)

False

Correct

3. You have a beautiful garden at home. On Sunday, you start budding your
rose plant to make few more samples of rose plants to plant in the garden. Mark for Review
Can you categorize how this scenario could be represented by classes and (1) Points
instances?

Samples of the rose plant are called classes and not the actual rose
plant.
Rose plant is the object and samples are not instances of the plant
because they have not grown yet.
Rose plant is the class and the samples generated from the rose plant
are instances of that class. (*)
Samples are the class and the rose plant is the instances of samples.

Incorrect. Refer to Section 2 Lesson 3.

4. If the requirement step of the Spiral Model of development is forgotten, which


of the following could occur? Mark for Review
(1) Points

The Program gives inaccurate results.

Code becomes messy.

Solutions seem elusive.

Required software features are missing from the program. (*)

Incorrect. Refer to Section 2 Lesson 1.

5. What is the correct order of steps in the Spiral Model of Development?


Mark for Review
(1) Points

Design, Requirements, Develop, Test

Requirements, Design, Develop, Test (*)

Design, Develop , Requirements, Test

Requirements, Design, Test, Develop

Incorrect. Refer to Section 2 Lesson 1.


6. A software
feature Mark for Review
may allow (1) Points
the user
to perform
a specific
task.

True (*)

False

Correct

7. Java mostly reads code line-by-line.


Mark for Review
(1) Points

True (*)

False

Correct

8. Which of the following three statements are true about breakpoint?


Mark for Review
(1) Points

(Choose all correct answers)

They can be used to check the current state of the program (*)

They help with debugging. (*)

They insert break statements.

They pause code execution. (*)

They abruptly ends the code execution.

Incorrect. Refer to Section 2 Lesson 2.

9. Which of the following 2 statements are true about whitespace?


Mark for Review
(1) Points

(Choose all correct answers)

Whitespace makes your code more readable. (*)

Whitespace eliminates typing mistakes while programming.

Whitespace reduces the performance of the program.

Whitespace helps to keep your code organized. (*)

Whitespace increases execution time of your program.

Incorrect. Refer to Section 2 Lesson 2.


Section 3
(Answer all questions in this section)

10. You write a statement that assigns a value to a String variable as shown below.
Mark for Review
String input = ”This is Java Program”; (1) Points

This way of assigning values to variables is known as hard-coding.

True (*)

False

Correct
11. System.in
readies Mark for Review
Scanner (1) Points
to collect
input
from the
console.

True (*)

False

Correct

12. The Scanner class accepts input in which form?


Mark for Review
(1) Points

Callables

Integer

Tokens (*)

Future

Incorrect. Refer to Section 3 Lesson 5.

13. Which two statements will not compile?


Mark for Review
(1) Points

(Choose all correct answers)

int abc = 10;

int age=20;

int break=10; (*)

double double=10; (*)


double salary = 20000.34;
Incorrect. Refer to Section 3 Lesson 1.

14. Which two are valid assignments of a?


Mark for Review
(1) Points

(Choose all correct answers)

int a = 10; (*)

int a = “10”;

int a; a = 10; (*)

int a = 10

Incorrect. Refer to Section 3 Lesson 1.

15. Java is a strongly typed language; therefore you must declare a data type for
all variables. Mark for Review
(1) Points

True (*)

False

Correct
16. Automatic
promotion Mark for Review
from (1) Points
smaller
data type
to a larger
data type
is not
allowed in
Java.

True

False (*)

Correct

17. Which is a valid way to parse a String as an int?


Mark for Review
(1) Points

nt intVar1 = (int)"100";

int intVar1 = Integer.parseInt("One Hundred");

int intVar1 = Integer.parseInt("100"); (*)

int intVar1 = "100";

Incorrect. Refer to Section 3 Lesson 4.


18. Which two statements are correct about the usage of an underscore?
Mark for Review
(1) Points

(Choose all correct answers)

Underscores help make large numbers more readable. (*)

Underscores do not affect the value of the variable. (*)

Underscores change the value of the number.

Underscores help the compiler interpret large numbers.

Incorrect. Refer to Section 3 Lesson 4.

19. This declaration represents a long data type.


long a = 123L; Mark for Review
(1) Points

True (*)

False

Correct

20. Which two are mathematical operators?


Mark for Review
(1) Points

(Choose all correct answers)

+ (*)

– (*)

Correct
21. Which
data type Mark for Review
is most (1) Points
commonly
used to
represent
numeric
data?

int (*)

float

String
short
Correct

22. The print() method prints to the console and automatically creates a line.
Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 3.

23. Double quotes may be used with char literal values.


Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 3.

24. Which two statements compile?


Mark for Review
(1) Points

(Choose all correct answers)

String name = new String ( ‘Java’);

String name = “J”; (*)

String name = “Java”; (*)

String name = ‘Java’;

Incorrect. Refer to Section 3 Lesson 3.

Section 4
(Answer all questions in this section)

25. Using the Random class requires an import statement.


Mark for Review
(1) Points

True (*)

False

Correct
26. Which
class is Mark for Review
used to (1) Points
generate
random
numbers?

Number

Double

Integer

Random (*)

Correct

27. You need to generate random integer values between 0 and 80 (inclusive).
Which statement should you use? Mark for Review
(1) Points

nextInt(81); (*)
nextInt(0-79);

nextInt(80);

nextInt();

Incorrect. Refer to Section 4 Lesson 4.

28. Which of the following two operations are appropriate for the main method?
Mark for Review
(1) Points

(Choose all correct answers)

Calling an instance object’s field and methods. (*)

Calling local variables declared within a class’s method

Creating instances of objects (*)

Assigning memory to the variables

Incorrect. Refer to Section 4 Lesson 1.

29. Which is a valid way of calling the testMethod in the TestClass? Assume a
testInstance has been created. Mark for Review
(1) Points
public void testMethod(int x, double y){
System.out.println(x/y);
}

testInstance.testMethod(3.5);

testInstance.testMethod(3.5, 10);
testInstance.testMethod(10);
testInstance.testMethod(10, 3.5); (*)

testInstance.testMethod(10, 3.5, 0);

Incorrect. Refer to Section 4 Lesson 1.

30. How many arguments does the following method accept?


Mark for Review
public void simpleInterest(double principal, int noofYears, double (1) Points
interestRate){
System.out.println(“The interest rate is ” +interestRate );
}

3 (*)

Incorrect. Refer to Section 4 Lesson 1.


31. In Java,
methods Mark for Review
usually (1) Points
hold the
properties
of an
object.

True

False (*)

Incorrect. Refer to Section 4 Lesson 1.

32. Which is a risk of using fully qualified class names when importing?
Mark for Review
(1) Points

The compiler runs longer.

Code readability is reduced. (*)

Performance of the code is reduced.

Memory usage is increased.

Incorrect. Refer to Section 4 Lesson 2.

33. Given the import statement:


import java.awt.font.TextLayout; Mark for Review
which is the package name? (1) Points

java.awt
java.awt.font (*)
java

awt.font

Incorrect. Refer to Section 4 Lesson 2.

34. Which statement is true about packages?


Mark for Review
(1) Points

A package makes it difficult to locate the related classes.

A package doesn’t contain a group of related classes.

Packages of the Java class library do not contain related classes.

A package contains a group of related classes. (*)

Incorrect. Refer to Section 4 Lesson 2.

35. Import statements are placed above the class definition.


Mark for Review
(1) Points

True (*)

False

Correct

36. What is the


approximate Mark for Review
value of PI? (1) Points

0
2.718

The value varies.

3.141 (*)

Incorrect. Refer to Section 4 Lesson 5.

37. A constant field, like Math.PI is used to represent a fixed value.


Mark for Review
(1) Points

True (*)

False

Correct
38. The String class must be imported using java.lang.String;
Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 4 Lesson 3.

39. The String concat() method concatenates only String data types.
Mark for Review
(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 3.

40. String objects are immutable.


Mark for Review
(1) Points

True (*)

False

Correct
41. The
indexOf() Mark for Review
method (1) Points
returns
the index
value of a
character
in the
string.

True (*)

False

Correct

Section 5
(Answer all questions in this section)

42. The switch statement is a more efficient way to write code when dealing with a
large range of unknown values. Mark for Review
(1) Points
True

False (*)

Incorrect. Refer to Section 5 Lesson 3.

43. A break statement causes control to transfer to the end of the switch
statement. Mark for Review
(1) Points

True (*)

False

Correct

44. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
String name = "Java";
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

False

JavaProgramming

Java Programming

True (*)

Incorrect. Refer to Section 5 Lesson 1.

45. A String comparison with == compares the Strings’ locations in memory and
not the content of the String. Mark for Review
(1) Points

True (*)

False

Correct
46. How
should Mark for Review
Strings be (1) Points
compared?

The equals() method (*)

~=
==
Correct

47. What are the possible values of a boolean data type in Java?
Mark for Review
(1) Points

yes/no

true/false (*)

0/1

good/bad

Correct

48. An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print? Mark for Review
(1) Points
int rating;
int experience;
if (rating > 1 && experience == 5) {
System.out.println (“Eligible for a bonus”);
}

Less than 5 experience and 1 rating.

5 experience and 2 or more rating (*)

5 rating and 1 experience

5 experience and 1 rating

Correct

49. A customer is eligible for a discount based on certain criteria. Under what
conditions does “You qualify for a discount” print? (Hint: There may be more Mark for Review
than one correct answer) (1) Points

int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
System.out.println("You qualify for discount");
}

(Choose all correct answers)

When rewardPoints is more than 2000 or purchase greater than 1000

When purchase is 4000 and rewardPoints is 2000 (*)

When purchase is 2000 regardless of the value of rewardPoints (*)

When rewardPoints is more than 1000 and purchase is 1000

Incorrect. Refer to Section 5 Lesson 2.


50. In the OR (||) test, if the first expression on the left hand side is true then there
is no need to evaluate the second statement. Mark for Review
(1) Points

True (*)

False

Correct

1. Which of the
following are Mark for Review
considered (1) Points
Whitespace?

(Choose all correct answers)

Space in the print statements.

Blank lines in the code. (*)

Indentation before the code. (*)

Space between the [ ] braces.

Space between words. (*)

Incorrect. Refer to Section 2 Lesson 2.

2. When the program runs normally (when not in debug mode), which statement
is true about breakpoints? Mark for Review
(1) Points

Breakpoints will not have any effect on program execution. (*)

Breakpoints will stop program execution at the last breakpoint.


Any Breakpoint will stop program execution.

Breakpoints will stop program execution at the first breakpoint.

Incorrect. Refer to Section 2 Lesson 2.

3. A Java program can be written in the single line.


Mark for Review
(1) Points

True (*)

False

Correct

4. In the code example below, identify any methods:


Mark for Review
public class Employee { (1) Points
public String name = " Duke";
public int empId = 12105;
public float salary;

public void displaySalary(){


System.out.println("Employee Salary: "+salary);
}
}

name

empId

salary

displaySalary() (*)

Correct

5. An object may interact with another object by invoking methods.


Mark for Review
(1) Points

True (*)
False

Correct
6. Which of
the Mark for Review
following (1) Points
language is
called a
procedural
language?

Java C

C++

Java

C (*)

Incorrect. Refer to Section 2 Lesson 3.

7. If the requirement step of the Spiral Model of development is forgotten, which of


the following could occur? Mark for Review
(1) Points

The Program gives inaccurate results.

Required software features are missing from the program. (*)

Code becomes messy.

Solutions seem elusive.

Correct
8. A software feature may allow the user to perform a specific task.
Mark for Review
(1) Points

True (*)

False

Correct

9. What is the correct order of steps in the Spiral Model of Development?


Mark for Review
(1) Points

Design, Requirements, Develop, Test

Requirements, Design, Develop, Test (*)

Requirements, Design, Test, Develop

Design, Develop , Requirements, Test

Correct

Section 3
(Answer all questions in this section)

10. Java is a strongly typed language; therefore you must declare a data type for all
variables. Mark for Review
(1) Points

True (*)

False

Correct
11. Which two
statements Mark for Review
will not (1) Points
compile?

(Choose all correct answers)

int break=10; (*)

double double=10; (*)

int abc = 10;

double salary = 20000.34;

int age=20;

Incorrect. Refer to Section 3 Lesson 1.


12. Identify the names of two variables used in the given code.
Mark for Review
public class Variables { (1) Points
public static void main(String args[]) {
String strVal = "Hello";
int intVal = 0;
System.out.println("Integer: " +intVal)
}
}

(Choose all correct answers)

strVal (*)

intVal (*)

String

Hello

int

Correct

13. Which two statements compile?


Mark for Review
(1) Points

(Choose all correct answers)

char size = ’m’; (*)

char size = ”m”;

String size = “M”; (*)

String size = ‘M’;

Incorrect. Refer to Section 3 Lesson 3.

14. Which two statements are true about String concatenation.


Mark for Review
(1) Points

(Choose all correct answers)

Strings can be combined using the ‘+’ operator (*)

String concatenation can be done with String variables and String


Literals. (*)
String concatenation cannot be done with more than two String Literals.

String concatenation cannot be done with numbers.

Incorrect. Refer to Section 3 Lesson 3.


15. An Object cannot have String objects as properties.
Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 3 Lesson 3.


16. Which two
statements Mark for Review
are correct (1) Points
about the
usage of an
underscore?

(Choose all correct answers)

Underscores do not affect the value of the variable. (*)

Underscores change the value of the number.

Underscores help the compiler interpret large numbers.

Underscores help make large numbers more readable. (*)

Correct

17. A double with the value of 20.5 is cast to an int. What is the value of the
int? Mark for Review
(1) Points

25

21

20 (*)

20.5

Correct

18. Which exception occurs because a String cannot be parsed as an int?


Mark for Review
(1) Points

NumberFormatException (*)

ArithmeticException

NullPointerException

ValueNotFoundException

Incorrect. Refer to Section 3 Lesson 4.


19. These two code fragments perform the same task.
Mark for Review
// Fragment 1 (1) Points
String inputString = JOptionPane.showInputDialog("??");
int input = Integer.parseInt(inputString);
input++;

// Fragment 2
int input = Integer.parseInt(JOptionPane.showInputDialog("??")) + 1;

True (*)

False

Correct

20. Which two statements are true about the Scanner class?
Mark for Review
(1) Points

(Choose all correct answers)

Scanners cannot read text files.

A Scanner object doesn’t have fields and methods.

A Scanner’s delimiter can be changed. (*)

A Scanner object opens a stream for collecting input. (*)

Correct

21. You write a


statement Mark for Review
that assigns (1) Points
a value to a
String
variable as
shown
below.

String input
= ”This is
Java
Program”;

This way of
assigning
values to
variables is
known as
hard-
coding.

True (*)

False

Correct
22. Assuming x is an int, which of the following are ways to increment the value of
x by 1? Mark for Review
(1) Points

(Choose all correct answers)

x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)

Correct

23. Which two are recommended practices for naming final variables?
Mark for Review
(1) Points

(Choose all correct answers)

Capitalize every letter (*)

Separate words with an underscore (*)

Capitalize first letter

Separate words with an space

Correct

24. What is the output? public static void main(String args[]) {


int x = 100; Mark for Review
int y = x; (1) Points
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}

Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)

Correct

Section 4
(Answer all questions in this section)

25. String objects are immutable.


Mark for Review
(1) Points

True (*)

False

Correct
26. What is the output?
Mark for Review
public static void main(String args[]) { (1) Points
String alphaNumeric = "Java
World!" + 8;
System.out.println(alphaNumeric);
}

Java World! 8

Java World! + 8

Compilation error.

Java World!8 (*)

Correct

27. Which method returns the length of a String?


Mark for Review
(1) Points

length() (*)

findLength ()
charAt()

compareTo()

Correct

28. The String class must be imported using


java.lang.String; Mark for Review
(1) Points

True

False (*)

Correct

29. Object instantiation is done using what keyword?


Mark for Review
(1) Points
System

new (*)

instance

void

Correct

30. void type methods don’t return any values


Mark for Review
(1) Points

True (*)

False

Correct
31. Which of
the Mark for Review
following (1) Points
scenarios
would be
ideal for
writing a
method?

To group similar data types together

When you don’t want to repeat similar lines of code to describe an object’s
behavior. (*)
When you don’t find similar lines of code to describe an object’s behavior.

For every five to six lines of code.

Incorrect. Refer to Section 4 Lesson 1.

32. Which of the following are the arguments in the following method?
Mark for Review
Employee emp = new Employee(); (1) Points
emp.calculateSalary(100000, 3.2, 15);

emp

100000, 3.2, 15 (*)

emp.calculateSalary(100000, 3.2, 15);

calculateSalary(100000, 3.2, 15);

Incorrect. Refer to Section 4 Lesson 1.

33. A constant field, like Math.PI is used to represent a fixed value.


Mark for Review
(1) Points

True (*)
False

Correct

34. Every method of the Math class returns a numerical result.


Mark for Review
(1) Points

True (*)

False

Correct

35. Using the Random class requires an import statement.


Mark for Review
(1) Points

True (*)

False

Correct
36. Which
class is Mark for Review
used to (1) Points
generate
random
numbers?

Number

Integer

Double

Random (*)

Correct

37. You need to generate random integer values in the range 2 through 10. This
code fragment will produce the desired result. Mark for Review
(1) Points
Random r = new Random();
r.nextInt(9) + 2;

True (*)

False

Correct

38. Which of the following wild card character is used to import all the classes in a
particular package? Mark for Review
(1) Points
!

* (*)

Correct

39. Which two are valid import statements of the Scanner class?
Mark for Review
(1) Points

(Choose all correct answers)

import java.util;

import java.util.*; (*)

import java.util.Scanner; (*)

import java.*;

Incorrect. Refer to Section 4 Lesson 2.

40. Which package is implicitly imported?


Mark for Review
(1) Points

ava.awt

java.lang (*)

java.io

java.math

Correct
41. The
classes of Mark for Review
the Java (1) Points
class
library are
organized
into
packages.

True (*)

False

Correct

Section 5
(Answer all questions in this section)

42. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
String name = "Java";
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

JavaProgramming

True (*)

Java Programming

False

Correct

43. The equal sign (=) is used to make an assignment, whereas the == sign
merely makes a comparison and returns a boolean. Mark for Review
(1) Points

True (*)

False

Correct

44. What are the possible values of a boolean data type in Java?
Mark for Review
(1) Points

good/bad

yes/no

0/1

true/false (*)

Correct

45. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}
Bob is 43 Bob is 50

Bob is 43 (*)

Bob is 50

No output

Correct
46. In Java, an
if Mark for Review
statement (1) Points
can be
nested
inside
another if
statement.

True (*)

False

Correct

47. Which two are not logical operators?


Mark for Review
(1) Points

(Choose all correct answers)

+ (*)

||

% (*)

&&

Correct

48. In the AND (&&) test, if the first expression on the left hand side is false, then
there is no need to evaluate the second statement. Mark for Review
(1) Points

True (*)

False

Correct

49. A break statement causes control to transfer to the end of the switch
statement. Mark for Review
(1) Points

True (*)
False

Correct

50. What is the output?


Mark for Review
char grade = 'A'; (1) Points
switch (grade) {
case 'A':
System.out.println("Congratulations!"); case 'B':
System.out.println("Good work");
case 'C':
System.out.println("Average");
case 'D':
System.out.println("Barely passing");
case 'F':
System.out.println("Failed");
}

Congratulations! Good Work Average Barely Passing Failed (*)

Congratulations!

Failed

Correct
1. Which is
used to Mark for Review
terminate (1) Points
a loop?

continue

catch

switch

break (*)

Incorrect. Refer to Section 6 Lesson 3.

2. The purpose of adding comments is to increase the ability to understand the logic
easily. Mark for Review
(1) Points

True (*)

False

Correct

3. Which two statements are true about the break statement?


Mark for Review
(1) Points

(Choose all correct answers)


When a break statement is executed inside a loop, the loop-statement is
terminated immediately. (*)
The execution of the program will continue with the statement following the
loop-statement. (*)
The execution of the program will stop at the statement following the loop-
statement.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately and comes out of the program.

Incorrect. Refer to Section 6 Lesson 3.

4. A while loop is often used with Scanner input as you don't know many times
you'll need to re-prompt the user if they type bad data. Mark for Review
(1) Points

True (*)

False

Correct

5. Which loop type is considered to be a post-test loop?


Mark for Review
(1) Points

forEach

while

do-while (*)

for

Incorrect. Refer to Section 6 Lesson 2.


6. Which
of the Mark for Review
two (1) Points
are
pre-
test
loops?

(Choose all correct answers)

forEach

for (*)

while (*)

do-while

Incorrect. Refer to Section 6 Lesson 2.

7. A do-while will always execute statements contained in the loop at least once.
Mark for Review
(1) Points
True (*)

False

Correct

8. A pre-test loop evaluates the condition prior to execution of the loop.


Mark for Review
(1) Points

True (*)

False

Correct

9. Which statement is false about infinite loop?


Mark for Review
(1) Points

An infinite loop is generally caused by a programming mistake.

An infinite loop is a commonly the result of a syntax error. (*)

An infinite loop is a code which will execute until the user interrupts the
program
The body of a while loop eventually must make the condition false to avoid
infinite loop.

Correct

10. You want to compute the sum of all the marks of a given subject. Which approach
will you choose? Mark for Review
(1) Points

if statement

switch statement

if/else statement

Looping (*)

Incorrect. Refer to Section 6 Lesson 1


11. The
initialization Mark for Review
expression (1) Points
initializes
the loop and
it is
executed
only once,
as the loop
begins.

True (*)
False

Correct

12. What is the result?


Mark for Review
public static void main(String[] args) { (1) Points
for (;;) {
System.out.println("Welcome to Java");
}
}

Program prints “Welcome to Java” an infinite number of times. (*)

Program prints “Welcome to Java” once.

Compilation error as expressions are missing in the for loop.

No error and no output.

Correct

13. When is an update expression in a for loop executed?


Mark for Review
(1) Points

Before the first iteration through the loop.

Before each iteration through the loop.

After two iterations through the loop.

After each iteration through the loop. (*)

Incorrect. Refer to Section 6 Lesson 1.

14. Which is not a looping statement in Java?


Mark for Review
(1) Points

switch (*)

for

do-while

while

Correct

15. Each expression in the header section of a for loop is optional.


Mark for Review
(1) Points

True (*)
False
Correct

1. The for loop


provides a Mark for Review
complicated (1) Points
way to
iterate over
a range of
values.

True

False (*)

Incorrect. Refer to Section 6 Lesson 1.

2. Looping continues as long as the boolean expression in the for loop is false.
Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 6 Lesson 1.

3. Which statement will produce the output: 2, 4, 6, 8, 10?


Mark for Review
(1) Points

for (int i = 0; i < 10; i += 2) {


System.out.print(i + " ");
}
for (int i = 1; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 2; i <= 10; i += 2) {
System.out.print(i + " ");
} (*)
for (int i = 0; i < 8; i += 2) {
System.out.print(i + " ");
}

Incorrect. Refer to Section 6 Lesson 1.

4. You want to compute the sum of all the marks of a given subject. Which
approach will you choose? Mark for Review
(1) Points

if statement

if/else statement

Looping (*)

switch statement
Correct

5. Given:
Mark for Review
for(int i = 0; i > 10; i++){ } (1) Points
What type of variable is i?

Local (*)

Static

Global

Member

Correct
6. When is
an update Mark for Review
expression (1) Points
in a for
loop
executed?

Before each iteration through the loop.

After two iterations through the loop.

After each iteration through the loop. (*)

Before the first iteration through the loop.

Incorrect. Refer to Section 6 Lesson 1.

7. The only way to exit a loop is for the loop condition to evaluate to false.
Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 6 Lesson 3.

8. A continue statement is used to skip the remaining statements in the body of a


loop and continue with the next iteration of the loop. Mark for Review
(1) Points

True (*)

False

Correct

9. What is the result?


Mark for Review
public static void main(String[] args) { (1) Points
for (int var1 = 0; var1 < 2; var1++) {
for (int var2 = 0; var2 < 2; var2++) {
if (var2 == 2) {
continue;
}
System.out.println("var1:" + var1 + ", var2:" + var2);
}
}
}

var1: 0, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0

var1: 0, var2: 0
var1: 0, var2: 1
var1: 0, var2: 2
var1: 1, var2: 0
var1: 1, var2: 1
var1: 1, var2: 2
var1: 2, var2: 0
var1: 2, var2: 1
var1: 2, var2: 2

var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1

(*)
var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
var1: 2, var2: 1

Incorrect. Refer to Section 6 Lesson 3.

10. The while loop continually executes a block of statements while a particular
condition is false. Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 6 Lesson 2.


11. After the
loop is Mark for Review
terminated, (1) Points
the
statement
immediately
following
the loop
body is
executed.

True (*)
False

Correct

12. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int num = 1;
while (num >= 200){
System.out.print(num + "" "");
num = num * 5;
}
}

1 5 25 125 175

No output. (*)

1 5 25 125

5 25 125

Incorrect. Refer to Section 6 Lesson 2.

13. Which of the two are pre-test loops?


Mark for Review
(1) Points

(Choose all correct answers)

do-while

forEach

while (*)

for (*)

Correct

14. Which statement is NOT true about do-while loops?


Mark for Review
(1) Points

Statements in the loop are executed repeatedly until the condition


becomes false.
Statements in the loop are executed once initially, and then the
condition is evaluated.
Statements in the loop are executed once until the condition becomes
false.
The number of times a do-while loop is executed is dependent upon the
value of the counter variable. (*)

Correct

15. Which loop type is considered to be a post-test loop?


Mark for Review
(1) Points
forEach

for

do-while (*)

while

Correct
16. How would you complete this code so that one add method calls the other add method?

public int add(int a, int b, int c) {

return(a+b+c);

public int add(int a, int b){

//Complete this line.

} Mark for Review

(1) Points

return (a, b);

return (a, b, c);

return add(a, b, c);

return add(a, b, 0); (*)

Correct Correct
17. Which three can vary in overloaded methods? Mark for Review

(1) Points

(Choose all correct answers)

Types of parameters. (*)

The names of parameters

Number of parameters. (*)

Method return type.

Order of parameters. (*)

Incorrect Incorrect. Refer to Section 7 Lesson 4.

18. Which is stored within the stack memory? Mark for Review

(1) Points

Objects
Instance variables

Strings

Local variables (*)

Incorrect Incorrect. Refer to Section 7 Lesson 2.

19. Objects are accessed using reference variables. Mark for Review

(1) Points

True (*)

False

Correct Correct

20. Which two statements are true about objects of the same class? Mark for
Review
(1) Points

(Choose all correct answers)

All objects are equal.

Each new instance of an object will have a different location in memory. (*)

All objects of the same class have the same methods. (*)

Each object will have the same reference variable to the location in memory.

Incorrect Incorrect. Refer to Section 7 Lesson 2.

21. Which two


statements Mark for Review
are NOT true (1) Points
about
constructors?

(Choose all correct answers)

A constructor method may return a value. (*)

A constructor method is called once for each instance of an object.

The constructor method is called during instantiation.

A constructor method has a void return type. (*)

Incorrect. Refer to Section 7 Lesson 3.


22. What will happen when you try to access an object reference with a null
value? Mark for Review
(1) Points

NullPointerException. (*)

The value null is retrieved from the memory location.

An empty object is returned.

You will get a compilation error.

Incorrect. Refer to Section 7 Lesson 3.

23. When you write your own constructor, the default constructor is no
longer available. Mark for Review
(1) Points

True (*)

False

Correct

24. An object reference with a null value points to an empty location in


memory. Mark for Review
(1) Points

True (*)

False

Correct

25. How would you instantiate the Employee class from a main method
located in another class? Mark for Review
(1) Points
public class Employee{
private String name;
private double salary;

public Employee(String n, double s){


name = n;
salary = s;
}
}

Employee emp1 = new Employee();

Employee emp1 = new Employee(50000);

Employee emp1 = new Employee(50000, "Syam");

Employee emp1 = new Employee("Syam", 50000); (*)

Correct
26. You have
created an Mark for Review
Employee (1) Points
class with
all required
fields and
methods.
10
employees
join the
company.
Should you
copy and
paste the
Employee
class for all
10
employees?

True

False (*)

Incorrect. Refer to Section 7 Lesson 1.

27. Variables created within a method can be accessed outside that method.
Mark for Review
(1) Points

True

False (*)

Correct

28. How can you retrieve a value from a method?


Mark for Review
(1) Points

Define the method return type as void

Define a variable as a field member of the method

Use a return statement and define the method’s return type as non-
void (*)
Pass a variable as an argument to the method.

Correct

Section 8
(Answer all questions in this section)

29. The size of an ArrayList can grow as needed.


Mark for Review
(1) Points
True (*)

False

Correct

30. A wrapper class encapsulates, or wraps, the primitive types within an


object. Mark for Review
(1) Points

True (*)

False

Correct

31. Which is
NOT a Mark for Review
benefit (1) Points
of
ArrayList
class?

An ArrayList shrinks as you remove elements.

You can use an ArrayList list to store Java primitive values (like int). (*)

An ArrayList grows as you add elements.

You can remove all of the elements of an ArrayList with a method.

Correct

32. Which two are limitations of an array of primitives (ie: int[] x)?
Mark for Review
(1) Points

(Choose all correct answers)

You can create only one array in a class.

You need to create your own methods to manipulate array contents.


(*)
The size of the array is fixed during array creation and cannot grow
once initialized. (*)
You cannot overwrite the contents of an array once initialized.

Incorrect. Refer to Section 8 Lesson 2.

33. You can access the size of any array by using the array’s “length” property.
Mark for Review
(1) Points

True (*)
False

Correct

34. What is the output?


int[] arr = new int[5]; Mark for Review
for(int i=0; i<arr.length; i++){ (1) Points
arr[i] = i;
}
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]);
}

012345

12345

01234 (*)

123

Incorrect. Refer to Section 8 Lesson 1.

35. An array allows you to create a single identifier that can be used to organize
many items of the same data type. Mark for Review
(1) Points

True (*)

False

Correct

36. Which
loop Mark for Review
type is (1) Points
specially
designed
to
traverse
an
array?

repeat loop

for loop (*)

while loop

do while loop

Correct

37. What is the danger of catching a generic Exception type as shown below?
Mark for Review
int[] array = {10, 20, 30}; (1) Points
int b = 0;
try{
System.out.println("1");
int c = (array[3] / b);
System.out.println("2");
}
catch(Exception ex){
System.out.println(ex.toString());
}

The details of the Exception object ex are too general to be useful. (*)

An Exception will never occur.

An ArithmeticException cannot be caught.

An ArrayIndexOutOfBoundsException cannot be caught.

Correct

38. If the try block succeeds then no exception has occurred.


Mark for Review
(1) Points

True (*)

False

Correct

39. Runtime errors can be caught by Java’s exception handling mechanism.


Mark for Review
(1) Points

True (*)

False

Correct

40. Using the NetBeans debugger, you can set breakpoints and trace through a
program one line at a time. Mark for Review
(1) Points

True (*)

False

Correct

41. What are


two Mark for Review
advantages (1) Points
of adding
print
statements
for
debugging?
(Choose all correct answers)

You can identify which methods have been called. (*)

You can identify the order in which methods have been called. (*)

You can identify compilation errors.

You can identify runtime errors.

Correct

42. Which is not a compilation error?


Mark for Review
(1) Points

int x=2

y = 3 + * 5;

x = ( 3 + 5;
int y;
y++; (*)

Incorrect. Refer to Section 8 Lesson 4.

Section 9
(Answer all questions in this section)

43. Audio can be played by referencing the Audio object directly.


Mark for Review
(1) Points

True (*)

False

Correct

44. JavaFX doesn’t provide you with UI elements, shapes and text. So you
must always create your own graphics. Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 9 Lesson 3.

45. When you write code for MouseEvents, you are telling a Node to listen for
a particular event. Mark for Review
(1) Points
True (*)

False

Correct
46. Which
is not Mark for Review
a (1) Points
JavaFX
Node?

Button

ScrollBar

ImageView

Object (*)

Correct

47. How would you set the title of the Stage primaryStage?
Mark for Review
(1) Points

primaryStage.setTitle("New Title!"); (*)

primaryStage("New Title!");

primaryStage.title = "New Title!";

primaryStage = "New Title!;

Correct

48. The start() method is the entry point for all JavaFX applications.
Mark for Review
(1) Points

True (*)

False

Correct

49. Which is the correct syntax to instantiate a JavaFX Rectangle?


Mark for Review
(1) Points

Rectangle rect = new Rectangle(20, 20);

Rectangle rect = new Rectangle(20, 20, 100);

Rectangle rect = Rectangle(20, 20, 100, 200);


Rectangle rect = new Rectangle(20, 20, 100, 200); (*)
Incorrect. Refer to Section 9 Lesson 2.

50. How would you create a custom color that is pure cyan (equal parts green and
blue)? Mark for Review
(1) Points

Color customColor = Color.rgb(0, 0, 255);

Color customColor = Color.rgb(255, 255, 0);

Color customColor = Color.rgb(0, 255, 255); (*)

Color customColor = Color.rgb(0, 255, 0);

Correct

You might also like