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
Java Test 21 – 2024
Welcome to your Java Test 21 - 2024
Name
Email
Phone
Q1. Which of the following are valid module definitions?
You had to 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{
}
Module definition must start with module keyword, not module-info.
//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 " );
}
}
You had to 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. 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);
}
You had to select 1 option(s)
None
Q4. Consider the following code...
class MyException extends Exception {}
public class TestClass{
public void myMethod() throws XXXX{
throw new MyException();
}
}
What can replace XXXX?
You had to select 3 option(s)
MyException
Exception
Because Exception is a superclass of MyException.
No throws clause is necessary
Throwable
RuntimeException
Q5. The following code snippet will print 4.
int i1 = 1, i2 = 2, i3 = 3;
int i4 = i1 + (i2=i3 );
System.out.println(i4);
You had to select 1 option(s)
True
False
None
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
}
}
You had to 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. Which of the following code fragments correctly loads a service provider that implements api.BloggerService?
You had to select 1 option(s)
None
Q8. What will the following code print when compiled and run?
class ABCD{
int x = 10;
static int y = 20;
}
class MNOP extends ABCD{
int x = 30;
static int y = 40;
}
public class TestClass {
public static void main(String[] args) {
System.out.println(new MNOP().x+", "+new MNOP().y);
}
}
You had to select 1 option(s)
10, 40
30, 20
10, 20
30, 40
20, 30
Compilation error.
None
Q9. Given:
StringBuilder sb = new StringBuilder("abcdef");
//INSERT CODE HERE
for(int i = 0, k = sb.length(); i<k; i++){
sb.replace(i, i+1, f.apply(sb.charAt(i)));
}
System.out.println(sb);
Which of the following statements can be inserted in the above code?
You had to select 1 option(s)
None
Q10. 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();
}
}
You had to 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
Q11. 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();
}
}
You had to 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(){
Q12. 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?
You had to 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 {
Q13. 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?
You had to select 1 option(s)
0
1
2
3
4
It will fail to compile.
None
Q14. 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?
You had to 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
Q15. What will be printed by the following code if it is run with command line: java TestClass -0.50 ?
public class TestClass{
public static double getSwitch(String str){
return Double.parseDouble(str.substring(1, str.length()-1) );
}
public static void main(String args []){
switch(getSwitch(args[0])){
case 0.0 -> System.out.println("Hello");
case 1.0 -> { System.out.println("World"); break; }
default -> System.out.println("Good Bye");
}
}
}
You had to select 1 option(s)
Hello
World
Hello World
Hello World Good Bye
The code will not compile because the type of the switch selector expression is invalid.
The code will not compile because the usage of break is invalid.
None
Q16. 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?
You had to 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
Q17. What will the following command show?
jdeps --list-deps moduleA.jar
You had to 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.
Q18. What will the following code print?
Stream ss = Stream.of("a", "b", "c");
String str = ss.collect(Collectors.joining(",", "-", "+"));
System.out.println(str);
You had to select 1 option(s)
-a+,-b+,-c+
a,-+b,-+c
-a,b,c+
It will throw an exception at run time.
None
Q19. 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
  }
}
Â
You had to select 1 option(s)
1
2
3
4
None of these.
None
Q20. 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?
You had to 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);
Q21. 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(); }
}
You had to 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
Q22. You are using a RDBMS database from a company named Fandu Tech. It provides a JDBC 4.0 compliant driver implementation in class com.fandu.sql.Driver.
Which of the following lines of code is/are required to get the driver loaded?
You had to select 1 option(s)
Connection c = DriverManager.getConnection("jdbc:fandu://localhost:1234/myDB", "user", "pwd");
(Assume that the parameters are valid.)
Class.forName("com.fandu.sql.Driver");
This is required for JDBC 1.3 and older versions. Not for JDBC 4.0.
com.fandu.sql.Driver d = com.fandu.sql.Driver.class.newInstance()
DriverManager.loadDriver("com.fandu.sql.Driver");
None of the above.
None
Q23. 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?
You had to 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
Q24. Consider the following method...
public int setVar(int a, int b, float c) { ...}
Which of the following methods correctly overload the above method?
You had to 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;
}
Q25. Given:
public class Book {
private String title;
private LocalDate releaseDate;
public Book(String title, LocalDate releaseDate){
this.title = title; this.releaseDate = releaseDate;
}
//accessors not shown
}
and the following code:
var books = new ArrayList( List.of(
new Book("The Outsider", LocalDate.of(2019, 1, 1)),
new Book("Becoming", LocalDate.of(2018, 1, 1)),
new Book("Uri", LocalDate.of(2017, 1, 1))) );
Predicate p =
b->b.getReleaseDate()
.isAfter(IsoChronology.INSTANCE.date(2018, 1, 1));
Set newBooks = books.stream().
INSERT CODE HERE
What can be inserted in the code above so that newBooks will be assigned a set of books that were released after the date indicated by the predicate p?
You had to select 3 option(s)
.collect(Collectors.partitioningBy(p))
.get(true).stream().map(Book::getTitle).collect(Collectors.toCollection(TreeSet::new));
.collect(Collectors.partitioningBy(p))
.get(true).stream().map(Book::getTitle).collect(Collectors.toSet());
.collect(Collectors.partitioningBy(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
.collect(Collectors.groupingBy(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
.collect(Collectors.filtering(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
Q26. Given that daylight Savings Time ends on Nov 6th 2021 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(2021, 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() );
You had to select 1 option(s)
1
2
-1
-2
None
Q27. Consider the following array definitions:
int[] array1, array2[];
int[][] array3;
int[] array4[], array5[];
Which of the following are valid statements?
You had to select 3 option(s)
array2 = array3;
array2 = array4;
array1 = array2;
array4 = array1;
array5 = array3;
Q28. Given the following class:
public class SpecialPicker{
public K pickOne(K k1, K k2){
return k1.hashCode()>k2.hashCode()?k1:k2;
}
}
what will be the result of running the following lines of code:
SpecialPicker sp = new SpecialPicker(); //1
System.out.println(sp.pickOne(1, 2).intValue()+1); //2
You had to select 1 option(s)
The first line of code will not compile.
The second line of code will not compile.
It will throw an exception at run time.
It will print 3.
None
Q29. 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?
You had to select 2 option(s)
Q30. 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);
You had to 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
Q31. 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) {}
}
You had to select 3 option(s)
1
2
3
4
5
Q32. 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);
You had to select 1 option(s)
2
3
Exception at run time.
Compilation failure
None
Q33. Which of these array declarations and initializations are NOT legal?
You had to 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} } ;
Q34. 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?
You had to select 1 option(s)
None
Q35. 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");
}
You had to select 1 option(s)
Compile time error.
It will print true;
It will print false;
Runtime error.
It will print nothing.
None
Q36. 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
You had to 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
Q37. 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?
You had to select 3 option(s)
Q38. 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?
You had to select 1 option(s)
WithdrawalException
Exception
WithdrawalException
RuntimeException
Exception
RuntimeException
RuntimeException
Exception
None
Q39. 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);
}
}
You had to 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
Q40. 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?
You had to 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.
Q41. 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);
You had to select 1 option(s)
1
2
3
Exception at run time.
It will not compile.
None
Q42. 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.
You had to select 1 option(s)
None
Q43. 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?
You had to select 1 option(s)
int, int
int, double
double, double
double, int
Nothing, they are simply not compatible.
None
Q44. Identity correct statements about the following code:
You had to select 1 option(s)
12345 //order of elements is unpredictable
15342
15314412
Compilation failure
None
Q45. 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?
You had to 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
Q46. 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 );
}
}
}
You had to 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
Q47. 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);
}
}
You had to select 1 option(s)
10 9
10 10
6 9
6 10
5 11
None
Q48. Consider the following code :
Connection connection = dataSource.getConnection();
PreparedStatement stmt = connection.prepareStatement(
"select * from CUSTOMER where EMAILID=?");
stmt.setObject(1, "bob@gmail.com"); //LINE 10
ResultSet rs = stmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString("EMAILID")); //LINE 12
}
connection.close();
Assuming that the query returns exactly 1 row, what will be printed when this code is run?
(Assume that items not specified such as import statements, DB url, and try/catch block are all valid.)
You had to select 1 option(s)
It will throw an exception at //LINE 12.
Compilation will fail due to //Line 12
It will print bob@gmail.com
It will print bob@gmail.com and then throw an exception.
None
Q49. 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?
You had to 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.
Q50. Consider the following code snippet:
Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample",
"app", "app");
try(Statement stmt = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);)
{
stmt.setMaxRows(5);
ResultSet rs = stmt.executeQuery("""
select customer_id from customer order by customer_id""")
rs.absolute(5);
if(rs.next()){
System.out.println(rs.getString(1));
}
}
catch(SQLException e){
e.printStackTrace();
}
Given that the query returns 5 rows with customer ids ranging from 1 to 5 (in that order), what will the above code print?
You had to select 1 option(s)
5
It will not print anything.
It will print an exception stack trace at runtime.
1
None
Q51. 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");
}
}
}
You had to 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
Q52. 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));
}
}
You had to 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
Q52. 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
}
}
You had to select 1 option(s)
It will fail to compile at line marked //1
It will fail to compile at line marked //3
No reason for any failure here.
It will print 40.
It will print 50.
It will throw an exception at run time.
None
Q54. Which of the following are benefits of the Java module system?
You had to 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
Q55. 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,
You had to 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
Time's up
Time is Up!
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US