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 Standard Test 13 – 2025
Welcome to your Standard Test 13 - 2025
Name
Email
Phone
Q1. A method named winLoseOrTie should accept any object as input and return a String.
If the argument is null or not an Integer it should return "invalid input".
If the argument is greater than 10, it should return "win".
If the argument is less than 10, it should return "lose".
If the argument is equal to 10, it should return "tie".
Which of the following options correctly implement the above requirement?
Select 1 option(s):
String winLoseOrTie(Object obj){
return switch(obj){
case null -> "invalid intput";
case Integer i
when i<10 -> "lose";
case Integer i
when i>10 -> "win";
case Integer i
when i==10 -> "tie";
}; }
String winLoseOrTie(Object obj){
return switch(obj){
case null -> "invalid input";
default -> "invalid input";
case Integer i
when i<10 -> "lose";
case Integer i
when i>10 -> "win";
case Integer i
when i==10 -> "tie";
}; }
String winLoseOrTie(Object obj){
return switch(obj){
case Integer i
when i<10 -> "lose";
case Integer i
when i>10 -> "win";
case Integer i
when i==10 -> "tie";
case null -> "invalid input";
}; }
String winLoseOrTie(Object obj){
return switch(obj){
case Integer i
when i<10 -> "lose";
case Integer i
when i>10 -> "win";
case Integer i
when i==10 -> "tie";
default -> "invalid intput";
}; }
String winLoseOrTie(Object obj){
return switch(obj){
case Integer i
when i<10 -> "lose";
case Integer i
when i>10 -> "win";
case Integer i
when i==10 -> "tie";
case null, default -> "invalid intput";
}; }
None
Q2. What will the following code print?
int[] ia1 = { 0, 1, 4, 5};
int[] ia2 = { 0, 1, 1, 5, 6};
int x = Arrays.compare(ia1, ia2);
int y = Arrays.mismatch(ia1, ia2);
System.out.println(x+" "+y);
Select 1 option(s):
1 2
2 2
1 3
-1 2
-1 -2
None
Q3. Identify the correct statements about the following code fragment:
var fw = new FileWriter("c:\\temp\\test.txt");
var bfw = new BufferedWriter(fw);
bfw.writeUTF("hello"); //1
bfw.newLine(); //2
bfw.write("world"); //3
Select 1 option(s):
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
It will compile but will throw an exception at runtime.
It will write "hello" in UTF encoding, followed by a new line, and then "world" in default encoding to test.txt.
None
Q4. Given:
module abc.blogger {
requires serviceapi;
provides api.BloggerService with abc.SimpleBlogger;
}
Which of the following code fragments appearing in another module correctly loads a service provider that implements api.BloggerService?
Select 1 option(s):
BloggerService blogger = BloggerService.getInstance();
ServiceLoader< BloggerService > bsLoader = ServiceLoader.load(BloggerService.class);
BloggerService bs = bsLoader.findFirst();
api.BloggerService bloggerServiceRef = abc.SimpleBlogger()
api.BloggerService bloggerServiceRef = ServiceLoader.get(abc.SimpleBlogger.class)
ServiceLoader< BloggerService > bsLoader = ServiceLoader.load(BloggerService.class);
bsLoader.forEach(bs->bs.blog("hello"));
(Assuming that BloggerService has a blog(String ) method.)
None
Q5. Which exact exception class will the following class throw when compiled and run?
class Test{
public static void main(String[] args) throws Exception{
int[] a = null;
int i = a [ m1() ];
}
public static int m1() throws Exception{
throw new Exception("Some Exception");
}
}
Select 1 option(s):
NullPointerException
ArrayIndexOutOfBoundsException
Exception
RuntimeException
None
Q6. What will the following code print when run?
public class TestClass {
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "c" : System.out.println( "cat" );
default : System.out.println( "none" );
}
}
public static void main(String[] args) throws Exception {
var tc = new TestClass();
tc.switchString("c");
}
}
Select 1 option(s):
apple
cat
none
apple
cat
cat
none
cat
None
Q7. Given the following module-info:
module book{
requires org.pdf;
uses org.pdf.Print;
}
Which of the following statements are correct?
Select 1 option(s):
book module can be compiled without requiring any module that provides Print service.
At least one implementation of Print service must be available on module-source-path for book module to compile.
At least one implementation of Print service must be available for book module to execute without an exception.
At least one implementation of Print service must be available for book module to load successfully at run time.
The requires org.pdf; clause in the given module-info is redundant.
None
Q8. What will be printed when the following code is compiled and run?
package trywithresources;
import java.io.IOException;
public class Device{
String header = null;
public void open(){
header = "OPENED";
System.out.println("Device Opened");
}
public String read() throws IOException{
throw new IOException("Unknown");
}
public void writeHeader(String str) throws IOException{
System.out.println("Writing : "+str);
header = str;
}
public void close(){
header = null;
System.out.println("Device closed");
}
public static void testDevice(){
try(Device d = new Device()){
d.open();
d.read();
d.writeHeader("TEST");
d.close();
}catch(IOException e){
System.out.println("Got Exception");
}
}
public static void main(String[] args) {
Device.testDevice();
}
}
Select 1 option(s):
Device Opened
Device closed
Got Exception
Device Opened
Got Exception
Device closed
Device Opened
Got Exception
The code will not compile.
None
Q9. What will the following program print?
class Test{
public static void main(String args[]){
var c = 0;
var flag = true;
for(var i = 0; i < 3; i++){
while(flag){
c++;
if(i>c || c>5) flag = false;
}
}
System.out.println(c);
}
}
Select 1 option(s):
3
4
5
6
7
None
Q10. Given:
List dList = Arrays.asList(10.0, 12.0);
DoubleFunction df = x->x+10;
dList.stream().forEach(df);
dList.stream().forEach(d->System.out.println(d));
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
Q11. Given:
package strings;
public class StringFromChar {
public static void main(String[] args) {
String myStr = "good";
char[] myCharArr = {'g', 'o', 'o', 'd' };
String newStr = null;
for(char ch : myCharArr){
newStr = newStr + ch;
}
System.out.println((newStr == myStr)+ " " + (newStr.equals(myStr)));
}
}
What will it print when compiled and run?
Select 1 option(s):
true true
true false
false true
false false
None
Q12. Consider the following class written by a novice programmer.
class Elliptical{
public int radiusA, radiusB;
public int sum = 100;
public void setRadius(int r){
if(r>99) throw new IllegalArgumentException();
radiusA = r;
radiusB = sum - radiusA;
}
}
After some time, the requirements changed and the programmer now wants to make sure that radiusB is always (200 - radiusA) instead of (100 - radiusA) without breaking existing code that other people have written. Which of the following will accomplish his goal?
Select 1 option(s):
Make sum = 200;
Make sum = 200 and make it private.
Make sum = 200 and make all fields (radiusA, radiusB, and sum) private.
Write another method setRadius2(int r) and set radiusB accordingly in this method.
His goal cannot be accomplished.
This class will not compile.
None
Q13. A programmer is using the following class for wrapping objects and passing it around to multiple threads. Which of the given statements regarding this class are correct?
public class DataObjectWrapper
{
private final Object obj;
public DataObjectWrapper(Object pObj){ obj = pObj; }
public Object getObject() { return obj; }
}
Select 1 option(s):
Objects of this class are thread safe but the objects wrapped by this class are not thread safe.
Objects of this class are thread safe but you cannot say anything about the objects wrapped by this class.
Objects of this class are not thread safe.
Objects of this class as well as the objects wrapped by this class are thread safe.
None of these.
None
Q14. Given:
interface Account{
public default String getId(){
return "0000";
}
}
interface PremiumAccount extends Account{
//INSERT CODE HERE
}
Which of the following options can be inserted in PremiumAccount independent of each other?
Select 2 option(s):
static String getId(){
return "1111";
}
String getId();
default String getId(){
return "1111";
}
abstract static String getName();
static String getName();
default String getName();
Q15. What will the following code fragment print when compiled and run?
Statement stmt = null;
Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample",
"app", "app");
try(stmt = c.createStatement();)
{
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
System.out.println(rs.getString(0));
}
}
catch(SQLException e){
System.out.println("Exception ");
}
(Assume that the method in which this code appears has appropriate throws clause.)
Select 1 option(s):
It will throw an exception if the first column of the result is not a String.
It will throw an exception every time it is run irrespective of what the query returns.
It will print the values for the first column of the result and if there is no row in STUDENT table, it will not print anything.
It will not compile.
None
Q16. What can you do to make the following code compile?
public class TestClass {
public static void main(String[] args) {
int[] values = { 10, 20, 30 };
for( /* put code here */ ){
}
}
}
Select 2 option(s):
int k : values
int k in values
var k; k<0; k++
;;
; k<values.length;k++
Q17. Given:
List lon = List.of(1, 2, 3, 4, 5, 6, 7);
Which of the following may return a different value every time it is executed?
Select 1 option(s):
lon.stream().reduce(5, (a, b)->a+b);
lon.stream().reduce(0, Integer::sum) + 5;
lon.parallelStream().reduce(0, Integer::sum) + 5;
lon.parallelStream().reduce(5, Integer::sum);
lon.parallelStream().reduce(Integer::sum).orElse(5)+5
None
Q18. Consider the following code:
//Assume appropriate imports
public class FileCopier {
public static void copy(String records1, String records2) throws IOException {
try (
InputStream is = new FileInputStream(records1);
OutputStream os = new FileOutputStream(records2);) {
var buffer = new byte[1024];
var bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (FileNotFoundException | java.io.InvalidClassException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
copy("c:\\temp\\test1.txt", "c:\\temp\\test2.txt");
}
}
Given that test1.txt exists but test2.txt does not exist, what will happen when the above program is compiled and run?
Select 1 option(s):
The program will not compile.
The program will compile and run without any exception. test2.txt will be created automatically and contents of test1.txt will be copied to it.
The program will compile and run without any exception but test2.txt will not be created.
An exception will be thrown at run time if the size of test1.txt is not a multiple of 1024.
None
Q19. What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
StringBuilder sb = new StringBuilder("12345678");
sb.setLength(5);
sb.setLength(10);
System.out.println(sb.length());
}
}
Select 1 option(s):
It will print 5.
It will print 10.
It will print 8.
Compilation error.
None of the above.
None
Q20. What will be the result of attempting to compile and run the following class?
public class TestClass{
public static void main(String args[ ] ){
int i = 1;
int[] iArr = {1};
incr(i) ;
incr(iArr) ;
System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ;
}
public static void incr(int n ) { n++ ; }
public static void incr(int[ ] n ) { n [ 0 ]++ ; }
}
Select 1 option(s):
The code will print i = 1 iArr[0] = 1
The code will print i = 1 iArr[0] = 2
The code will print i = 2 iArr[0] = 1
The code will print i = 2 iArr[0] = 2
The code will not compile.
None
Q21. Identify the correct statements regarding DateFormat and NumberFormat classes.
Select 1 option(s):
They allow you to format a date or a number into a string but not vice-versa.
You can set the Locale after constructing a DateFormat or a NumberFormat object and before using it to do country specific formatting.
The following line of code will work on a machine in any locale :
double x = 12345.123; String str = NumberFormat.getInstance().format(x);
NumberFormat should not be used for negative values.
None of these.
None
Q22. Consider the following code:
var s = "hello";
byte i = 100;
var fos = new FileOutputStream("c:\\temp\\data.bin");
var dos = new DataOutputStream(fos);
//WRITE s to file
//WRITE i to file
dos.flush(); dos.close(); fos.close();
var dis = new DataInputStream(new FileInputStream("c:\\temp\\data.bin"));
//READ s from file
//READ i from file
Which methods should be used to write and read s and i to/from the data.bin file?
Select 1 option(s):
writeString, writeByte and readString, readByte
writeString, writeInt and readString, readInt
writeChars, writeByte and readChars, readByte
writeUTF, writeByte and readUTF, readByte
writeUTF, writeInt and readUTF, readInt
None
Q23. What will the following code print?
AtomicInteger ai = new AtomicInteger();
Stream stream = Stream.of(
"old", "king", "cole", "was", "a", "merry", "old", "soul")
.parallel();
stream.filter( e->{
ai.incrementAndGet();
return e.contains("o");
}).allMatch(x->x.indexOf("o")>0);
System.out.println("AI = "+ai);
Select 1 option(s):
Any number between 1 to 8
Any number between 0 to 7
Any number between 1 to 6
8
4
None
Q24.Given:
public class Book{
private int id;
private String title;
//constructors and accessors not shown
}
Assuming that book is a reference to a valid Book object, which of the following code fragments correctly prints the details of the Book?
Select 1 option(s)
Consumer< Book > c = b->b.getId()+":"+b.getTitle();
c.accept(book);
Consumer< Book > c = b->System.out.println(b.getId()+":"+b.getTitle());
c.accept(book);
Consumer< Book > c = b->{ String details = b.getId()+":"+b.getTitle();};
c.accept(book);
System.out.println(c);
Consumer< Book > c = System.out::println;
c.accept(book);
None
Q25. Given:
abstract class Vehicle{ }
interface Drivable{ }
class Car extends Vehicle implements Drivable{ }
class SUV extends Car { }
Which of the following options will fail to compile?
Select 1 option(s):
ArrayList< Vehicle > al1 = new ArrayList< >();
al1.add(new SUV());
ArrayList< Drivable > al2 = new ArrayList< >();
al2.add(new Car());
ArrayList< Drivable > al3 = new ArrayList< >();
al3.add(new SUV());
ArrayList< SUV > al4 = new ArrayList< >();
al4.add(new Car());
ArrayList< Vehicle > al5 = new ArrayList< >();
al5.add(new Car());
None
Q26. Given: Daylight Savings Time ends on Nov 6 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, 5, 10, 0);
ZonedDateTime date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
date = date.plus(Duration.ofDays(1));
System.out.println(date);
date = ZonedDateTime.of(ld, ZoneId.of("US/Eastern"));
date = date.plus(Period.ofDays(1));
System.out.println(date);
Select 1 option(s):
2022-11-06T09:00-05:00[US/Eastern]
2022-11-06T09:00-05:00[US/Eastern]
2022-11-06T09:00-05:00[US/Eastern]
2022-11-06T10:00-05:00[US/Eastern]
2022-11-06T10:00-05:00[US/Eastern]
2022-11-06T09:00-05:00[US/Eastern]
2022-11-06T10:00-05:00[US/Eastern]
2022-11-06T10:00-05:00[US/Eastern]
None
Q27. Consider the following code appearing in Eagle.java
class Bird {
private Bird(){ }
}
class Eagle extends Bird {
public String name;
public Eagle(String name){
this.name = name;
}
public static void main(String[] args) {
System.out.println(new Eagle("Bald Eagle").name);
}
}
What can be done to make this code compile?
Select 1 option(s):
Nothing, it will compile as it is.
Make Eagle class declaration public:
public class Eagle extends Bird { ... }
Make the Eagle constructor private:
private Eagle(String name){ ... }
Make Bird constructor public:
public Bird() { ... }
Insert super(); as the first line in Eagle constructor:
public Eagle(String name){
super();
this.name = name;
}
None
Q28. Consider the following classes in one file named A.java:
abstract class A{
protected int m1(){ return 0; }
}
class B extends A{
@Override
int m1(){ return 1; }
}
Which of the following statements are correct.
Select 1 option(s):
The code will not compile as you cannot have more than one class in one file.
The code will not compile because class B does not override the method m1() correctly.
The code will not compile as A is an abstract class but does not have any abstract method.
The code will not compile because @Override annotation is used incorrectly.
The code will compile fine.
None
Q29. Identify correct statement about the following code -
class X{
int val = 10;
}
class Y extends X{
Y val = null; //1
}
public class TestClass extends X{
public static void main(String[] args){
Y y = new Y();
int k = (X) y.val ; //2
System.out.println(k);
}
}
Select 1 option(s):
It will compile and print 10 when run.
It will fail to compile due to line marked //1.
It will fail to compile due to line marked //2.
It will compile but will throw a NullPointerException at line marked //2.
None
Q30. MOVE What is the result of compiling and running the following code ?
public class TestClass{
static int si = 10;
public static void main (String args[]){
new TestClass();
}
public TestClass(){
System.out.println(this);
}
public String toString(){
return "TestClass.si = "+this.si;
}
}
Select 1 option(s):
The class will not compile because you cannot override toString() method.
The class will not compile as si being static, this.si is not a valid statement.
It will print TestClass@nnnnnnnn, where nnnnnnnn is the hash code of the TestClass object referred to by 'this'.
It will print TestClass.si = 10
None of the above.
None
Q31. Given:
import java.util.*;
class Student{
int marks;
}
public class TestClass {
static var getHighest(var students){
int highest = 0;
for(var student : students){
if(highest <student.marks) highest = student.marks;
}
return highest;
}
public static void main(String[] args) {
var student = new Student();
var allStudents = new ArrayList();
allStudents.add(student);
var h = getHighest(allStudents);
System.out.println(h);
}
}
Identify correct statements about the above code.
Select 1 option(s):
It will compile if the getHighest method declaration is changed to:
static var getHighest(ArrayList< Student > students)
It will compile if the getHighest method declaration is changed to:
static int getHighest(var students)
It will compile if allStudents type is changed from var to ArrayList< Student >.
It will compile if the type of h is changed from var to int.
None of the above.
None
Q32. What will the following code print?
import java.util.Optional;
public class NewClass {
public static Optional getGrade(int marks){
Optional grade = Optional.empty();
if(marks>50){
grade = Optional.of("PASS");
}
else {
grade.of("FAIL");
}
return grade;
}
public static void main(String[] args) {
Optional grade1 = getGrade(50);
Optional grade2 = getGrade(55);
System.out.println(grade1.orElse("UNKNOWN"));
if(grade2.isPresent()){
grade2.ifPresent(x->System.out.println(x));
}else{
System.out.println(grade2.orElse("Empty"));
}
}
}
Select 1 option(s):
UNKNOWN
PASS
Optional[UNKNOWN]
PASS
Optional[UNKNOWN]
Optional[PASS]
FAIL
PASS
Optional[FAIL]
OPTIONAL[PASS]
None
Q33. Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 1 option(s):
public List< Integer > getList(){
public List< Object > getList(){
public ArrayList< Number > getList(){
public ArrayList< Integer > getList(){
public ArrayList< Object > getList(){
None
Q34. Consider the following code for the main() method:
public static void main(String[] args) throws Exception{
int i = 1, j = 10;
do {
if (i++ > --j) continue;
} while (i < 5);
System.out.println("i=" + i + " j=" + j);
}
What will be the output when the above code is executed?
Select 1 option(s):
i=6 j=6
i=5 j=6
i=5 j=5
i=6 j=5
None of these.
None
Q35. Given:
class Base{
public Collection transform(Collection list)
{
return new ArrayList();
}
}
class Derived extends Base{
//public Collection transform(Collection list) {
return new HashSet(); }; //1
//public Collection transform(Collection list) {
return new HashSet();}; //2
//public List transform(Collection list) {
return new ArrayList(); }; //3
//public Collection transform(List list) {
return new HashSet(); }; //4
//public Collection transform(List list) {
return new HashSet(); };//5
//public Collection transform(Collection list) {
return new HashSet();}; //6
}
Identify correct statements about the methods defined in Derived assuming they are uncommented one at a time individually.
(Ignore the extra line breaks.)
Select 1 option(s):
//1 correctly overrides the method in Base
//2 correctly overrides the method in Base
//3 correctly overrides the method in Base
//4 correctly overloads the method in Base.
//5 correctly overloads the method in Base
//6 correctly overloads the method in Base.
//4 and //5 can be inserted independently in the code.
None
Q36. Given:
public static void main(String[] args){
FileInputStream tempFis = null;
try(FileInputStream fis = new FileInputStream("c:\\temp\\test.text")){
System.out.println(fis);
tempFis = fis;
}
//line 1
}
Which of the following options can be inserted at //1 independent of each other to make the above code compile?
Select 2 option(s):
finally{ tempFis.close(); }
catch(IOException|NullPointerException e){ }
catch(IOException ioe){ }
catch(IOException|FileNotFoundException e){ }
catch(IOException e){ }
finally{ tempFis.close(); }
Q37. What will the following code print when compiled and run:
class Data {
int intVal = 0;
String strVal = "default";
public Data(int k){
this.intVal = k;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d1 = new Data(10);
d1.strVal = "D1";
Data d2 = d1;
d2.intVal = 20;
System.out.println("d2 val = "+d2.strVal);
}
}
Select 1 option(s):
d2 val =
d2 val = default
d2 val = D1
Exception at run time.
None
Q38. Which of the following statements are correct regarding the module system of Java.
Select 1 option(s):
A module can access all public classes of another module.
A module can access all public classes of another module if it declares that it requires the other module.
A module can access all public classes of another module if those classes are exported by the other module.
A module can access public classes of only those packages of another module that the other module exports.
A module can access another module if both are in the same folder.
None
Q39. Given:
class Base{
public ArrayList transform(Set list){
//valid code
};
}
class Derived extends Base{
*INSERT CODE HERE*
//valid code
}
}
What can be inserted in the above code?
Select 1 option(s):
public List< Number > transform(Set< Integer > list){
public List< Integer > transform(Set< Integer > list){
public ArrayList< ? super Integer > transform(Set< Integer > list){
public ArrayList< ? extends Integer > transform(Set< Integer > list){
public ArrayList< Number > transform(Set list){
None
Q40. What will the following code print?
List s1 = new ArrayList( );
s1.add("a");
s1.add("b");
s1.add("c");
s1.add("a");
System.out.println(s1.remove("a")+" "+s1.remove("x"));
Select 1 option(s):
1 0
2 -1
2 0
1 -1
true false
None
Q41.What will be the result of attempting to compile and run the following code?
Select 1 option(s):
The code will fail to compile.
The program will print str1 and str1.
The program will print str1 and str1str2
The program will print str1str2 and str1
The program will print str1str2 and str1str2.
None
Q42. Given the following definitions and reference declarations:
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
class C3 extends C1 implements I2 { }
C1 o1;
C2 o2;
C3 o3;
Which of these statements are legal?
Select 3 option(s):
class C4 extends C3 implements I1, I2 { }
o3 = o1;
o3 = o2;
I1 i1 = o3; I2 i2 = (I2) i1;
I1 b = o3;
Q43. Assuming the following enum declaration and a variable s of type Switch, identify potentially valid code fragments.
public enum Switch{ ON, OFF }
Select 3 option(s):
if( s == Switch.OFF) { System.out.println("It is off!"); }
if( s.equals(Switch.OFF)) { System.out.println("It is off!"); }
switch(s)
{
case Switch.OFF -> System.out.println("It is off!"); break;
}
switch(s)
{
case OFF : System.out.println("It is off!"); break;
}
while(s)
{
System.out.println("It is off!");
}
switch(s)
{
case Switch.OFF.valueOf() : System.out.println("It is off!"); break;
}
switch(s)
{
case OFF.toString() : System.out.println("It is off!"); break;
}
return switch(s)
{
case OFF -> 1;
};
Q44. What will the following code print when compiled and run?
var strList1 = new ArrayList();
strList1.add("A");
var strList2 = Collections.unmodifiableList(strList1);
strList1.add(null);
System.out.println(strList1+" "+strList2);
strList2.add(null);
System.out.println(strList1+" "+strList2);
Select 2 option(s):
[A, null] [A, null]
[A, null] [A]
It will throw a java.lang.UnsupportedOperationException at run time.
It will throw a java.lang.NullPointerException at run time.
It will not generate any output other than an exception stack trace.
Q45. Which statements about the output of the following programs are true?
public class TestClass{
public static void main(String args[ ] ){
int i = 0 ;
boolean bool1 = true;
boolean bool2 = false;
boolean bool = false;
bool = (bool2 & method1("1")); //1
bool = (bool2 && method1("2")); //2
bool = (bool1 | method1("3")); //3
bool = (bool1 || method1("4")); //4
}
public static boolean method1(String str){
System.out.println(str);
return true;
}
}
Select 2 option(s):
1 will be the part of the output.
2 will be the part of the output.
3 will be the part of the output.
4 will be the part of the output.
None of the above
Q46. What will the following code fragment print?
Path p1 = Paths.get("x\\y");
Path p2 = Paths.get("z");
Path p3 = p1.relativize(p2);
System.out.println(p3);
Select 1 option(s):
x\y\z
\z
..\z
..\..\z
None
Q47. Given:
public int switchTest(byte x){
return switch(x){ //1
case 'b', 'c' -> 10; //2
case -2 -> 20; // 3
case 80, default -> 30; // 4
};
}
What is the result?
Select 1 option(s):
Compilation failure at //1.
Compilation failure at //2.
Compilation failure at //3.
Compilation failure at //4.
Successful compilation.
None
Q48. In the following code, after which statement (earliest), the object originally referred to by the variable s, may be garbage collected ?
1. public class TestClass{
2. public static void main (String args[]){
3. Student s = new Student("Vinny", "930012");
4. s.grade();
5. System.out.println(s.getName());
6. s = null;
7. s = new Student("Vinny", "930012");
8. s.grade();
9. System.out.println(s.getName());
10 s = null;
}
}
public class Student{
private String name, rollNumber;
public Student(String name, String rollNumber) {
this.name = name;
this.rollNumber = rollNumber;
}
//valid setter and getter for name and rollNumber follow
public void grade() {
}
}
Select 1 option(s):
It will not be Garbage Collected till the end of the program.
Line 5
Line 6
Line 7
Line 10
None
Q49. Which of the following methods are available in java.io.Console?
Select 5 option(s):
readPassword
reader
writer
readLine
read
getPassword
format
Q50. You want to use a module built by another team in your company. The name of the module is abc.math.utils and the module is packaged as a jar file named mathutils.jar. The module contains a class named abc.utils.Main.
You want to run this class from the command line. Which of the following commands can be used?
(Assume that the jar file is located in the current directory.)
Select 1 option(s):
java --module-source-path mathutils.jar --module abc.math.utils/abc.utils.Main
java --module-path mathutils.jar --module abc.math.utils/abc.utils.Main
java --module-path mathutils.jar --main-module abc.math.utils
java --module-source-path mathutils.jar --main-class abc.utils.Main
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