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 1
Welcome to your Standard Tests - Unique Test 1 : 2025
Name
Email
Phone
Q1. Which of the following are valid module definitions?
Select 1 option(s):
//In file module.java:
module autos{
}
//In file autos.java:
module autos{
}
//In file module-info.java:
module autos{
}
//In file module-info.java:
module cars{
exports com.car;
}
module trucks{
requires cars;
}
//In file module-info.java:
module-info autos{
}
//In file module-info.java:
sealed module autos{
}
None
Q2. What will be the output of the following program:
public class TestClass{
public static void main(String args[]){
try{
m1();
}catch(IndexOutOfBoundsException e){
System.out.println("1");
throw new NullPointerException();
}catch(NullPointerException e){
System.out.println("2");
return;
}catch (Exception e) {
System.out.println("3");
}finally{
System.out.println("4");
}
System.out.println("END");
}
static void m1(){
System.out.println("m1 Starts");
throw new IndexOutOfBoundsException( "Big Bang " );
}
}
Select 3 option(s):
The program will print m1 Starts.
The program will print m1 Starts, 1 and 4, in that order.
The program will print m1 Starts, 1 and 2, in that order.
The program will print m1 Starts, 1, 2 and 4 in that order.
END will not be printed.
Q3. What will be the output of the following code?
List numbers = new ArrayList();
numbers.addAll(List.of(-2, -1, 19, 2, 111) );
Comparator cmp = (n1, n2)->n1.toString().compareTo(n2.toString());
Collections.sort(numbers, cmp);
System.out.println(
Collections.binarySearch(numbers, 111)+" "+
Collections.binarySearch(numbers, 19, cmp) );
Select 1 option(s):
< undefined result >, 3
-1, -1
2, < undefined result >
0, 0
< undefined result >, < undefined result >
2, 3
None
Q4. Replace XXX with a declaration such that the following code will compile without any error or warning.
public void m1(XXX list)
{
Number n = list.get(0);
}
Select 1 option(s):
List< ? super Number >
List< ? >
List< ? extends Number >
List< Number extends ? >
List< Number super ? >
None
Q5. Consider the following code...
class MyException extends Exception {}
public class TestClass{
public void myMethod() throws XXXX{
throw new MyException();
}
}
What can replace XXXX?
Select 3 option(s):
MyException
Exception
No throws clause is necessary
Throwable
RuntimeException
Q6. What will the following code print when compiled and run?
import java.time.*;
import java.time.format.*;
public class DateTest{
public static void main(String[] args){ //1
LocalDateTime greatDay = LocalDateTime.parse("2022-01-01");//2
String greatDayStr = greatDay.format(DateTimeFormatter.ISO_DATE_TIME); //3
System.out.println(greatDayStr);//4
}
}
Select 1 option(s):
//1 will not compile because of lack of throws clause.
//2 will not compile because of invalid date string.
//2 will throw an exception at run time.
It will print 2022-01-01T00:00:00
It will print null.
None
Q7. Given:
class Booby{
}
class Dooby extends Booby{
}
class Tooby extends Dooby{
}
public class TestClass {
Booby b = new Booby();
Tooby t = new Tooby();
public void do1(List dataList){
//1 INSERT CODE HERE
}
public void do2(List dataList){
//2 INSERT CODE HERE
}
}
and the following four statements:
1. b = dataList.get(0);
2. t = dataList.get(0);
3. dataList.add(b);
4. dataList.add(t);
What can be inserted in the above code?
Select 1 option(s):
Statements 1 and 3 can inserted at //1 and Statements 2 and 4 can be inserted at //2.
Statement 4 can inserted at //1 and Statement 1 can be inserted at //2.
Statements 3 and 4 can inserted at //1 and Statements 1 and 2 can be inserted at //2.
Statements 1 and 2 can inserted at //1 and Statements 3 and 4 can be inserted at //2.
Statement 1 can inserted at //1 and Statement 4 can be inserted at //2.
None
Q8. Which of the following code fragments correctly loads a service provider that implements api.BloggerService?
Select 1 option(s):
Iterable< api.BloggerService > bsLoader = ServiceLoader.load(api.BloggerService.class);
api.BloggerService bloggerServiceRef = ServiceLoader.load(api.BloggerService.class);
api.BloggerService bloggerServiceRef = ServiceLoader< api.BloggerService >.load(api.BloggerService.class);
ServiceLoader< api.BloggerService > bsLoader = new ServiceLoader<>(api.BloggerService.class);
api.BloggerService bloggerServiceRef
= java.util.service.Provider.getProvider(api.BloggerService.class);
None
Q9. Which statements 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 void lockTheGates(){
System.out.println("Locking HomeOffice");
}
}
public class TestClass {
public static void main(String[] args) {
Office off = new HomeOffice(); //2
off.lockTheGates();
}
}
Select 1 option(s):
Code for class HomeOffice will cause compilation to fail.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
The code will compile successfully if the lockTheGates method is removed from class HomeOffice.
It will compile fine and print Locking HomeOffice when run.
None
Q10. What will the following code print when compiled and run?
interface Pow{
static void wow(){
System.out.println("In Pow.wow");
}
}
abstract class Wow{
static void wow(){ // LINE 9
System.out.println("In Wow.wow");
}
}
public class Powwow extends Wow implements Pow {
public static void main(String[] args) {
Powwow f = new Powwow();
f.wow();
}
}
Select 2 option(s):
In Wow.wow
In Pow.wow
It will print In Pow.wow if f.wow() is replaced with ((Pow)f).wow();
It will not compile as is.
It will not compile if the line marked //LINE 9 is replaced with:
@Override
static void wow(){
Q11. Given:
//Insert code here
public abstract void draw();
}
//Insert code here
public void draw(){ System.out.println("in draw..."); }
}
Which of the following lines of code can be used to complete the above code?
Select 2 option(s):
sealed class Shape {
and
class Circle extends Shape {
public class Shape {
and
class Circle extends Shape {
abstract Shape {
and
public class Circle extends Shape {
public abstract class Shape {
and
class Circle extends Shape {
@Override
public abstract class Shape {
and
class Circle implements Shape {
public interface Shape {
and
class Circle implements Shape {
@Override
sealed abstract class Shape permits Circle{
and
class Circle extends Shape {
Q12. Consider the following code:
String[] dataList = {"x", "y", "z"};
for (var dataElement : dataList) {
int innerCounter = 0;
while (innerCounter < dataList.length) {
System.out.println(dataElement + ", " + innerCounter);
innerCounter++;
}
}
How many times will the output contain 2?
Select 1 option(s):
0
1
2
3
4
It will fail to compile.
None
Q13. Given:
class T extends Thread
{
public T(String name){ super(name); }
public void run()
{
try{
for(int i=0; i<2; i++){
Thread.sleep(1000);
System.out.println(getName()+" "+getState());
}
}catch(InterruptedException ie){
System.out.println(getName()+" "+getState()+" ");
}
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
T t1 = new T("T1");
t1.start();
T t2 = new T("T2");
t2.start();
Thread.sleep(300);
t1.interrupt();
}
}
Which of the following is a possible output?
Select 2 option(s):
T1 RUNNABLE
T2 RUNNABLE
T2 RUNNABLE
T1 RUNNABLE
T1 RUNNABLE
T2 RUNNABLE
T2 RUNNABLE
T1 RUNNABLE
T2 RUNNABLE
T2 RUNNABLE
T1 TERMINATED
T1 TERMINATED
T2 RUNNABLE
T2 RUNNABLE
T2 RUNNABLE
T1 BLOCKED
T1 TERMINATED
T2 RUNNABLE
Q14. Consider the following class:
public class Student implements Serializable{
public static final long serialVersionUID = 1;
public String name;
public String grade;
public String toString(){ return "["+name+", "+grade+"]"; }
}
An object of this class was created as follows and was serialized to a file c:\temp\bob.ser:
Student s = new Student();
s.name = "bob";
s.grade = "10";
After some time the Student class was changed as follows:
public class Student implements Serializable{
public static final long serialVersionUID = 1;
public String id="S111";
public String name;
public String grade;
public int age=15;
public String toString(){ return "["+id+", "+name+", "+grade+", "+age+"]"; }
}
Now, the serialized file is read back as follows:
FileInputStream fis = new FileInputStream("c:\\temp\\bob.ser");
ObjectInputStream is = new ObjectInputStream(fis);
s = (Student) is.readObject();
is.close();
System.out.println("Loaded "+s);
What will it print?
Select 1 option(s):
It will throw an exception while deserializing the file.
Loaded [null, bob, 10, 0]
Loaded [S111, bob, 10, 15]
It will have unpredicable values for id and age.
None
Q15. What will the following command show?
jdeps --list-deps moduleA.jar
Select 2 option(s):
It will list all the modules on which moduleA depends.
It will list all the packages of all the modules on which moduleA depends.
It will list all the standard JDK modules on which moduleA depends.
It checks whether moduleA.jar contains all the required modules and prints the ones not present.
It will show an error if moduleA requires any other application module.
Q16. Which line will print the string "MUM"?
public class TestClass{
public static void main(String args []){
String s = "MINIMUM";
System.out.println(s.substring(4, 7)); //1
System.out.println(s.substring(5)); //2
System.out.println(s.substring(s.indexOf('I', 3))); //3
System.out.println(s.substring(s.indexOf('I', 4))); //4
}
}
Select 1 option(s):
1
2
3
4
None of these.
None
Q17. Given:
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList al = new ArrayList();
//INSERT CODE HERE
}
}
What can be inserted in the above code so that it can compile without any error?
Select 2 option(s):
al.add(111);
System.out.println(al.indexOf(1.0));
System.out.println(al.contains("string"));
Double d = al.get(al.length);
Q18. Given:
class Data implements Serializable{
int id = 20;
static LocalDate dummyDate = LocalDate.of(2000, 01, 01);
transient LocalDate ld = LocalDate.of(2010, 01, 01);
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
System.out.println("in readObject before " +id+" "+ld);
stream.defaultReadObject();
System.out.println("in readObject after " + id+" "+ld);
ld = dummyDate;
}
public Data(int id, LocalDate ld){
this.id = id; this.ld = ld;
}
public String toString(){
return "Data "+id+" "+ld;
}
}
public class TestClass {
public static void main(String[] args) throws IOException, ClassNotFoundException{
Data d = new Data(10, LocalDate.of(2024, 10, 10));
ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("c:\\temp\\data.ser"));
oos.writeObject(d); oos.close();
ObjectInputStream ois = new ObjectInputStream( new FileInputStream("c:\\temp\\data.ser"));
d = (Data) ois.readObject();
System.out.println(d);
}
}
What will be the output?
Select 1 option(s):
in readObject before 0 null
in readObject after 10 2010-01-01
Data 10 2000-01-01
in readObject before 0 2010-01-01
in readObject after 10 2010-01-01
Data 10 2000-01-01
in readObject before 0 null
in readObject after 10 null
Data 10 2000-01-01
Data 10 2010-01-01
Data 10 null
in readObject before 20 null
in readObject after 10 null
Data 10 2000-01-01
None
Q19. What will be the output of the following program ?
class CorbaComponent{
String ior;
CorbaComponent(){ startUp("IOR"); }
void startUp(String s){ ior = s; }
void print(){ System.out.println(ior); }
}
class OrderManager extends CorbaComponent{
OrderManager(){ }
void startUp(String s){ ior = getIORFromURL(s); }
String getIORFromURL(String s){ return "URL://"+s; }
}
public class Application{
public static void main(String args[]){ start(new OrderManager()); }
static void start(CorbaComponent cc){ cc.print(); }
}
Select 1 option(s):
It will throw an exception at run time.
It will print IOR
It will print URL://IOR
It will not compile.
None of the above.
None
Q20. Consider the following code:
public class Student {
private Map marksObtained
= new HashMap();
private ReadWriteLock lock = new ReentrantReadWriteLock();
public void setMarksInSubject(String subject, Integer marks){
// 1 INSERT CODE HERE
try{
marksObtained.put(subject, marks);
}finally{
// 2 INSERT CODE HERE
}
}
public double getAverageMarks(){
// valid code that computes average
}
}
What should be inserted at //1 and //2?
Select 1 option(s):
lock.writeLock().acquire();
and
lock.writeLock().release();
lock.writeLock().lock();
and
lock.writeLock().unlock();
lock.acquire();
and
lock.release();
lock.readLock().lock();
and
lock.readLock().unlock();
None
Q21. Consider the following method...
public int setVar(int a, int b, float c) { ...}
Which of the following methods correctly overload the above method?
Select 2 option(s):
public int setVar(int a, float b, int c){
return (int)(a + b + c);
}
public int setVar(int a, float b, int c){
return this(a, c, b);
}
public int setVar(int x, int y, float z){
return x+y;
}
public float setVar(int a, int b, float c){
return c*a;
}
public float setVar(int a){
return a;
}
Q22. Given that Daylight Savings Time ends on Nov 6th 2022 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 1 AM. In other words, one minute after 1.59 AM, the clock shows 1 AM instead of 2 AM.), what will the following code print?
LocalDateTime ld = LocalDateTime.of(2022, Month.NOVEMBER, 6, 1, 30);
ZonedDateTime date1 = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
ZonedDateTime date2 = date1.plusHours(1);
System.out.println( Duration.ofSeconds( date1.getOffset().compareTo(date2.getOffset()))
.toHours() );
Select 1 option(s):
0
1
-1
2
-2
None
Q23. Consider the following array definitions:
int[] array1, array2[];
int[][] array3;
int[] array4[], array5[];
Which of the following are valid statements?
Select 3 option(s):
array2 = array3;
array2 = array4;
array1 = array2;
array4 = array1;
array5 = array3;
Q24. Given:
class Base{
public List transform(List list)
{
return new ArrayList();
}
}
class Derived extends Base{
*INSERT CODE HERE*
}
What can be inserted in the above code?
Select 2 option(s):
public ArrayList< Number > transform(List< Number > list) {
return new ArrayList< Number >();
};
public ArrayList< Object > transform(List< Object > list) {
return new ArrayList< Object >();
};
public < T > ArrayList< T > transform(List< T > list) {
return new ArrayList< T >();
};
public < T > Collection< T > transform(List< T > list) {
return new ArrayList< T >();
};
public < T > Collection< T > transform(Collection< T > list) {
return new HashSet< T >();
};
Q25. Given:
public class Student {
private String name;
private int marks;
//constructor and getters and setters not shown
public void addMarks(int m){
this.marks += m;
}
public void debug(){
System.out.println(name+":"+marks);
}
}
What will the following code print when compiled and run?
List slist = Arrays.asList(new Student("S1", 40),
new Student("S2", 35), new Student("S3", 30));
Consumer increaseMarks = s->s.addMarks(10);
slist.forEach(increaseMarks);
slist.stream().forEach(Student::debug);
Select 1 option(s):
S1:50
S2:45
S3:40
S1:40
S2:35
S3:30
It will not print anything.
It will not compile.
None
Q26. Which code fragments will print the last argument given on the command line to the standard output, and exit without any output or exception stack trace if no arguments are given?
1.
public static void main(String args[ ]){
if (args.length != 0) System.out.println(args[args.length-1]);
}
2.
public static void main(String args[ ]){
try { System.out.println(args[args.length-1]); }
catch (ArrayIndexOutOfBoundsException e) { }
}
3.
public static void main(String args[ ]){
int i = args.length;
if (i != 0) System.out.println(args[i-1]);
}
4.
public static void main(String args[ ]){
int i = args.length-1;
if (i > 0) System.out.println(args[i]);
}
5.
public static void main(String args[ ]){
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}
}
Select 3 option(s):
1
2
3
4
5
Q27. What will the following code print when compiled and run?
List names = Arrays.asList("charles", "chuk", "cynthia", "cho", "cici");
int x = names.stream().filter(name->name.length()>4).collect(Collectors.counting());
System.out.println(x);
Select 1 option(s):
2
3
Exception at run time.
Compilation failure
None
Q28. Which of these array declarations and initializations are NOT legal?
Select 2 option(s):
int[ ] i[ ] = { { 1, 2 }, { 1 }, { }, { 1, 2, 3 } } ;
int i[ ] = new int[2] {1, 2} ;
int i[ ][ ] = new int[ ][ ] { {1, 2, 3}, {4, 5, 6} } ;
int i[ ][ ] = { { 1, 2 }, new int[ 2 ] } ;
int i[4] = { 1, 2, 3, 4 } ;
var i = new int[ ][ ] { {1, 2, 3}, {4, 5, 6} } ;
Q29. You are writing a class named Bandwidth for an internet service provider that keeps track of number of bytes consumed by a user. The following code illustrates the expected usage of this class -
class User{
Bandwidth bw = new Bandwidth();
public void consume(int bytesUsed){
bw.addUsage(bytesUsed);
}
... other irrelevant code
}
class Bandwidth{
private int totalUsage;
private double totalBill;
private double costPerByte;
//add your code here
...other irrelevant code
}
Your goal is to implement a method addUsage (and other methods, if required) in Bandwidth class such that all the bandwidth used by a User is reflected by the totalUsage field and totalBill is always equal to totalUsage*costPerByte. Further, that a User should not be able to tamper with the totalBill value and is also not able to reduce it.
Which of the following implementation(s) accomplishes the above?
Select 1 option(s):
public void addUsage(int bytesUsed){
if(bytesUsed>0){
totalUsage = totalUsage + bytesUsed;
totalBill = totalBill + bytesUsed*costPerByte;
}
}
protected void addUsage(int bytesUsed){
totalUsage += bytesUsed;
totalBill = totalBill + bytesUsed*costPerByte;
}
private void addUsage(int bytesUsed){
if(bytesUsed>0){
totalUsage = totalUsage + bytesUsed;
totalBill = totalUsage*costPerByte;
}
}
public void addUsage(int bytesUsed){
if(bytesUsed>0){
totalUsage = totalUsage + bytesUsed;
}
}
public void updateTotalBill(){
totalBill = totalUsage*costPerByte;
}
None
Q30. What is the result of executing the following fragment of code:
var b1 = false;
var b2 = false;
if (b2 = b1 != b2){
System.out.println("true");
} else{
System.out.println("false");
}
Select 1 option(s):
Compile time error.
It will print true
It will print false
Runtime error.
It will not print anything.
None
Q31. Consider the following code.
import java.time.*;
import java.time.format.*;
public class TestClass
{
public static void main(String[] args) throws Exception
{
LocalDate d = LocalDate.now();
//INSERT CODE HERE
System.out.println(s);
}
}
What should be inserted in the code above so that it will print the date in the following format:
Saturday 1st day of January 2000
Select 1 option(s):
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeeeeeee d'st day of' MMMMMMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeee d"+"st day of"+ "MMMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eee d'st day of' MMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eee d\"st day of\" MMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeee d'st day of' MMMM yyyy");
String s = dtf.format(d);
None
Q32. Given :
interface Process{
public void process(int a, int b);
}
public class Data{
int value;
Data(int value){
this.value = value;
}
}
and the following code fragments:
public void processList(ArrayList
dataList, Process p){
for(Data d: dataList){
p.process(d.value, d.value);
}
}
....
ArrayList
al = new ArrayList
();
al.add(new Data(1));al.add(new Data(2));al.add(new Data(3));
//INSERT METHOD CALL HERE
Which of the following options can be inserted above so that it will print 1 4 9?
Select 3 option(s):
processList(al, a, b->System.out.println(a*b));
processList(al, (int a, int b)->System.out.println(a*b) );
processList(al, (int a, int b)->System.out.println(a*b); );
processList(al, (a, b)->System.out.println(a*b));
processList(al, (a, b) ->{ System.out.println(a*b); } );
Q33. Given:
class LowBalanceException extends ______{ //1
public LowBalanceException(String msg){ super(msg); }
}
class WithdrawalException extends ______{ //2
public WithdrawalException(String msg){ super(msg); }
}
class Account{
double balance;
public void withdraw(double amount) {
try{
throw new LowBalanceException("Not Implemented");
}catch(WithdrawalException e){
throw new RuntimeException(e.getMessage());
}
}
public static void main(String[] args) {
try{
Account a = new Account();
a.withdraw(100.0);
}catch(WithdrawalException e){
System.out.println(e.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What can be inserted in the above code at //1 and //2 so that it will print "Not Implemented" when run?
Select 1 option(s):
WithdrawalException
Exception
WithdrawalException
RuntimeException
Exception
RuntimeException
RuntimeException
Exception
None
Q34. What will be the result of attempting to compile and run the following code?
public class PromotionTest{
public static void main(String args[]){
int i = 5;
float f = 5.5f;
double d = 3.8;
char c = 'a';
if (i == f) c++;
if (((int) (f + d)) == ((int) f + (int) d)) c += 2;
System.out.println(c);
}
}
Select 1 option(s):
The code will fail to compile.
It will print d.
It will print c.
It will print b
It will print a.
None
Q35. A new Java programmer has written the following method that takes an array of ints and sums up all the integers that are less than 100.
public void processArray(int[] values){
int sum = 0;
int i = 0;
try{
while(values[i]<100){
sum = sum +values[i];
i++;
}
}
catch(Exception e){ }
System.out.println("sum = "+sum);
}
Which of the following can be considered a good practice to improve this code?
Select 2 option(s):
Use ArrayIndexOutOfBoundsException for the catch argument.
Use ArrayIndexOutOfBoundsException for the catch argument and add code in the catch block to log or print the exception.
Add code in the catch block to handle the exception.
Use flow control to terminate the loop.
Q36. What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.push(1);
d.offerLast(2);
d.push(3);
d.peekFirst();
d.removeLast();
d.pop();
System.out.println(d);
Select 1 option(s):
1
2
3
Exception at run time.
It will not compile.
None
Q37. Given:
class Game{ }
class Cricket extends Game{ }
class Instrument{ }
class Guitar extends Instrument{ }
interface Player{ void play(E e); }
interface GamePlayer extends Player{ }
interface MusicPlayer extends Player{ }
Identify valid declarations.
Select 1 option(s):
class Batsman implements GamePlayer< Cricket >{
public void play(Game o){ }
}
class Bowler implements GamePlayer< Guitar >{
public void play(Guitar o){ }
}
class Bowler implements Player< Guitar >{
public void play(Guitar o){ }
}
class MidiPlayer implements MusicPlayer {
public void play(Guitar g){ }
}
class MidiPlayer implements MusicPlayer< Instrument > {
public void play(Guitar g){ }
}
None
Q38. Consider the following code:
class A{
public XXX m1(int a){
return a*10/4-30;
}
}
class A2 extends A{
public YYY m1(int a){
return a*10/4.0;
}
}
What can be substituted for XXX and YYY so that it can compile without any problems?
Select 1 option(s):
int, int
int, double
double, double
double, int
Nothing, they are simply not compatible.
None
Q39. Identity correct statements about the following code:
Select 1 option(s)
12345 //order of elements is unpredictable
15342
15314412
Compilation failure
None
Q40. Consider the following program:
public class TestClass{
public static void main(String[] args) {
calculate(2);
}
public static void calculate(int x){
final int TWO = 2;
String val =
switch(x){
case TWO ->
default -> "def";
};
System.out.println(val);
}
}
What will happen if you try to compile and run the program?
Select 1 option(s):
It will compile and print def
It will compile and print null
It will generate compilation error saying val may not have been initialized.
It will not compile because case label TWO is neither followed by an expression nor by a code block.
It will not compile because case labels can't use variables, so case TWO is invalid.
None
Q41. Consider the following code:
interface Bar{
void bar();
default void printBar(){
print("printing");
}
private void showBar(){
print("showing");
}
public static void print(String x){
System.out.println(x+" bar");
};
}
class FooBar implements Bar{
public void bar(){
System.out.println("In foobar");
}
}
public class TestClass {
public static void main(String[] args){
//INSERT CODE HERE
}
}
What can be inserted in the above code?
Select 2 option(s):
FooBar.printBar();
new FooBar().showBar();
FooBar.print("test");
FooBar.bar();
new FooBar().printBar();
Bar.print("test");
new Bar().print("test");
new Bar(){}.printBar();
Q42. What will be the result of attempting to compile and run the following code?
class SwitchTest{
public static void main(String args[]){
for ( var i = 0 ; i < 3 ; i++){ //1
var flag = false;
switch (i){ //2
flag = true; //3
}
if ( flag ) System.out.println( i );
}
}
}
Select 1 option(s):
It will print 0, 1 and 2.
It will not print anything.
Runtime error.
Compilation error at line marked //1.
Compilation error at line marked //2.
Compilation error at line marked //3.
None
Q43. What will the following code print?
public class Test{
public static void testInts(Integer obj, int var){
obj = var++;
obj++;
}
public static void main(String[] args) {
Integer val1 = Integer.valueOf(5);
int val2 = 9;
testInts(val1++, ++val2);
System.out.println(val1+" "+val2);
}
}
Select 1 option(s):
10 9
10 10
6 9
6 10
5 11
None
Q44. Consider the following code:
public class SubClass extends SuperClass{
int i, j, k;
public SubClass( int m, int n ) { i = m ; j = m ; } //1
public SubClass( int m ) { super(m ); } //2
}
Which of the following constructors MUST exist in SuperClass for SubClass to compile correctly?
Select 2 option(s):
It is ok even if no explicit constructor is defined in SuperClass
public SuperClass(int a, int b)
public SuperClass(int a)
public SuperClass()
only public SuperClass(int a) is required.
Q45. What will the following program print?
public class TestClass{
public static void main(String[] args){
for : for(var i = 0; i< 10; i++){
for (var j = 0; j< 10; j++){
if ( i+ j > 10 ) break for;
}
System.out.println( "hello");
}
}
}
Select 1 option(s):
It will print hello 6 times.
It will not compile.
It will print hello 2 times.
It will print hello 5 times.
It will print hello 4 times.
None
Q46. What will happen when the following program is compiled and run?
public class SM{
public String checkIt(String s){
if(s.length() == 0 || s == null){
return "EMPTY";
}
else return "NOT EMPTY";
}
public static void main(String[] args){
SM a = new SM();
System.out.println(a.checkIt(null));
}
}
Select 1 option(s):
It will print EMPTY.
It will print NOT EMPTY.
It will throw NullPointerException.
It will print EMPTY if || is replaced with |.
None
Q47. What will the following code print when run?
import java.util.function.*;
class Employee{
int age;
}
public class TestClass{
public static void main(String[] args) {
Employee e = new Employee();
Supplier se = ()->{ e.age = 40; return e; }; //1
e.age = 50;//2
System.out.println(se.get().age); //3
}
}
Select 1 option(s):
It will fail to compile at line marked //1
It will fail to compile at line marked //3
It will print 40.
It will print 50.
It will throw an exception at run time.
None
Q48. Given:
record Point(int x, int y){};
Identify valid method implementations.
Select 2 option(s):
public boolean testPoint1(Point p){
return switch(p){
case Point(var x, var y) when x>y -> true;
null -> false;
};
}
public boolean testPoint2(Point p){
return switch(p){
case Point(var x, var y) when x>y -> true;
default -> false;
};
}
public boolean testPoint3(Point p){
return switch(p){
case Point(var x, var y) when x>y -> true;
case Point(var x, var y) when x<=y -> false;
};
}
public boolean testPoint5(Point p){
return switch(p){
case Point(var x, var y) when x>y -> true;
case Point(var x, var y) when x<=y -> false;
case null -> false;
};
}
public boolean testPoint4(Point p){
return switch(p){
case Point p1 when p1.x()>p1.y() -> true;
case Point(var x, var y) -> false;
};
}
Q49. Which of the following are benefits of the Java module system?
Select 1 option(s):
It saves application developers from Jar hell.
It improves security and maintainability.
It makes it easier to expose implementation details.
It eliminates the need of making custom runtime linked applications.
None
Q50.Consider the following code:
try(var sp = Files.walk(Path.of("c:\\temp"), 2, FileVisitOption.FOLLOW_LINKS)){
sp.filter(p -> p.getName(p.getNameCount()-1).toString().contains("n"))
.sorted()
.forEach(System.out::println);
}
What will be the output if the directory structure is as follows:
c:\temp\
face.jpg
surnames.txt
documents\
files.txt
pdfs\
new.pdf
Select 1 option(s):
c:\temp\documents
c:\temp\surnames.txt
c:\temp\surnames.txt
c:\temp\documents
c:\temp\documents\pdfs\new.pdf
c:\temp\surnames.txt
c:\temp\documents\pdfs\new.pdf
c:\temp\documents
c:\temp\documents\pdfs\new.pdf
c:\temp\surnames.txt
c:\temp\documents\pdfs\new.pdf
c:\temp\surnames.txt
c:\temp\surnames.txt
c:\temp\documents
None
Q51. Given:
enum Coffee
{
ESPRESSO("Very Strong"), MOCHA("Bold"), LATTE("Mild");
public String strength;
Coffee(String strength)
{
this.strength = strength;
}
public String toString(){ return strength; }
}
Which of the given code snippets will produce the following output:
ESPRESSO:Very Strong, MOCHA:Bold, LATTE:Mild,
Select 1 option(s):
List.of(Coffee.values()).stream().forEach(e->{System.out.print(e+":"+e.value()+", ");});
List.of(Coffee.values()).stream().forEach(e->{System.out.print(e.name()+":"+e+", ");});
Coffee.values().forEach(e->{System.out.print(e.name()+":"+e+", ");});
List.of(Coffee.values()).forEach(e->{System.out.print(e+":"+e.name()+", ");});
Coffee.forEach(e->{System.out.print(e.strength+":"+e.name()+", ");});
None
Q52. Given:
List list = Arrays.asList(-1, 1, 2);
String str = list.stream().collect(Collectors.mapping(v -> ""+Transformer.transform(v), Collectors.joining(" ")));
System.out.println(str);
Which of the following implementations of Transformer enum will cause the above code to print -1 2 1?
Select 1 option(s):
enum Transformer{
DoubleIt( (Integer i) -> i*2 ),
HalfIt( (Integer i) -> i/2 );
UnaryOperator<Integer> op;
Transformer(UnaryOperator<Integer> op){
this.op = op;
}
public static int transform(Integer value){
return switch(value){
case Integer i when i<0 -> i;
case Integer i when i%2==0 -> HalfIt.op.apply(value);
case Integer i when i%2==1 -> DoubleIt.op.apply(value);
};
}
}
enum Transformer{
DoubleIt( (Integer i) -> i*2 ),
HalfIt( (Integer i) -> i/2 );
UnaryOperator<Integer> op;
Transformer2(UnaryOperator<Integer> op){
this.op = op;
}
public static int transform(Integer value){
return Transformer.valueOf(value%2==0?"HalfIt":"DoubleIt").op.apply(value);
}
}
enum Transformer{
DoubleIt( (Integer i) -> i*2 ),
HalfIt( (Integer i) -> i/2 );
UnaryOperator<Integer> op;
Transformer(UnaryOperator<Integer> op){
this.op = op;
}
public static int transform(Integer value){
return switch(value){
case Integer i when i<0 -> i;
case Integer i when i%2==0 -> HalfIt.op.apply(value);
default -> DoubleIt.op.apply(value);
};
}
}
enum Transformer2{
DoubleIt( (Integer i) -> i*2 ),
HalfIt( (Integer i) -> i/2 );
UnaryOperator<Integer> op;
Transformer2(UnaryOperator<Integer> op){
this.op = op;
}
public String toString(){ return this == DoubleIt? "D":"H"; }
public static int transform(Integer value){
if(value>=0){
return Transformer2.valueOf(value%2==0?"H":"D").op.apply(value);
}else{ return value; }
}
}
None
Q53. Identify correct statements about the modular JDK.
Select 4 option(s):
The base module does not depend on any module while every other module depends on the base module.
The set of modules of the modular JDK can be combined to create configurations corresponding to the full Java SE Platform, the full JRE, and the full JDK.
The standard modules of the modular JDK are governed by the Java Community Process while non-standard ones are not.
A standard module may contain a standard or non-standard API package but must not export any non-standard package.
The modularized JDK allows you to create a customized JRE image containing just the parts that are required for a modular or a non-modular application to run.
Q54. Given:
interface Account{
int LIMIT = 100;
public default boolean canWithdraw(int amount){
return false;
}
public static int getBalanceAmount(int amount){
return LIMIT - amount;
}
int makeBid();
String toString();
}
public class VirtualAccount implements Account{
//INSERT CODE HERE
int amount;
public VirtualAccount(int amount){
this.amount = amount;
}
public static void main(String[] args) {
try{
VirtualAccount va = new VirtualAccount(10);
int balance = va.makeBid();
System.out.println("Account Balance : "+va.amount+" Balance: "+balance);
}catch(Exception e){
System.out.println(e);
}
}
}
Which of the following options when inserted in the above code will make the VirtualAccount class correctly implement the Account interface?
Note: You may find a few very long questions in the real exam. Eliminating obviously wrong options quickly will help you save time while attempting such questions.
Select 2 option(s):
@Override
public int makeBid() throws Exception{
if(canWithdraw(amount)){
return Account.getBalanceAmount(amount);
}else{
throw new RuntimeException("Not enough balance");
}
}
@Override
public String toString(){
return "Acct balance "+this.amount+" margin: "+Account.getBalanceAmount(amount);
}
@Override
public int makeBid() throws RuntimeException{
if(canWithdraw(amount)){
return Account.getBalanceAmount(amount);
}else{
throw new RuntimeException("Not enough balance");
}
}
@Override
public int makeBid() throws RuntimeException{
if(canWithdraw(amount)){
return Account.getBalanceAmount(amount);
}else{
throw new Exception("Not enough balance");
}
}
@Override
public String toString(){
return "Acct balance "+this.amount+" margin: "+Account.getBalanceAmount(amount);
}
@Override
public int makeBid() {
if(canWithdraw(amount)){
return Account.getBalanceAmount(amount);
}else{
throw new RuntimeException("Not enough balance");
}
}
@Override
public String toString(){
return "Acct balance "+this.amount+" margin: "+Account.getBalanceAmount(amount);
}
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