wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Simulacro Java 21 - 9

Total questions: 55

Worksheet time: 1hrs 23mins

Name
Class
Date
1.

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.

a)

java --module-path mywidgets.jar --module mywids.Widget

b)

java --module-path mywidgets.jar --module mod.wids/mywids.Widget

c)

java --module-path mywidgets.jar --module mod.wids --main-class mywids.Widget

d)

java --module-path mywidgets.jar --module mod.wids mywids.Widget

2.

Select 2 options.

a)

interface Value extends Cacheable{ }

non-sealed abstract class Result implements Cacheable{ }

b)

non-sealed interface Value extends Cacheable{ }

non-sealed abstract class Result implements Cacheable{ }

c)

abstract non-sealed interface Value extends Cacheable{ }

sealed abstract class Result implements Cacheable permits IntResult{ }

final class IntResult extends Result{ }

d)

non-sealed interface Value extends Cacheable{ }

non-sealed abstract class Result { }

e)

non-sealed interface Value extends Cacheable{ }

abstract class Result { }

final class IntResult extends Result implements Cacheable{ }

3.

Please select 3 options.

a)

public int sum(int a, int b) { return a + b; }

b)

public int sum(long i1, long i2) { return (int) i1; }

c)

public int sum(int i1, long i2) { return (int) i2; }

d)

public long sum(long i1, int i2) { return i1 + i2; }

e)

public long sum(int i1, int i2) { return i1 + i2; }

4.

Please select 1 option.

a)

0123456700

b)

0123401234

c)

01234567

d)

0123456734

e)

0000000000

5.

Hint: It is possible to update the database table while iterating through the result set of a query. Please select 2 options.

a)

Two PreparedStatement objects are created.

b)

Three PreparedStatement objects are created.

c)

Two SQL statements are executed.

d)

Three SQL statements are executed.

e)

An SQLException will be thrown because the ResultSet is not closed.

6.

Please select 1 option.

a)

file:///c:/temp/test.txt

b)

file:///c:/../temp/test.txt

c)

file:///c:/test.txt

d)

An exception will be thrown.

7.

Select 1 option.

a)

!str.isBlank()

b)

!str.isEmpty()

c)

str.strip() != ""

d)

!str.equalsIgnoreBlanks("")

e)

str.compareTo("") != 0

8.

Please select 3 options.

a)

T1 gets a Student object and T2 gets IndexOutOfBoundsException.

b)

T1 and T2 get two different instances of Student objects

c)

T1 gets a Student object and T2 gets null.

d)

T1 gets a Student object and T2 gets a ConcurrentModificationException.

e)

Both the threads get a reference to the same Student object.

9.

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.

a)

jdeps -module-path lib\a.jar; -classpath lib\b.jar

b)

jdeps --module-path lib\a.jar; lib\b.jar

c)

jdeps --class-path lib\a.jar; lib\b.jar

d)

jdeps -cp lib\b.jar lib\a.jar

e)

jdeps -cp lib\b.jar;lib\a.jar

10.

Which of the following are valid ways to create a LocalDateTime? Please select 1 option.

a)

java.time.LocalDate.parse("2015-01-02");

b)

java.time.LocalDateTime.parse("2015-01-02");

c)

java.time.LocalDateTime.of(2015, 10, 1, 10, 10);

d)

java.time.LocalDateTime.of(2015, "January", 1, 10, 10);

11.

Please select 1 option.

a)

Change //1 toStream<Book> bkStrm = books.stream();//1

b)

Change //2 to :long count = bkStrm.peek(x->x.getTitle()).count();

c)

Change //2 to :int count = bkStrm.peek(x->((Book)x).getTitle()).count();

d)

Change //2 to :int count = bkStrm.peek((Book x)->x.getTitle()).count();

e)

Change //2 to :long count = bkStrm.peek(x->((Book)x).getTitle()).count();

12.

Please select 2 options.

a)

dt.format(java.time.format.DateTimeFormatter.DATE_TIME);

b)

dt.format(java.time.format.DateTimeFormatter.ISO_DATE_TIME);

c)

dt.format(java.time.format.DateTimeFormatter.LOCAL_DATE_TIME);

d)

dt.toString();

13.

Please select 1 option.

a)

P-1D

PT9H10M

b)

P1D

PT9H10M

c)

P-1D

P9H10M

d)

P1D

P9H10M

14.

Please select 3 options.

a)

Runnable r = ()->System.out.println("Hello");

b)

Runnable r = { System.out.println("Hello");}

c)

Runnable r = () -> System.out::println();

d)

Runnable r = ()-> { someMethod(); };

e)

Runnable r = ()-> someMethod();

15.

Please select 1 option.

a)

java.io.FileNotFoundException: test.txt

b)

java.nio.file.FileNotFoundException: test.txt

c)

java.nio.file.NoSuchFileException: test.txt

d)

java.nio.file.InvalidPathException : test.txt

16.

Please select 1 option.

a)

0 0 will be printed twice.

b)

1 1 will be printed once.

c)

0 1 will be printed followed by 1 2.

d)

0 0 will be printed followed by 1 1.

e)

It will print 0 0 and then 0 1.

17.

Please select 1 option.

a)

int

b)

long

c)

only double

d)

double or float

e)

float

18.

Please select 3 options. (Ignore //6 y //7)

a)

//1

b)

//2

c)

//3

d)

//4

e)

//5

19.

Please select 1 option.

a)

6 4 10 10

b)

7 4 11 10

c)

7 3 8 9

d)

6 3 1 1

20.

Please select 2 options.

a)

private void foo(){ };

b)

private abstract void foo();

c)

static void foo();

d)

protected void foo();

e)

@Override void moo();

21.

Which of the following statements will compile without any error?. Please select 4 options.

a)

System.out.println("a"+'b'+63);

b)

System.out.println("a"+63);

c)

System.out.println('b'+new Integer(63));

d)

String s = 'b'+63+"a";

e)

String s = 63 + new Integer(10);

22.

Please select 1 option.

a)

8 Accelerate : Car

b)

9 Accelerate : Car

c)

8 Accelerate : SportsCar

d)

9 Accelerate : SportsCar

e)

None of the above.

23.

Which of the following methods can be called on a String object? Please select 4 options.

a)

substring(int i)

b)

substring(int i, int j)

c)

substring(int i, int j, int k)

d)

equals(Object o)

e)

formatted(Object... o)

24.

Please select 1 option.

a)

working

off

b)

working

c)

No output will be produced

d)

compilation failure

e)

Exception will be thrown at run time.

25.

Please select 2 options. (ignore //1 and //2)

a)

//3

b)

//4

c)

//5

d)

//6

e)

//7

26.

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.

a)

public class ReconciliationException extends Throwable{}

b)

public class ReconciliationError extends Error{}

c)

public class ReconciliationException extends Exception{}

d)

public class ReconciliationException {}

27.

Which of the following code snippets appearing in a method are valid. Please select 1 option.

a)

for(var x : System.getProperties().entrySet()){  

var m = x.getKey();

}

b)

for(var x : System.getProperties().keySet()){  

System.out.println(x.length());

}

c)

var obj = null;

d)

var k = System.out::println;

e)

var _ = new ArrayList<>();

28.

Please select 1 option.

a)

Compilation failture at //1

b)

Compilation failture at //2

c)

It will print:Exception - Code=404, Msg=NOT FOUND, OrigMsg=FILE UNREADABLE

d)

It will print:Exception - Code=404, Msg=, OrigMsg=FILE UNREADABLE

e)

It will print:Exception - Code=404, Msg=, OrigMsg=

29.

Please select 1 option.

a)

bfr.close();

b)

bfw.close();

c)

bfr.flush();

d)

bfw.flush();

e)

None of the above.

30.

Please select 1 option.

a)

4

b)

2

c)

It will not compile

d)

It will throw an exception at runtime.

e)

None of the above

31.

Please select 1 option.

a)

At Line 1.

b)

At Line 2.

c)

At Line 3.

d)

At Line 4.

e)

None of the above.

32.

Please select 1 option.

a)

It will print whatever password is entered by the user.

b)

It will print a garbled version of whatever password is entered by the user.

c)

It will throw an exception at run time.

d)

It will not compile because it does not incorporate exception handling for the readPassword method.

e)

It will not compile because it does not incorporate exception handling for System.console() method.

33.

Please select 1 option.

a)

S1:50

S2:45

S3:40

b)

S1:40

S2:35

S3:30

c)

It will not print anything.

d)

It will not compile.

34.

Please select 2 options.

a)

Consumer x = ()->{ System.out::println; }

b)

Consumer x = System.out::println;

c)

var x = System.out::println;

d)

Consumer x = (m)->{ };

e)

Consumer x = (String msg)->{ System.out.println(msg); };

35.

Please select 1 option.

a)

Optional<Book> bk = bkStrm.findFirst(b->b.getAuthor().equals("Stephen King"));

b)

Book bk = bkStrm.findFirst(b->b.getAuthor().equals("Stephen King"));

c)

Optional<Book> bk = bkStrm.filter(b->b.getAuthor().equals("Stephen King")).findFirst();

d)

Book bk = bkStrm.filter(b->b.getAuthor().equals("Stephen King")).findFirst();

e)

Optional<Book> bk = bkStrm.firstMatch(b->b.getAuthor().equals("Stephen King"));

36.

Please select 1 option.

a)

int

b)

float

c)

long

d)

double

e)

char

37.

Please select 1 option.

a)

1 1 FINANCE 222

b)

1 1 HR 111

c)

0 null null null

d)

Exception at run time.

e)

true 1 FINANCE 222

38.

Please select 1 option.

a)

It will not compile.

b)

It will throw an exception at run time.

c)

The program will compile without error, and print a, c and d in that order when run.

d)

The program will compile without error, and print a, b and d in that order when run.

e)

The program will compile without error, and print b, c and a in that order when run.

39.

Which of the following correctly identify the differences between a Callable and a Runnable? Please select 3 options.

a)

A Callable cannot be passed as an argument while creating a Thread but a Runnable can be.

b)

A Callable needs to implement call() method while a Runnable needs to implement run() method.

c)

A Callable can return a value but a Runnable cannot.

d)

A Callable can be used with ExecutorService but a Runnable cannot be.

40.

Please select 1 option.

a)

hidden

b)

readonly

c)

archive

d)

Copying of the attributes is platform and system dependent.

e)

It will print unable to copy file and test2.txt will not be created.

41.

Please select 1 option.

a)

lock.lock();

and

lock.unlock();

b)

lock.readLock();

and

lock.readUnlock()

c)

lock.read();

and

lock.unlock();

d)

lock.readLock().lock();

and

lock.readLock().unlock();

42.

Please select 1 option.

a)

It will not compile.

b)

It will throw ArrayIndexOutOfBoundsError at Runtime.

c)

false, true

d)

true, false

e)

It will print false, false.

43.

Please select 1 option.

a)

It will print A.

b)

It will print B.

c)

It will not compile.

d)

It will compile but will not run.

e)

None of the above

44.

Please select 2 options.

a)

No throws clause is necessary.

b)

throws ClassNotFoundException, NoSuchFieldException

c)

throws ClassNotFoundException

d)

throws NoSuchFieldException

e)

throws Exception

45.

Please select 1 option.

a)
b)
c)
d)
46.

Please select 1 option.

a)

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.

b)

The characters printed by forEachOrdered will always be in the same order as the one printed by the peek method.

c)

If forEachOrdered is replaced with forEach, the order of the characters printed by forEach will be the same as the one printed by peek.

d)

Both - peek and forEachOrder - may print the characters in any order.

47.

Which of the following statements are correct regarding the module system of Java. Please select 3 options.

a)

Although not recommended, it is possible to customize what packages a module exports from the command line.

b)

An advantage of java modules functionality is that users of a module cannot alter the list of exported packages of that module.

c)

If a module does not export a package, there is no way to export that package to all other modules from the command line.

d)

If a module wants to read another module but only temporarily, it can request such access using command line options.

e)

Modules allows a sealed class and its direct subtypes to be members of different packages.

48.

Which of the following are valid implementations of java.lang.Comparable? Please select 1 option.

a)
b)
c)
d)
49.

Please select 2 options.

a)

super.processEvents(events.values());

b)

super.processEvents(events);

c)

events.forEach( (k, v)->processEvents(v));

d)

processEvents(events.values());

e)

processEvents(new List(events.values));

50.

Please select 2 options.

a)

Declarations (1) and (3) cannot occur in the same class definition.

b)

Declarations (2) and (4) cannot occur in the same class definition.

c)

Declarations (1) and (4) cannot occur in the same class definition.

d)

Declarations (2) and (3) cannot occur in the same class definition.

e)

Declarations (1) and (2) cannot occur in the same class definition.

51.

Please select 1 option.

a)

In float 3

b)

In float 3.0

c)

In double 3.0

d)

In double 3

e)

In intfloat 3.0

52.

Please select 1 option.

a)

7

b)

8

c)

9

d)

10

e)

11

53.

Please select 1 option.

a)

It will print 1 and 2

b)

It will print 1 to N where N depends on the value passed as an argument to the parameter d.

c)

It will not compile.

d)

It will throw an exception at runtime.

54.

java.util.Locale allows you to do which of the following? Please select 2 options.

a)

Provide country specific formatting for fonts.

b)

Provide country and language specific formatting for HTML pages.

c)

Provide country and language specific formatting for Dates.

d)

Provide country specific formatting for Currencies.

e)

Provide country and language specific formatting for properties files.

55.

Which of the following commands can be used to identify class and module dependencies? Please select 1 option.

a)

jar -describe

b)

java --describe

c)

jmod describe

d)

jmod --describe

e)

jmod --show-module-resolution