Font size
WorksheetsSimulacro Java 21 - 9
Total questions: 55
Worksheet time: 1hrs 23mins
Given that a class named mywids.Widget is part of a module named mod.wids packaged in mywidgets.jar, which of the following commands can be used to execute this class? (Assume that the jar file is located in the current directory and the jar file does not have any entry in its manifest.). Select 1 option.
java --module-path mywidgets.jar --module mywids.Widget
java --module-path mywidgets.jar --module mod.wids/mywids.Widget
java --module-path mywidgets.jar --module mod.wids --main-class mywids.Widget
java --module-path mywidgets.jar --module mod.wids mywids.Widget
Select 2 options.
interface Value extends Cacheable{ }
non-sealed abstract class Result implements Cacheable{ }
non-sealed interface Value extends Cacheable{ }
non-sealed abstract class Result implements Cacheable{ }
abstract non-sealed interface Value extends Cacheable{ }
sealed abstract class Result implements Cacheable permits IntResult{ }
final class IntResult extends Result{ }
non-sealed interface Value extends Cacheable{ }
non-sealed abstract class Result { }
non-sealed interface Value extends Cacheable{ }
abstract class Result { }
final class IntResult extends Result implements Cacheable{ }
Please select 3 options.
public int sum(int a, int b) { return a + b; }
public int sum(long i1, long i2) { return (int) i1; }
public int sum(int i1, long i2) { return (int) i2; }
public long sum(long i1, int i2) { return i1 + i2; }
public long sum(int i1, int i2) { return i1 + i2; }
Please select 1 option.
0123456700
0123401234
01234567
0123456734
0000000000
Hint: It is possible to update the database table while iterating through the result set of a query. Please select 2 options.
Two PreparedStatement objects are created.
Three PreparedStatement objects are created.
Two SQL statements are executed.
Three SQL statements are executed.
An SQLException will be thrown because the ResultSet is not closed.
Please select 1 option.
file:///c:/temp/test.txt
file:///c:/../temp/test.txt
file:///c:/test.txt
An exception will be thrown.
Select 1 option.
!str.isBlank()
!str.isEmpty()
str.strip() != ""
!str.equalsIgnoreBlanks("")
str.compareTo("") != 0
Please select 3 options.
T1 gets a Student object and T2 gets IndexOutOfBoundsException.
T1 and T2 get two different instances of Student objects
T1 gets a Student object and T2 gets null.
T1 gets a Student object and T2 gets a ConcurrentModificationException.
Both the threads get a reference to the same Student object.
Your application uses one modular jar (a.jar), which, in turn, uses one non-modular jar (b.jar). Which of the following commands will cause jdeps to include the non-modular jar in its analysis?. Please select 1 option.
jdeps -module-path lib\a.jar; -classpath lib\b.jar
jdeps --module-path lib\a.jar; lib\b.jar
jdeps --class-path lib\a.jar; lib\b.jar
jdeps -cp lib\b.jar lib\a.jar
jdeps -cp lib\b.jar;lib\a.jar
Which of the following are valid ways to create a LocalDateTime? Please select 1 option.
java.time.LocalDate.parse("2015-01-02");
java.time.LocalDateTime.parse("2015-01-02");
java.time.LocalDateTime.of(2015, 10, 1, 10, 10);
java.time.LocalDateTime.of(2015, "January", 1, 10, 10);
Please select 1 option.
Change //1 toStream<Book> bkStrm = books.stream();//1
Change //2 to :long count = bkStrm.peek(x->x.getTitle()).count();
Change //2 to :int count = bkStrm.peek(x->((Book)x).getTitle()).count();
Change //2 to :int count = bkStrm.peek((Book x)->x.getTitle()).count();
Change //2 to :long count = bkStrm.peek(x->((Book)x).getTitle()).count();
Please select 2 options.
dt.format(java.time.format.DateTimeFormatter.DATE_TIME);
dt.format(java.time.format.DateTimeFormatter.ISO_DATE_TIME);
dt.format(java.time.format.DateTimeFormatter.LOCAL_DATE_TIME);
dt.toString();
Please select 1 option.
P-1D
PT9H10M
P1D
PT9H10M
P-1D
P9H10M
P1D
P9H10M
Please select 3 options.
Runnable r = ()->System.out.println("Hello");
Runnable r = { System.out.println("Hello");}
Runnable r = () -> System.out::println();
Runnable r = ()-> { someMethod(); };
Runnable r = ()-> someMethod();
Please select 1 option.
java.io.FileNotFoundException: test.txt
java.nio.file.FileNotFoundException: test.txt
java.nio.file.NoSuchFileException: test.txt
java.nio.file.InvalidPathException : test.txt
Please select 1 option.
0 0 will be printed twice.
1 1 will be printed once.
0 1 will be printed followed by 1 2.
0 0 will be printed followed by 1 1.
It will print 0 0 and then 0 1.
Please select 1 option.
int
long
only double
double or float
float
Please select 3 options. (Ignore //6 y //7)
//1
//2
//3
//4
//5
Please select 1 option.
6 4 10 10
7 4 11 10
7 3 8 9
6 3 1 1
Please select 2 options.
private void foo(){ };
private abstract void foo();
static void foo();
protected void foo();
@Override void moo();
Which of the following statements will compile without any error?. Please select 4 options.
System.out.println("a"+'b'+63);
System.out.println("a"+63);
System.out.println('b'+new Integer(63));
String s = 'b'+63+"a";
String s = 63 + new Integer(10);
Please select 1 option.
8 Accelerate : Car
9 Accelerate : Car
8 Accelerate : SportsCar
9 Accelerate : SportsCar
None of the above.
Which of the following methods can be called on a String object? Please select 4 options.
substring(int i)
substring(int i, int j)
substring(int i, int j, int k)
equals(Object o)
formatted(Object... o)
Please select 1 option.
working
off
working
No output will be produced
compilation failure
Exception will be thrown at run time.
Please select 2 options. (ignore //1 and //2)
//3
//4
//5
//6
//7
Your application includes a method that generates a report using Employee data. While generating the report, if this method detects inconsistent payment records, it cannot generate the report. You want to create a new exception class that should be thrown in this situation. Which of the following is a valid implementation for this exception?. Please select 1 option.
public class ReconciliationException extends Throwable{}
public class ReconciliationError extends Error{}
public class ReconciliationException extends Exception{}
public class ReconciliationException {}
Which of the following code snippets appearing in a method are valid. Please select 1 option.
for(var x : System.getProperties().entrySet()){
var m = x.getKey();
}
for(var x : System.getProperties().keySet()){
System.out.println(x.length());
}
var obj = null;
var k = System.out::println;
var _ = new ArrayList<>();
Please select 1 option.
Compilation failture at //1
Compilation failture at //2
It will print:Exception - Code=404, Msg=NOT FOUND, OrigMsg=FILE UNREADABLE
It will print:Exception - Code=404, Msg=, OrigMsg=FILE UNREADABLE
It will print:Exception - Code=404, Msg=, OrigMsg=
Please select 1 option.
bfr.close();
bfw.close();
bfr.flush();
bfw.flush();
None of the above.
Please select 1 option.
4
2
It will not compile
It will throw an exception at runtime.
None of the above
Please select 1 option.
At Line 1.
At Line 2.
At Line 3.
At Line 4.
None of the above.
Please select 1 option.
It will print whatever password is entered by the user.
It will print a garbled version of whatever password is entered by the user.
It will throw an exception at run time.
It will not compile because it does not incorporate exception handling for the readPassword method.
It will not compile because it does not incorporate exception handling for System.console() method.
Please select 1 option.
S1:50
S2:45
S3:40
S1:40
S2:35
S3:30
It will not print anything.
It will not compile.
Please select 2 options.
Consumer x = ()->{ System.out::println; }
Consumer x = System.out::println;
var x = System.out::println;
Consumer x = (m)->{ };
Consumer x = (String msg)->{ System.out.println(msg); };
Please select 1 option.
Optional<Book> bk = bkStrm.findFirst(b->b.getAuthor().equals("Stephen King"));
Book bk = bkStrm.findFirst(b->b.getAuthor().equals("Stephen King"));
Optional<Book> bk = bkStrm.filter(b->b.getAuthor().equals("Stephen King")).findFirst();
Book bk = bkStrm.filter(b->b.getAuthor().equals("Stephen King")).findFirst();
Optional<Book> bk = bkStrm.firstMatch(b->b.getAuthor().equals("Stephen King"));
Please select 1 option.
int
float
long
double
char
Please select 1 option.
1 1 FINANCE 222
1 1 HR 111
0 null null null
Exception at run time.
true 1 FINANCE 222
Please select 1 option.
It will not compile.
It will throw an exception at run time.
The program will compile without error, and print a, c and d in that order when run.
The program will compile without error, and print a, b and d in that order when run.
The program will compile without error, and print b, c and a in that order when run.
Which of the following correctly identify the differences between a Callable and a Runnable? Please select 3 options.
A Callable cannot be passed as an argument while creating a Thread but a Runnable can be.
A Callable needs to implement call() method while a Runnable needs to implement run() method.
A Callable can return a value but a Runnable cannot.
A Callable can be used with ExecutorService but a Runnable cannot be.
Please select 1 option.
hidden
readonly
archive
Copying of the attributes is platform and system dependent.
It will print unable to copy file and test2.txt will not be created.
Please select 1 option.
lock.lock();
and
lock.unlock();
lock.readLock();
and
lock.readUnlock()
lock.read();
and
lock.unlock();
lock.readLock().lock();
and
lock.readLock().unlock();
Please select 1 option.
It will not compile.
It will throw ArrayIndexOutOfBoundsError at Runtime.
false, true
true, false
It will print false, false.
Please select 1 option.
It will print A.
It will print B.
It will not compile.
It will compile but will not run.
None of the above
Please select 2 options.
No throws clause is necessary.
throws ClassNotFoundException, NoSuchFieldException
throws ClassNotFoundException
throws NoSuchFieldException
throws Exception
Please select 1 option.
Please select 1 option.
The characters printed by peek may be in any order but the characters printed by forEachOrdered will always be in the same order as the original list i.e. bcaed.
The characters printed by forEachOrdered will always be in the same order as the one printed by the peek method.
If forEachOrdered is replaced with forEach, the order of the characters printed by forEach will be the same as the one printed by peek.
Both - peek and forEachOrder - may print the characters in any order.
Which of the following statements are correct regarding the module system of Java. Please select 3 options.
Although not recommended, it is possible to customize what packages a module exports from the command line.
An advantage of java modules functionality is that users of a module cannot alter the list of exported packages of that module.
If a module does not export a package, there is no way to export that package to all other modules from the command line.
If a module wants to read another module but only temporarily, it can request such access using command line options.
Modules allows a sealed class and its direct subtypes to be members of different packages.
Which of the following are valid implementations of java.lang.Comparable? Please select 1 option.
Please select 2 options.
super.processEvents(events.values());
super.processEvents(events);
events.forEach( (k, v)->processEvents(v));
processEvents(events.values());
processEvents(new List(events.values));
Please select 2 options.
Declarations (1) and (3) cannot occur in the same class definition.
Declarations (2) and (4) cannot occur in the same class definition.
Declarations (1) and (4) cannot occur in the same class definition.
Declarations (2) and (3) cannot occur in the same class definition.
Declarations (1) and (2) cannot occur in the same class definition.
Please select 1 option.
In float 3
In float 3.0
In double 3.0
In double 3
In intfloat 3.0
Please select 1 option.
7
8
9
10
11
Please select 1 option.
It will print 1 and 2
It will print 1 to N where N depends on the value passed as an argument to the parameter d.
It will not compile.
It will throw an exception at runtime.
java.util.Locale allows you to do which of the following? Please select 2 options.
Provide country specific formatting for fonts.
Provide country and language specific formatting for HTML pages.
Provide country and language specific formatting for Dates.
Provide country specific formatting for Currencies.
Provide country and language specific formatting for properties files.
Which of the following commands can be used to identify class and module dependencies? Please select 1 option.
jar -describe
java --describe
jmod describe
jmod --describe
jmod --show-module-resolution
