Professional Documents
Culture Documents
Congratulations!
Failed
Incorrect.
Refer to
Section 5
Lesson 3.
boolean
float
String (*)
int (*)
Incorrect.
Refer to
Section 5
Lesson 3.
Compilation error
Vowels
Consonants (*)
Vowels
Correct
True
False (*)
Incorrect.
Refer to
Section 5
Lesson 3.
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
False
JavaProgramming
Java Programming
True (*)
Loops
Errors
Operators (*)
Variables (*)
Correct
~=
==
== (*)
<=
>=
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 (*)
True (*)
False
Correct
Compilation error
I scored 1 point
True (*)
False
Correct
When the input does not match any of the cases, the default
statement is executed. (*)
Consonants (*)
Vowels
Vowels
Compilation error
Correct
Bob is 50
Bob is 43 (*)
Bob is 43 Bob is 50
No output
10. Which operator is used to test if both sides of a boolean expression are
equal?
<=
== (*)
>=
True (*)
False
Correct
Bob is 50
Bob is 43 Bob is 50
No output
Bob is 43 (*)
True (*)
JavaProgramming
False
Java Programming
Errors
Loops
Operators (*)
Variables (*)
good/bad
true/false (*)
yes/no
0/1
if statement (*)
for loop
do while loop
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?
If both the first condition and second condition are true (*)
||
&&
% (*)
+ (*)
Correct
6. Which three are
conditional Mark for Review
statements? (1) Points
if statement (*)
for loop
do while loop
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?
If both the first condition and second condition are true (*)
||
&&
% (*)
+ (*)
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.
True (*)
False
Correct
True (*)
False
Correct
They can be used to check the current state of the program (*)
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
True (*)
False
Correct
11. System.in
readies Mark for Review
Scanner (1) Points
to collect
input
from the
console.
True (*)
False
Correct
Callables
Integer
Tokens (*)
Future
int age=20;
int a = “10”;
int a = 10
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
nt intVar1 = (int)"100";
True (*)
False
Correct
+ (*)
– (*)
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 (*)
True
False (*)
Section 4
(Answer all questions in this section)
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();
28. Which of the following two operations are appropriate for the main method?
Mark for Review
(1) Points
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); (*)
3 (*)
True
False (*)
32. Which is a risk of using fully qualified class names when importing?
Mark for Review
(1) Points
java.awt
java.awt.font (*)
java
awt.font
True (*)
False
Correct
0
2.718
3.141 (*)
True (*)
False
Correct
38. The String class must be imported using java.lang.String;
Mark for Review
(1) Points
True
False (*)
39. The String concat() method concatenates only String data types.
Mark for Review
(1) Points
True (*)
False
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 (*)
43. A break statement causes control to transfer to the end of the switch
statement. Mark for Review
(1) Points
True (*)
False
Correct
False
JavaProgramming
Java Programming
True (*)
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?
~=
==
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
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");
}
True (*)
False
Correct
1. Which of the
following are Mark for Review
considered (1) Points
Whitespace?
2. When the program runs normally (when not in debug mode), which statement
is true about breakpoints? Mark for Review
(1) Points
True (*)
False
Correct
name
empId
salary
displaySalary() (*)
Correct
True (*)
False
Correct
6. Which of
the Mark for Review
following (1) Points
language is
called a
procedural
language?
Java C
C++
Java
C (*)
Correct
8. A software feature may allow the user to perform a specific task.
Mark for Review
(1) Points
True (*)
False
Correct
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?
int age=20;
strVal (*)
intVal (*)
String
Hello
int
Correct
True
False (*)
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
NumberFormatException (*)
ArithmeticException
NullPointerException
ValueNotFoundException
// 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
Correct
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
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
Correct
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)
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.
Correct
length() (*)
findLength ()
charAt()
compareTo()
Correct
True
False (*)
Correct
new (*)
instance
void
Correct
True (*)
False
Correct
31. Which of
the Mark for Review
following (1) Points
scenarios
would be
ideal for
writing a
method?
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.
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
True (*)
False
Correct
True (*)
False
Correct
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
import java.util;
import java.*;
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)
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
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
+ (*)
||
% (*)
&&
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
Congratulations!
Failed
Correct
1. Which is
used to Mark for Review
terminate (1) Points
a loop?
continue
catch
switch
break (*)
2. The purpose of adding comments is to increase the ability to understand the logic
easily. Mark for Review
(1) Points
True (*)
False
Correct
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
forEach
while
do-while (*)
for
forEach
for (*)
while (*)
do-while
7. A do-while will always execute statements contained in the loop at least once.
Mark for Review
(1) Points
True (*)
False
Correct
True (*)
False
Correct
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 (*)
True (*)
False
Correct
Correct
switch (*)
for
do-while
while
Correct
True (*)
False
Correct
True
False (*)
2. Looping continues as long as the boolean expression in the for loop is false.
Mark for Review
(1) Points
True
False (*)
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?
7. The only way to exit a loop is for the loop condition to evaluate to false.
Mark for Review
(1) Points
True
False (*)
True (*)
False
Correct
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
10. The while loop continually executes a block of statements while a particular
condition is false. Mark for Review
(1) Points
True
False (*)
True (*)
False
Correct
1 5 25 125 175
No output. (*)
1 5 25 125
5 25 125
do-while
forEach
while (*)
for (*)
Correct
Correct
for
do-while (*)
while
Correct
16. How would you complete this code so that one add method calls the other add method?
return(a+b+c);
(1) Points
Correct Correct
17. Which three can vary in overloaded methods? Mark for Review
(1) Points
18. Which is stored within the stack memory? Mark for Review
(1) Points
Objects
Instance variables
Strings
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
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.
NullPointerException. (*)
23. When you write your own constructor, the default constructor is no
longer available. Mark for Review
(1) Points
True (*)
False
Correct
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;
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 (*)
27. Variables created within a method can be accessed outside that method.
Mark for Review
(1) Points
True
False (*)
Correct
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)
False
Correct
True (*)
False
Correct
31. Which is
NOT a Mark for Review
benefit (1) Points
of
ArrayList
class?
You can use an ArrayList list to store Java primitive values (like int). (*)
Correct
32. Which two are limitations of an array of primitives (ie: int[] x)?
Mark for Review
(1) Points
33. You can access the size of any array by using the array’s “length” property.
Mark for Review
(1) Points
True (*)
False
Correct
012345
12345
01234 (*)
123
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
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. (*)
Correct
True (*)
False
Correct
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
You can identify the order in which methods have been called. (*)
Correct
int x=2
y = 3 + * 5;
x = ( 3 + 5;
int y;
y++; (*)
Section 9
(Answer all questions in this section)
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 (*)
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("New Title!");
Correct
48. The start() method is the entry point for all JavaFX applications.
Mark for Review
(1) Points
True (*)
False
Correct
50. How would you create a custom color that is pure cyan (equal parts green and
blue)? Mark for Review
(1) Points
Correct