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
Blog
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
Blog
Welcome to your Standard Java Test - 5
Name
Email
Phone
1.
Question: Assuming that the following method will always be called with a phone number in the format ddd-ddd-dddd (where d stands for a digit), what can be inserted at //1 so that it will return a String containing the same number except its last four digits will be masked with xxxx?
public static String hidePhone(String fullPhoneNumber){
//1 Insert code here
}
Select 3 option(s)
return new StringBuilder(fullPhoneNumber).substring(0, 8)+"xxxx";
return new StringBuilder(fullPhoneNumber).replace(8, 12, "xxxx").toString();
return new StringBuilder(fullPhoneNumber).append("xxxx", 8, 12).toString();
return new StringBuilder("xxxx").append(fullPhoneNumber, 0, 8).toString();
return new StringBuilder("xxxx").insert(0, fullPhoneNumber, 0, 8).toString();
2.
Question: Consider the following classes:
class Boo {
public Boo(){ System.out.println("In Boo"); }
}
class BooBoo extends Boo {
public BooBoo(){ System.out.println("In BooBoo"); }
}
class Moo extends BooBoo implements Serializable {
int moo = 10; { System.out.println("moo set to 10"); }
public Moo(){ System.out.println("In Moo"); }
}
First, the following code was executed and the file moo1.ser was created successfully:
Moo moo = new Moo();
moo.moo = 20;
FileOutputStream fos = new FileOutputStream("c:\\temp\\moo1.ser");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(moo);
os.close();
Next, the following code was executed.
FileInputStream fis = new FileInputStream("c:\\temp\\moo1.ser");
ObjectInputStream is = new ObjectInputStream(fis);
Moo moo = (Moo) is.readObject();
is.close();
System.out.println(moo.moo);
Which of the following will be a part of the output of the second piece of code?
Select 3 option(s)
In Boo
In BooBoo
In Moo
10
20
moo set to 10
3.
Question: Which of these array declarations and instantiations are legal?
Select 4 option(s)
int[ ] a[ ] = new int [5][4] ;
int a[ ][ ] = new int [5][4] ;
int a[ ][ ] = new int [ ][4] ;
int[ ] a[ ] = new int[4][ ] ;
int[ ][ ] a = new int[5][4] ;
var[ ] a[ ] = new int [5][4] ;
var[ ][ ] a = new int [5][4] ;
4.
Question: Given the following code:
List aList = List.of(40, 30, 20); //1
List bList = List.copyOf(aList); //2
bList.sort((Integer::compare)); //3
System.out.println( bList ); //4
aList.sort((Integer::compare)); //5
System.out.println( aList ); //6
Identify correct statement.
Select 1 option(s)
Line //2 will cause compilation failure.
Lines //3 and //5 will cause compilation failure.
Lines //3 and //5 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Only line //3 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Only line //5 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
There will be no compilation error or exception at runtime, but both the print statements will print unsorted values.
Line //3 will cause an java.lang.UnsupportedOperationException to be thrown at runtime.
Line //5 will not cause any exception at runtime.
Line //6 will print sorted values.
None
5.
Question: Given:
DoubleStream ds = DoubleStream.of(1.0, 2.0, 3.0);
//INSERT CODE HERE
ds.map(doubleF.apply(5.0)).forEach(System.out::println);
Which of the following statements can be inserted in the above code?
Select 1 option(s)
None
6.
Question: Your group has an existing application (reports.jar) that uses a library (analytics.jar) from another group in your company. Both - the application and the library - use a JDBC driver packaged in ojdbc8.jar.
Which of the following options describes the steps that will be required to modularize your application?
Select 1 option(s)
1. Convert analytics.jar and ojdbc8.jar into automatic modules.
2. Convert reports.jar into a named module.
3. Add requires clauses for analytics and ojdbc8 in reports.jar in its module-info.java.
1. Modularize analytics.jar and ojdbc8.jar into modules by adding module-info.java to these jars.
2. Convert reports.jar into a named module.
3. Add requires clauses for all packages contained in analytics.jar and ojdbc8.jar that are directly referred to by classes in reports.jar in its module-info.java.
1. Convert reports.jar into a named module.
2. Add requires clauses for analytics and ojdbc8 modules in reports.jar in its module-info.java.
3. Use analytics.jar and ojdbc8.jar as unnamed modules.
1. Convert ojdbc8.jar into automatic module.
2. Convert analytics.jar into a named module by adding module-info.java to it. In this module-info, export all packages that are used by reports.jar and add requires clauses for all packages of ojdbc.jar that are used by analytics.jar.
3. Convert reports.jar into a named module. Add requires clause for analytics module in reports's module-info.java.
None
7.
Question: What will be written to the standard output when the following program is run?
public class TrimTest{
public static void main(String args[]){
String blank = " "; // one space
String line = blank + "hello" + blank + blank;
line.concat("world");
String newLine = line.trim();
System.out.println((int)(line.length() + newLine.length()));
}
}
Select 1 option(s)
25
24
23
22
None of the above.
None
8.
Question: What will the following code print when compiled and run?
interface Pow{
static void wow(){
System.out.println("In Pow.wow");
}
}
abstract class Wow{
static void wow(){ // LINE 9
System.out.println("In Wow.wow");
}
}
public class Powwow extends Wow implements Pow {
public static void main(String[] args) {
Powwow f = new Powwow();
f.wow();
}
}
Select 2 option(s)
In Wow.wow
In Pow.wow
It will print In Pow.wow if f.wow() is replaced with ((Pow)f).wow();
It will not compile as is.
It will not compile if the line marked //LINE 9 is replaced with:
@Override
static void wow(){
9.
Question: Consider the following code:
public class FileCopier {
public static void copy(String records1, String records2) {
try (
InputStream is = new FileInputStream(records1);
OutputStream os = new FileOutputStream(records2); ) { //1
if(os == null) os = new FileOutputStream("c:\\default.txt"); //2
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) { //3
os.write(buffer, 0, bytesRead);
System.out.println("Read and written bytes " + bytesRead);
}
} catch (IOException e) { //4
e.printStackTrace();
}
}
public static void main(String[] args) {
copy("c:\\temp\\test1.txt", "c:\\temp\\test2.txt");
}
}
Assuming appropriate import statements and the existence of both the files, what will happen when the program is compiled and run?
Select 1 option(s)
The program will not compile because the try statement is used incorrectly.
The program will not compile because the catch clause is used incorrectly.
The program will not compile because line //2 is invalid.
It will compile and run without any error or exception.
None
10.
Question: Given the following code, which of these statements are true?
class TestClass{
public static void main(String args[]){
int k = 0;
int m = 0;
for ( var i = 0; i <= 3; i++){
k++;
if ( i == 2){
// line 1
}
m++;
}
System.out.println( k + ", " + m );
}
}
Select 3 option(s)
It will print 3, 2 when line 1 is replaced by break;
It will print 3, 2 when line 1 is replaced by continue.
It will print 4, 3 when line 1 is replaced by continue.
It will print 4, 4 when line 1 is replaced by i = m++;
It will print 3, 3 when line 1 is replaced by i = 4;
11.
Question: What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.push(1);
d.offerLast(2);
d.push(3);
d.peekFirst();
d.removeLast();
d.pop();
System.out.println(d);
Select 1 option(s)
1
2
3
Exception at run time.
It will not compile.
None
12.
Question: Given that java.lang.String has two overloaded toUpperCase methods - toUpperCase() and toUpperCase(Locale ), consider the following code:
String name = "bob";
String val = null;
//Insert code here
System.out.print(val);
Which of the following code fragments can be inserted in the above code so that it will print BOB?
Select 2 option(s)
Supplier
String
s = name::toUpperCase;
val = s.get();
Supplier
String
s = name::toUpperCase;
val = s.apply();
Function< String > f = name::toUpperCase;
val = f.get();
Function< String > f = name::toUpperCase;
val = f.apply();
Function< String, Locale > f = name::toUpperCase;
val = f.apply();
Only one of the above is correct.
13.
Question: Identify correct statements about the modular JDK.
Select 3 option(s)
The base module does not depend on any module while every other module depends on the base module.
The set of modules of the modular JDK can be combined to create configurations corresponding to the full Java SE Platform, the full JRE, and the full JDK.
The standard modules of the modular JDK are governed by the Java Community Process while non-standard ones are not.
A standard module may contain a standard or non-standard API package but must not export any non-standard package.
14.
Question: Identify the valid for loop constructs assuming the following declarations:
Object o = null;
Collection c = //valid collection object.
int[][] ia = //valid array
Select 2 option(s)
for(o : c){ }
for(final var o2 : c){ }
for(int i : ia) { }
for(Iterator it : c.iterator()){ }
for(int i : ia[0]){ }
15.
Question: Given the following code fragment:
var raf = new RandomAccessFile("c:\\temp\\test.txt", "rwd");
//INSERT CODE HERE
raf.close();
var dis = new DataInputStream(new FileInputStream("c:\\temp\\test.txt"));
String value = dis.readUTF();
System.out.print(value);
dis.close();
Which of the following options can be inserted in the above code so that it will print hello world?
Select 1 option(s)
raf.writeString("hello world");
raf.writeChars("hello world");
raf.writeUTF("hello world");
raf.writeData("hello world");
None
16.
Question: 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 = new Integer(5);
int val2 = 9;
testInts(val1++, ++val2);
System.out.println(val1+" "+val2);
}
}
Select 1 option(s)
10 9
10 10
6 9
6 10
5 11
None
17.
Question: Consider the following code...
class MyException extends Exception {}
public class TestClass{
public void myMethod() throws XXXX{
throw new MyException();
}
}
What can replace XXXX?
Select 3 option(s)
MyException
Exception
No throws clause is necessary
Throwable
RuntimeException
18.
Question: What will the following class print ?
class Test{
public static void main(String[] args){
int[][] a = { { 00, 01 }, { 10, 11 } };
int i = 99;
try {
a[val()][i = 1]++;
} catch (Exception e) {
System.out.println( i+", "+a[1][1]);
}
}
static int val() throws Exception {
throw new Exception("unimplemented");
}
}
Select 1 option(s)
99 , 11
1 , 11
1 and an unknown value.
99 and an unknown value.
It will throw an exception at Run time.
None
19.
Question: Identify the correct statements about the following code:
import java.util.*;
import java.util.function.*;
class Account {
private String id;
public Account(String id){ this.id = id; }
//accessors not shown
}
public class BankAccount extends Account{
private double balance;
public BankAccount(String id, double balance){ super(id); this.balance = balance;}
//accessors not shown
public static void main(String[] args) {
Map myAccts = new HashMap();
myAccts.put("111", new Account("111"));
myAccts.put("222", new BankAccount("111", 200.0));
BiFunction bif =
(a1, a2)-> a2 instanceof BankAccount?new BankAccount(a1, 300.0):new Account(a1); //1
myAccts.computeIfPresent("222", bif);//2
BankAccount ba = (BankAccount) myAccts.get("222");
System.out.println(ba.getBalance());
}
}
Select 1 option(s)
It will not compile due to code at //1.
It will not compile due to code at //2.
It will print 200.0
It will print 300.0
None
20.
Question: You are designing a class that will cache objects. It should be able to store and retrieve an object when supplied with an object identifier.
Further, this class should work by tracking the "last accessed times" of the objects. Thus, if its capacity is full, it should remove only the object that hasn't been accessed the longest.
Which collection class would you use to store the objects?
Select 1 option(s)
HashSet
ArrayList
LinkedHashMap
LinkedList
TreeMap
None
21.
Question: Given:
List dList = Arrays.asList(10.0, 12.0);
dList.stream().forEach(x->{ x = x+10; });
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
22.
Question: Assume that dt refers to a valid java.util.Date object and that df is a reference variable of class DateFormat.
Which of the following code fragments will print the country and the date in the correct local format?
Select 1 option(s)
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance(l);
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt, l));
Locale l = Locale.getDefault();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
Locale l = new Locale();
DateFormat df = DateFormat.getDateInstance();
System.out.println(l.getCountry()+" "+ df.format(dt));
None
23.
Question: Which of the following code fragments will successfully initialize a two-dimensional array of chars named cA with a size such that cA[2][3] refers to a valid element?
1.
char[][] cA = { { 'a', 'b', 'c' }, { 'a', 'b', 'c' } };
2.
char cA[][] = new char[3][];
for (int i=0; i<cA.length; i++) cA[i] = new char[4];
3.
char cA[][] = { new char[ ]{ 'a', 'b', 'c' } , new char[ ]{ 'a', 'b', 'c' } };
4
char cA[3][2] = new char[][] { { 'a', 'b', 'c' }, { 'a', 'b', 'c' } };
5.
char[][] cA = { "1234", "1234", "1234" };
6.
var cA[][] = new char[3][];
for (var i=0; i<cA.length; i++) cA[i] = new char[4];
Select 1 option(s)
1, 3
4, 5
2, 3
1, 2, 3
2, 6
2
1, 3, 6
2, 3, 6
None
24.
Question: Consider the contents of following two files:
//In file A.java
package a;
public class A{
A(){ }
public void print(){ System.out.println("A"); }
}
//In file B.java
package b;
import a.*;
public class B extends A{
B(){ }
public void print(){ System.out.println("B"); }
public static void main(String[] args){
new B();
}
}
What will be printed when you try to compile and run class B?
Select 1 option(s)
It will print A.
It will print B.
It will not compile.
It will compile but will not run.
None of the above.
None
25.
Question: Consider the following class...
class TestClass{
int i;
public TestClass(int i) { this.i = i; }
public String toString(){
if(i == 0) return null;
else return ""+i;
}
public static void main(String[ ] args){
TestClass t1 = new TestClass(0);
TestClass t2 = new TestClass(2);
System.out.println(t2);
System.out.println(""+t1);
}
}
What will be the output when the above program is run?
Select 1 option(s)
It will throw NullPointerException when run.
It will not compile.
It will print 2 and then will throw NullPointerException.
It will print 2 and null.
None of the above.
None
26.
Question: Consider the following classes...
class Teacher{
void teach(String student){
/* lots of code */
}
}
class Prof extends Teacher{
//1
}
Which of the following methods can be inserted at line //1 ?
Select 4 option(s)
public void teach() throws Exception
private void teach(int i) throws Exception
protected void teach(String s)
public final void teach(String s)
public abstract void teach(String s)
27.
Question: 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
28.
Question: What will happen when the following code is compiled and run?
class AX{
static int[] x = new int[0];
static{
x[0] = 10;
}
public static void main(String[] args){
var ax = new AX();
}
}
Select 1 option(s)
It will throw NullPointerException at runtime.
It will throw ArrayIndexOutOfBoundsException at runtime.
It will throw ExceptionInInitializerError at runtime.
It will not compile.
None
29.
Question: Given:
List l1 = Arrays.asList("a", "b");
List l2 = Arrays.asList("1", "2");
Which of the following lines of code will print the following output?
a
b
1
2
Select 1 option(s)
Stream.of(l1, l2).forEach((x)->System.out.println(x));
Stream.of(l1, l2).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));
Stream.of(l1, l2).flatMap((x)->x.stream()).forEach((x)->System.out.println(x));
Stream.of(l1, l2).flatMap((x)->x.iterator()).forEach((x)->System.out.println(x));
None
30.
Question: 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
31.
Question: Given:
public class Book {
private String title;
private String genre;
public Book(String title, String genre){
this.title = title; this.genre = genre;
}
//accessors and toString code not shown
}
and the following code:
var books = new ArrayList(List.of(new Book("The Outsider", "fiction"),
new Book("Becoming", "non-fiction"),new Book("Uri", "non-fiction")));
books.sort(Comparator.comparing(Book::getGenre).thenComparing(Book::getTitle).reversed());
System.out.println(books);
What will be the result?
Select 1 option(s)
[non-fiction:Uri, non-fiction:Becoming, fiction:The Outsider]
[non-fiction:Becoming, non-fiction:Uri, fiction:The Outsider]
[fiction:The Outsider, non-fiction:Becoming, non-fiction:Uri]
[fiction:The Outsider, non-fiction:Uri, non-fiction:Becoming ]
[non-fiction:Becoming, fiction:The Outsider, non-fiction:Uri]
The code will fail to compile.
None
32.
Question: Given:
List strList = Arrays.asList("a", "aa", "aaa");
Function f = x->x.length();
Consumer c = x->System.out.print("Len:"+x+" ");
Predicate p = x->"".equals(x);
strList.forEach( *INSERT CODE HERE* );
What can be inserted in the code above?
Select 1 option(s)
f
c
p
c and p
All of the above.
None of the above.
None
33.
Question: Given:
HashMap hm = new HashMap();
hm.put(1, "a"); hm.put(2, "b"); hm.put(3, "c");
Which of the following statements will print the keys as well as values contained in the map?
Select 1 option(s)
hm.forEach((key, entry)->System.out.println(entry));
hm.forEach(System.out.println("%d %s"));
hm.forEach((key, value)->System.out.printf("%d %s ", key, value));
hm.forEach(System.out::println);
hm.forEach(entry->System.out.println(entry));
None
34.
Question: Given the follow two module definitions:
module author{
requires serviceapi;
uses api.BloggerService;
}
and
module abc.blogger{
requires serviceapi;
provides api.BloggerService with abc.SimpleBlogger;
}
Identify correct statement(s).
Select 2 option(s)
api.BloggerService should be defined in author module.
api.BloggerService should be defined in abc.blogger module.
api.BloggerService should be defined in serviceapi module.
abc.blogger module should be on --module-path while executing author module but is not required while compiling.
author module should be on --module-path while executing abc.blogger module but is not required while compiling.
35.
Question: You want to use a third party JDBC driver for a database. Which of the following actions must you take to retrieve a Connection using that driver in your JDBC program?
Select 2 option(s)
Put the driver jar in the class path.
Load the driver class using Class.forName
Create an instance of the Driver class using the new keyword.
Retrieve a connection using DriverManager.getConnection.
Load the driver class using Class.forName and then retrieve a connection using DriverManager.getConnection.
36.
Question: What will the following code print when compiled and run?
//imports not shown
class Movie{
static enum Genre {DRAMA, THRILLER, HORROR, ACTION };
private Genre genre;
private String name;
private char rating = 'R';
Movie(String name, Genre genre, char rating){
this.name = name; this.genre = genre; this.rating = rating;
}
//accessors not shown
}
public class FilteringStuff {
public static void main(String[] args) {
List movies = Arrays.asList(
new Movie("Titanic", Movie.Genre.DRAMA, 'U'),
new Movie("Psycho", Movie.Genre.THRILLER, 'U'),
new Movie("Oldboy", Movie.Genre.THRILLER, 'R'),
new Movie("Shining", Movie.Genre.HORROR, 'U')
);
movies.stream()
.filter(mov->mov.getRating()=='R')
.peek(mov->System.out.println(mov.getName()))
.map(mov->mov.getName());
}
}
Select 1 option(s)
It will not print anything.
Titanic
Psycho
Oldboy
Oldboy
Shining
Oldboy
Oldboy
Oldboy
It will throw an exception at run time.
None
37.
Question: Given:
public class Book{
String isbn;
String title;
public Book(String isbn, String title){
this.isbn = isbn;
this.title = title;
}
//accessors not shown
//assume appropriate implementations of equals and hashCode based on isbn property
}
and the following code snippet:
List books = getBooksByAuthor("Ludlum");
books.stream().sorted().forEach(b->System.out.println(b.getIsbn())); //1
Assuming that getBooksByAuthor is a valid method that returns a List of Books, which of the following statements is/are true?
Select 1 option(s)
Compilation failure at //1.
It will throw an exception at run time due to code at //1.
It will print isbns of the books in sorted fashion.
It will print isbns of the books but NOT in sorted fashion.
None
38.
Question: What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
var b = false;
var i = 1;
do{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
Select 1 option(s)
The code will fail to compile, 'while' has an invalid condition expression.
It will compile but will throw an exception at runtime.
It will print 3.
It will go in an infinite loop.
It will print 1.
None
39.
Question: Consider the following code:
class Bond
{
String ticker; double coupon; java.time.LocalDate maturity;
}
class Portfolio implements Serializable
{
String accountName;
Bond[] bonds;
}
public class TestClass {
public static void main(String[] args) throws Exception{
Portfolio portfolio = // get portfolio somehow
// serialize portfolio
}
}
Which of the following approaches can be taken independent of each other so that a Portfolio object can be serialized while preserving the state of the Bond objects contained in Portfolio?
Select 2 option(s)
It can be serialized as it is without any modification.
Just have Bond class implement Serializable.
Just make 'bonds' field in Portfolio transient.
Change the type of bonds from Bond[] to ArrayList<Bond> bonds;
Make bonds array transient in Portfolio and implement readObject(ObjectInputStream os) and writeObject(ObjectOutputStream os) methods to read and write the state of Bond objects explicitly.
40.
Question: What will the following code print when compiled and run?
(Assume that MySpecialException is an unchecked exception.)
1. public class ExceptionTest {
2. public static void main(String[] args) {
3. try {
4. doSomething();
5. } catch (MySpecialException e) {
6. System.out.println(e);
7. }
8. }
9.
10. static void doSomething() {
11. int[] array = new int[4];
12. array[4] = 4;
13. doSomethingElse();
14. }
15.
16. static void doSomethingElse() {
17. throw new MySpecialException("Sorry, can't do something else");
18. }
}
Select 1 option(s)
It will not compile.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: 4
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:12)
at ExceptionTest.main(ExceptionTest.java:4)
Exception in thread "main" MySpecialException: Sorry, can't do something else
at ExceptionTest.doSomethingElse(ExceptionTest.java:17)
at ExceptionTest.doSomething(ExceptionTest.java:13)
at ExceptionTest.main(ExceptionTest.java:4)
None
41.
Question: Given:
List ls = Arrays.asList(11, 11, 22, 33, 33, 55, 66);
Which of the following expressions will return true?
Select 2 option(s)
42.
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
43.
Question: This following code appears in a file named VehicleType.java. Why would it not compile?
//In file VehicleType
package objective1;
public enum VehicleType
{
SUV, SEDAN, VAN, SPORTSCAR;
public VehicleType()
{
}
}
Select 1 option(s)
VehicleType's definition cannot be public.
VehicleType's constructor cannot be public.
Package statement is invalid for VehicleType.
VehicleType must be defined as a class instead of enum since it is the only definition in the file.
None
44.
Question: Consider the following program:
class Game {
public void play() throws Exception {
System.out.println("Playing...");
}
}
class Soccer extends Game {
public void play(String ball) {
System.out.println("Playing Soccer with "+ball);
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Game g = new Soccer();
// 1
Soccer s = (Soccer) g;
// 2
}
}
Which of the given options can be inserted at //1 and //2?
Select 2 option(s)
It will not compile as it is.
It will throw an Exception at runtime if it is run as it is.
g.play(); at //1 and s.play("cosco"); at //2
g.play(); at //1 and s.play(); at //2
g.play("cosco"); at //1 and s.play("cosco"); at //2
45.
Question: Given:
public @interface Authors {
Author[] value();
String team() default "enthuware";
}
@Repeatable(Authors.class)
public @interface Author {
int id() default 0;
String[] value();
}
Identify correct usages of the above annotations.
Select 2 option(s)
class TestClass{
@Authors(value=@Author("bob"), team="java")
String value;
}
@Authors(value=@Author("bob"), team="java")
@Author("alice")
void someMethod(int index){
}
@Author(value="alice", team="networking")
class TestClass{
}
@Authors(team="database")
@Author(value="alice")
void someMethod(int index){
}
@Author(1, null)
void someMethod(int index){
}
46.
Question: 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
47.
Question: Given:
public class Book{
private String title;
private Double price;
public Book(String title, Double price){
this.title = title;
this.price = price;
}
//accessor methods not shown
}
What will the following code print when compiled and run?
Book b1 = new Book("Java in 24 hrs", 30.0);
Book b2 = new Book("Thinking in Java", null);
Supplier s1 = b1::getPrice;
System.out.println(b1.getTitle()+" "+s1.get());
Supplier s2 = b2::getPrice;
System.out.println(b2.getTitle()+" "+s2.getAsDouble());
Select 1 option(s)
Java in 24 hrs 30.0
< exception stack trace >
Java in 24 hrs 30.0
Thinking in Java 0.0
< exception stack trace >
It will not compile.
None
48.
Question: Given:
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
}
Identify correct statements.
Select 2 option(s)
An exception will be thrown at runtime if p2 is a symbolic link.
If p2 is a symbolic link, then that link, and not the target of that link, will be replaced .
If p1 is a symbolic link, then the final target of the link is copied to p2.
An exception will be thrown at runtime if either of p1 or p2 is a symbolic link.
Result is OS dependent if either of p1 or p2 is a symbolic link.
49.
Question: Given the following code:
Transaction t1 = new Transaction(1, 2); //1
Transaction t2 = new Transaction(1, "2"); //2
It is required that //1 must compile and //2 must NOT compile. Which of the following declarations of class Transaction will satisfy the requirement?
Select 1 option(s)
public class Transaction
T, S extends T
{
public Transaction(T t, S s){
}
}
public class Transaction
T, S super T
{
public Transaction(T t, S s){
}
}
public class Transaction< T, S< T > > {
public Transaction(T t, S s){
}
}
public class Transaction< T, S > {
public Transaction(T t, S s){
}
}
It is not possible to define such a class.
None
50.
Question: Given:
import java.util.*;
public class EventProcessor{
public void processEvents(Collection c){
c.forEach(o -> System.out.println(o));
}
}
class MapEventProcessor extends EventProcessor{
public void processEvents(Map events){
*INSERT CODE HERE*
}
}
Which of the following options can be inserted in the above code without compilation error?
Select 2 option(s)
super.processEvents(events.values());
super.processEvents(events);
events.forEach( (k, v)->processEvents(v));
processEvents(events.values());
processEvents(new List(events.values));
51.
Question: Your application includes a method that generates a report using Employee data. While generating the report, if this method detects inconsistent payment records, it cannot generate the report. You want to create a new exception class that should be thrown in this situation. Which of the following is a valid implementation for this exception?
Select 1 option(s)
public class ReconciliationException extends Throwable{
}
public class ReconciliationError extends Error{
}
public class ReconciliationException extends Exception{
}
public class ReconciliationException {
}
None
52.
Question: What will the following code print when compiled and run?
Stream values = IntStream.rangeClosed(10, 15).boxed(); //1
Object obj = values.collect(Collectors.partitioningBy(x->x%2==0)); //2
System.out.println(obj);
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
{[11, 13, 15], [10, 12, 14]}
[[11, 13, 15], [10, 12, 14]]
{false=[11, 13, 15], true=[10, 12, 14]}
None
53.
Question: Given:
public class Movie{
private String title;
private String genre;
public Movie(String title, String genre){
this.title = title;
this.genre = genre;
}
//accessors not shown
}
and
Stream sm = Stream.of(new Movie("a1", "a"), new Movie("a2", "a"), new Movie("b1", "b"), new Movie("c1", null));
Which of the following code fragments will get the number of movies that do not belong to any genre (i.e. where genre is null)?
Select 1 option(s)
None
54.
Question: Given:
public class TestClass
{
public static void main(String[] args) {
String s = "/usr/home1/test.txt";
String d = "/usr/home2/test.txt";
//INSERT CODE HERE
}catch(Exception e){ }
}
}
Which of the following code fragments can be inserted in the above code so that the file test.txt can be moved to the destination location even if a file by the same name already esists at the destination location?
Select 1 option(s)
try{
Files.move(Paths.get(s), Paths.get(d), StandardCopyOption.CREATE_NEW);
Files.delete(Paths.get(s));
try{
Files.move(Paths.get(s), Paths.get(d), StandardCopyOption.REPLACE_EXISTING);
try(FileChannel in = new FileInputStream(s).getChannel();
FileChannel out = new FileOutputStream(d).getChannel()){
in.transferTo(0, in.size(), out);
}catch(Exception e){
}
try{
Files.move(Paths.get(s), Paths.get(d));
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
Blog
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
Blog
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US