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
Standard Unique Test 3
Welcome to your Standard Tests - Unique Test 3 : 2025
Name
Email
Phone
Q1. What will the following program print?
class Test{
public static void main(String[] args){
var i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+ ia[0][0].length);
}
}
Select 1 option(s):
It will not compile.
3, 4, 3
3, 3, 3
4, 3, 4
4, 3, 3
None
Q2. 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
Q3. 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.
Only a modular app can be packaged as a jimage.
None
Q4. 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):
Map m = new TreeMap();
Map< Object, Object > m = new TreeMap< Object, Object >();
Map< Object, ? > m = new LinkedHashMap< Object, Object >();
Map< Object, ? super ArrayList > m = new LinkedHashMap< Object, ArrayList >(); will work if lines //2 and //3 are commented out.
Map< Object, ? super ArrayList > m = new LinkedHashMap< Object, ArrayList >(); will work if lines //1 and //3 are commented out.
Map m = new HashMap();
Q5. 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
Q6. 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));
Period p = Period.of(0, 2, 1);
p.plusMonths(-1);
ld = ld.plus(p);
None
Q7. 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
Q8. 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):
BiFunction< String, String > f = String::concat;
Function< String > f = String::concat;
BiFunction< String, String, String > f = String::concat;
Function< String, String > f = String::concat;
None
Q9. Given:
public class TestClass {
static class Delimiter{
char value = '|';
Delimiter(){
this('-');
}
Delimiter(char ch){
this.value = ch;
}
static{
System.out.print('.');
}
{ System.out.print(value); }
public String toString(){ return String.valueOf(value); }
}
public static void main(String[] args) {
Delimiter d1 = new Delimiter();
Delimiter d2 = new Delimiter('#');
System.out.println(d1+""+d2);
}
}
What will be the output?
Select 1 option(s):
||-#
-#-#
..-#-#
.-#-#
.||-#
..||-#
None
Q10. 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";
Q11. 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.
Q12. 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.
Q13. 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
Q14. 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
Q15. 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
Q16. 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
Q17. Given:
class MeanTest{
int mean(int i, String s){
return (Integer.parseInt(s)+i)/2;
}
double mean(int i, int j){
return Math.sqrt(i*j);
}
double mean(double i, long j){
return Math.sqrt(i*j);
}
float mean(String s){
return Integer.parseInt(s)/1f;
}
float mean(int i){
return i/1.0f;
}
public static void main(String[] args) {
MeanTest ot = new MeanTest();
var a = "10";
var b = ot.mean(a);
//INSERT CODE HERE
System.out.println(c+" "+d+" "+e);
}
}
Which of the following options when inserted in the above code will produce the output:
10.0 10 10
Select 1 option(s):
var c = ot.mean(Math.round(b));
var d = ot.mean(Math.round(c), a);
var e = ot.mean(d, d);
var c = ot.mean(Math.round(b), a);
var d = ot.mean(Math.round(c));
var e = ot.mean(c, c);
var c = ot.mean(Math.round(b), Math.round(b));
var d = ot.mean(c, c);
var e = ot.mean(Math.round(b), a);
var c = ot.mean(Math.round(b));
var d = ot.mean(Math.round(c), a);
var e = ot.mean(d, a);
None
Q18. 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):
DoubleOperator myop = (a, b)->a+b;
double total = bkStrm.map(b->b.getPrice()).reduce(0.0, myop);
double total = bkStrm.map(b->b.getPrice())
.reduce((a, b)->{ return a+b;}).ifPresent(p->p.doubleValue());
DoubleBinaryOperator dbo = (a, b)->a+b;
double total = bkStrm.mapToDouble(b->b.getPrice()).reduce(0.0, dbo);
BinaryOperator< Double > bo = (a, b)->a+b;
double total = bkStrm.mapToDouble(b->b.getPrice()).reduce(0.0, bo);
DoubleBinaryOperator dbo = (a, b)->a+b;
double total = bkStrm.mapToDouble(b->b.getPrice()).reduce(dbo).get();
None
Q19. 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
Q20. 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
Q21.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
sharview 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
Q22. 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
Q23. 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
Q24. 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
Q25. What will the following code print?
Select 1 option(s):
1234123 ( always in this order ).
1234 but the order of numbers is unpredictable.
1234123 but the order of numbers is unpredictable.
1234 (always in this order).
None
Q26. 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
Q27. 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
Q28. 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
Q29. 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.
Q30. 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.
Q31. 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
Q32. 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
Q33. 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)?
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); }
Q34. 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
Q35. 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
Q36. 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
Q37. 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
Q38. 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
Q39. 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
Q40. 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):
public List< ? extends Integer > getList(){
public List< ? super Integer > getList(){
public ArrayList< ? extends Number > getList(){
public ArrayList< ? super Number > getList(){
public ArrayList< Number > getList(){
None
Q41. 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
Q42. Given:
List ls = Arrays.asList(11, 11, 22, 33, 33, 55, 66);
Which of the following expressions will return true?
Select 2 option(s):
ls.stream().anyMatch(44);
ls.stream().anyMatch(11);
ls.stream().distinct().anyMatch(x->x==11);
ls.stream().distinct().allMatch(11);
ls.stream().noneMatch(x->x>0);
Q43. 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
Q44. 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
Q45. 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
Q46. 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();
Q47. 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
Q48. 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
Q49. 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
Q50. Identify correct statements regarding Java threads.
Select 2 option(s):
A thread in any of the waiting states does not consume CPU cycles.
A thread in TIMED_WAITING state goes to TERMINATED state upon expiry of the timed wait.
A thread in any of the waiting states must handle InterruptedException.
An IllegalStateException is thrown when a thread in a waiting state is moved to the runnable state.
Calling interrupt() on a thread will put that thread into one of WAITING, TIMED_WAITING, or BLOCKED states.
A virtual threads's priority can be lowered using the setPriority method.
Q51. Given:
public class TestClass {
static interface Media{
default void play(){
System.out.println("Media playing");
}
}
static class DvD implements Media{
public void play(){
System.out.println("DvD playing");
}
}
static class CD implements Media{
public void play(){
System.out.println("CD playing");
}
}
static void play(Media m){
m.play();
}
public static void main(String[] args){
Media m1 = new DvD();
DvD d = new DvD();
Media m2 = new CD();
play(m1);
play(d);
play(m2);
}
}
What will be the output?
Select 1 option(s):
DvD playing
DvD playing
CD playing
Media playing
DvD playing
Media playing
Media playing
Media playing
Media playing
Compilation error
None
Q52. What will the following code fragment print?
ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
Lock rlock = rl.readLock();
Lock wlock = rl.writeLock();
String result = "default ";
try{
rlock.lock();
result = result+"1 ";
if(wlock.tryLock()){
result = result+"2 ";
}else{
rlock.lock();
result = result+"3 ";
}
}catch(Exception e){
result = result+"4 ";
}finally{
rlock.unlock();
result = result+rl.getReadHoldCount()+" "+rl.isWriteLocked();
}
System.out.println(result);
Select 1 option(s):
default 1 3 1 true
default 1 4 1 false
default 1 3 1 false
default 4
< an exception stack trace >
default 1 1 false
None
Q53. Which statements regarding the following code are correct?
class A implements Runnable
{
public void run()
{
System.out.println("Starting loop");
try{
Thread.sleep(10000); //1 sleep for 10 secs
}catch(Exception e){ e.printStackTrace(); }
System.out.println("Ending loop");
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
A a = new A();
Thread t = Thread.startVirtualThread(a);
Thread.sleep(1000);
t.interrupt();
}
}
Select 2 option(s):
As exception will be received by the main thread as soon as it calls t.interrupt().
It will run and will most likely end without throwing any exception.
It will run and will most likely end with a java.lang.InterruptedException stack trace on the command line.
It will run and will end without an InterruptedException if //1 is replaced with while(!isInterrupted()) { };
The code will compile even if catch(Exception e) is replaced with catch(RuntimeException e).
The code will work fine even if A is made to implement Callable instead of Runnable because Thread.startVirtualThread method can accept a Callable object or a Runnable object.
Q54. Given:
public class TestClass2 {
static ArrayList al = new ArrayList();
public static void main(String[] args) {
Runnable r = ()->{
for(int i=0; i<5000; i++){
synchronized (al) {
al.add(i);
}
}
};
Thread t1 = new Thread(r, "T1");
Thread t2 = new Thread(r, "T2");
ExecutorService es = Executors.newFixedThreadPool(2);
Future f1 = es.submit(t1);
Future f2 = es.submit(t2);
es.shutdown();
try{
f1.get();
f2.get();
System.out.println(al);
}catch(Exception e){
e.printStackTrace();
}
}
}
What is the result?
Select 1 option(s):
An exception stack trace will be printed.
Exactly 10000 random numbers ranging from 0 to 4999 will be printed.
Every number ranging from 0 to 4999 will be printed exactly twice in stochastic order.
Every number ranging from 0 to 4999 will be printed exactly twice in increasing order.
Every number ranging from 0 to 4999 will be printed exactly twice.
Only some numbers ranging from 0 to 4999 will be printed.
An empty ArrayList MAY BE printed.
Every number ranging from 0 to 4999 will be printed.
None
Time's 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