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 2
Welcome to your Standard Tests - Unique Test 2 : 2025
Name
Email
Phone
Q1. What will the following code print when compiled and run?
record Student(int id, String... subjects) {
public Student{
if(id<0) throw new IllegalArgumentException();
if( subjects == null || subjects.length == 0) {
subjects = new String[] {"english" };
}
}
}
public class TestClass{
public static void main(String[] args) {
Student s = new Student(123, null);
switch(s){
case Student(var id, var subjects) : System.out.println(s);
default : System.out.println("default");
}
}
}
Select 1 option(s):
It will not compile because its compact constructor is defined incorrectly.
It will throw a NullPointerException at run time.
Student[id=123, subjects=null]
Student[id=123, subjects=[Ljava.lang.String;@568db2f2]
Student[id=123, subjects=[Ljava.lang.String;@568db2f2]
default
It will not compile because the switch statement is syntactically invalid.
None
Q2. Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList("aa", "aaa", "b", "cc", "ccc", "ddd", "a");
//INSERT CODE HERE
System.out.println(count);
}
}
Which of the following options will correctly print the number of elements that will come before the string "c" if the list were sorted alphabetically?
Select 1 option(s):
int count = al.stream().filter((str)->str.compareTo("c")<0).count();
long count = al.stream().filter((str)->str.compareTo("c")<0).count();
int count = al.stream().filter((str)->str.compareTo("c")<0).sort().count();
int count = al.stream().filter((str)->str.compareTo("c")<0).sorted().count();
int count = 0;
al.stream().forEach(s->{
count = (s.compareTo("c")<0)?count+1:count;
});
None
Q3. 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){
System.out.print("Media: ");
m.play();
}
static void play(DvD d){
System.out.print("DvD: ");
d.play();
}
public static void main(String[] args){
Media m = new DvD();
DvD d = new DvD();
CD c = new CD();
play(m);
play(d);
play(c);
}
}
What will be the output?
Select 1 option(s):
Media: DvD playing
Media: DvD playing
Media: CD playing
Media: DvD playing
DvD: DvD playing
Media: CD playing
Media: DvD playing
DvD: DvD playing
< exception at runtime >
Media: Media playing
DvD: DvD playing
Media: Media playing
Compilation error
None
Q4. Given the following code for Book class:
record Book(String title, String isbn){
//insert code here
}
What of the following options illustrates correct usage of instanceof with pattern matching?
Select 2 option(s):
@Override
public boolean equals(Object o){
return (o instanceof Book b && b.isbn().equals(this.isbn()));
}
@Override
public boolean equals(Object o){
Book b = o instanceof Book;
return b.isbn().equals(this.isbn()));
}
@Override
public boolean equals(Object o){
Book b as o instanceof Book;
return b.isbn().equals(this.isbn()));
}
@Override
public boolean equals(Object o){
Book b = (Book) o;
return b.isbn().equals(this.isbn()));
}
@Override
public boolean equals(Object o){
return (o instanceof Book(var t, var i) && i.equals(this.isbn()));
}
@Override
public boolean equals(Object o){
return (o instanceof Book(var t, String i) b && i.equals(this.isbn()));
}
@Override
public boolean equals(Object o){
return (o instanceof Book(String t, String i) || !i.equals(this.isbn()));
}
Q5. Which of the following code snippets will print a String containing exactly 100 characters?
Select 2 option(s):
IntStream is = ThreadLocalRandom.current().ints('a', 'z'+1);
String s = is.parallel().limit(100).mapToObj(i->String.valueOf(i)).collect(Collectors.joining());
System.out.println(s);
IntStream is = ThreadLocalRandom.current().ints('a', 'z'+1);
String s = is.parallel().limit(100).mapToObj(i->""+((char)i)).collect(Collectors.joining());
System.out.println(s);
IntStream is = ThreadLocalRandom.current().ints(0, 26);
StringBuilder s = is.limit(100).map(i->i+97).parallel().collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append);
System.out.println(s);
StringBuilder s = new StringBuilder();
IntStream is = ThreadLocalRandom.current().ints('a', 'z'+1);
is.limit(100).parallel().forEach(ch -> s.appendCodePoint(ch));
StringBuilder s = new StringBuilder();
IntStream is = ThreadLocalRandom.current().ints('a', 'z'+1);
is.parallel().takeWhile(i->s.length()<1000).forEach( ch -> s.append((char)ch) );
Q6. Given:
public class TestClass {
static interface Media{
default void play(){
System.out.println("Media playing");
}
}
static class ROM implements Media{
public void play(){
System.out.println("ROM playing");
}
}
static class CdROM extends ROM implements Media{
}
static void play(Media m){
System.out.print("Media: ");
m.play();
}
static void play(CdROM d){
System.out.print("CdROM: ");
d.play();
}
public static void main(String[] args){
ROM r1 = new ROM();
Media r2 = new CdROM();
play(r1);
play(r2);
}
}
What will be the output?
Select 1 option(s):
Media: Media playing
Media: Media playing
Media: ROM playing
CdROM: ROM playing
Media: ROM playing
CdROM: Media playing
Media: ROM playing
Media: ROM playing
Compilation error
None
Q7. Consider the following code :
public class TestClass extends Thread
{
class Runner implements Runnable
{
public void run()
{
var t = new Thread[5];
for(int i=0; i<t.length; i++) System.out.println(t[i]);
}
}
public static void main(String args[]) throws Exception
{
var tc = new TestClass();
new Thread( tc.new Runner() ).start();
}
}
How many Thread objects are created by the above program when it is compiled and run?
Select 1 option(s):
1
2
6
7
None, because the program will not compile.
None
Q8. Consider the following code:
class A {
public void doA(int k) throws Exception { // 0
for(int i=0; i< 10; i++) {
if(i == k) throw new Exception("Index of k is "+i); // 1
}
}
public void doB(boolean f) { // 2
if(f) {
doA(15); // 3
}
else return;
}
public static void main(String[] args) { // 4
A a = new A();
a.doB(args.length>0); // 5
}
}
Which of the following statements are correct?
Select 1 option(s):
This will compile and run without any errors or exception.
This will compile if throws Exception is added at line //2
This will compile if throws Exception is added at line //4
This will compile if throws Exception is added at line //2 as well as //4
This will compile if line marked // 1 is enclosed in a try - catch block.
None
Q9. Given that Book is a valid class with appropriate constructor and getPrice method that returns a double, what can be inserted at //1 so that it will sum the price of all the books that are priced greater than 5.0?
List books = Arrays.asList(
new Book("Gone with the wind", 10.0),
new Book("Atlas Shrugged", 10.0),
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0)
);
//1 INSERT CODE HERE
System.out.println(sum);
Select 2 option(s):
double sum = books.stream()
.filter(b->b.getPrice()<=5.0)
.mapToInt(b->b.getPrice())
.sum();
double sum = books.stream()
.filter(b->b.getPrice()<=5.0)
.mapToInt(b->(int)b.getPrice())
.sum();
double sum = books.stream()
.filter(b->b.getPrice()<5.0)
.mapToDouble(b->b.getPrice())
.sum();
double sum = books.stream()
.mapToDouble(b->b.getPrice()>5?b.getPrice():0.0)
.sum();
double sum = books.stream()
.mapToDouble(b->b.getPrice())
.filter(b->b>5.0)
.sum();
double sum = books.stream()
.flatMapToDouble(b->b.getPrice())
.filter(b->b>5.0)
.sum();
Q10. What will the following code print?
public class Test{
public int luckyNumber(int seed){
if(seed > 10) return seed%10;
int x = 0;
try{
if(seed%2 == 0) throw new Exception("No Even no.");
else return x;
}
catch(Exception e){
return 3;
}
finally{
return 7;
}
}
public static void main(String args[]){
int amount = 100, seed = 6;
switch( new Test().luckyNumber(6) ){
case 3: amount = amount * 2;
case 7: amount = amount * 2;
case 6: amount = amount + amount;
default :
}
System.out.println(amount);
}
}
Select 1 option(s):
It will not compile.
It will throw an exception at runtime.
800
200
400
None
Q11. Which of the given lines can be inserted at //1 of the following program ?
public class TestClass
{
public static void main(String[] args)
{
short s = 9;
//1
}
}
Select 2 option(s):
Short k = new Short(9);
System.out.println(k instanceof Short);
System.out.println(s instanceof Short);
Short k = 9;
System.out.println( k instanceof s);
int i = 9;
System.out.println(s == i);
Boolean b = s instanceof Number;
Short k = 9; Integer i = 9;
System.out.println(k == i);
Integer i = 9;
System.out.println( s == i );
Q12. What, if anything, is wrong with the following code?
interface T1{
}
interface T2{
int VALUE = 10;
void m1();
}
interface T3 extends T1, T2{
public void m1();
public void m1(int x);
}
Select 1 option(s):
T3 cannot implement both T1 and T2 because it leads to ambiguity.
There is nothing wrong with the code.
The code will work fine only if VALUE is removed from T2 interface.
The code will work fine only if m1() is removed from either T2 and T3.
None of the above.
None
Q13. Consider the following code:
class A
{
}
public class TestClass
{
public class A
{
public void m() { }
}
class B extends A
{
B(){ m(); }
}
public static void main(String args[])
{
new TestClass().new A() { public void m() { } }; //1
var tc = new TestClass();
//insert call to A's m() here
}
}
Select 4 option(s):
This program will not compile.
class created inside the main method at //1 is static.
class created inside the main method at //1 is final.
Objects of class B cannot be created inside the main method just by doing "new B()"
new TestClass().new A().m(); can be inserted in main to invoke A's m().
new A().m(); can be inserted in main to invoke A's m().
tc.new A().m(); can be inserted in main to invoke A's m().
Q14. What will the following code NEVER print when run?
enum SIZE
{
TALL, JUMBO, GRANDE;
}
class CoffeeMug
{
public static void main(String[] args)
{
var hs = new HashSet();
hs.add(SIZE.TALL); hs.add(SIZE.JUMBO); hs.add(SIZE.GRANDE);
hs.add(SIZE.TALL); hs.add(SIZE.TALL); hs.add(SIZE.JUMBO);
for(SIZE s : hs) System.out.print(s+" ");
}
}
Select 2 option(s):
GRANDE TALL JUMBO
TALL JUMBO GRANDE
TALL GRANDE JUMBO
TALL JUMBO GRANDE TALL TALL JUMBO
TALL JUMBO GRANDE TALL JUMBO
Q15. Given:
public class Book{
private String title;
private Double price;
public Book(String title, Double price){
this.title = title;
this.price = price;
}
//accessor methods not shown
What will the following code print when compiled and run?
Book b1 = new Book("Java in 24 hrs", null);
DoubleSupplier ds1 = b1::getPrice;
System.out.println(b1.getTitle()+" "+ds1.getAsDouble());
Select 1 option(s):
Java in 24 hrs null
Java in 24 hrs 0.0
Java in 24 hrs
It will throw a NullPointerException.
It will not compile.
None
Q16. Given:
module broker{
exports org.broker.api;
}
The broker module contains org.broker.api.Installer interface, which is implemented by com.foo.AppInstaller class of com.foo module.
Which of the following is a valid module definition for com.foo module?
Select 1 option(s):
module com.foo{
exports broker;
}
module com.foo{
provider broker;
}
module com.foo{
requires broker;
provides org.broker.api;
}
module com.foo{
requires broker;
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
module com.foo{
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
None
Q17. The following are complete contents of TestClass.java:
class Book{
protected final int pages = 100;
final void mA(){
System.out.println("In B.mA "+pages);
}
}
class Encyclopedia extends Book{
private int pages = 200; //1
void mB(){
System.out.println("In E.mB "+pages);
}
void mA(){ //2
System.out.println("In E.mA "+pages);
}
}
public class TestClass {
public static void main(String[] args) {
Book o1 = new Encyclopedia (); //3
Book o2 = new Book();
o1.mA(); //4
o1.mB(); //5
o2.mA();
}
}
Which lines will cause compilation to fail?
Select 1 option(s):
//1 and //2
//2 and //5
//1 //2 and //5
//1 and //5
//1 and //3
//1 //3 and //4
None
Q18. Given:
int expr1 = 3 + 5 * 9 - 7;
int expr2 = 3 + (5 * 9) - 7;
int expr3 = 3 + 5 * (9 - 7);
int expr4 = (3 + 5) * 9 - 7;
Which of the above variables will have the value 45?
Select 1 option(s):
expr1
expr2
expr3
expr4
None of them.
None
Q19. Given the following command:
javac --module-source-path c:\java\a -d c:\java\b -p c:\java\c -m x.y
Which of the following statements are correct?
Select 1 option(s):
A directory named out will be created under c:\java\b
A directory named x/y will be created under c:\java\b
A directory named x.y will be created under c:\java\c
Class files will be created under c:\java\b\x.y
Class files will be created under c:\java\a
This command is not valid because -classpath option is missing.
None
Q20. Given:
public class Triangle{
public int base;
public int height;
public double area;
public Triangle(int base, int height){
this.base = base; this.height = height;
updateArea();
}
void updateArea(){
area = base*height/2;
}
public void setBase(int b){ base = b; updateArea(); }
public void setHeight(int h){ height = h; updateArea(); }
}
The above class needs to protect an invariant on the "area" field (meaning, the value of the ///area/// field should always be equal to the value computed using the formula for area of a triangle). Which three members must have the public access modifiers removed to ensure that the invariant is maintained?
Select 3 option(s):
the base field
the height field
the area field
the Triangle constructor
the setBase method
the setHeight method
Q21. What will the following code print?
int[] a = { 'h', 'e', 'l'};
int[] b = { 'h', 'e', 'l', 'l', 'o'};
int x = Arrays.compare(a, b);
int y = Arrays.mismatch(a, b);
System.out.println(x+" "+y);
Select 1 option(s):
1 3
-1 3
-2 3
-2 -3
The code will not compile.
None
Q22. What will the following code print when compiled and run?
public class TestClass {
public static void main(String[] args) {
String s = "blooper";
StringBuilder sb = new StringBuilder(s);
s.append("whopper");
sb.append("shopper");
System.out.println(s);
System.out.println(sb);
}
}
Select 1 option(s):
blooper and bloopershopper
blooperwhopper and bloopershopper
blooper and blooperwhoppershopper
It will not compile.
None
Q23. Identify correct statement(s) about the following code:
var value = 1,000,000; //1
switch(value){
case 1_000_000 -> { //2
System.out.println("A million 1");
break; //3
}
case 1000000 -> { //4
System.out.println("A million 2");
}
}
Select 1 option(s):
It will print A million 1 when compiled and run.
It will print A million 2 when compiled and run.
Compilation fails only at line //1
Compilation fails only at line //2
Compilation fails only at line //4
Compilation fails at line //1 and //4
Compilation fails at line //1, //3, and //4
None
Q24. Consider the following code:
public class FileCopier {
public static void copy(String records1, String records2) throws IOException {
try (
InputStream is = new FileInputStream(records1);
OutputStream os = new FileOutputStream(records2);) {
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
System.out.println("Read and written bytes " + bytesRead);
}
} catch (IOException | IndexOutOfBoundsException e) {
e = new FileNotFoundException();
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
copy("c:\\temp\\test1.txt", "c:\\temp\\test2.txt");
}
}
Assuming appropriate import statements and the existence of both the files, what will happen when the program is compiled and run?
Select 1 option(s):
The program will not compile because the try statement is used incorrectly.
The program will not compile because the catch clause is used incorrectly.
The program will not compile because the line e = new FileNotFoundException(); in catch block is invalid.
The program will not compile because the line e.printStackTrace(); in catch block is invalid.
It will compile and run without any error or exception.
It will compile but will throw an exception when run.
None
Q25. What will the following code print when run?
public class Test{
static String j = "";
public static void method( int i){
try{
if(i == 2){
throw new Exception();
}
j += "1";
}
catch (Exception e){
j += "2";
return;
}
finally{
j += "3";
}
j += "4";
}
public static void main(String args[]){
method(1);
method(2);
System.out.println(j);
}
}
Select 1 option(s):
13432
13423
14324
12434
12342
None
Q26. Which of the following approaches are good to perform thread safe iteration of elements of a collection?
Select 1 option(s):
Perform the iteration on immutable collection within a synchronized method.
Perform the iteration on copy-on-write collections within a synchronized method.
Implement your own synchronized method to work with synchronized collections.
Use synchronized iterators provided by mutable collections.
Use synchronized iterators provided by synchronized collections.
None
Q27. What will the following code print?
Path p1 = Paths.get("/photos/vacation");
Path p2 = Paths.get("/yellowstone");
System.out.println(p1.resolve(p2)+" "+p1.relativize(p2));
Select 1 option(s):
yellowstone ../../yellowstone
/yellowstone ../../yellowstone
/yellowstone /yellowstone
/yellowstone yellowstone
None
Q28. Given the following class, which statements can be inserted at line 1 without causing the code to fail compilation?
public class TestClass{
int a;
int b = 0;
static int c;
public void m(){
int d;
int e = 0;
// Line 1
}
}
Select 4 option(s):
a++;
b++;
c++;
d++;
e++;
Q29.Given:
List dList = Arrays.asList(10.0, 12.0);
dList.forEach(x->{ x = x + 10; });
dList.forEach(x->System.out.println(x));
What will it print when compiled and run?
Select 1 option(s):
A compilation error will occur.
10.0
12.0
20.0
22.0
It will compile but throw an exception at run time.
None
Q30. Given the following method code:
public void myMethod() throws MyException {
//method code
}
Select 1 option(s):
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be an unchecked exception.
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be extending RuntimeException.
A method that calls myMethod must wrap the call in a try block.
The code in myMethod can throw only MyException.
If MyException class is made to extend RuntimeException, there would be no impact on myMethod.
None
Q31. Which of the following commands can be used to run a class named com.foo.Bar, which is part of a module named foo.bar packaged in foobar.jar
(Assume that the jar file is located in the current directory.)
Select 1 option(s):
java --classpath foobar.jar --module foo.bar/com.foo.Bar
java --module foobar.jar foo.bar/com.foo.Bar
java --classpath foobar.jar --module-path foo.bar/com.foo.Bar
java --module-path foobar.jar com.foo.Bar
java --module-path foobar.jar --module foo.bar/com.foo.Bar
None
Q32. Which of these are valid expressions to create a string of value "hello world" ?
Select 3 option(s):
Q33. What will the following code print when compiled and run?
(Assume that MySpecialException is an unchecked exception.)
1. public class ExceptionTest {
2. public static void main(String[] args) {
3. try {
4. doSomething();
5. } catch (MySpecialException e) {
6. System.out.println(e);
7. }
8. }
9.
10. static void doSomething() {
11. int[] array = new int[4];
12. array[4] = 4;
13. doSomethingElse();
14. }
15.
16. static void doSomethingElse() {
17. throw new MySpecialException("Sorry, can't do something else");
18. }
}
Select 1 option(s):
It will not compile.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: 4
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:13)
at ExceptionTest.main(ExceptionTest.java:4)
None
Q34. What will the following code print?
List str = Arrays.asList(1,2, 3, 4 );
str.stream().filter(x->{
System.out.print(x+" ");
return x>2;
});
Select 1 option(s):
1 2 3 4
1 2 3 4 4
4
It will not print anything.
None
Q35. The following code snippet will print true.
String str1 = "one";
String str2 = "two";
System.out.println( str1.equals(str1=str2) );
Select 1 option(s):
True
False
None
Q36. Given:
public class Book {
private int id;
private String title;
private String genre;
private String author;
private double price;
//constructors and accessors not shown
}
Assuming that books is a List of Book objects, what can be inserted in the code below at DECLARATION and EXPRESSION so that it will classify the books by genre and then also by author?
DECLARATION classified = null;
classified = books.stream().collect(Collectors.groupingBy(
EXPRESSION
));
System.out.println(classified);
Select 1 option(s):
Map< String, Map< String, List< Book >>>
and
x->x.getGenre(), x->x.getAuthor()
Map< String, Map< String, Book >>
and
x->x.getGenre(), x->x.getAuthor()
Map< String, Map< String, List< Book >>>
and
Book::getGenre, Collectors.groupingBy(Book::getAuthor)
Map< String, Map< String, List< Book >>>
and
Book::getGenre().groupingBy(Book::getAuthor)
Map< String, Map< String, List< Book >>>
and
Book::getGenre, Collectors.mapping(Book::getAuthor, Collectors.toList())
None
Q37. Given:
StringBuilder sb = new StringBuilder("asdf");
Which of the following code fragments will print true?
Select 1 option(s):
String str1 = sb.toString();
String str2 = sb.toString();
System.out.println(str1 == str2);
String str1 = sb.toString();
String str2 = str1;
System.out.println(str1 == str2);
String str1 = sb.toString();
System.out.println(str1 == sb);
System.out.println(sb == new StringBuilder(sb));
None
Q38. Given:
class OverloadingTest{
void m1(int x){
System.out.println("m1 int");
}
void m1(float x){
System.out.println("m1 float");
}
void m1(String x){
System.out.println("m1 String");
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
OverloadingTest ot = new OverloadingTest();
ot.m1(1.0);
}
}
What will be the output?
Select 1 option(s):
It will fail to compile.
m1 int
m1 float
m1 String
None
Q39. Consider the following
public class TestClass {
public static void main(String[] args) {
TestClass tc = new TestClass();
tc.myMethod();
}
public void myMethod() {
yourMethod();
}
public void yourMethod() {
throw new Exception();
}
}
What changes can be done to make the above code compile?
Select 1 option(s):
Change declaration of main to :
public static void main(String[] args) throws Exception
Change declaration of myMethod to
public void myMethod throws Exception
Change declaration of yourMethod to
public void yourMethod throws Exception
Change declaration of main and yourMethod to :
public static void main(String[] args) throws Exception and
public void yourMethod throws Exception
Change declaration of all the three method to include throws Exception.
None
Q40. 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(); }
}
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
Q41. Given:
abstract class Vehicle{ }
interface Drivable{ }
class Car extends Vehicle implements Drivable{ }
class SUV extends Car { }
Which of the following options will compile?
Select 2 option(s):
ArrayList< Vehicle > al1 = new ArrayList< >();
SUV s = al1.get(0);
ArrayList< Drivable > al2 = new ArrayList<>();
Car c1 = al2.get(0);
ArrayList< SUV > al3 = new ArrayList<>();
Drivable d1 = al3.get(0);
ArrayList< SUV > al4 = new ArrayList<>();
Car c2 = al4.get(0);
ArrayList< Vehicle > al5 = new ArrayList<>();
Drivable d2 = al5.get(0);
Q42. What will the following code most likely print when compiled and run?
List names = Arrays.asList("greg", "dave", "don", "ed", "fred" );
Map data = names.stream().collect(Collectors.groupingBy(
String::length,
Collectors.counting()) );
System.out.println(data.values());
Select 1 option(s):
[1, 1, 3]
[1, 2, 3]
[2, 3, 4]
["greg", "dave", "don", "ed", "fred"]
The data variable should be declared of type Map for the code to compile.
None
Q43. Assume that dt refers to a valid java.util.Date object and that df is a reference variable of class DateFormat.
Which of the following code fragments will print the country and the date in the correct local format?
Select 1 option(s):
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance(l);
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt, l));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = new Locale();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
None
Q44. Given that c:\temp\pathtest is a directory that contains several directories. Each sub directory contains several files but there is exactly one regular file named test.txt within the whole directory structure.
Which of the given options can be inserted in the code below so that it will print complete path of test.txt?
try{
Stream s = null;
INSERT CODE HERE
s.forEach(System.out::println);
}catch(IOException ioe){
ioe.printStackTrace();
}
Select 1 option(s):
s = Files.list(Paths.get("c:\\temp\\pathtest\\**\\test.txt"));
s = Files.walk(Paths.get("c:\\temp\\pathtest"), "test.txt");
s = Files.find(Paths.get("c:\\temp\\pathtest"),
Integer.MAX_VALUE, (p, a)->p.endsWith("test.txt")&& a.isRegularFile());
s = Files.find(Paths.get("test.txt"));
s = Files.list(Paths.get("c:\\temp\\pathtest"),
(p, a)->p.endsWith(".txt")&&a.isRegularFile());
s = Files.walk(Paths.get("c:\\temp\\pathtest"),
(p, a)->p.endsWith(".txt")&&a.isRegularFile());
None
Q45. Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?
abstract class Bang{
// abstract void f(); // LINE 0
final void g(){}
// final void h(){} // LINE 1
protected static int i;
private int j;
}
final class BigBang extends Bang{
// BigBang(int n) { m = n; } // LINE 2
public static void main(String args[]){
Bang mc = new BigBang();
}
// @Override // LINE 3
void h(){}
// void k(){ i++; } // LINE 4
// void l(){ j++; } // LINE 5
int m;
}
Consider each line independently.
Select 1 option(s):
abstract void f( ) ; //(0)
final void h( ) { } //(1)
BigBang(int n) { m = n; } //(2)
@Override //(3)
void k( ) { i++; } //(4)
void l( ) { j++; } //(5)
None
Q46. Given that listOfWords points to a List of words, which of the following code snippets will create a list of two letter words?
Select 3 option(s):
List< String > list2 = listOfWords.stream().filter(s->s.length()==2)
.parallel().collect(Collectors.toList());
List< String > list2 = listOfWords.stream().parallel().filter(s->s.length()==2)
.collect(Collectors.toList());
List< String > list2 = listOfWords.parallel().filter(s->s.length()==2)
.collect(Collectors.toList());
List< String > list2 = null;
listOfWords.stream().filter(s->s.length()==2).parallel().collect(list2);
var list2 = new ArrayList< String >();
listOfWords.parallelStream().forEach(
s->{ if(s.length()==2) { synchronized(list2){list2.add(s);} } });
Q47. Given:
public class Book {
private String title;
private String genre;
public Book(String title, String genre){
this.title = title; this.genre = genre;
}
//accessors not shown
}
and the following code:
List books = Arrays.asList(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
Reader r = b->{
System.out.println("Reading book "+b.getTitle());
};
books.forEach(x->r.read(x));
What would be a valid definition of Reader for the above code to compile and run without any error or exception?
Select 2 option(s):
abstract class Reader{
abstract void read(Book b);
}
abstract class Reader{
void read(Book b);
}
@FunctionalInterface
interface Reader{
void read(Book b);
default void unread(Book b){ }
}
interface Reader{
default void read(Book b){ }
void unread(Book b);
private void doSomethingelse(){ }
}
@FunctionalInterface
interface Reader{
default void read(Book b){ System.out.println("Default read");};
}
Q48. Given:
public static void main(String[] args) {
String str = "10";
int iVal = 0;
Double dVal = 0.0;
try{
iVal = Integer.parseInt(str, 2); //1
if((dVal = Double.parseDouble(str)) == iVal){ //2
System.out.println("Equal");
}
}catch(NumberFormatException e){
System.out.println("Exception in parsing");
}
System.out.println(iVal+" "+dVal);
}
What is the result?
Select 1 option(s):
Compilation failure at //1.
Compilation failure at //2.
Exception in parsing
0 0.0
Exception in parsing
10 0.0
Equal
10 10.0
10 10.0
2 10.0
Exception in parsing
2 0.0
None
Q49. Identify the right declaration for 'box' for the following code.
import java.util.*;
class Dumper {
// declaration for box
public void dumpStuff(){
for(List l : box.values()){
System.out.println(l);
}
}
}
Select 2 option(s):
List< String > box = new ArrayList< String >();
Map< List< String > > box = new TreeMap< List< String > >();
Map< String, List< String > > box = new HashMap< String, List< String > >();
LinkedList< String > box = new LinkedList< String >();
HashMap< ?, List< String > > box = new HashMap< String, List< String > >();
HashMap< ?, List< String > > box = new HashMap< ?, List< String > >();
Q50. What will the following program print when run?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[] ){ A b = new B("good bye"); }
}
class A{
A() { this("hello", " world"); }
A(String s) { System.out.println(s); }
A(String s1, String s2){ this(s1 + s2); }
}
class B extends A{
B(){ super("good bye"); };
B(String s){ super(s, " world"); }
B(String s1, String s2){ this(s1 + s2 + " ! "); }
}
Select 1 option(s):
It will print "good bye".
It will print "hello world".
It will print "good bye world".
It will print "good bye" followed by "hello world".
It will print "hello world" followed by "good bye".
None
Q51. Given that daylight Savings Time starts on March 13th, 2022 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 3 AM. In other words, 1 minute after 1.59AM, the clock goes to 3.00 AM instead of 2 AM), what will the following code print?
LocalDateTime ld1 = LocalDateTime.of(2022, Month.MARCH, 13, 2, 0);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2022, Month.MARCH, 13, 3, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));
long x = ChronoUnit.HOURS.between(zd1, zd2);
System.out.println(x);
Select 1 option(s):
1
-1
0
2
-2
It will not compile.
None
Q52. Given that New York is 3 hours ahead of Los Angeles, what will the following code print?
LocalDateTime ldt = LocalDateTime.of(2022, 12, 02, 6, 0, 0);
ZonedDateTime nyZdt = ldt.atZone(nyZone);
ZonedDateTime laZdt = ldt.atZone(laZone);
Duration d = Duration.between(nyZdt, laZdt);
System.out.println(d);
Select 1 option(s):
PT0S
PT3H
PT-3H
PT0H
None
Q53. What will be the output when the following code is compiled and run?
class Person implements Serializable{
private String name;
Person(String name){
this.name = name;
System.out.print("Person ");
}
public String toString(){ return name; }
}
class Student extends Person{
public String school;
public Student(String name, String school){
super(name);
this.school = school;
System.out.print("Student ");
}
public String toString(){
return super.toString()+" "+school;
}
}
public class SerialTest {
public static void main(String[] args) throws Exception {
Person p = new Student("Bob Dylan", "NYU");
try(
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("c:\\temp\\student.ser"));
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream("c:\\temp\\student.ser"));
){
oos.writeObject(p);
oos.flush();
System.out.println((Person)ois.readObject());
}
}
}
Select 1 option(s):
Person Student null NYU
Person Student Student Person Bob Dylan NYU
Student Person Person Student Bob Dylan NYU
Person Student Person Student null null
Person Student Bob Dylan NYU
Person Student null null
None
Q54. Given:
class InternalException extends RuntimeException {
public InternalException(String message) {
super (message);
}
}
class ExternalException extends Exception{
public ExternalException (String message) {
super (message);
}
}
class MicroService implements AutoCloseable{
private String name;
public MicroService(String name){
this.name = name;
System.out.println(name+" started");
}
public void availService(String name) {
if (!this.name.equals(name)) {
throw new InternalException ("Unknown service "+name);
}
}
@Override
public void close() throws ExternalException {
if (name.equals("X")) {
throw new ExternalException("Can't close X service");
}
System.out.println(name+" closed");
}
public static void main(String[] args) {
try(MicroService ms = new MicroService("X")){
ms.availService("test");
}
catch(Exception e){
System.out.println(e);
}
}
}
What will be the result?
Select 1 option(s):
This code will produce the same output if catch(Exception e) is replaced by catch(InternalException|ExternalException e) in the main method.
A no-args constructor must be added to InternalException and ExternalException classes.
This code will produce the same output if catch(Exception e) is replaced by catch(InternalException e) in the main method.
It will print:
X started
Exception: Unknown service test
It will print:
X started
ExternalException: Can't close X service
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