
OCP Java 11 Developer 1Z0-819 Free Practice Questions
These practice questions are designed to help you prepare for the Oracle Certified Professional: Java SE 11 Developer certification exam. Successful candidates of this certification have demonstrated their proficiency in developing Java (Standard Edition) software, which is recognized in a variety of industries worldwide. They have also exhibited a comprehensive understanding of the Java programming language, coding practices, and utilization of new features in Java SE 11. By passing the required exam, certified individuals demonstrate their fluency in Java SE and their ability to perform as a Java software developer. This includes a deep understanding of object-orientation, functional programming using lambda expressions and streams, and modularity.
These practice questions are based on the 1Z0-819 Practice Tests Study Plan provided by MyExamCloud. This study plan is a comprehensive guide to help you prepare for the certification exam. By completing these practice questions, you can become familiar with the exam format and content, and improve your chances of success.
To better understand the content of the questions, you can also refer to the explanations provided by taking the 1Z0-819 Java SE 11 Developer Free Practice Mock Exam. These explanations are brief but can help you review key concepts and prepare effectively for the exam.
Topic:Working with Java data types
QUESTION: 1
Which of the following are valid String declarations inside a method?
A:String name = null;
B:var name = "Brian";
C:String name = new String("Brian");
D:var name = 'Brian';
E:String name = Brian;
ANSWER: Choice A,Choice B,Choice C
Topic:Working with Java data types
QUESTION: 2
Which code can convert the following String into a Boolean object?
String isCorporateCustomer = "false";
A:Boolean.getBoolean(isCorporateCustomer);
B:Boolean.valueOf(isCorporateCustomer);
C:Boolean.parseBoolean(isCorporateCustomer);
D:Object.parseBoolean(isCorporateCustomer);
ANSWER: Choice B
Topic:Working with Java data types
QUESTION: 3
i. The equals method check reference equality.
ii. The "==" invokes the equals method when used to check objects equality.
iii. The equals method defined in the Object class.
Which of the above is/are true?
A:Only I
B:Only III
C:Only I and II
D:Only I and III
E:All of above
ANSWER: Choice B
Topic:Working with Java data types
QUESTION: 4
Code :
var arr1=new int[]{} ;
String[] arr2=new String[]{};
if(arr1 instanceof Object)
System.out.println("Inside");
What will happen when we try to compile the above code?
A:The code will not compile
B:ClassCastException will be thrown
C:It compiles without error and prints "Inside"
ANSWER: Choice C
Topic:Working with Java data types
QUESTION: 5
Code :
var cs = "1234567890";
var pageContent = new StringBuilder(cs);
What is the capacity of pageContent?
A:16
B:10
C:26
D:9
ANSWER: Choice C
Topic:Working with Java data types
QUESTION: 6
You are assigned to develop an algorithm to find out card type.An American Express cards start with either 34 or 37. Mastercard numbers begin with 51–55. Visa cards start with 4. And so on.
var cardNumber = "5134567891123589";
Which of the following choices print the following output?
MasterCard-xx89
5134 5678 9112 9112
A:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
StringBuilder sb = new StringBuilder(cardNumber);
String part1 = sb.substring(4);
String part2 = sb.substring(4, 8);
String part3 = sb.substring(8, 12);
String part4 = sb.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(part1.substring(0, 2));
if (part1.startsWith("34") || part1.startsWith("37"))
cardType = "AmericanExpress";
if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
if (part1.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
B:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
StringBuilder sb = new StringBuilder(cardNumber);
String part1 = sb.substring(0, 4);
String part2 = sb.substring(4, 8);
String part3 = sb.substring(8, 12);
String part4 = sb.substring(12, 16);
String cardType = "Visa";
String firstTwoDigit = part1.substring(0, 2);
if (part1.startsWith("34") || part1.startsWith("37"))
cardType = "AmericanExpress";
if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
if (part1.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
C:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
StringBuilder sb = new StringBuilder(cardNumber);
String part1 = sb.substring(0, 4);
String part2 = sb.substring(4, 8);
String part3 = sb.substring(8, 12);
String part4 = sb.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(part1.substring(0, 2));
if (cardNumber.startsWith("34") || cardNumber.startsWith("37"))
cardType = "AmericanExpress";
else if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
else if (cardNumber.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
D:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
StringBuilder sb = new StringBuilder(cardNumber);
String part1 = sb.substring(0, 4);
String part2 = sb.substring(4, 8);
String part3 = sb.substring(8, 12);
String part4 = sb.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(cardNumber.substring(0, 2));
if(cardNumber.startsWith("4"))
cardType = "Visa";
else if (cardNumber.startsWith("34") || cardNumber.startsWith("37"))
cardType = "AmericanExpress";
else if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
E:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
StringBuilder sb = new StringBuilder(cardNumber);
String part1 = sb.substring(0, 4);
String part2 = sb.substring(4, 8);
String part3 = sb.substring(8, 12);
String part4 = sb.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(cardNumber.substring(2));
if (cardNumber.startsWith("34") || cardNumber.startsWith("37"))
cardType = "AmericanExpress";
if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
if (cardNumber.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
F:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
String part1 = cardNumber.substring(0, 4);
String part2 = cardNumber.substring(4, 8);
String part3 = cardNumber.substring(8, 12);
String part4 = cardNumber.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(cardNumber.substring(0, 2));
switch (firstTwoDigit) {
case 34:
cardType = "AmericanExpress";
break;
case 37:
cardType = "AmericanExpress";
break;
}
if (firstTwoDigit >= 51 && firstTwoDigit<= 55)
cardType = "MasterCard";
else if (cardNumber.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
G:public class MyExamCloud {
public static void main(String args[]) {
var cardNumber = "5134567891123589";
String part1 = cardNumber.substring(0, 4);
String part2 = cardNumber.substring(4, 8);
String part3 = cardNumber.substring(8, 12);
String part4 = cardNumber.substring(12, 16);
String cardType = "Visa";
int firstTwoDigit = Integer.parseInt(cardNumber.substring(0, 2));
switch (firstTwoDigit) {
case 34:
cardType = "AmericanExpress";
break;
case 37:
cardType = "AmericanExpress";
break;
case 51:
cardType = "MasterCard";
break;
case 55:
cardType = "MasterCard";
break;
}
if (cardNumber.startsWith("4"))
cardType = "Visa";
StringBuilder save = new StringBuilder(cardType + "-xx" + part4.substring(2));
StringBuilder display = new StringBuilder(part1 + " " + part2 + " " + part3 + " " + part3);
System.out.println(save);
System.out.println(display);
}
}
ANSWER: Choice A,Choice C,Choice D,Choice F,Choice G
Topic:Working with Java data types
QUESTION: 7
Code:
1. public class MyExamCloud{
2.
3. public static void main(String args[]){
4. int x = 10, y = 12;
5.
6. if( x++>11 & y-- > x){
7. System.out.println("passed");
8. } else{
9. System.out.println("failed");
10. }
11. }
12. }
Which of the following can be used to replace line 6?
A:if( Boolean.logicalAnd(x++>11 , y-- > x)){
B:if( Boolean.and(x++>11 , y-- > x)){
C:if( Boolean.or(x++>11 , y-- > x)){
D:if( Boolean.combine(x++>11 , y-- > x)){
ANSWER: Choice A
Topic:Working with Java data types
QUESTION: 8
Code:
1. class MyExamCloud{
2. public static void main(String [] args){
3. String s = "Java";
4. s.append("SE 11");
5. System.out.print(s.length());
6. }
7. }
What is the result?
A:4
B:8
C:9
D:Compilation fails due to an error at line 4.
E:Compilation fails due to an error at line 5.
ANSWER: Choice D
Topic:Working with Java data types
QUESTION: 9
Code:
1. class MyExamCloud{
2. public static void main(String[] args){
3. StringBuilder s =new StringBuilder("MyExamCloud");
4. var ss = new String(s.toCharArray());
5. ss = ss.concat(".com");
6. System.out.print(ss);
7. }
8. }
What is the result?
A:MyExamCloud
B:MyExamCloud.com
C:.com
D:An Exception.
E:Compilation fails.
ANSWER: Choice E
Topic:Controlling Program Flow
QUESTION: 10
Code:
1. public class MyExamCloud{
2. public static void main(String[] args){
3. final var x = 2;
4. short in = 4;
5.
6. switch(in){
7. default : System.out.print("default");
8. case 1 : System.out.print(1);break;
9. case 2 : System.out.print(2);break;
10. case x + 1 : System.out.print(3);break;
11. }
12. }
13.}
What is the output?
A:3
B:default
C:default1
D:No output.
E:Compilation fails.
ANSWER: Choice C
Topic:Controlling Program Flow
QUESTION: 11
Code:
1. public class MyExamCloud{
2. public static void main(String[] args){
3. for(var x = 0;x < 10;System.out.print(x))
4. x++;
5. }
6. }
What is the output?
A:0123456789
B:123456789
C:12345678910
D:An Exception is thrown
E:Compilation fails.
ANSWER: Choice C
Topic:Controlling Program Flow
QUESTION: 12
Code:
1. class MyExamCloud{
2.
3. public static void main(String args[]){
4. var a=1;
5. while(a<=3){
6. if(a++ ==2)
7. continue;
8. System.out.print(a + " ");
9. }
10. }
11.}
What is the output?
A:1 2 3
B:2 4
C:1
D:1 3
E:Compilation fails
ANSWER: Choice B
Topic:Controlling Program Flow
QUESTION: 13
Code:
1. public class MyExamCloud {
2. public static void main(String[] args){
3.
4. byte x = 100;
5. var y = x;
6. switch(x){
7. case 100 : {System.out.print("1");}
8. case 110 : {System.out.print("2");}
9. case 120 : {System.out.print("3");} break;
10. case 130: {System.out.print("4");}
11. default : {System.out.print("default ");} break;
12. }
13. }
14. }
Which is the output?
A:1
B:12
C:123
D:1234
E:Compilation fails
ANSWER: Choice E
Topic:Controlling Program Flow
QUESTION: 14
Code :
var myArray =new int[] {0,1,2,3,4,5,6,7,8,9};
for (var i=0; i< myArray.length; i++)
Select the enhanced for loop for the above code.
A:for (var i : myArray; i++)
B:for (var i : myArray)
C:for (var i=0; i : myArray)
ANSWER: Choice B
Topic:Java Object-Oriented Approach
QUESTION:15
Which is correct?
A:The access modifier "private" can be used with every class.
B:The access modifier "protected" can be used with every class.
C:The only access modifier which can be used inside a method is final.
D:Default access level is more restrictive than the protected access level.
E:None of above
ANSWER: Choice D
Topic:Java Object-Oriented Approach
QUESTION: 16
Code : OverLoadTest.java
class OverLoadTest {
void aMethod(Object ob) {
System.out.println("Inside---> 1");
}
void aMethod(String ob) {
System.out.println("Inside---> 2");
}
void aMethod(Float ob) {
System.out.println("Inside---> 3");
}
void aMethod(Integer ob) {
System.out.println("Inside---> 4");
}
public static void main(String as[]) {
OverLoadTest test = new OverLoadTest();
test.aMethod(test);
test.aMethod(test.toString());
test.aMethod(0.0);
}
}
What will be the output of an attempt to compile and run the above code?
A:
Inside---> 1
Inside---> 2
Inside---> 1
B:
Inside---> 1
Inside---> 2
Inside---> 3
C:
Inside---> 1
Inside---> 1
Inside---> 1
D:Compiler complains about an ambiguous method call
ANSWER: Choice A
Topic:Java Object-Oriented Approach
QUESTION: 17
Code:
1. class Bird extends Animal{ }
2. class Animal{}
3. class MyExamCloud{
4. public static void main(String []args){
5. Animal aa = new Bird();
6. Bird bb = new Bird();
7. Animal aaa = new Animal();
8. }
9. }
Consider following three statements about the above code fragment.
I. Object type of the variable "aa" is Animal.
II. Reference type of the variable "bb" is Bird.
III. Object type of the variable "aaa" is Animal.
Which is true?
A:Only I.
B:Only II.
C:Only I and II.
D:Only II and III.
E:All.
ANSWER: Choice D
Topic:Java Object-Oriented Approach
QUESTION: 18
Which of the following method can be inserted in to an interface?
A:default void method(){ }
B:static int getSpeed() {return 10; }
C:abstract int getSpeed();
D:public void meth();
E:All of above
ANSWER: Choice E
Topic:Java Object-Oriented Approach
QUESTION: 19
Consider following three statements.
I. The variables declared inside a method are called as class variables.
II. The class variables are initialized to its default value.
III. The variable "s" in the declaration "short s = 10" should be an instance variable.
Which is/are true?
A:Only I.
B:Only II.
C:Only III.
D:Only I and II.
E:Only I and III.
ANSWER: Choice B
Topic:Java Object-Oriented Approach
QUESTION 20:
Code:
1. class Ab{
2. void meth1(){ System.out.print(" A B"); }
3. }
4. class Cd extends Ab{
5. protected void meth1()throws NullPointerException{
6. System.out.print(" C D");
7. }
8. }
9. class MyExamCloud{
10. public static void main(String [] args){
11. Ab cd = new Cd();
12. cd.meth1();
13. }
14. }
Which is true?
A:Compilation fails due to multiple errors
B:The output will be C D
C:The output will be A B
D:Compilation fails due to error on line 8 since overriding method has declared with new exception.
E:No output.
ANSWER: Choice B
Topic:Java Object-Oriented Approach
QUESTION: 21
Code:
1. class A {}
2. class B extends A {}
3. class MyExamCloud{
4. public static void main(String []args){
5. A aa = new B();
6. A bb = new B();
7. A aaa = new A();
8. }
9. }
Consider following three statements about the above code fragment.
I. Object type of the variable "aa" is B.
II. Reference type of the variable "bb" is B.
III. Object type of the variable "aaa" is A.
Which is true?
A:Only I
B:Only II
C:Only I and II
D:Only I and III
E:All
ANSWER: Choice D
Topic:Java Object-Oriented Approach
QUESTION: 22
Methods:
public String getAccountNumber(String customerID) {}
public String getAccountNumber(String customerID,Data date) {}
Which of the following OO statement describes the above methods?
A:Method overloading
B:Method overriding
C:Polymorphism
D:Abstraction
ANSWER: Choice A
Topic:Exception Handling
QUESTION: 23
Given the following set of classes:
class A extends Exception {}
class B extends A {}
class C extends B {}
What is the correct sequence of catch blocks for the following try block?
try {
// codes
}
A:Catch Exception, A, B,C
B:Catch Exception, C, B, and A
C:Catch A, B, C, and Exception
D:Catch C, B ,A and Exception
E:Any order.
ANSWER: Choice D
Topic:Exception Handling
QUESTION: 24
Given:
class MyExamCloud {
public static void main(String args[]) {
int x = 10, y = 0;
try {
int c = x / y;
} catch (IllegalArgumentException | NullPointerException e) {
System.out.print("Multi");
} catch (Exception e) {
System.out.print("Exc");
}
}
}
Which is the output?
A:No output
B:Multi
C:Exc
D:An uncaught exception will be thrown.
E:Compilation fails.
ANSWER: Choice C
Topic:Java Object-Oriented Approach
QUESTION: 25
Code:
public interface A extends B {}
public interface B {
public void print(T t);
}
public interface C extends A, B {
default void printer(T t) {}
}
Which of the interfaces can be considered as functional interface/s?
A:Only interface A.
B:Only interface B.
C:Only interfaces A and B.
D:Only interfaces B and C.
E:A, B and C, all three interface are functional interface
ANSWER: Choice E
Topic:Working with Arrays and Collections
QUESTION: 26
Code:
import java.util.ArrayList;
import java.util.List;
public class MyExamCloud {
public static void main(String args[]) {
var strings = new ArrayList<>();
strings.add("A");
strings.add("B");
strings.add("C");
strings.set(2, "C");
strings.add(0, "E");
System.out.print(strings.indexOf("C"));
}
}
What is the output?
A:1
B:2
C:3
D:An Exception is thrown.
E:Compilation fails.
ANSWER: Choice C
Topic:Working with Arrays and Collections
QUESTION: 27
Given:
import java.util.stream.Stream;
public class MyExamCloud {
public static void main(String[] args) {
var stream = Stream.of("A", "B", "C", "D");
System.out.println(stream.peek(System.out::print).findAny().orElse("NA"));
}
}
What is the output?
A:NA
B:AA.
C:ABCDANA
D:An Exception.
E:Compilation fails.
ANSWER: Choice B
Topic:Working with Arrays and Collections
QUESTION: 28
Given:
import java.util.TreeMap;
public class MyExamCloud {
public static void main(String args[]) {
var tmap = new TreeMap<>();
tmap.put(new Key(), 1);
tmap.put(new Key(), 2);
tmap.put(new Key(), 2);
System.out.println(tmap.values());
}
static class Key {}
}
What is the output?
A:[1, 2, 2]
B:[1 , 2]
C:[]
D:An Exception.
E:Compilation fails.
ANSWER: Choice D
Topic:Java Platform Module System
QUESTION: 29
You are developing an Exam Management Desktop app to conduct offline exams. You are requested to reduce the application size as much as possible.
What is the best Java SE 11 feature that reduces app sizes of desktop or mobile applications?
A:Java Packaging System
B:Optimizing performance with help of JHM framework
C:Java Module System
D:None of the above
ANSWER: Choice C
Topic:Concurrency
QUESTION: 30
Consider the following code fragment.
1. String []s = new String[2];
2. s[1] = "B";
3. var cmap = new ConcurrentHashMap();
4. cmap.put("A", new Integer(1));
5. cmap.put(s[0], new Integer(2));
6. cmap.put("C", 3);
7. cmap.putIfAbsent("D", new Integer(4));
8. System.out.print(cmap);
Which of the following is true?
A:The output will be {C=3, D=4, A=1, B=2}.
B:The output will be {D=4, null=2, A=1, C=3}.
C:This code fragment won't compile due to error on line 7.
D:This code fragment won't compile due to error on line 6.
E:An exception will be thrown at the runtime.
ANSWER: Choice E
Topic:Concurrency
QUESTION: 31
Code:
1. import java.util.concurrent.ForkJoinPool;
2. import java.util.concurrent.RecursiveTask;
3.
4. public class MyExamCloud {
5.
6. public static void main(String []args) {
7. var fPool = new ForkJoinPool();
8. var rem = new Reminder(10,3);
9. //insert here
10. System.out.println(i);
11. }
12. }
13.
14. class Reminder extends RecursiveTask {
15.
16. int num;
17. int devi;
18.
19. Reminder(int i, int j) {
20. num = i;
21. devi = j;
22. }
23.
24. public Integer compute() {
25. return (num%devi);
26. }
27. }
And two declarations to be insert independently at line 9.
I. int i = fPool.invoke(rem);
II. int i = rem.compute();
Which of the following is true?
A:With both declarations the code will compile
B:With only the declaration I, the code will have the advantage of parallelism
C:With only the declaration II, the code will have the advantage of parallelism
D:With both declarations, the code won't produce have the advantage of parallelism
E:Declaration will cause compile time error
ANSWER: Choice A,Choice D
Topic:Java I/O API
QUESTION: 32
Code:
1. import java.io.Console;
2. class MyExamCloud{
3.
4. public static void main(String args[]) {
5.
6. Console con = System.console();
7. String s = con.readPassword("Password : ");
8. if(s.equals("Sanka")) {
9. System.out.print("Welcome");
10. } else {
11. System.out.print("Sorry");
12. }
13. }
14. }
Note: assume that you have access to console object.
Which is true?
A:Compilation will succeeds and will give prompt to enter Password and if we enter "Sanka" then "Welcome" will be printed
B:Compilation will succeeds and will give prompt to enter Password and if we enter "Sanka" then "Welcome" will be printed
C:Compilation will succeeds and will give prompt to enter Password and if we enter "sanka" then "Sorry" will be printed
D:Compilation will succeeds and will give prompt to enter Password and if we don't enter anythingthen an exception will be thrown at runtime
E:Compilation fails
ANSWER: Choice E
Topic:Java I/O API
QUESTION: 33
Given
1. import java.io.IOException;
2. import java.nio.file.Files;
3. import java.nio.file.Path;
4. import java.nio.file.Paths;
5.
6. public class MyExamCloud{
7. public static void main(String args[]) throws IOException{
8. var path = Paths.get("new.txt");
9. Files.move(path, Paths.get("old.txt"));
10. }
11. }
Assume that 'new.txt' file exists.
What is the output?
A:new.txt file will be replaced with 'old.txt' file.
B:new.txt file will be renamed to 'old.txt'.
C:New file called 'old.txt' will be created.
D:An exception.
E:Compilation fails.
ANSWER: Choice B
Topic:Localization
QUESTION: 34
Code:
1. import java.text.*;
2. import java.util.*;
3.
4. class MyExamCloud {
5.
6. public static void main(String args[]){
7.
8. var df = DateFormat.getInstance(DateFormat.SHORT);
9.
10. try {
11. var date2 = df.parse("28/11/89");
12. System.out.print(df.format(date2));
13. } catch(ParseException pe) {
14. System.out.print("Parse Exception");
15. }
16. }
17. }
Whichis true?
A:The output will be systems current date and it will be in SHORT format
B:The output will be 89/11/94
C:Compilation fails due to an error on line 8
D:An uncaught exception will be thrown at runtime
E:The output will be Parse Exception
ANSWER: Choice C
Topic:Localization
QUESTION: 35
Given
import java.util. * ;
public class MyExamCloud {
public static void main(String args[]) {
var ENUS = new Locale.Builder().setLanguage("en").setRegion("US").build();
System.out.print(ENUS.getDisplayCountry(new Locale("fr")));
}
}
What is the output?
A:Code will print the word "English" in English language (English).
B:Code will print the word "english" in French language (anglais).
C:Code will print the word "anglais" in English language (English).
D:Code will print the word "french" in French language (french).
E:Code will print the word "United States" in French language (Etats-Unis).
ANSWER: Choice E
Topic:Annotations
QUESTION: 36
Identify correct usages of the following annotation:
public @interface StudyPlan {
String name() default "";
}
A:@StudyPlan ("Java")
class A{
}
B:interface I{
@StudyPlan (name="Java")
String x = "";
}
C:class A{
void m1(@StudyPlan int x){ }
}
D:@StudyPlan ("Java")
interface I{
}
E:class A{
@StudyPlan
String x = "";
}
F:class A{
@StudyPlan ("Java")
void m1(){ };
}
G:interface A{
@StudyPlan ("Java")
private void m1(){ };
}
ANSWER: Choice B,Choice C,Choice E
Topic:Working with Streams and Lambda expressions
QUESTION: 37
Which of the following is true about the java inbuilt Supplier interfaces?
A:Its' functional method name is get.
B:Its' functional method name is apply.
C:It's functional method doesn't return anything.
D:It doesn't have Bi version.
E:It has a static method called compose.
ANSWER: Choice A,Choice B
Topic:Working with Streams and Lambda expressions
QUESTION: 38
Consider following
(x,y) -> Double.compare(x, y);
Which of the following functional method can be satisfied by above given lambda?
A:public abstract int compare(double d1,double d2);
B:public abstract Double compare(double d1,double d2);
C:public abstract int compare(double d1);
D:public abstract double compare(double i);
E:None of above
ANSWER: Choice A
Topic:Working with Streams and Lambda expressions
QUESTION: 39
Given
1. import java.util.function.*;
2. public class MyExamCloud {
3.
4. public static void main(String[] args) {
5. Supplier sup = User::new;
6. System.out.println(sup.get().getName());
7. }
8. }
9.
10. class User {
11. String name = "Unknown";
12.
13. User(String s) {
14. name = s;
15. }
16.
17. public String getName() {
18. return name;
19. }
20. }
What is the output?
A:Unknown
B:No output.
C:An Exception is thrown.
D:Compilation fails due to error at line 5.
E:Compilation fails due multiple errors
ANSWER: Choice D
Topic:Working with Streams and Lambda expressions
QUESTION: 40
Code:
1. import java.util.DoubleSummaryStatistics;
2. import java.util.stream.Collectors;
3. import java.util.stream.IntStream;
4.
5. public class MyExamCloud {
6. public static void main(String [ ] args){
7. IntStream ins = IntStream.of(1,4,7);
8. DoubleSummaryStatistics stats =
9. ins.boxed().collect(Collectors.summarizingDouble(i -> (double)i ));
10. System.out.println(stats.getSum()+stats.getCount());
11. }
12. }
What is the output?
A:12
B:3
C:15
D:An Exception.
E:Compilation fails.
ANSWER: Choice C
Topic:Working with Streams and Lambda expressions
QUESTION: 41
Given:
1. import java.util.Optional;
2. import java.util.stream.Stream;
3.
4.
5. public class MyExamCloud{
6. public static void main(String[] args){
7. var strs = Stream.of("A","B","C");
8. Optional opt = strs.limit(2).skip(1).findAny();
9. opt.ifPresent(System.out::print);
10. }
11.}
What is the output?
A:A
B:B
C:No output
D:An Exception
E:Compilation fails
ANSWER: Choice B
Topic:Java Platform Module System
QUESTION: 42
The Test Generator Lab platform is upgraded with Java module to reduce application size.
You are assigned to develop course module named epractizelabs.course of Test Generator Lab.
Your epractizelabs.course module requires a epractizelabs.question module, which will be delivered by another team of your company in the form of epractizelabs.question.jar file. You have kept this jar in lib directory.
You have saved all of your module source files under src directory.
Which of the following commands can be used to compile your module?
A:javac -source-path src -classpath lib -d out --module epractizelabs.course
B:javac --module-source-path src -m lib -d out -s epractizelabs.course
C:javac --module-source-path src -classpath lib/epractizelabs.question.jar --m epractizelabs.course
D:javac -s src -p lib -d out -m epractizelabs.course
E:javac --module-source-path src -p lib/epractizelabs.question.jar -d out -m epractizelabs.course
F:javac --module-source-path src -classpath lib/epractizelabs.question.jar --m epractizelabs.course
ANSWER: Choice F
Topic:Database Applications with JDBC
QUESTION: 43
Given:
String cr = "insert into Customer ( ID, EMAIL, NAME, PHONE ) values( ?, ?, ?, ?)";
String[] emailIds = {"aa@somemail.com", "bb@someemail.com", "cc@someemail.com", "dd@someemail.com" };
You are trying to initialize the Customer table and for that you need to insert one row for each of the email value in the emailIds array. Each row has to be initialized with the same values except the ID and EMAIL columns, which are different for each row. The ID column is defined as AUTO_INCREMENT and so you need to pass only 0 for this column.
Which of the following code snippets would you use?
A:for (String email: emailIds)
try (PreparedStatement ps = c.prepareStatement(qr);) {
ps.setInt(1, 0);
ps.setString(2, email);
ps.setString(3, "Joe");
ps.setString(4, "512456789");
ps.executeUpdate();
}
B:for (String email: emailIds)
try (Statement s = c.createStatement(qr);) {
s.executeUpdate("insert into CUSTOMER ( ID, EMAIL, NAME, PHONE) values( 0, '" + email + "', 'Joe', '512456789')");
}
C:try (PreparedStatement ps = c.prepareStatement(qr);) {
for (String email: emailIds) {
ps.setInt(1, 0);
ps.setString(2, email);
ps.setString(3, "Joe");
ps.setString(4, "512456789");
ps.executeUpdate();
}
}
D:try (PreparedStatement ps = c.prepareStatement(qr);) {
ps.setInt(1, 0);
ps.setString(3, "Joe");
ps.setString(4, "512456789");
for (String email: emailIds) {
ps.setString(2, email);
ps.executeUpdate();
}
}
ANSWER: Choice D
Topic:Concurrency
QUESTION: 44
Consider the following program and select the right option(s).
public class TestClass {
static StringBuffer sb1 = new StringBuffer();
static StringBuffer sb2 = new StringBuffer();
public static void main(String[] args) {
new Thread
(
new Runnable() {
public void run() {
synchronized(sb1) {
sb1.append("X");
synchronized(sb2) {
sb2.append("Y");
}
}
System.out.println(sb1);
}
}
).start();
new Thread
(
new Runnable() {
public void run() {
synchronized(sb2) {
sb2.append("Y");
synchronized(sb1) {
sb1.append("X");
}
}
System.out.println(sb2);
}
}
).start();
}
}
A:The above code may result in a deadlock and so nothing can be said for sure about the output.
B:It will print YY followed by XX
C:It will print XX followed by XX.
D:It will print XX followed by YY
E:It will print XY followed by YX
ANSWER: Choice A
Topic:Database Applications with JDBC
QUESTION: 45
A JDBC driver implementation must provide implementation classes for which of the following interfaces?
A:java.sql.Driver
B:java.sql.Statement
C:java.sql.Connection
D:java.sql.SQLException
E:java.sql.DriverManager
F:java.sql.Date
G:java.sql.SQLPermission
ANSWER: Choice A,Choice B,Choice C
Topic:Secure Coding in Java SE Application
QUESTION: 46
Assume that appconfig.xml holds application sensitive information. When the following code throws an exception, AppException will be directly shown to the end user.
var confFile = new File("/var/opt/myappserver/default/conf/appconfig.xml");
try (var fin = new FileInputStream(confFile)) {
// ... more code here
} catch (java.io.FileNotFoundException fe) {
throw new AppException(confFile + " Not found");
}
What is wrong in the code with respect to security?
A:The code does not have any security flaws.
B:The code does not have finalize block.
C:The code does not close fin.
D:The confFile in exception log must be avoided.
ANSWER: Choice D
Topic:Java Platform Module System
QUESTION: 47
Select all valid Java Module command parameters.
A:--module
B:-cp or –class-path
C:--module-source-path
D:--module-version
E:--patch-module
F:--module-class-path
ANSWER: Choice A,Choice C,Choice D,Choice E
Topic:Annotations
QUESTION: 48
Which of the following are uses of Java annotations?
A:It has information for the compiler
B:Software tools can process annotation information to generate code,
C:It improves performance.
D:It improves security.
E:Compile time error can be detected with the help of annotations.
ANSWER: Choice A,Choice B,Choice E
Topic:Database Applications with JDBC
QUESTION: 49
Assume that con is an valud Connection (java.sql.Connection) object.
Which of the following terminates this open connection?
A:con.close();
B:con.abort(Runnable::run);
C:con.abort();
D:con.close(Runnable::run);
E:None of the above.
ANSWER: Choice B
Topic:Working with Streams and Lambda expressions
QUESTION: 50
Given
1. import java.util.HashMap;
2. import java.util.Map;
3. import java.util.function.BiFunction;
4.
5. public class MyExamCloud{
6. public static void main(String[] args){
7.
8. Map<Integer,String> numbers = new HashMap<Integer,String>();
9.
10. numbers.put(1, "one");
11. numbers.put(3, "Three");
12. numbers.put(4, "Four");
13.
14. BiFunction<Integer,String,String> func = (k,v) -> "Two";
15.
16. numbers.compute(2, func);
17.
18. System.out.println(numbers);
19. }
20. }
What is the output?
A:{1=one, 3=Three, 4=Four}
B:{1=one, 2=Two, 3=Three, 4=Four}
C:An exception is thrown.
D:Compilation fails due to error at line 14.
E:Compilation fails due to error at line 16.
ANSWER: Choice B
Author | JEE Ganesh | |
Published | 10 months ago | |
Category: | Java Certification | |
HashTags | #Java #JavaCertification |