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 Code 1Z 829
Welcome to your Java Test - 13
Name
Email
Phone
1.
Question: What will the following code print?
public class Test{
public static void stringTest(String s){
s.replace("h", "s");
}
public static void stringBuilderTest(StringBuilder s){
s.append("o");
}
public static void main(String[] args){
String s = "hell";
StringBuilder sb = new StringBuilder("well");
stringTest(s);
stringBuilderTest(sb);
System.out.println(s + sb);
}
}
Select 1 option(s)
sellwello
hellwello
hellwell
sellwell
None of these.
None
2.
Question: What will be the output when the following program is run?
public class TestClass{
char c;
public void m1(){
char[ ] cA = { 'a' , 'b'};
m2(c, cA);
System.out.println( ( (int)c) + "," + cA[1] );
}
public void m2(char c, char[ ] cA){
c = 'b';
cA[1] = cA[0] = 'm';
}
public static void main(String args[]){
new TestClass().m1();
}
}
Select 1 option(s)
Compile time error.
,m
0,m
b,b
b,m
None
3.
Question: Which of the following are valid code snippets appearing in a method:
Select 3 option(s)
var a = b = c = 100;
var a = 100, b = 10;
var a = b;
int a, b, c=100;
int a=100, b, c;
int a = 100 = b = c;
int a = b = c = 100;
int a, b, c; a = b = c = 100;
4.
Question: What will the following code print when compiled and run?
List values = Arrays.asList("Java EE", "C#", "Python");
boolean flag = values.stream().allMatch(str->{
System.out.println("Testing: "+str);
return str.equals("Java");
});
System.out.println(flag);
Select 1 option(s)
Testing: Java EE
false
Testing: Java EE
Testing: C#
Testing: Python
false
Testing: Java EE
true
It will not compile because lambda expression is built incorrectly.
None
5.
Question: Which of the following lines will cause the compilation to fail?
interface I { }
public enum EnumA implements I, Serializable { A, AA, AAA}; //1
class TestClass
{
public enum EnumB{ B, BB, BBB;
public Object clone(){ return B; } //2
}
public static enum EnumC{ C, CC, CCC };
public static enum EnumD extends EnumC{ DDD }; //3
public TestClass()
{
System.out.println(EnumC.CC.index()); //4
}
public static void main(String[] args)
{
System.out.println(EnumC.valueOf("ccc")); //5
System.out.println(EnumC.CCC.name()); //6
System.out.println(EnumC.CCC.ordinal()); //7
}
}
Select 3 option(s)
1
2
3
4
5
6
7
6.
Question: Given:
class Buddy {
public Buddy(){ }
}
public class GCTest
public static void initBuddies(Buddy[] ba){
ba[0] = new Buddy(); //1
ba[1] = new Buddy(); //2
ba[0] = ba[1]; //3
ba[1] = ba[2]; //4
}
public static void main(String[] args) {
Buddy[] ba = new Buddy[3]; //5
initBuddies(ba); //6
//7
}
}
How many Buddy objects will be eligible for garbage collection at line marked //7?
Select 1 option(s)
1
2
3
4
5
0
None
7.
Question: Which of the following illustrates a good coding practice given that the database connection is to be reused?
Select 1 option(s)
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); )
{
while(rs.next()){
//do something with the row
}
}
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); ) {
while(rs.next()){
//do something with the row
}
}
finally{
rs.close();
stmt.close();
}
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); ) {
while(rs.next()){
//do something with the row
}
}
catch(SQLException e){
}
Statement stmt = null;
ResultSet rs = null;
try{
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
//do something with the row
}
}
finally{
rs.close(); stmt.close();
}
None
8.
Question: Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID ?
class Widget{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget(){
//3
}
Widget(int k){
//4
}
}
Select 2 option(s)
Modify lines //1 and //2 as : static int MAX = 111; static final String CLASS_GUID = "XYZ123";
Add the following line just after //2 : static { MAX = 111; CLASS_GUID = "XYZ123"; }
Add the following line just before //1 : { MAX = 111; CLASS_GUID = "XYZ123"; }
Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID = "XYZ123";
Only option 3 is valid.
9.
Question: Your application consists of two jar files produced by two different teams - accounting-3.2.jar and reporting-5.6.jar. Classes in reporting-5.6.jar uses a class com.abc.account.Account in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.=
The accounting team has decided to modularize their jar. Which of the following would be a valid module-info.java for the new accounting-3.3.jar?
Select 1 option(s)
module accounting{
requires com.abc.account;
}
module accounting{
export com.abc.account.*;
}
module accounting{
exports com.abc.account;
}
module accounting{
export com.abc.account;
}
module accounting{
export com.abc.account.Account;
}
module accounting{
provides com.abc.account;
}
None
10.
Question: Consider the following piece of code:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = new Locale("jp", "JP");
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundle files with the following contents:
#In appmessages.properties:
greetings=Hello
#In appmessages_fr_FR.properties:
greetings=bonjour
Given that this code is run on machines all over the world. Which of the following statements are correct?
Select 1 option(s)
It will throw an exception when the default locale of the machine where it is run is different from fr/FR and fr/CA.
It will throw an exception where ever it is run.
It will throw an exception when the default locale of the machine is fr/CA.
It will throw an exception when the default locale of the machine is jp/JP.
It will run without any exception all over the world.
None
11.
Question: Given the following module definitions:
module m${
requires _n;
exports o;
}
module _n{
requires m$;
exports p;
}
Identify the correct statements.
Select 1 option(s)
The definitions are invalid because of circular dependency.
The definitions are invalid because the package names in the export clauses are invalid.
The definitions are invalid because the modules names are invalid.
The definitions are invalid because they don't declare dependency on java.base module.
The definitions are invalid because of circular dependency as well as ommission of requires java.base;.
None
12.
Question: What will the following code print?
public static void main(String[] args) {
Integer x = 3;
switch(x){
case 1, 2 -> System.out.println("A");
case 3, 4 -> System.out.println("B");
default -> System.out.println("C");
}
}
Select 1 option(s)
B
B
C
C
It will not compile.
It will compile but will not print anything.
None
13.
Question: Given a class named Test, which of these would be valid definitions for a constructor for the class?
Select 1 option(s)
Test(Test b) { }
Test Test( ) { }
private final Test( ) { }
void Test( ) { }
public static void Test(String args[ ] ) { }
None
14.
Question: Given:
Map<String , List> stateCitiesMap =
new HashMap<String, List>();
Which of the following options correctly achieves the same or compatible declaration using type inference?
Select 2 option(s)
15.
Question: Which of the statements regarding the given code are correct?
public class Test extends Thread
{
static Object obj1 = new Object();
static Object obj2 = new Object();
public void m1()
{
synchronized(obj1)
{
System.out.print("1 ");
synchronized(obj2)
{
System.out.println("2");
}
}
}
public void m2()
{
synchronized(obj2)
{
System.out.print("2 ");
synchronized(obj1)
{
System.out.println("1");
}
}
}
public void run()
{
m1();
m2();
}
public static void main(String[] args)
{
new Test().start();
new Test().start();
}
}
Select 1 option(s)
It may result in a deadlock and the program might get stuck.
There is no potential for deadlock.
Deadlock may occur but the program will not get stuck as the JVM will resolve the deadlock.
The program will always print 1 2, 2 1, 1 2 and 21
None
16.
Question: What will the following code print when compiled and run?
interface Eatable{
int types = 10;
}
class Food implements Eatable {
public static int types = 20;
}
public class Fruit extends Food implements Eatable{ //LINE1
public static void main(String[] args) {
types = 30; //LINE 2
System.out.println(types); //LINE 3
}
}
Select 1 option(s)
Compilation failure at //LINE 1.
Compilation failure at //LINE 2.
Compilation failure at //LINE 3.
10
20
30
Compilation failure at //LINE 2 as well as at //LINE 3.
None
17.
Question: Consider the following code:
interface Classic {
int version = 1;
public void read() ;
}
class MediaReader implements Classic{
int version = 2;
public void read() {
//Insert code here
}
}
public class ReaderTest{
public static void main(String[] args) {
MediaReader mr = new MediaReader();
mr.read();
}
}
What can be inserted in the code above so that it will print 1 when run?
Select 1 option(s)
System.out.println(version);
System.out.println((Classic)version);
System.out.println(((Classic)this).version);
System.out.println(this.Classic.version);
System.out.println(MediaReader.version);
None
18.
Question: Given:
public class TestClass {
public void myMethod(String... params) {
var a = params;
var b = params[0];
}
}
What are the types of the variables a and b?
Select 1 option(s)
Object[] and Object
String[] and Object
String[] and String
List and Object
List and String
None
19.
Question: What will the following code print when run?
public class TestClass
{
public static void main(String args[])
{
A a = new B();
if( a instanceof B b){
b.b();
}
System.out.println(b);
}
}
class A {
void a(){ System.out.println("a"); }
}
class B extends A {
void b(){ System.out.println("b"); }
}
Select 1 option(s)
Compilation failure
b
null
b
bull
None
20.
Question: Identify correct statements about Java platform module system.
Select 2 option(s)
A module is a set of packages that make sense being grouped together and is designed for reuse.
The module system ensures that code that is internal to a platform implementation is not accessible from outside the implementation.
The module system uses only two phases - compile time and run time - for building an application.
All classes in a module are concealed and cannot be accessed by code from other modules. Only interfaces are visibile outside the package.
21.
Question: Which of the following classes have a default constructor?
class A{ }
class B { B(){ } }
class C{ C(String s){ } }
Select 1 option(s)
A
A and B
B
C
B and C
None
22.
Question: You want to print the date that represents upcoming tuesday from now even if the current day is a tuesday. Which of the following lines of code accomplishe(s) this?
Select 2 option(s)
System.out.println(LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY)));
System.out.println(new LocalDate().with(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(new LocalDate().adjust(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(TemporalAdjusters.next(DayOfWeek.TUESDAY).adjustInto(LocalDate.now()));
23.
Question: Identify the correct statements about ArrayList?
Select 3 option(s)
Standard JDK provides no subclasses of ArrayList.
An ArrayList cannot store primitives.
It allows constant time access to all its elements.
ArrayList cannot resize dynamically if you add more number of elements than its capacity.
An ArrayList is backed by an array.
24.
Question: Which of the following lines of code that, when inserted at line 1, will make the overriding method in SubClass invoke the overridden method in BaseClass on the current object with the same parameter.
class BaseClass{
public void print(String s) { System.out.println("BaseClass :"+s); }
}
class SubClass extends BaseClass{
public void print(String s){
System.out.println("SubClass :"+s);
// Line 1
}
public static void main(String args[]){
SubClass sc = new SubClass();
sc.print("location");
}
}
Select 1 option(s)
this.print(s);
super.print(s);
print(s);
BaseClass.print(s);
None
25.
Question: Consider the directory structure and its contents shown in the figure.
(c:\temp is a directory that contains two text files - test1.txt and text2.txt)
What should be inserted at //Line 10 in the following code so that it will write "hello" to text2.txt?
public static void writeData() throws Exception{
var p1 = Paths.get("c:\\temp\\test1.txt");
var p2 = //LINE 10 - INSERT CODE HERE
var bw = new BufferedWriter(new FileWriter(p2.toFile()));
bw.write("hello");
bw.close();
}
Select 1 option(s)
p1.resolve("text2.txt");
p1.relativize("c:\\temp\\text2.txt");
p1.resolveSibling("text2.txt");
p1.relativize(Paths.get("text2.txt"));
None
26.
Question: What will the following code print when compiled and run?
var numA = new Integer[]{1, 2};
var list1 = List.of(numA);
numA[0] = 2;
var list2 = List.copyOf(list1);
System.out.println(list1+" "+list2);
Select 1 option(s)
It will not compile.
[1, 2] [1, 2]
[2, 2] [1, 2]
[2, 2] [2, 2]
None
27.
Question: Given that the user account under which the following code is run does not have the permission to access a.java, what will the the following code print when run?
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;
public class IOTest {
public static void main(String[] args) {
try(BufferedReader bfr = new BufferedReader(
new FileReader("c:\\works\\a.java"))){
String line = null;
while( (line = bfr.readLine()) != null){
System.out.println(line);
}
}catch(NoSuchFileException|IOException|AccessDeniedException e){
e.printStackTrace();
}
}
}
Select 1 option(s)
It will run without any exception and without any output.
It will print a stack trace for AccessDeniedException.
It will print a stack trace for IOException.
It will print a stack trace for NoSuchFileException.
It will not compile because the catch clause is invalid.
It will not compile because AccessDeniedException is not a valid exception class in java.nio.file package.
None
28.
Question: Given:
abstract class AmazingClass{
void amazingMethod(Collection c){
System.out.println("Got collection");
};
}
public class SpecialAmazingClass extends AmazingClass{
void amazingMethod(List l){
System.out.println("Got list");
};
public static void main(String[] args) {
List al = new ArrayList();
Collection c = al;
AmazingClass ac = new SpecialAmazingClass();
ac.amazingMethod(c);
}
}
What is the output?
Select 1 option(s)
Compilation error
Exception at run time.
got collection
got list
None
29.
Question: Given:
String s1 = "Hello World";
String s2 = """
Hello World""";
String s3 = """
Hello World
""";
System.out.println((s1 == s2)+" "+s2.equals(s3)+" "+s2.intern().equals(s3.intern()));
What is the result?
Select 1 option(s)
true false true
true true true
false true false
true false false
false false false
None
30.
Question: Consider the following code:
class A
{
byte getStatusCode(Object obj) throws NullPointerException
{
if(obj != null ) return 128;
else return -1;
}
}
class B extends A
{
//override getStatusCode method.
}
Which of the following statements are valid?
Select 3 option(s)
Overriding method cannot throw IOException
Overriding method can throw Throwable
class A will not compile as it is.
Overriding method can throw any exception
Overriding method may choose not to throw any exception.
31.
Question: What letters will be printed by this program?
public class ForSwitch{
public static void main(String args[]){
char i;
LOOP: for (i=0;i<5;i++){
switch(i++){
case '0': System.out.println("A");
case 1: System.out.println("B"); break LOOP;
case 2: System.out.println("C"); break;
case 3: System.out.println("D"); break;
case 4: System.out.println("E");
case 'E' : System.out.println("F");
}
}
}
}
Select 2 option(s)
A
B
C
D
F
32.
Question: Which of the following are valid method implementations?
Select 2 option(s)
public void outputText(PrintWriter pw, String text){
try{
pw.write(text);
}catch(IOException e){
System.out.println("exception in writing");
}
}
public void outputText(PrintWriter pw, String text){
pw.write(text);
if(pw.checkError()) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
boolean flag = pw.write(text);
if(!flag) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
pw.printf(text).print("success");
}
public void outputText(PrintWriter pw, String text){
pw.println(text).println("success");
}
33.
Question: What will the following code print when run?
import java.nio.file.Path;
import java.nio.file.Paths;
public class PathTest {
static Path p1 = Paths.get("c:\\finance\\data\\reports\\daily\\pnl.txt");
public static void main(String[] args) {
System.out.println(p1.subpath(0, 2));
}
}
Select 1 option(s)
finance\data
\finance\data\reports
c:\finance\data
c:\finance
None
34.
Question: Given:
Path p = Paths.get("c:\\temp\\out");
try{
var b = Files.deleteIfExists(p);
System.out.println(b);
}catch(Exception e){
e.printStackTrace();
}
Identify correct statements.
Select 1 option(s)
It will print "c:\temp\out" if the file referred to by p is not deleted for any reason.
It will print an exception stack trace if p refers to a directory instead of a file.
It will print an exception stack trace if p refers to an empty file or a non-empty directory.
It will print an exception stack trace the file referred to by p cannot be deleted due to lack of appropriate file permissions.
It will print true if p refers to an empty directory.
None
35.
Question: What will the following code print when compiled and run?
List countries = List.of("US", "UK", "India", "Argentina");
List capitals = List.of("Washington DC", "London", "New Delhi" );
Stream is = IntStream
.range(0, Math.min(countries.size(), capitals.size()))
.mapToObj(i->countries.get(i)+" "+capitals.get(i));
is.forEach(System.out::println);
Select 1 option(s)
It will not compile.
It will throw an exception at run time.
It will not print anything.
US Washington DC
UK London
India New Delhi
US Washington DC
UK London
None
36.
Question: Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){ this.side = length; }
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
double getArea() { return area; }
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
}
}
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 2 option(s)
Make setSide() method private.
Make getArea() method private.
Make side and area fields private.
Make the side field private and remove the area field.
Change getArea method to:
public double getArea(){ return side*side; }
Add a setArea() method.
37.
Question: What will the following code print when compiled and run?
ArrayList als = new ArrayList(List.of("a", "b", "c"));
Set ss = new HashSet();
ss.addAll(als); //1
als.clear(); //2
System.out.println(ss.size());
Select 1 option(s)
It will throw an java.lang.UnsupportedOperationException at //1.
It will throw an java.lang.UnsupportedOperationException at //2.
0
3
None
38.
Question: Which of the changes given in options can be done (independent of each other) to let the following code compile and run without errors when its generateReport method is called?
class SomeClass{
String s1 = "green mile"; // 0
public void generateReport( int n ){
String local; // 1
if( n > 0 ) local = "good"; //2
System.out.println( s1+" = " + local ); //3
}
}
Select 2 option(s)
Replace String at //0 with var.
Insert after line 2 : if(n <= 0) local = "bad";
Move line 1 and place it after line 0.
change line 1 to : final String local = "rocky";
Insert after line 2 : else local = "bad";
The program already is without any errors.
39.
Question: Given:
public class Book {
private String title;
private String genre;
public Book(String title, String genre){
this.title = title; this.genre = genre;
}
//accessors not shown
}
and the following code:
List books = Arrays.asList(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
List genreList = new ArrayList();
//INSERT CODE HERE
System.out.println(genreList);
Which of the following options will correctly make genreList refer to a List containing the genres of the books present in books List?
Select 4 option(s)
books.stream().map(Book::getGenre).forEach(s->genreList.add(s));
genreList = books.stream().map(Book::getGenre).collect(Collectors.toList());
books.stream().map(Book::getGenre).collect(Collectors.toList(genreList));
books.stream().map(Book::getGenre).forEach(genreList::add);
books.stream().map(b->b.getGenre()).forEach(genreList::add);
books.stream().flatMap(b->b.getGenre()).forEach(g->genreList.add(g));
40.
Question: Assume that a method named 'method1' contains code which may raise a non-runtime (checked) Exception.
What is/are the possible way(s) to declare this method so that it indicates that it expects the caller to handle that exception?
Select 2 option(s)
public void method1() throws Throwable
public void method1() throw Exception
public void method1() throw new Exception
public void method1() throws Exception
public void method1()
41.
Question: Given:
public class Student {
public static enum Grade{ A, B , C, D, F}
private String name;
private Grade grade;
public Student(String name, Grade grade){
this.name = name;
this.grade = grade;
}
public String toString(){
return name+":"+grade;
}
//getters and setters not shown
}
What can be inserted in the code below so that it will print:
{C=[S3], A=[S1, S2]}
List ls = Arrays.asList( new Student("S1", Student.Grade.A),
new Student("S2", Student.Grade.A),
new Student("S3", Student.Grade.C));
//INSERT CODE HERE
System.out.println(grouping);
Select 1 option(s)
None
42.
Question: What will the following class print when compiled and run?
class Holder{
int value = 1;
Holder link;
public Holder(int val){ this.value = val; }
public static void main(String[] args){
final var a = new Holder(5);
var b = new Holder(10);
a.link = b;
b.link = setIt(a, b);
System.out.println(a.link.value+" "+b.link.value);
}
public static Holder setIt(final Holder x, final Holder y){
x.link = y.link;
return x;
}
}
Select 1 option(s)
It will not compile because 'a' is final.
It will not compile because method setIt() cannot change x.link.
It will print 5, 10.
It will print 10, 10.
It will throw an exception when run.
None
43.
Question: Which of the following code snippet will print 10 random double values?
Select 3 option(s)
new Random().doubles(10).forEach(System.out::print);
Random r = new Random();
DoubleStream rDoubles = r.generate().limit(10);
rDoubles.forEach(System.out::print);
Random r = new Random();
DoubleStream rDoubles = r.doubles().limit(10);
rDoubles.forEach(System.out::print);
Random r = new Random();
DoubleStream.generate(()->r.nextDouble()).limit(10).forEach(System.out::print);
DoubleStream.generate(Random::nextDouble).limit(10).forEach(System.out::print);
44.
Question: What will the following code print when compiled and run?
public class Paper {
public String title;
public int id;
public Paper(String title, int id){
this.title = title;
this.id = id;
}
public static void main(String[] args) {
var papers = new Paper[]{
new Paper("T1", 1),
new Paper("T2", 2),
new Paper("T3", 3)
};
System.out.println(papers);
System.out.println(papers[1]);
System.out.println(papers[1].id);
}
}
Select 1 option(s)
None
45.
Question: What will the following code print when compiled and run?
class Base{
void methodA(){
System.out.println("base - MethodA");
}
}
class Sub extends Base{
public void methodA(){
System.out.println("sub - MethodA");
}
public void methodB(){
System.out.println("sub - MethodB");
}
public static void main(String args[]){
Base b=new Sub(); //1
b.methodA(); //2
b.methodB(); //3
}
}
Select 1 option(s)
sub - MethodA and sub - MethodB
base - MethodA and sub - MethodB
Compile time error at //1
Compile time error at //2
Compile time error at //3
None
46.
Question: Given:
String[] p = {"1", "2", "3" };
Which of the following lines of code is/are valid?
Select 1 option(s)
None
47.
Question: What will the following program print when compiled and run?
class Boo implements Serializable {
transient int ti = 10;
static int si = 20;
}
public class TestClass
{
public static void main(String[] args) throws Exception
{
Boo boo = new Boo();
boo.si++;
System.out.println(boo.ti+" "+boo.si);
var fos = new FileOutputStream("c:\\temp\\boo.ser");
var os = new ObjectOutputStream(fos);
os.writeObject(boo);
os.close();
var fis = new FileInputStream("c:\\temp\\boo.ser");
var is = new ObjectInputStream(fis);
boo = (Boo) is.readObject();
is.close();
System.out.println(boo.ti+" "+boo.si);
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at run time.
10 21
10 21
10 21
10 20
10 21
0 20
10 21
0 21
None
48.
Question: Consider the following code.
LocalDate d = LocalDate.now();
Locale loc = new Locale("fr", "FR");
// 1 insert code here.
What should be inserted at //1 above so that it will print the date in French format?
Select 1 option(s)
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy", loc);
System.out.println(df.format(d));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d, loc));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
df.setLocale(loc);
System.out.println(df.format(d));
d.setLocale(loc);
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d));
None
49.
Question: What would be the result of compiling and running the following program?
class SomeClass{
public static void main(String args[]){
var size = 10;
var arr = new int[size];
for (var i = 0 ; i < size ; ++i) System.out.println(arr[i]);
}
}
Select 1 option(s)
The code will fail to compile, because the int[] array declaration is incorrect.
The program will compile, but will throw an IndexArrayOutOfBoundsException when run.
The program will compile and run without error, and will print nothing.
The program will compile and run without error and will print null ten times.
The program will compile and run without error and will print 0 ten times.
The code will fail to compile, because the array elements are being accessed without being initialized first.
None
50.
Question: Consider the following code appearing in the same file:
class Data {
int x = 0, y = 0;
public Data(int x, int y){
this.x = x; this.y = y;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d = new Data(1, 1);
//add code here
}
}
Which of the following options when applied individually will change the Data object currently referred to by the variable d to contain 2, 2 as values for its data fields?
Select 2 option(s)
Add the following two statements:
d.x = 2;
d.y = 2;
Add the following statement:
d = new Data(2, 2);
Add the following two statements:
d.x += 1;
d.y += 1;
Add the following statement:
d = d + 1;
51.
Question: Your application consists of two jar files produced by two different teams - accounting-3.2.jar and reporting-5.6.jar. Classes in reporting-5.6.jar uses classes from com.abc.accounts package in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.
The application is currently launched using the following command:
java -classpath accounting-3.2.jar;reporting-5.6.jar com.abc.reporting.Main
The accounting team has decided to modularize the new version of their jar but the reporting team hasn't.
Which of the following commands can be used to launch the reporting application using the new version of accounting jar?
Select 2 option(s)
java -classpath accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java -classpath reporting-5.6.jar --module-path accounting-3.3.jar; com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar
--add-modules accounting
--module reporting/com.abc.reporting.Main
(Assume that the module name in accounting-3.3.jar is accounting.)
52.
Question: Consider the following code snippet:
//INSERT LINE OF CODE HERE
switch( condition ){
case 1 -> System.out.println("1");
case 2 -> System.out.println("2");
case 3 -> System.out.println("3");
}
What type can be inserted in the code above so that the above code compiles and runs as expected ?
Select 2 option(s)
int condition;
long condition = 2;
var condition = new Integer("1");
String condition = "1";
var condition = new Short(1);
Byte condition = 1;
53.
Question: Which of the following code fragments will NOT cause a compilation error when put inside the following code?
public TestClass{
public static void main(String[] args) {
//INSERT CODE HERE
}
}
Select 2 option(s)
var m = 20;
m = "20";
var list = new ArrayList<>();
list.add(20);
list.add("20");
var ex = new Exception();
ex = new java.io.IOException();
var str = null;
Runnable r = new Runnable(){
var str = "hello";
public void run(){
System.out.println(str);
}
};
54.
Question: Consider the following class...
import java.awt.*;
import java.awt.event.*;
class TestFrame extends Frame
{
String s="Message";
public static void main(String args[])
{
var t = new TestFrame();
var b = new Button("press me");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Message is " +s);
}
}
);
t.add(b);
}
}
What will happen when you attempt to compile and run the program?
NOTE: Although this question uses classes from the AWT package, it is not about those class. You may see exam questions referring to classes that are not on the exam objectives. If you see such classes, you can safely assume that the question is not about them.
Select 1 option(s)
It will not compile because the variable s is not accessible from the inner class.
It will compile but not show anything when run.
It will compile and show a very small Frame.
It will compile and show a frame big enough to display the button.
It will not compile because of incorrect usage of var.
None
55.
Question: Which statements, when inserted in the code below, will cause an exception at run time?
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest{
public static void main(String args[]){
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
// insert statement here
}
}
Select 1 option(s)
b = b1;
b2 = b;
b1 = (B1) b;
b2 = (B2) b1;
b1 = (B) b1;
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