Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Unique Java Test – 3 Code 1Z 829
Welcome to your Standard Tests - Unique Test 3
Name
Email
Phone
1.
Question: Given:
public static void generateMultiplicationTable(int number){
Stream sin = Stream.of(1, 2, 3 );
Consumer c1 = System.out::print;
Consumer c2 = x->{ System.out.println(" * "+number+" = "+x*number); };
INSERT CODE HERE
}
public static void main(String[] args) throws Exception{
generateMultiplicationTable(2);
}
Which of the options, when inserted in the above code, will produce the following output:
1 * 2 = 2
2 * 2 = 4
3 * 2 = 6
Select 1 option(s)
sin.forEach(c1).forEach(c2);
sin.forEach(c1.andThen(c2));
sin.forEach(c2.and(c1));
sin.forEach(c2.andThen(c1));
sin.forEach(c1);
sin.forEach(c2);
None
2.
Question: Identify correct statements regarding Java module system.
Select 1 option(s)
The file in which module information is specified must be named moduleinfo.java.
Module information can also be specified using @Module annotation
Every class of a module must specify which module it belongs to either using @Module annotation or using a command line option.
module-info.java must list all packages that you want to add to that module.
The only information required in the file that specifies module information is the module name.
A module must specify all sealed classes belonging to that module in its module-info.
None
3.
Question: What will the following code print?
Instant ins = Instant.parse("2022-06-25T16:43:30.00z");
ins.plus(10, ChronoUnit.HOURS);
System.out.println(ins);
Select 1 option(s)
2022-06-25T16:43:30Z
2022-06-26T02:43:30Z
Exception at run time.
It will not compile.
None
4.
Question: Consider the following code:
import java.util.*;
public class TestClass {
public static void main(String[] args)
{
// put declaration here
m.put("1", new ArrayList()); //1
m.put(1, new Object()); //2
m.put(1.0, "Hello"); //3
System.out.println(m);
}
}
How can 'm' be declared such that the above code will compile and run without errors?
Select 2 option(s)
5.
Question: What will the following code print?
var flag = true;
if(flag = false){
System.out.println("1");
}else if(flag){
System.out.println("2");
}else if(!flag){
System.out.println("3");
}else System.out.println("4");
Select 1 option(s)
1
2
3
4
Compilation error.
None
6.
Question: Which of the following options correctly add 1 month and 1 day to a given LocalDate -
public LocalDate process(LocalDate ld){
//INSERT CODE HERE
return ld2;
}
Select 1 option(s)
LocalDate ld2 = ld.plus(Period.ofMonths(1).ofDays(1));
LocalDate ld2 = ld.plus(new Period(0, 1, 1));
LocalDate ld2 = ld.plus(new Period(31)).plus(new Period(1));
LocalDate ld2 = ld.plus(Period.of(0, 1, 1));
None
7.
Question: Given:
public class Book{
String isbn;
String title;
public Book(String isbn, String title){
this.isbn = isbn;
this.title = title;
}
//accessors not shown
//assume appropriate implementations of equals and hashCode based on isbn property
}
and the following code snippet:
List books = getBooksByAuthor("Ludlum");
books.stream().sorted().forEach(b->System.out.println(b.getIsbn())); //1
Assuming that getBooksByAuthor is a valid method that returns a List of Books, which of the following statements is/are true?
Select 1 option(s)
Compilation failure at //1.
It will throw an exception at run time due to code at //1.
It will print isbns of the books in sorted fashion.
It will print isbns of the books but NOT in sorted fashion.
None
8.
Question: What can be inserted in the code below so that it will print {a=x, b=xy, c=y}?
Map map1 = new HashMap();
map1.put("a", "x");
map1.put("b", "x");
//INSERT CODE HERE
map1.merge("b", "y", f);
map1.merge("c", "y", f);
System.out.println(map1);
Select 1 option(s)
None
9.
Question: Which of the following statements will correctly create and initialize an array of Strings to non null elements?
Select 4 option(s)
String[] sA = new String[1] { "aaa"};
String[] sA = new String[] { "aaa"};
var[] sA = new String[1] ; sA[0] = "aaa";
String[] sA = {new String( "aaa")};
String[] sA = { "aaa"};
String[] sA = new String[1] ; sA[0] = "aaa";
10.
Question: Which of the following statements are correct regarding synchronization and locks?
Select 2 option(s)
A thread exclusively owns the intrinsic lock between the time it has acquired the lock and released the lock.
A thread can acquire a lock on the class.
A thread will release the intrinsic lock if the synchronized method calls a non-synchronized method and then reacquire the lock upon returning from that method.
Java allows a thread to acquire the intrinsic lock of only one object at a time to prevent deadlocks.
11.
Question: Which of the following statements regarding java.io.File are true?
Select 3 option(s)
You can delete the actual file or directory represented by the File object using that object.
You cannot create a File object if a file or directory does not actually exist by that name.
You can create files in any directory using File class's API.
Once created there is no way to change the File object to make it represent a different file or directory.
The same File object can be used to traverse between the directories.
12.
Question: What exception will be thrown out of the main method when the following program is run?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public void open() throws IOException{
header = "OPENED";
System.out.println("Device Opened");
throw new IOException("Unknown");
}
public String read() throws IOException{
return "";
}
public void close(){
System.out.println("Closing device");
header = null;
throw new RuntimeException("rte");
}
public static void main(String[] args) throws Exception {
try(Device d = new Device()){
throw new Exception("test");
}
}
}
Select 1 option(s)
java.lang.Exception
java.lang.RuntimeException
java.io.IOException
The given code will not compile.
None
13.
Question: Given:
module abc.print{
requires org.pdf;
provides org.pdf.Print with com.abc.print.SimplePrintImpl;
provides org.pdf.Print with com.abc.print.ComplexPrintImpl;
}
Assuming that another module named book uses abc.print module and contains the following code,
ServiceLoader psLoader = ServiceLoader.load(Print.class);
for (Print p : psLoader){
p.print("Hello");
}
identify correct statements.
Select 1 option(s)
Only the print method from SimplePrintImpl will be invoked.
Only the print method from ComplexPrintImpl will be invoked.
print methods from SimplePrintImpl as well as ComplexPrintImpl will be invoked.
abc.print module will not compile.
An exception will be thrown at run time when the given code is executed.
None
14.
Question: Given:
List strList = Arrays.asList("a", "aa", "aaa");
Function f = x->x.length();
Consumer c = x->System.out.print("Len:"+x+" ");
strList.stream().map(f).forEach(c);
What will it print when compiled and run?
Select 1 option(s)
A compilation error will occur.
Len:a Len:aa Len:aaa
Len:1 Len:2 Len:3
It will compile and run fine but will not print anything.
None
15.
Question: You are trying to compile your module named mycompany.finance. You have put all the source files for your module in src directory. However, your module requires a mycompany.utils module, which is delivered by another team of your company in the form of mycompany.utils.jar file. You have kept this jar in libs directory.
Which of the following commands can be used to compile your module?
Select 1 option(s)
javac --module-source-path src -classpath libs/mycompany.utils.jar --module src
javac --module-source-path src -p libs/mycompany.utils.jar -d out -m mycompany.finance
javac -source-path src -classpath libs -d out --module mycompany.finance
javac --module-source-path src -m libs -d out -s mycompany.finance
javac -s src -p libs -d out -m mycompany.finance
None
16.
Question: Given:
//using title, price constructor to create Book instances
var books = List.of(new Book("The Outsider", 2.99),
new Book("Where the Crawdads Sing", 4.99 ),
new Book("Elevation", 2.99), new Book("Coffin from Hong Kong", 1.99) );
Stream bkStrm = books.stream();//
double total = bkStrm.map(b->b.getPrice()).reduce(0.0, (a, b)->{ return a+b;}); //1
Assuming appropriate constructor and methods, which of the following options are equivalent to the statement at //1 of the above code?
Select 1 option(s)
None
17.
Question: Assume that a stored procedure named generateDailyGainsReport exists in your database. It takes two parameters - portfolioId and a date and returns a result set with several rows of data.
Consider the following Java code:
try(Connection c = ds.getConnection();
var stmt = c.prepareCall("{call generateDailyGainsReport(?,?)}") ) { //1
stmt.setObject("PORTFOLIOID", portfolioId, JDBCType.VARCHAR); //2
stmt.setObject("VALUEDATE", date, JDBCType.DATE); //3
boolean hasResult = stmt.execute(); //4
if(hasResult){
ResultSet rs = stmt.getResultSet(); //5
//code to process result
}
}
What will happen when the above code is complied and run?
Select 1 option(s)
It will throw an exception at runtime due to code at //1 because the syntax to invoke a stored procedure is incorrect.
It will fail to compile unless statements at //2 and //3 are replaced with:
stmt.setObject(1, portfolioId, java.sql.Types.STRING); //2
stmt.setObject(2, date, java.sql.Types.DATE); //3
It will fail to compile unless stmt.setString and stmt.setDate are used at //2 and //3.
It will cause a compilation error at //4 because stmt.execute() returns void.
It will throw an exception at runtime at //5 because the stmt.execute was called instead of stmt.executeQuery.
None
18.
Question: What can be inserted at //1 and //2 in the code below so that it can compile without errors:
class Doll{
String name;
Doll(String nm){
this.name = nm;
}
}
class Barbie extends Doll{
Barbie(){
//1
}
Barbie(String nm){
//2
}
}
public class TestClass {
public static void main(String[] args) {
Barbie b = new Barbie("mydoll");
}
}
Select 2 option(s)
this("unknown"); at 1 and super(nm); at 2
super("unknown"); at 1 and super(nm); at 2
super(); at 1 and super(nm); at 2
super(); at 1 and Doll(nm); at 2
super("unknown"); at 1 and this(nm); at 2
Doll(); at 1 and Doll(nm); at 2
19.
Question: Consider the following code appearing in a module-info.java
module com.amazing.movies{ //1
exports com.amazing.movies; //2
exports com.amazing.movies to com.amazing.rentals;//3
requires transitive com.amazing.customer;//4
}
Identify correct statements.
Select 1 option(s)
This is a valid module info.
This is an invalid module info because the name of the module and the name of a package that it exports are the same.
This is an invalid module info because line marked //3 uses incorrect syntax.
This is an invalid module info because lines marked //2 and //3 are in conflict.
This is an invalid module info because lines marked //3 and //4 use incorrect syntax.
None
20.
Question: Which statement(s) about the following code are correct?
interface House{
public default void lockTheGates(){
System.out.println("Locking House");
}
}
interface Office {
public void lockTheGates();
}
class HomeOffice implements House, Office{ //1
}
public class TestClass {
public static void main(String[] args) {
Office off = new HomeOffice(); //2
off.lockTheGates(); //3
House home = (House) off; //4
home.lockTheGates(); //5
}
}
Select 1 option(s)
Code for class HomeOffice will cause compilation to fail at //1.
Lines at //3 and //5 will cause compilation to fail.
Line at //4 will cause compilation to fail.
There will no compilation error. The code will print Locking House twice.
None
21.
Question: Consider the following piece of code, which is run in an environment where the default locale is English - US:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = Locale.getDefault();
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundles for appmessages, with the following contents:
#In English US resource bundle file
greetings=Hello
#In French CA resource bundle file
greetings=bonjour
What will be the output?
Select 1 option(s)
Hello
bonjour
An exception at run time.
No message will be printed.
None
22.
Question: Which of the following code snippets will print exactly 10?
1. Object t = new Integer(106);
int k = ((Integer) t).intValue()/10;
System.out.println(k);
2. System.out.println(100/9.9);
3. System.out.println(100/10.0);
4. System.out.println(100/10);
5. System.out.println(3 + 100/10*2-13);
Select 3 option(s)
1
2
3
4
5
23.
Question: What will be the output of the following code?
List letters = new ArrayList();
letters.addAll(List.of("a", "c", "b"));
Collections.sort(letters);
System.out.println(Collections.binarySearch(letters, "c"));
Collections.reverse(letters);
System.out.println(Collections.binarySearch(letters, "c"));
Select 1 option(s)
2
0
2
2
1
2
2
-4
2
An unpredicatable int value.
1
Exception at run time.
None
24.
Question: Given the following code fragment, which of the following lines would be a part of the output?
outer:
for ( var i = 0 ; i<3 ; i++ ){
for ( var j = 0 ; j<2 ; j++ ){
if ( i == j ){
continue outer;
}
System.out.println( "i=" + i + " , j=" + j );
}
}
Select 2 option(s)
i = 1, j = 0
i = 0, j = 1
= 1, j = 2
i = 2, j = 1
i = 2, j = 2
25.
Question: Consider :
class A {}
class B extends A {}
class C extends B {}
Which of the following boolean expressions correctly identify when the variable o actually refers to an object of class B and not of class C?
Select 2 option(s)
(o instanceof B) && (!(o instanceof A))
!((o instanceof A) || (o instanceof B))
(o instanceof B) && (!(o instanceof C))
! ( !(o instanceof B) || (o instanceof C))
(o instanceof B) && !((o instanceof A) || (o instanceof C))
26.
Question: Given the following complete contents of TestClass.java:
import java.util.ArrayList;
import java.util.Collections;
class Address implements Comparable
{
String street;
String zip;
public Address(String street, String zip){
this.street = street; this.zip = zip;
}
public int compareTo(Address o) {
int x = this.zip.compareTo(o.zip);
return x == 0? this.street.compareTo(o.street) : x;
}
}
public class TestClass {
public static void main(String[] args) {
ArrayList
al = new ArrayList();
al.add(new Address("dupont dr", "28217"));
al.add(new Address("sharview cir", "28217"));
al.add(new Address("yorkmont ridge ln", "11223"));
Collections.sort(al);
for(Address a : al) System.out.println(a.street+" "+ a.zip);
}
}
What will be printed?
Select 1 option(s)
yorkmont ridge ln 11223
dupont dr 28217
sharview cir 28217
sharview cir 28217
yorkmont ridge ln 11223
dupont dr 28217
harview cir 28217
dupont dr 28217
yorkmont ridge ln 11223
The order of output messages cannot be determined.
It will throw an exception at run time.
It will not compile.
None
27.
Question: You are the maintainer of a library packaged as bondanalytics.jar, which is used by several groups in your company. It has the following two packages that are used by other applications:
com.abc.bonds
com.abc.bonds.analytics
You want to modularize this jar but some groups have not yet modularized their applications. How will such groups use the modularized jar?
Select 1 option(s)
They cannot. Two versions of the jar will need to be maintained - one modularized and one old.
They can remove module-info.class from your modular jar and use the jar just as before.
They can use the new modular jar just like they use the old jar earlier without any changes.
They would have to use the --module-path option to use the new modular jar.
None
28.
Question: What should be inserted in the following code so that it works as expected?
String token = "xyz";
String output = null;
String processedValueCall = "{call reconciler(?,?)}";
CallableStatement callableStatement = dbConnection.prepareCall(processedValueCall);
*INSERT CODE HERE*
callableStatement.executeUpdate();
String value = callableStatement.getString(2);
Assume that the token variable is the first parameter to be passed.
Select 1 option(s)
callableStatement.registerInParameter(1, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.setString(2, output);
callableStatement.setString(1, token);
callableStatement.setString(2, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, output);
None
29.
Question: Given:
class Book{
private String title;
private double price;
public Book(String title, double price){
this.title = title;
this.price = price;
}
//getters/setters not shown
}
What will the following code print?
List books = Arrays.asList(new Book("Thinking in Java", 30.0),
new Book("Java in 24 hrs", 20.0),
new Book("Java Recipies", 10.0));
double averagePrice = books.stream().filter(b->b.getPrice()>10)
.mapToDouble(b->b.getPrice())
.average().getAsDouble();
System.out.println(averagePrice);
Select 1 option(s)
It will not compile.
It will throw an exception at runtime.
0.0
25.0
10.0
None
30.
Question: Which statements about the following code are correct?
interface House{
public default String getAddress(){
return "101 Main Str";
}
}
interface Office {
public static String getAddress(){
return "101 Smart Str";
}
}
interface WFH extends House, Office{
private boolean isOffice(){ return true; }
}
class HomeOffice implements House, Office{
public String getAddress(){
return "R No 1, Home";
}
}
public class TestClass {
public static void main(String[] args) {
Office off = new HomeOffice(); //1
System.out.println(off.getAddress()); //2
}
}
Select 1 option(s)
Code for class HomeOffice will cause compilation to fail.
Code for interface WFH will cause compilation to fail.
It will compile fine and print R No 1, Home when run.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
None
31.
Question: What will the following code print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList al = new ArrayList();
al.add("111");
al.add("222");
System.out.println(al.get(al.size()));
}
}
Select 1 option(s)
It will not compile.
It will throw a NullPointerException at run time.
It will throw an IndexOutOfBoundsException at run time.
222
null
None
32.
Question: Given:
ConcurrentMap cache = new ConcurrentHashMap();
cache.put("111", student1);
(Assume that student1 and student2 are references to a valid objects.)
Which of the following statements are legal but will NOT modify the Map referenced by cache?
Select 1 option(s)
cache.put("111", student2);
cache.putIfAbsent("111", student2);
cache.checkAndPut("111", student2);
cache.putIfNotLocked("111", student2);
None
33.
Question: Given:
ConcurrentMap cache = new ConcurrentHashMap();
Which of the given statements are correct about the following code fragment:
if(!cache.containsKey(key)) cache.put(key, value);
(Assume that key and value refer to appropriate objects.)
Select 1 option(s)
This will ensure that an entry in cache will never be overwritten.
To ensure that an entry in cache must never be overwritten, this statement should be replaced with:
cache.putIfAbsent(key, value);
To ensure that an entry in cache must never be overwritten, this statement should be replaced with:
cache.putAtomic(key, value);
To ensure that an entry in cache must never be overwritten, this statement should be enclosed in a synchronized block that synchronizes on "this".
None
34.
Question: Consider the following method...
public void ifTest(boolean flag){
if (flag) //1
if (flag) //2
System.out.println("True False");
else // 3
System.out.println("True True");
else // 4
System.out.println("False False");
}
Which of the following statements are correct ?
Select 3 option(s)
If run with an argument of 'false', it will print 'False False'
If run with an argument of 'false', it will print 'True True'
If run with an argument of 'true', it will print 'True False'
It will never print 'True True'
It will not compile.
35.
Question: Which of the given statements are correct about the following code?
// Filename: TestClass.java
class TestClass
{
public static void main(String[] args)
{
A a = new A();
B b = new B();
};
}
class A implements T1, T2{}
class B extends A implements T1{}
interface T1 { }
interface T2 { }
Select 5 option(s)
a instanceof T1 is true.
a instanceof T2 is true.
b instanceof T1 is true.
b instanceof T2 is true.
b instanceof A is false.
a instanceof A is true.
36.
Question: What will the following code print when run?
public class TestClass {
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "B" : System.out.println( "big bat" );
default : System.out.println( "none" );
}
}
public static void main(String[] args) throws Exception {
var tc = new TestClass();
tc.switchString("B");
}
}
Select 1 option(s)
bat
big bat
big bat
none
big bat
bat
The code will not compile.
None
37.
Question: What will be the result of compiling and running the following program ?
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String[] args) throws Exception{
try{
m2();
}
finally{
m3();
}
catch (NewException e){}
}
public static void m2() throws NewException { throw new NewException(); }
public static void m3() throws AnotherException{ throw new AnotherException(); }
}
Select 1 option(s)
It will compile but will throw AnotherException when run.
It will compile but will throw NewException when run.
It will compile and run without throwing any exceptions.
It will not compile.
None of the above.
None
38.
Question: Given the following code, which of the constructors shown in the options can be added to class B without causing a compilation to fail (independent of each other)?
class A{
int i;
public A(int x) { this.i = x; }
}
class B extends A{
int j;
public B(int x, int y) { super(x); this.j = y; }
}
Select 2 option(s)
B( ) { }
B(int y ) { j = y; }
B(int y ) { super(y*2 ); j = y; }
B(int y ) { i = y; j = y*2; }
B(int z ) { this(z, z); }
39.
Question: What will be the output of the following code snippet:
List li = List.of(3, 7, 2, 1, 4, 6, 5, 8);
Spliterator sit1 = li.spliterator();
Spliterator sit2 = sit1.trySplit();
sit1.forEachRemaining(System.out::print);
System.out.println("");
sit2.forEachRemaining(System.out::print);
Select 1 option(s)
3721
4658
4658
3721
1237
4568
(The order of the numbers on each line is unpredictable)
4568
1237
(The order of the numbers on each line is unpredictable)
None
40.
Question: What will the following code print when compiled and run?
class Names{
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public void printNames(){
System.out.println(getList());
}
public static void main(String[] args) {
List list = Arrays.asList(
"Bob Hope",
"Bob Dole",
"Bob Brown"
);
Names n = new Names();
n.setList(list.stream().collect(Collectors.toList()));
n.getList().forEach(Names::printNames);
}
}
Select 1 option(s)
[Bob Hope, Bob Dole, Bob Brown]
Bob HopeBob DoleBob Brown
[null, null, null]
Compilation error
An exception will be thrown at run time.
None
41.
Question: Which of the following is a valid module-info for a service provider that provides an Order service defined in OrderServiceAPI module?
Select 1 option(s)
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
requires OrderServiceAPI;
provides com.orderservice.api.Order;
}
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
uses OrderServiceAPI;
provides com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.provider;
provides com.orderservice.api.Order;
}
module OrderServiceProvider{
requires OrderServiceAPI;
provides com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
None
42.
Question: Identify the correct statements about the following code:-
List values = Arrays.asList(2, 4, 6, 9); //1
Predicate check = (Integer i) -> {
System.out.println("Checking");
return i == 4; //2
};
Predicate even = (Integer i)-> i%2==0; //3
values.stream().filter(check).filter(even).count(); //4
Select 1 option(s)
It will not compile because of code at //1.
It will not compile because of code at //2.
It will not compile because of code at //3.
It will not compile because of code at //4.
It will compile fine and print Checking four times.
It will compile fine and print Checking three times.
It will compile fine and print Checking one time.
It will compile fine but will print nothing.
None
43.
Question: Which of these array declarations and initializations are legal?
Select 1 option(s)
var i[][] = { { 1, 2 }, { 1 }, { }, { 1, 2, 3 } } ;
var i[ ] = new int[2] {1, 2} ;
var i = new int[ ][ ] { {1, 2, 3}, {4, 5, 6} } ;
var i = { { 1, 2 }, new int[ 2 ] } ;
var i[4] = new int[]{ 1, 2, 3, 4 } ;
var fa = new Float{ 1.1F, 2.2F, 3.3F };
None
44.
Question: Given the following code:
public String getDateString(LocalDateTime ldt){
return DateTimeFormatter.ISO_ZONED_DATE_TIME.format(ldt);
}
Which of the following statements are correct?
Select 1 option(s)
The code will compile but will always throw a DateTimeException (or its subclass) at run time.
DateTimeException must either be caught or declared in the throws clause of this method.
The method parameter type must be changed from LocalDateTime to ZonedDateTime for it to compile.
It will return the date string as per the default time zone of the system on which it is run.
None
45.
Question: Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 1 option(s)
None
46.
Question: Identify the correct statements about the following code:
import java.util.*;
import java.util.function.*;
class Account {
private String id;
public Account(String id){ this.id = id; }
//accessors not shown
}
public class BankAccount extends Account{
private double balance;
public BankAccount(String id, double balance){ super(id); this.balance = balance;}
//accessors not shown
public static void main(String[] args) {
Map myAccts = new HashMap();
myAccts.put("111", new Account("111"));
myAccts.put("222", new BankAccount("111", 200.0));
BiFunction bif =
(a1, a2)-> a2 instanceof BankAccount?new BankAccount(a1, 300.0):new Account(a1); //1
myAccts.computeIfPresent("222", bif);//2
BankAccount ba = (BankAccount) myAccts.get("222");
System.out.println(ba.getBalance());
}
}
Select 1 option(s)
It will not compile due to code at //1.
It will not compile due to code at //2.
It will print 200.0
It will print 300.0
None
47.
Question: Given:
List ls = Arrays.asList(11, 11, 22, 33, 33, 55, 66);
Which of the following expressions will return true?
Select 2 option(s)
48.
Question: What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
var b = false;
var i = 1;
do{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
Select 1 option(s)
The code will fail to compile, 'while' has an invalid condition expression.
It will compile but will throw an exception at runtime.
It will print 3.
It will go in an infinite loop.
It will print 1.
None
49.
Question: What will the following code print when compiled and run?
interface Boiler{
public void boil();
private static void log(String msg){ //1
System.out.println(msg);
}
public static void shutdown(){
log("shutting down");
}
}
interface Vaporizer extends Boiler{
public default void vaporize(){
boil();
System.out.println("Vaporized!");
}
}
public class Reactor implements Vaporizer{
public void boil() {
System.out.println("Boiling...");
}
public static void main(String[] args) {
Vaporizer v = new Reactor(); //2
v.vaporize(); //3
v.shutdown(); //4
}
}
Select 1 option(s)
Boiling...
Vaporized!
shutting down
Compilation failure at //1.
Compilation failure at //2.
Compilation failure at //4.
If code at //4 is changed to Vaporizer.shutdown();, it will print
Boiling...
Vaporized!
shutting down
Definition of interface Vaporizer will cause compilation to fail.
None
50.
Question: Which of the following are valid JDBC URLs?
Select 3 option(s)
jdbc.derby.localhost/sample
jdbc://mysql.com/sample
http://jdbc.mysql/sample
jdbc:oracle:thin:@localhost:1521:mydb
jdbc:mysql://192.168.1.10:3306/sample
jdbc:xderby:1106:sample
51.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[]){
Exception e = null;
throw e;
}
}
Select 1 option(s)
The code will fail to compile.
The program will fail to compile, since it cannot throw a null.
The program will compile without error and will throw an Exception when run.
The program will compile without error and will throw java.lang.NullPointerException when run.
The program will compile without error and will run and terminate without any output.
None
52.
Question: Given:
var nums = List.of(1, 2, 3, 4).stream();
Which of the following options will compute the average of the numbers in the nums stream?
Select 2 option(s)
double average = nums.collect(Collectors.averagingInt(i->i));
double average = nums.mapToObj(i->i).collect(Collectors.averagingInt(i->i));
double average = nums.average().getAsDouble();
double average = nums.parallel().mapToInt(i->i).average();
double average = nums.parallel().mapToDouble(i->i).average().getAsDouble();
53.
Question: Given the following lines of code:
int rate = 10;
XXX amount = 1 - rate/100*1 - rate/100;
What can XXX be?
Select 1 option(s)
only int or long
only long or double
only double
double or float
long or double but not int or float.
int, long, float or double
None
54.
Question: What will the following code print when compiled and run?
List iList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
Predicate p = x->x%2==0;
List newList = iList.stream().filter(p).filter(x->x>3).collect(Collectors.toList());
System.out.println(newList);
Select 1 option(s)
It will fail to compile.
null
[1]
[2]
[5, 7]
[4, 6]
None
55.
Question: Given:
sealed interface Member permits Person{ //LINE A
String role();
void role(String role);
}
final class Person implements Member{ //LINE B
private String role = "UNKNOWN";
public String role(){ return role; }
public void role(String role){ this.role = role; }
}
record Student(int id, Person person) //LINE C
{
public String getRole(){ return person.role(); }
public void setRole(String role){ person.role(role); } //LINE D
}
public class TestClass{
public static void main(String[] args) {
Student s = new Student(123, new Person()); //LINE E
s.setRole("student"); //LINE F
System.out.println(s);
}
}
Which lines will cause compilation issues?
Select 1 option(s)
LINE A
LINE B
LINE C
LINE D
LINE E
There is no problem with any of the marked lines but the given code will not compile.
The given code will compile without any problem.
None
Time's up
Time is Up!
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US