Visit Official SkillCertPro Website :-
For a full set of 1800+ questions. Go to
https://skillcertpro.com/product/ocp-java-se-11-developer-1z0-819-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.
Question 1:
Given code:
package com.skillcertpro.ocp;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) {
var path = Paths.get(“F:“, “user“, “..“, “Jason..“);
System.out.println(path.normalize());
}
}
What is the result?
A. F:\
B. F:\user
C. F:\user\Jason
D. F:\Jason..
Answer: D
Explanation:
Variable ‘path‘ infers to Path type and refers to {F:\user\..\Jason..}
According to Javadoc of normalize method:
1. It removes all the redundant name elements.
2. “.“ represents current directory in Windows/Linux environment, hence it is considered redundant.
3. “..“ represents parent directory in Windows/Linux environment. If a “..“ is preceded by a non-“..“ name, then both names are considered redundant.
To normalize, “user“ and “..“ are redundant, hence these are removed and path.normalize() returns {F:\Jason..}
NOTE: double dot with ‘Jason‘ is not removed as these are not path symbol.
Question 2:
How can you force JVM to run Garbage Collector?
A. JVM cannot be forced to run Garbage Collector
B. By calling: System.gc();
C. By setting the reference variable to null
D. By calling: Runtime.getRuntime().gc();
Answer: A
Explanation:
Both Runtime.getRuntime().gc(); and System.gc(); do the same thing, these make a request to JVM to run Garbage Collector.
JVM makes the best effort to run Garbage Collector but nothing is guaranteed.
Setting the reference variable to null will make the object, eligible for Garbage Collection, if there are no other references to this object. But this doesn‘t force JVM to run the Garbage Collector. Garbage Collection cannot be forced.
Question 3:
package com.skillcertpro.ocp;
public class Test {
public static void main(String [] args) {
int a = 1000;
System.out.println(-a++);
}
}
What is the result?
A. -1000
B. -999
C. -1001
D. Compilation error
E. 999
Answer: A
Explanation:
First add parenthesis (round brackets) to the given expression: -a++.
There are 2 operators involved. unary minus and Postfix operator. Let‘s start with expression and value of a.
-a++; [a = 1000].
-(a++); [a = 1000] Postfix operator has got higher precedence than unary operator.
-(1000); [a = 1001] Use the value of a (1000) in the expression and after that increase the value of a to 1001.
-1000; [a = 1001] -1000 is printed on to the console.
Question 4:
Given code of Test.java file:
package com.skillcertpro.ocp;
class Printer {}
public class Test {
public static void main(String[] args) {
Printer printer = new Printer();
System.out.println(printer);
}
}
What will be the result of compiling and executing Test class?
A. Some text containing @ symbol
B. Compilation error for Test class
C. Compilation error for Printer class
Answer: C
Explanation:
For bounds, extends keyword is used for both class and interface.
Correct declaration of Printer class should be:
class Printer {}
Question 5:
Given code:
package com.skillcertpro.ocp;
import java.util.stream.IntStream;
public class Test {
public static void main(String[] args) {
IntStream.iterate(1, i -> i + 1)
.limit(11)
.filter(i -> i % 2 != 0)
.forEach(System.out::print);
}
}
What is the result?
A. 24681012
B. 246810
C. 1357911
D. 13579
Answer: C
Explanation:
IntStream.iterate(1, i -> i + 1) => [1,2,3,4,5,6,7,…]. This is an infinite stream.
limit(11) => [1,2,3,4,5,…,11]. Eleven elements from the above stream.
filter(i -> i % 2 != 0) => [1,3,5,7,9,11]. Returns a stream consisting of all odd numbers.
forEach(System.out::print); => Prints 1357911 on to the console.
For a full set of 1800+ questions. Go to
https://skillcertpro.com/product/ocp-java-se-11-developer-1z0-819-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.
Question 6:
Consider below code of Test.java file:
package com.skillcertpro.ocp;
public class Test {
public static void main(String [] args) {
var val = 9;
System.out.println(val += 10 – -val– – –val);
}
}
What will be the result of compiling and executing Test class?
A. 22
B. Compilation error
C. 21
D. 26
E. 24
F. 25
Answer: C
Explanation:
Given expression:
val += 10 – -val– – –val
val = val + 10 – -val– – –val
val = val + 10 – -(val–) – –val //Postfix operator has higher precedence than other available operators
val = val + 10 – (-(val–)) – (–val) //Unary minus and prefix operator has same preference
val = (val + 10) – (-(val–)) – (–val) // + and – have same preference and both are left associative, hence grouping + first.
val = ((val + 10) – (-(val–))) – (–val) //Grouping – next
Expression on right side of assignment operator has 2 parts: Left: ((val + 10) – (-(val–))) and Right: (–val). Expression on Left side needs to be evaluated first.
val = ((9 + 10) – (-(val–))) – (–val) //val=9
val = (19 – (-(val–))) – (–val) //val=9
val = (19 – (-9)) – (–val) //val=8
val = 28 – (–val) //val=8
val = 28 – 7 //val=7
val = 21 21 is assigned to val and 21 is printed on to the console as well.
Question 7:
Consider below code:
package com.skillcertpro.ocp;
import java.text.NumberFormat;
public class Test {
public static void main(String[] args) {
System.out.println(NumberFormat.____________________.format(5));
}
}
The default locale of the system is ‘en_US‘.
Which of the options correctly fills the blank, such that output is $5.00?
Choose 2 options.
A. getInstance(java.util.Locale.US)
B. getCurrencyInstance()
C. getInstance()
D. getCurrencyInstance(java.util.Locale.US)
Answer: B, D
Explanation:
As expected output is: $5.00, which means formatter must be for the currency and not the number.
′NumberFormat.getInstance()′ and ′NumberFormat.getInstance(Locale)′ return the formatter for the number and hence will display 5 on to the console.
′NumberFormat.getCurrencyInstance()′ returns the currency formatter for default Locale which is en_US, hence format(5) will display $5.00 on to the console.
NumberFormat.getCurrencyInstance(java.util.Locale.US) returns the currency formatter for the specified Locale, which is again en_US, hence format(5) will display $5.00 on to the console.
Question 8:
Given code of Test.java file:
package com.skillcertpro.ocp;
public class Test {
static String str = “KEEP IT “; //Line n1
public static void main(String[] args) {
String str = str + “SIMPLE“; //Line n2
System.out.println(str);
}
}
What will be the result of compiling and executing Test class?
A. Compilation error
B. KEEP IT SIMPLE
C. SIMPLE
D. KEEP IT
Answer: A
Explanation:
At Line n2, local variable ‘str‘ shadows the static variable ‘str‘ created at Line n1. Hence, for the expression ′str + “SIMPLE“′, Java compiler complains as local variable ‘str‘ is not initialized.
Question 9:
Given code:
package com.skillcertpro.ocp;
import java.util.stream.IntStream;
public class Test {
public static void main(String[] args) {
int res = 1;
IntStream stream = IntStream.rangeClosed(1, 4);
System.out.println(stream.reduce(res++, (i, j) -> i * j));
}
}
What is the result?
A. 24
B. Compilation error as res should be effectively final
C. 6
D. 12
E. 48
Answer: A
Explanation:
IntStream.rangeClosed(1, 4); => [1, 2, 3, 4]
To understand, ′stream.reduce(res++, (i, j) -> i * j)′ can be somewhat written as:
int result = res++;
for (int element : stream) {
result = accumulator.applyAsInt(result, element);
}
return result;
Above code is just for understanding purpose, you can‘t iterate a stream using given loop.
result will be initialized to 1 and after that res will be incremented to 2. But value of ‘result‘ is used and not ‘res‘.
Hence output will be result of ‘1 * 1 * 2 * 3 * 4‘, which is 24.
Question 10:
Which of the 4 interfaces must be implemented by a JDBC driver?
A. java.sql.Date
B. java.sql.Statement
C. java.sql.Connection
D. java.sql.DriverManager
E. java.sql.ResultSet
F. java.sql.Driver
Answer: B, C, E, F
Explanation:
DriverManager and Date are classes and hence not correct options.
A JDBC drive must provide implementation for Driver, Statement, PreparedStatement, CallableStatement, ResultSet and Connection interfaces.
For a full set of 1800+ questions. Go to
https://skillcertpro.com/product/ocp-java-se-11-developer-1z0-819-exam-questions/
SkillCertPro offers detailed explanations to each question which helps to understand the concepts better.
It is recommended to score above 85% in SkillCertPro exams before attempting a real exam.
SkillCertPro updates exam questions every 2 weeks.
You will get life time access and life time free updates
SkillCertPro assures 100% pass guarantee in first attempt.