Oracle Fondation 2
Oracle Fondation 2
False
Correct
False
Correct
NetBeans automatically runs the program once all the braces in the
code are matched.
Once NetBeans spots a problem, it won’t allow you to continue coding
until the progrblem is fixed.
NetBeans highlights matching braces. (*)
7. There are several fields and methods in a Shirt class. Which of the following
could be a method in the Shirt class? Mark for Review
(1) Points
price
color
size
getShirtSize() (*)
Correct
True (*)
False
Correct
salary
displaySalary() (*)
empId
Correct
C++
C (*)
Java C
Rose plant is the class and the samples generated from the rose
plant are instances of that class. (*)
Rose plant is the object and samples are not instances of the plant
because they have not grown yet.
Samples of the rose plant are called classes and not the actual rose
plant.
Correct
12. A software feature may allow the user to perform a specific task.
Mark for Review
(1) Points
True (*)
False
Correct
Correct
Correct
15. You’d like to see a movie with a few friends. You write an email to
confirm plans. Mark for Review
(1) Points
Hi Friends,
There’s a new movie “Attack of the Duke!” premiering this Friday at
Oracle Cinema at 4:30 PM. The cinema is at the corner of South Street
and Walnut Ave. Subway would be the best way to get there.
Correct
1. During the
Design phase of Mark for Review
software (1) Points
development,
the programmer
implements
features
gathered during
the Requirement
phase.
True
False (*)
Correct
2. During the Testing phase of software development, which of the
following are the tasks undertaken by the programmer? Mark for Review
(1) Points
(Choose all correct answers)
Fixing the bugs. (*)
Correct
3. The Spiral Model reflects an iterative development process.
Mark for Review
(1) Points
True (*)
False
Correct
4. You’d like to see a movie with a few friends. You write an email to
confirm plans. Mark for Review
(1) Points
Hi Friends,
There’s a new movie “Attack of the Duke!” premiering this Friday at
Oracle Cinema at 4:30 PM. The cinema is at the corner of South
Street and Walnut Ave. Subway would be the best way to get there.
False
Correct
6. Which of the
following Mark for Review
three (1) Points
statements
are true about
breakpoint?
(Choose all correct answers)
They abruptly ends the code execution.
They can be used to check the current state of the program (*)
Correct
7. Java mostly reads code line-by-line.
Mark for Review
(1) Points
True (*)
False
Correct
8. What is the purpose of adding comments in the code?
Mark for Review
(1) Points
Provide good look and feel of the code.
Correct
9. You can set any number of breakpoints for your program.
Mark for Review
(1) Points
True (*)
False
Correct
10. Which of the following 2 statements are true about whitespace?
Mark for Review
(1) Points
(Choose all correct answers)
Whitespace reduces the performance of the program.
Correct
11. In object
oriented Mark for Review
programming, (1) Points
there is an
emphasis on
which of the
following two:
(Choose all correct answers)
Modeling objects. (*)
Writing algorithms.
Creation of procedures.
Correct
12. You have a beautiful garden at home. On Sunday, you start
budding your rose plant to make few more samples of rose Mark for Review
plants to plant in the garden. Can you categorize how this (1) Points
scenario could be represented by classes and instances?
Rose plant is the class and the samples generated from the
rose plant are instances of that class. (*)
Rose plant is the object and samples are not instances of
the plant because they have not grown yet.
Samples of the rose plant are called classes and not the
actual rose plant.
Samples are the class and the rose plant is the instances of
samples.
Correct
13. 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;
name
empId
salary
Correct
14. In object oriented programming, an object comprises of
properties and behaviors where properties represented as fields Mark for Review
of the object and behavior is represented as method. (1) Points
True (*)
False
Correct
15. An object may interact with another object by invoking methods.
Mark for Review
(1) Points
True (*)
False
Correct
1. Which two are
recommended Mark for Review
practices for (1) Points
naming final
variables?
(Choose all correct answers)
Capitalize every letter (*)
Correct
2. What is the range of the byte data type?
Mark for Review
(1) Points
–27 to 27–1 (*)
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct
3. This declaration represents a long data type.
long a = 123L; Mark for Review
(1) Points
True (*)
False
Correct
4. Which of the following data types is the largest?
Mark for Review
(1) Points
byte
short
int
long (*)
8 (*)
Correct
6. Which keyword
makes a variable’s Mark for Review
value (1) Points
unchangeable?
const
final (*)
static
break
Correct
7. Which data type is most commonly used to represent numeric
data? Mark for Review
(1) Points
int (*)
float
String
short
Correct
8. 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
9. Identify the variable declared in the given code.
Mark for Review
public class Welcome { (1) Points
public static void main(String args[]) {
int a = 2;
System.out.println("a is " + a);
}
}
Welcome
a (*)
int
Correct
10. Which is valid syntax to declare and initialize a String variable?
Mark for Review
(1) Points
String x= “Java”; (*)
String “x” = Java;
String x = Java;
Correct
11. Assigning a
value to the Mark for Review
variable is called (1) Points
“initialization”.
True (*)
False
Correct
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)
String
intVal (*)
int
strVal (*)
Hello
Hello
Hello
World
Hello World
False
8 (*)
Correct
2. 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
3. Which of the following data types is the largest?
Mark for Review
(1) Points
byte
short
int
long (*)
Correct
4. Which two are mathematical operators?
Mark for Review
(1) Points
(Choose all correct answers)
+ (*)
– (*)
Correct
5. This declaration represents a long data type.
long a = 123L; Mark for Review
(1) Points
True (*)
False
Correct
6. Which keyword
makes a variable’s Mark for Review
value (1) Points
unchangeable?
const
final (*)
static
break
Correct
7. Which data type is most commonly used to represent numeric
data? Mark for Review
(1) Points
int (*)
float
String
short
Correct
8. 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
9. Which is valid syntax to declare and initialize a String variable?
Mark for Review
(1) Points
String “x” = Java;
String x = Java;
int age=20;
intVal (*)
int
strVal (*)
String
Correct
13. Assigning a value to the variable is called “initialization”.
Mark for Review
(1) Points
True (*)
False
Correct
14. Which two are valid?
Mark for Review
(1) Points
(Choose all correct answers)
double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)
Correct
15. Which of the following two statements are true about variables?
Mark for Review
(1) Points
(Choose all correct answers)
They make code more flexible. (*)
Correct
1. char is the
primitive Mark for Review
textual (1) Points
data type
in Java.
True (*)
False
Correct
2. Which two statements compile?
Mark for Review
(1) Points
(Choose all correct answers)
String name = “J”; (*)
False
Correct
4. What is the output?
Mark for Review
public static void main(String args[]) { (1) Points
String greet1 = "Hello";
String greet2 = "World";
String message2 = greet1 +" " +greet2 +" " +2016 +"!";
System.out.println(message2);
}
Hello World
False
Correct
6. Which two
statements are Mark for Review
true about (1) Points
String
concatenation.
(Choose all correct answers)
String concatenation cannot be done with more than two String
Literals.
String concatenation can be done with String variables and
String Literals. (*)
Strings can be combined using the ‘+’ operator (*)
False
Correct
8. Which two statements are true about the Scanner class?
Mark for Review
(1) Points
(Choose all correct answers)
A Scanner object doesn’t have fields and methods.
A Scanner’s delimiter can be changed. (*)
Tokens (*)
Callables
Integer
False
20 (*)
25
20.5
double (*)
boolean
long (*)
byte
Correct
1. When the
result of an Mark for Review
expression (1) Points
is assigned
to a
temporary
memory
location,
what is the
size of
memory
allocated?
The size of the smallest data type used in the expression.
The size of the largest data type used in the expression. (*)
20 (*)
21
25
Correct
3. Which exception occurs because a String cannot be parsed as an int?
Mark for Review
(1) Points
NumberFormatException (*)
ArithmeticException
NullPointerException
ValueNotFoundException
int (*)
boolean
byte
long (*)
Correct
5. Which is a valid way to parse a String as an int?
Mark for Review
(1) Points
int intVar1 = Integer.parseInt("100"); (*)
nt intVar1 = (int)"100";
Correct
6. The Java
compiler Mark for Review
automatically (1) Points
promotes
byte, short,
and chars
data type
values to int
data type.
True (*)
False
Correct
7. It's best-practice to close the Scanner stream when finished
Mark for Review
(1) Points
True (*)
False
Correct
8. The Scanner class considers space as the default delimiter while
reading the input. Mark for Review
(1) Points
True (*)
False
Correct
10. char is the primitive textual data type in Java.
Mark for Review
(1) Points
True (*)
False
Correct
11. Which two
statements are Mark for Review
true about (1) Points
String
concatenation.
(Choose all correct answers)
Strings can be combined using the ‘+’ operator (*)
String concatenation cannot be done with numbers.
False
Correct
13. Char data types cannot handle multiple characters.
Mark for Review
(1) Points
True (*)
False
Correct
14. An Object cannot have String objects as properties.
Mark for Review
(1) Points
True
False (*)
Correct
15. A character preceded by backslash is called an escape sequence.
Mark for Review
(1) Points
True (*)
False
Correct
1. Methods
allow all Mark for Review
instance of (1) Points
a class to
share
same
behaviors.
True (*)
False
Correct
2. Which of the following statements are true?
Mark for Review
(1) Points
(Choose all correct answers)
Methods can be written with any number of parameters. (*)
Parameter values can never be used within the method code block.
Parameter values can be used within the method code block. (*)
Correct
3. In Java, methods usually hold the properties of an object.
Mark for Review
(1) Points
True
False (*)
Correct
4. An argument is a value that's passed during a method call
Mark for Review
(1) Points
True (*)
False
Correct
5. Once an object is instantiated, how might its fields and methods be
accessed in Java? Mark for Review
(1) Points
Using the double-colon(::) operator
False
emp
ava.awt
java.io
java.lang (*)
Incorrect. Refer to Section 4 Lesson 2.
10. Import statements are placed above the class definition.
Mark for Review
(1) Points
True (*)
False
Correct
11. Which two
are valid Mark for Review
import (1) Points
statements
of the
Scanner
class?
(Choose all correct answers)
import java.util.*; (*)
import java.util;
import java.*;
False
Correct
13. Given the import statement:
import java.awt.font.TextLayout; Mark for Review
which is the package name? (1) Points
java
java.awt
awt.font
java.awt.font (*)
import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing.*; (*)
import javax.swing;
False
True (*)
False
Correct
System
instance
new (*)
emp
Correct
testInstance.testMethod(3.5, 10);
testInstance.testMethod(3.5);
testInstance.testMethod(10);
testInstance.testMethod(10, 3.5, 0);
testInstance.testMethod(10, 3.5); (*)
Correct
Correct
6. Which of
the Mark for Review
following (1) Points
scenarios
would be
ideal for
writing a
method?
Correct
False
Correct
False
Correct
Correct
10. Which two are valid import statements of the Scanner class?
Mark for Review
(1) Points
import java.*;
Correct
11. The JFrame
and Mark for Review
JOptionPane (1) Points
classes are in
the javax.swing
package.
Which two will
import those
classes?
(Choose all correct answers)
import javax.swing;
import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing.J*;
False
Correct
13. The classes of the Java class library are organized into packages.
Mark for Review
(1) Points
True (*)
False
Correct
ava.awt
java.math
java.lang (*)
java.io
Correct
False
Correct
1. 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")
;
}
}
Consonants (*)
Vowels
Compilation error
Vowels
Correct
Below Performer
Correct
3. What is the output?
Mark for
char grade = 'A'; Review
switch (grade) { (1) Points
case 'A':
System.out.println("Congratulations!"); cas
e '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!
Correct
boolean
float
int (*)
Correct
0/1
yes/no
true/false (*)
good/bad
Correct
6. A String
comparison Mark for Review
with == (1) Points
compares
the Strings’
locations in
memory and
not the
content of
the String.
True (*)
False
Correct
True (*)
False
Correct
Variables (*)
Operators (*)
Errors
Loops
Correct
== (*)
>=
<=
Correct
No output
Bob is 43 (*)
Bob is 50
Bob is 43 Bob is 50
Correct
1. Which of
the Mark for
following Review
language (1) Points
is called a
procedural
language?
Java
Java C
C (*)
C++
Correct
2. You design a Circle class with various fields and methods. Which of the
following could be fields in this class? Distinguish which of these are Mark for Review
between the properties and behavior. (1) Points
calculateDiameter()
radius (*)
color (*)
calculateCircumference()
calculateArea()
Correct
3. There are several fields and methods in a Shirt class. Which of the following
could be a method in the Shirt class? Mark for Review
(1) Points
getShirtSize() (*)
size
color
price
Correct
False
Correct
6. You’d like to
see a movie Mark for
with a few Review
friends. You (1) Points
write an
email to
confirm
plans.
Hi Friends,
There’s a
new movie
“Attack of the
Duke!”
premiering
this Friday at
Oracle
Cinema at
4:30 PM. The
cinema is at
the corner of
South Street
and Walnut
Ave. Subway
would be the
best way to
get there.
Would any of
you be
interested in
going?
Which of the
following are
requirements
for this plan?
Double check the location by verifying you’re on South Street and
Walnut Ave.
Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30 PM.
(*)
Travel via subway.
Correct
Start with two slashes (//). End when the line ends. (*)
Start with two slashes and a star (//*). End with a star-slash (*/).
False
Correct
True (*)
False
Correct
Section 3
(Answer all questions in this section)
int a = 10
int a = “10”;
Correct
11. Assigning a
value to the Mark for
variable is Review
called (1) Points
“initialization”.
True (*)
False
Correct
12. Java is a strongly typed language; therefore you must declare a data
type for all variables. Mark for
Review
(1) Points
True (*)
False
Correct
False (*)
Correct
String message
message
Correct
16. What
is the Mark for
range Review
of the (1) Points
byte
data
type?
–27 to 27–1 (*)
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct
18. Which data type is most commonly used to represent numeric data?
Mark for
Review
(1) Points
int (*)
float
String
short
Correct
19. You write a statement that assigns a value to a String variable as shown below.
Mark for
String input = ”This is Java Program”; Review
(1) Points
This way of assigning values to variables is known as hard-coding.
True (*)
False
Correct
Tokens (*)
Callables
Future
Correct
21. The
Scanner Mark for
class Review
considers (1) Points
space as
the
default
delimiter
while
reading
the
input.
True (*)
False
Correct
nt intVar1 = (int)"100";
Correct
Type casting retains the size of the value or the original data type.
Correct
24. 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
20 (*)
25
20.5
21
Correct
Section 4
(Answer all questions in this section)
25. The replaceFirst() method replaces only the first occurrence of matching
character pattern in a string. Mark for
Review
(1) Points
True (*)
False
Correct
26. A String is
a sequence Mark for
characters. Review
(1) Points
True (*)
False
Correct
27. The indexOf() method returns the index value of a character in the string.
Mark for
Review
(1) Points
True (*)
False
Correct
Compilation error.
Java World! + 8
Java World! 8
nextInt(81); (*)
nextInt(80);
nextInt(0-79);
An integer value.
Either a true or false. (*)
Nothing is returned.
Random r
= new
Random();
r.nextInt(9)
+ 2;
True (*)
False
Correct
False
Correct
33. Which of the following wild card character is used to import all the classes
in a particular package? Mark for
Review
(1) Points
* (*)
Correct
34. Which two are valid import statements of the Scanner class?
Mark for
Review
(1) Points
(Choose all correct answers)
import java.util.Scanner; (*)
import java.util;
import java.*;
Correct
35. Which package is implicitly imported?
Mark for
Review
(1) Points
java.math
ava.awt
java.io
java.lang (*)
Correct
36. In Java,
methods Mark for
usually Review
hold the (1) Points
properties
of an
object.
True
False (*)
37. 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. (*)
Parameter values can be used within the method code block. (*)
False
Correct
41. What is the
approximate Mark for
value of PI? Review
(1) Points
0
2.718
3.141 (*)
Section 5
(Answer all questions in this section)
42. What is the output?
Mark for
public static void main(String args[]) { Review
char grade ='E'; (1) Points
if (grade == 'A') {
System.out.println("Excellent performer");
}else if (grade == 'B') {
System.out.println("Good Performer");
}else if (grade == 'C') {
System.out.println("Average Performer");
}else {
System.out.println("Below Average Performer");
}
}
Below Average Performer (*)
Excellent performer
Below Performer
Failed
Congratulations!
Correct
I scored 1 point
Correct
41. What is the
approximate Mark for
value of PI? Review
(1) Points
0
The value varies.
2.718
3.141 (*)
Section 5
(Answer all questions in this section)
42. What is the output?
Mark for
public static void main(String args[]) { Review
char grade ='E'; (1) Points
if (grade == 'A') {
System.out.println("Excellent performer");
}else if (grade == 'B') {
System.out.println("Good Performer");
}else if (grade == 'C') {
System.out.println("Average Performer");
}else {
System.out.println("Below Average Performer");
}
}
Below Average Performer (*)
Excellent performer
Below Performer
Failed
Congratulations!
Correct
I scored 1 point
Correct
46. In a boolean
expression which Mark for
uses the && Review
operator, what (1) Points
would make this
expression
evaluate to true?
boolean x =
(firstCondition &&
secondCondition);
If both the first condition and second condition are false
If both the first condition and second condition are true (*)
True (*)
False
JavaProgramming
Java Programming
Correct
48. An if/else statement is used when you need to choose between
two alternatives. Mark for
Review
(1) Points
True (*)
False
~=
==
False
Correct
1. What is the result?
Mark for Review
public static void main(String[] (1) Points
args) {
for (;;) {
System.out.println("Welcom
e to Java");
}
}
Correct
False
Correct
False
Correct
Looping (*)
switch statement
if statement
Global
Local (*)
Static
Member
Correct
7. After the loop is terminated, the statement immediately following the loop
body is executed. Mark for Review
(1) Points
True (*)
False
Correct
True (*)
False
Correct
while (*)
for (*)
forEach
do-while
Correct
No output. (*)
5 25 125
1 5 25 125
Correct
11. A while
loop is Mark for Review
often (1) Points
used
with
Scanner
input as
you
don't
know
many
times
you'll
need to
re-
prompt
the
user if
they
type
bad
data.
True (*)
False
Correct
forEach
do-while (*)
for
13. Which two statements are true about the break statement?
Mark for Review
(1) Points
(Choose all correct answers)
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.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately. (*)
Incorrect. Refer to Section 6 Lesson 3.
14. 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
15. The purpose of adding comments is to increase the ability to understand the
logic easily. Mark for Review
(1) Points
True (*)
False
False
Correct
2. You have created an Employee class with all required fields and methods.
10 employees join the company. Should you copy and paste the Employee Mark for Review
class for all 10 employees? (1) Points
True
False (*)
4. What will happen when you try to access an object reference with a null
value? Mark for Review
(1) Points
NullPointerException. (*)
False
boolean
int
String (*)
double
False
Correct
A space
“Name”
“default”
Heap memory
PileDriver memory
All objects of the same class have the same methods. (*)
12. Which keyword is used to allocate memory for a newly created object?
Mark for Review
(1) Points
new (*)
store
address
memory
Correct
True (*)
False
Correct
null
Class
Student (*)
String