O
R
A
C
L
100

Package, import, class

100

public void item () 

{____item=9.99;}

Pick two that fills the blank. 

var                  byte             double

float                short



double and var

Answer byte and short do not store values with decimal points.  It requires casting to float or writing 9.99f to be assigned to a float. 9.99 is automatically a double. Answer var is also correct as local variable type inference can automatically determine the type is double.


100

Which double declaration does not compile? 

A. double num1, int num2=0;
B. int num1, num2 = 0;
C. int num1, num2;
D. int num1 =0, num2 =0;
E. All
F. None

A. double num1, int num2 =0;

Java does not allow different types in one declaration.

100

What is the output?
var items = Arrays.asList("one","two","three");
items.replaceAll(x -> {var newValue = "four"; return newValue;});
System.out.println(items);

A. [four,four,four]                B. [four]                C.[one,two,three]

D. None of these                 E. Code doesn't compile


A. [four,four,four]

the code defines a local variable inside the lambda, replacing each value.

100

A. Four          B. Zero          C.Two     
D.Five            E. One           F.Three

F. Three

All parameters in a lambda must use either type or var consistently. The three lines compile.

200

What is the value of item after it is executed?

A. Two         B.One          C.Three
D. None            E. Does not compile

C. Three

Parentheses are recommended the embedded ternary operations. The first ternary evaluates to 10 >=10. The second ternary evaluates to 3<=2, which is false, so Three is selected

200

What is the output?

A.1 2 3                   B. Code does not compile

C.1                         D. Outputs something else

A. 1 2 3

StringBuilder is mutable, each call to append adds the value.

200

What is the output?

A.2                  B.1           C. Does not compile 
D. 4                 E. 3

D. 4

The substring method of StringBuilder trurns a String with the value 321 without changing the StringBuilder itself. The last line retrieves the second index element 4.

200

How many lines compile?

A. Two               B. Four            C.Zero
D. Three            E. Five             F.One

A. Two

Bool  and Bool should be boolean and Boolean respectively. Integer and String are objects so those lines compile; int is a primitive so assigning null to it does not compile.

200

What is the output? 

A. [10,9]               B.[9,10]            

C.[]                      D.[9]

C.[]

The code creates and removes elements, printing an empty list[]

300

Which lines can you independently  uncomment having the code compile?

A.#2 and #3      B. None of these         C.#3

D. #2                E. All


B.None of these

local variable type interference requires a value to infer the type. The statement without a value is not allowed.

300

What is the output?

A. Doesn't Compile     B.false false false     

C. true false true        D. false true true

E.true true true          F. false false true

F.false false true


300

Which is a true statement?


If str.startsWith("abc") is true then str.contains("abc") is also true

and

If str.contains("abc") is true then str.equals("abc")


300

What is the output?

A. 123                       B. 12

C. Doesn't compile     D.321

C.Doesn't compile since there is no reverse method on the String class

300

What is the output?

A.true 2        B.false 1       C.Does not compile

D. true 1       E.false 2

B.false 1 

String is immutable, one and two are different objects.

400

Which is equivalent to var item = 1.0f; ?

A. Float item = 1.0f;
B. double item = 1.0f;
C.Double item =1.0f;
D.Object item = 1.0f;
E.float item=1.0f;

E. float item = 1.0f; 

The f on 1.0f means the type is a float, since local variable type inference chooses as exact match rather than autoboxing.

400

What is the output?

A. 3-             B.None of these           C.5-

D.2-3-           E. 4-                          F.2-

B.None of these

The switch statement is missing the case keyword for each value and the two case values cannot be combined.

400

Which of the snippets create infinite loop? Pick two.


for (;;){}

do{}while(true);

while(!false){}

Both while and do/while loops require a boolean expression. For each statement needs an assignment type and an object to iterate on.

400

Which statements are correct? Pick three.

A.do/while loop cannot be exited early with a return statement
B.while loop requires a conditional expression
C.while loop executes the body(if any) at least once.
D. do/while loop requires a body
E.while loop cannot be exiled early with a return statement
F.do/while loop executes the body (if any) at least once

B, D, F

do/while requires a body and a conditional expression. do/while loops execute its body at least once.

400

What is the output?

A. None of these           B. doesn't compile

C. throws an exception    D.Cat      D.Dog

B. doesn't compile - due to non-boolean value.

500

Which declarations are correct? Pick three.

A. class 5Ocean {}
B. class Pond2$ {}
C. class river {}
D. class _var_ {}
E. class Str3@m {}
F. class _ {}

B, C, and D

Class names begin with letters,$,or underscore(_).  Class names can also include (but not start with) digits. 

Spaces and special characters can not be part of class names.

500

What is the purpose of the "new" keyword?
A. Create a copy of the object
B. Assign a new object reference to a variable
C. Instantiate a new object
D. Create a new primitive
E.None of these

C. Instantiate a new object

The "new" keyword calls a constructor of the class

500

Which statements are correct? Pick three.

A. Static interface methods can lack access modifiers
B. Static interface method can be protected
C. Static interface method can be package-private
D. Static interface method can be private
E. Static interface method can be final
F.Static interface method can be public

A, D, F

Interface methods cannot be final, interface static methods cannot be protected. Static interfaces can lack access modifiers - makes the method implicitly public

500

Which statements are correct? Pick two?

A. Inheritance of two interfaces is allowed
B. Inheritance of two abstract classes is allowed
C.Multiple inheritance is not allowed
D. Interface can implement another interface 
E.Interface can extend another inheritance

A and E

500

How to execute a garbage collection in the code?

A. No way
B. GarbageCollection.clean()
C. System.forceGc()
D. System.requireGc()
E. System.gc()

A. No way

We can notify JVM about a garbage collection in the code, but an execution of the cycle is not guaranteed

M
e
n
u