Font size
WorksheetsSimulacro Java 21 - 5
Total questions: 55
Worksheet time: 2hrs 50mins
Which of the following is/are valid record definition(s)?. Please select 3 options.
Which of these expressions will obtain the substring "456" from a string defined by
String str = """
0123\
4567"""?
Please select 1 option
str.substring(4, 7)
str.substring(4)
str.substring(5, 7)
str.substring(5, 8)
str.substring(4, 3)
Java's exception mechanism helps in which of the following ways? Please select 2 options.
It allows creation of new exceptions that are custom to a particular application domain.
It improves code because error handling code is clearly separated from the main program logic.
It enhances the security of the application by reporting errors in the logs.
It improves the code because the exception is handled right at the place where it occured.
It provides a vast set of standard exceptions that covers all possible exceptions.
Please select 2 options.
printUsefulData(al, (Data d)-> { return d.value>2; } );
printUsefulData(al, d-> d.value>2 );
printUsefulData(al, (d)-> return d.value>2; );
printUsefulData(al, Data d-> d.value>2 );
printUsefulData(al, d -> d.value>2; );
Please select 1 option.
Replace the line at //1 with:
filterData(al, x -> x.value==0);
Add implements java.util.function.Predicate to MyFilter definition and replace the line at //1 with:
filterData(al, x -> x.value==0);
Add implements java.util.function.Predicate<Data> to MyFilter definition and replace the line at //1 with:
filterData(al, x -> x.value==0);
Remove MyFilter class altogether.Change type of f from MyFilter to java.util.function.Predicate in filterData method and replace the line at //1 with:
filterData(al, x -> x.value==0);
Remove MyFilter class altogether.
Change type of f from MyFilter to java.util.function.Predicate<Data> in filterData method and replace the line at //1 with:
filterData(al, x -> x.value==0);
Please select 1 option.
Compiler error at line 3.
Runtime error at line 3.
It will print:
Automobile: drive
Truck: drive
Automobile: drive
in that order.
It will print:
Automobile: drive
Truck: drive
Truck: drive
in that order.
It will print:
Automobile: drive
Automobile: drive
Automobile: drive
in that order.
Please select 1 option.
Device should extend AutoCloseable and override close() method.
Device should implement Closeable and override close() method.
Device should implement Closeable and override autoClose() method.
Device should implement AutoCloseable and override autoClose() method.
Device should implement AutoCloseable and override close() method.
Please select 1 option.
mon
thu
fri
It will not compile.
It will throw an exception at run time.
Please select 1 option.
charlie andy
andy charlie
charlie charlie
andy andy
It will throw an exception at run time.
The program will fail to compile.
Class cast exception at runtime.
It will print 30, 20
It will print 30, 30.
It will print 20, 20.
Please select 1 option.
34
38
29
25
Please select 1 option.
try{
Files.move(Paths.get(s), Paths.get(d), StandardCopyOption.CREATE_NEW);
Files.delete(Paths.get(s));
try{
Files.move(Paths.get(s), Paths.get(d), StandardCopyOption.REPLACE_EXISTING);
try(FileChannel in = new FileInputStream(s).getChannel();
FileChannel out = new FileOutputStream(d).getChannel()){
in.transferTo(0, in.size(), out);
}catch(Exception e){
}
try{
Files.move(Paths.get(s), Paths.get(d));
Please select 1 option.
appmessages_es_ES.properties is not present in PATH.
appmessages_es_ES.properties is not present in CLASSPATH.
appmessages_es_ES.properties is not specified using -D option on command line.
appmessages_es_ES.properties is not present in JAVA_HOME.
Given that your code is being run in a locale where the language code is fr and country code is CA, which of the following file names represents a valid resource bundle file name?. Please select 1 option.
MyResource_fr_CA.xml
MyResource_fr_CA.properties
MyResource_fr_CA.java
MyResource_fr_CA.profile
Please select 2 options.
If run with no arguments, the program will only print 'The end'.
If run with one argument, the program will only print 'The end'.
If run with one argument, the program will print 'Exception in Main' and 'The end'.
If run with one argument, the program will only print 'Exception in Main'.
If run with no arguments, the program will not print anything.
Please select 1 option.
wordStream.collect(Collectors.groupingBy(Collectors.counting()));
wordStream.collect(Collectors.groupingBy(String::equals, Collectors.counting()));
wordStream.collect(Collectors.groupingBy(String::toUpperCase, Collectors.counting()));
wordStream.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
Please select 1 option.
Exception
false
Exception
true
Exception
<stack trace for a NullPointerException>
Infinity
true
Infinity
Exception
<stack trace for a NullPointerException>
Please select 1 option.
P-1D
PT-14H-50M
P1D
PT9H10M
P-1D
P-9H-10M
P1D
PT14H50M
It will throw an exception at run time.
Given that a method named Double getPrice(String id) exists and may potentially return null, about which of the following options can you be certain that a runtime exception will not be thrown?. Please select 2 options.
Optional<Double> price = Optional.of(getPrice("1111"));
Optional<Double> price = Optional.ofNullable(getPrice("1111"));
Double x = price.orElse(getPrice("2222"));
Optional<Double> price = Optional.ofNullable(getPrice("1111"));
Double y = price.orElseGet(()->getPrice("333"));
Optional<Double> price = Optional.of(getPrice("1111"), 10.0);
Optional<Double> price = Optional.of(getPrice("1111"));
Double z = price.orElseThrow(()->new RuntimeException("Bad Code"));
Which of the following code fragments correctly executes the blog(String data) method of a blogging service that implements api.Blogger interface assuming that you already have a reference to the loader for this service? Assume that data refers to the data that needs to be blogged. Please select 2 options.
for (Blogger b : loader){
b.blog("Hello from textbook");
}
Please select 1 option.
1 ,2 ,3 4.
1 ,4, 2 ,3
3, 1, 2, 4
2, 1, 4, 3
2, 3, 1, 4
Which of the following statements will print /test.txt when executed on a Unix/Linux system? Please select 1 option.
System.out.println(Path.get("/test.txt"));
System.out.println(new Path("/test.txt"));
System.out.println(Paths.get("/", "test.txt"));
System.out.println(Path.toPath("/test.txt"));
System.out.println(Paths.toPath("/test.txt"));
Please select 1 option.
10000
Honda,Toyota
10000.0
Honda,Toyota
10000.0
Ford,Honda,Chevy,Toyota
ClassCastException at run time.
Compilation failure.
Please select 1 option.
for(int i=INT1; i<INT2; System.out.println(++i));
for(int i=INT1; i++<INT2; System.out.println(i));
int i=INT1; while(i++<INT2) { System.out.println(i); }
int i=INT1; do { System.out.println(i); }while(i++<INT2);
None of these.
Identify correct statement(s) regarding the benefit of using PreparedStatement over Statement. Please select 1 option.
PreparedStatement offers protection against SQL injection attacks.
PreparedStatement allows transactions to span across multiple databases.
PreparedStatement allows easier customization of joins at run time.
PreparedStatement allows BLOB and CLOB on all databases.
Please select 1 option.
The FileWriter object will always be closed before the FileReader object.
The order of the closure of the FileWriter and FileReader objects is platform dependent and should not be relied upon.
The FileWriter object will not be closed if an exception is thrown while closing the FileReader object.
This is not a fail safe approach to managing resources because in certain situations one or both of the resources may be left open after the end of the try block.
Which of the following lambda expressions can be used to invoke a method that accepts a java.util.function.Predicate as an argument?. Please select 2 options.
x -> System.out.println(x)
x -> System.out.println(x);
x -> x == null
() -> true
x->true
The main declares that it throws SomeThrowable but throws MyThrowable.
You cannot have more than 2 classes in one file.
The catch block in the main method must declare that it catches MyThrowable rather than SomeThrowable.
There is nothing wrong with the code and Done will be printed.
Please select 2 options.
If IOException gets thrown at line1, then the whole method will end up throwing SQLException.
If IOException gets thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
If IOException gets thrown at line1, then the whole method will end up throwing InstantiationException.
If no exception is thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
If SQLException gets thrown at line1, then the whole method will end up throwing InstantiationException.
Please select 1 option.
stmt.commit();
con.commit();
stmt.commit(true);
con.commit(true);
No code is necessary.
Please select 1 option.
$20,000.00
20000
$20,000.00
20K
$20,000.00
200000.00
20,000.00
20000
Which of the following are benefits of ArrayList over an array?. Please select 1 option.
You do not have to worry about the size of the ArrayList while appending elements.
It consumes less memory space.
You do not have to worry about thread safety.
It allows you to write type safe code.
Please select 2 options
Object o = a; Runnable r = o;
Object o = a; Runnable r = (Runnable) o;
Object o = a; Observer ob = (Observer) o ;
Object o = b; Observer o2 = o;
Object o = b; Runnable r = (Runnable) b;
Given:
var sList = new CopyOnWriteArrayList<Student>();
which of the following statements are correct?. Please select 1 option.
Student class must be Cloneable or Serializable
Student objects retrieved from sList are thread safe.
Multiple threads can get Student objects from sList but can't add to it in a thread safe manner simultaneously.
Multiple threads can safely add and remove objects from sList simultaneously.
Any code that adds objects to sList must be synchronized but code that gets objects need not be.
Please select 1 option.
-9
-10
-11
-12
Yoy want to use a third party JDBC driver for a database. Which of the following actions must you take to retrieve a Connection using that driver in your JDBC program? Please select 2 options.
Put the driver jar in the class path.
Load the driver class using Class.forName
Create an instance of the Driver class using the new keyword.
Retrieve a connection using DriverManager.getConnection.
Load the driver class using Class.forName and then retrieve a connection using DriverManager.getConnection.
Please select 3 options
return new ArrayList<Integer>();
return new ArrayList<Number>();
return new ArrayList<Object>();
return new ArrayList();
return new ArrayList<? super Number>();
Please select 1 option
IllegalArgumentException
ArrayIndexOutOfBoundsException
c:\
c:
main
Please select 1 option
//1, //2, and //3 correctly override the method in Base.
//2, //3, and //4 correctly overload the method in Base
//2 and //3 correctly override the method in Base.
//1 correctly overloads while //4 correctly overrides the method in Base.
//1 correctly overrides the method in Base.
Which of these statements are true? Please select 2 options.
If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
An overriding method must declare that it throws the same exception classes as the method it overrides.
The main method of a program can declare that it throws checked exceptions.
A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
Please select 1 option.
Mysql driver jar and datalayer.jar must first be converted into modular jars.
datalayer.jar must first be converted into modular jar. The mysql jar need not be converted.
The mysql jar must first be converted into modular jar. The datalayer.jar need not be converted.
Neither datalayer nor mysql driver need to be converted into modular jars.
Which of the following statements are correct about --jdk-internals option of jdeps tool when run on a jar file or a class file? . Please select 2 options.
It analyzes all classes of the given jar file for class level dependence on Java API.
It analyzes all classes of the given jar file for class level dependence on jdk's deprecated API. If any such dependence is found, it is printed with a suggestion for replacement.
It analyzes all classes of the given jar file for class level dependence on jdk's internal API. If any such dependence is found, it is printed with a suggestion for replacement.
It analyzes all input modules and list all jdk internal modules on which the input modules depend. If any such dependence is found, it is printed with a suggestion for replacement.
It performs static analysis.
123
246
Compilation failure
exception at run time
Please select 1 option.
It will not compile.
It will compile but throw an exception at runtime.
It will print 'null' (without quotes).
It will print nothing.
None of the above.
Please select 1 option.
13.0
4.0
4
The code will not compile.
Please select 1 option.
A compilation error will occur.
10.0
12.0
20.0
22.0
It will compile but throw an exception at run time.
Please select 3 options.
jdeps -cp file1.jar;file2.jar app.jar
jdeps --upgrade-module-path file1.jar;file2.jar app.jar
jdeps --class-path file1.jar;file2.jar app.jar
jdeps -classpath file1.jar;file2.jar app.jar
jdeps app.jar
Please select 1 option.
5 5
5 6
6 6
6 5
4 5
Identify correct statements about the modular JDK. Please select 3 options.
The foundational APIs of the Java SE platform are found in java.base module.
The modular JDK is composed of two modules - the java module and the jdk module.
JDK is divided into a set of modules that can be combined at compile time, build time, and run time into a variety of configurations.
The modular JDK is divided of two kinds of modules - the standard modules and the non-standard modules.
Please select 1 option.
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
USA, UK, Netherlands, India, France
USA, Netherlands, UK, India, France
Please select 1 option.
It will not compile.
It will print 10 and then 10
It will print 20 and then 20
It will print 10 and then 20
It will print 20 and then 10
Please select 1 option.
ls.stream().map(a->a).max();
ls.stream().max(Comparator.comparing(a->a)).get();
ls.stream().reduce((a, b)->a>b?a:b);
All of above.
None of the above.
Please select 1 option.
Compilation error.
Exception at run time.
2015-12-31
2015-11-30
Please select 3 options.
package p1;
public class CompoundIntCalculator extends InterestCalculator{ }
package p1;
non-sealed abstract class CompoundIntCalculator extends InterestCalculator{ }
package p1.p2;
public non-sealed class CompoundIntCalculator extends InterestCalculator{ }
package p1;
final class CompoundIntCalculator extends InterestCalculator{ }
package p1;
public non-sealed class CompoundIntCalculator extends InterestCalculator{ }
Please select 1 option.
It will print MR, MS1, MS2, but the order is unpredictable.
MS2, MR, MS1,
MR, MS1, MS2,
It will not compile.
