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 - 4
Name
Email
Phone
1.
Question: What will be the result of compilation and execution of the following code?
DoubleStream is = DoubleStream.of(0, 2, 4); //1
double sum = is.filter( i->i%2 != 0 ).sum(); //2
System.out.println(sum); //3
Select 1 option(s)
It will print 0.0
It will print 6.0
It will print OptionalDouble[0.0] if line at //2 is replaced with OptionalDouble x = is.sum();
It will not compile.
It will throw an exception at run time.
None
2.
Question: What will the following code fragment print?
Path p1 = Paths.get("photos\\..\\beaches\\.\\calangute\\a.txt");
Path p2 = p1.normalize();
Path p3 = p1.relativize(p2);
Path p4 = p2.relativize(p1);
System.out.println(
p1.getNameCount()+" "+p2.getNameCount()+" "+
p3.getNameCount()+" "+p4.getNameCount());
Select 1 option(s)
6 4 10 10
7 4 11 10
7 3 8 9
6 3 1 1
None
3.
Question: Given:
public static void main(String[] args) {
String str = "10";
int iVal = 0;
Double dVal = 0.0;
try{
iVal = Integer.parseInt(str, 2); //1
if((dVal = Double.parseDouble(str)) == iVal){ //2
System.out.println("Equal");
}
}catch(NumberFormatException e){
System.out.println("Exception in parsing");
}
System.out.println(iVal+" "+dVal);
}
What is the result?
Select 1 option(s)
Compilation failure at //1.
Compilation failure at //2.
Exception in parsing
0 0.0
Exception in parsing
10 0.0
Equal
10 10.0
10 10.0
2 10.0
Exception in parsing
2 0.0
None
4.
Question: Which statements about the following code are correct?
interface House{
public default String getAddress(){
return "101 Main Str";
}
}
interface Bungalow extends House{
public default String getAddress(){
return "101 Smart Str";
}
}
class MyHouse implements Bungalow, House{
}
public class TestClass {
public static void main(String[] args) {
House ci = new MyHouse(); //1
System.out.println(ci.getAddress()); //2
}
}
Select 1 option(s)
Code for interface House will cause compilation to fail.
Code for interface Bungalow will cause compilation to fail.
Code for class MyHouse will cause compilation to fail.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
The code will compile successfully.
None
5.
Question: Given:
public @interface MyArtifact {
int id() default 0;
String name();
}
Which of the following are correct usages of the above annotation?
Select 2 option(s)
@MyArtifact("method")
void someMethod(int index){
}
void someMethod(@MyArtifact(name="param") int index){
}
@MyArtifact("")
public class TestClass{
}
@MyArtifact
public class TestClass{
}
@MyArtifact(id=10, name="class")
public class TestClass{
}
6.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[]){
int x = 0;
labelA: for (var i=10; i<0; i--){
var j = 0;
labelB:
while (j < 10){
if (j > i) break labelB;
if (i == j){
x++;
continue labelA;
}
j++;
}
x--;
}
System.out.println(x);
}
}
Select 1 option(s)
It will not compile.
It will go in infinite loop when run.
The program will write 10 to the standard output.
The program will write 0 to the standard output.
None of the above.
None
7.
Question: Given that Book is a valid class with appropriate constructor and getPrice and getTitle methods that returns a double and a String respectively, consider the following code:
List<List> books = Arrays.asList(
Arrays.asList(
new Book("Windmills of the Gods", 7.0),
new Book("Tell me your dreams",9.0) ),
Arrays.asList(
new Book("There is a hippy on the highway", 5.0),
new Book("Easy come easy go", 5.0)) );
double d = books.stream()
INSERT CODE HERE //1
INSERT CODE HERE //2
.sum();
System.out.println(d);
What can be inserted in the above code so that it will print 26.0?
Select 1 option(s)
None
8.
Question: Consider the following method which is called with an argument of 7, d, where d is some double value:
public void method1(int i, double d){
int j = (i*30 - 2)/100;
POINT1 : for(;j<10; j++){
var flag = false;
while(!flag){
if(d > 0.5) break POINT1;
}
}
while(j>0){
System.out.println(j--);
if(j == 4) break POINT1;
}
}
What will it print?
Select 1 option(s)
It will print 1 and 2.
It will print 1 to N where N depends on the value passed as an argument to the parameter d.
It will not compile.
It will throw an exception at runtime.
None
9.
Question: What will the following code print when compiled and run?
class Test{
public static void main(String args[]){
int c = 0;
A: for(var i = 0; i < 2; i++){
B: for(var j = 0; j < 2; j++){
C: for(var k = 0; k < 3; k++){
c++;
if(k>j) break;
}
}
}
System.out.println(c);
}
}
Select 1 option(s)
7
8
9
10
11
None
10.
Question: What will be the output?
var ca = new char[]{'a', 'b', 'c', 'd'};
var i = 0;
for(var c : ca){
switch(c){
case 'a' : i++;
case 'b' : ++i;
case 'c'|'d' : i++;
}
}
System.out.println("i = "+i);
Select 1 option(s)
Compilation failure.
i = 5
i = 6
i = 7
None
11.
Question: Consider the following code:
public static void findFiles() throws Exception{
Path dir = Paths.get("c:\\temp");
//INSERT CODE HERE
for(Path p : ds){
System.out.println(p);
}
}
catch(Exception e){
e.printStackTrace();
}
}
What should be inserted in the above code so that it will print all the files with extension gif and jpeg?
Select 1 option(s)
try{ DirectoryStream
Path
ds = Files.newDirectoryStream(dir, "*.[gif,jpeg]");
try{ DirectoryStream
Path
ds = Files.newDirectoryStream(dir, "*.{gif,jpeg}");
try{ DirectoryStream
Path
ds = Files.newDirectoryStream(dir, "*.gif,*.jpeg");
try{ DirectoryStream
Path
ds = Files.newDirectoryStream(dir, "gif,jpeg");
None
12.
Question: Which of the following declarations is/are valid inside a static method:
1. bool b = null;
2. boolean b = 1;
3. boolean b = true|false;
4. bool b = (10<11);
5. boolean b = true||false;
6. var b = 10>11;
Select 1 option(s)
1 and 4
2, 3, 5, and 6
2 and 3
3, 5, and 6
5 and 6
3 and 5
1, 4, and 6
None
13.
Question: Given the following interface definition, which definitions are valid?
interface I1{
void setValue(String s);
String getValue();
}
Select 2 option(s)
class A extends I1{
String s;
@Override
void setValue(String val) { s = val; }
String getValue() { return s; }
}
interface I2 extends I1{
void analyse();
}
abstract class B implements I1{
@Override
int getValue(int i) { return 0; }
}
interface I3 implements I1{
void perform_work();
}
abstract class B implements I1{
int getValue(int i) { return 0; }
}
14.
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:\\a\\b\\c");
public static String getValue(){
String x = p1.getName(1).toString();
String y = p1.subpath(1,2).toString();
return x+" : "+y;
}
public static void main(String[] args) {
System.out.println(getValue());
}
}
Select 1 option(s)
\b : \b
b : b
b : b\c\
a : a\b
b : b\c
None
15.
Question: What will be the output if you run the following program?
public class TestClass{
public static void main(String args[]){
int i;
int j;
for (i = 0, j = 0 ; j < 1 ; ++j , i++){
System.out.println( i + " " + j );
}
System.out.println( i + " " + j );
}
}
Select 1 option(s)
0 0 will be printed twice.
1 1 will be printed once.
0 1 will be printed followed by 1 2.
0 0 will be printed followed by 1 1.
It will print 0 0 and then 0 1.
None
16.
Question: What will the following code print when compiled and run?
class X{
public X(){
System.out.println("In X");
}
}
class Y extends X{
public Y(){
super();
System.out.println("In Y");
}
}
class Z extends Y{
public Z(){
System.out.println("In Z");
}
}
public class Test {
public static void main(String[] args) {
Y y = new Z();
}
}
Select 1 option(s)
It will not compile.
In X
In Y
In Z
In Z
In Y
In X
In Y
In X
In Z
In Z
In X
In Y
None
17.
Question: Given the following class which intends to customize the logic for equals method:
class A{
private String s;
//1
public boolean equals(A a){ //override the equals methods
return this.s != null && this.s.equals(a.s);
}
}
Select 2 option(s)
@Override should be applied at //1.
Applying @Override at //1 will cause compilation failure.
There is no need to apply @Override at //1.
A warning will be generated if @Override is not applied at //1.
@SuppressWarnings("override") should be applied at //1.
18.
Question: Consider the following code:
public class TestClass{
public void method(Object o){
System.out.println("Object Version");
}
public void method(java.io.FileNotFoundException s){
System.out.println("java.io.FileNotFoundException Version");
}
public void method(java.io.IOException s){
System.out.println("IOException Version");
}
public static void main(String args[]){
TestClass tc = new TestClass();
tc.method(null);
}
}
What would be the output when the above program is compiled and run? (Assume that FileNotFoundException is a subclass of IOException, which in turn is a subclass of Exception)
Select 1 option(s)
It will print Object Version.
It will print java.io.IOException Version.
It will print java.io.FileNotFoundException Version.
It will not compile.
It will throw an exception at runtime.
None
19.
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:\\main\\project\\Starter.java");
public static String getRoot(){
String root = p1.getRoot().toString();
return root;
}
public static void main(String[] args) {
System.out.println(getRoot());
}
}
Select 1 option(s)
\
c:
c:\
It will print an empty string.
None
20.
Question: Given:
import java.util.*;
class Student{ }
public class TestClass {
var students = new ArrayList(); //1
public static void main(String[] args) {
var student = new Student(); //2
var allStudents = new ArrayList(); //3
allStudents.add(student); //4
for(var s : allStudents){ //5
System.out.println(s);
}
Student s2 = allStudents.get(0); //6
var var = "what?"; //7
}
}
Which lines will cause compilation error?
Select 2 option(s)
//1
//2
//3
//4
//5
//6
//7
21.
Question: What will the following code print when compiled and run?
class StringWrapper {
private String theVal;
public StringWrapper(String str){ this.theVal = str; }
}
public class Tester{
public static void main(String[] args) {
StringWrapper sw = new StringWrapper("How are you?");
StringBuilder sb = new StringBuilder("How are you?");
System.out.println("Hello, "+sw);
System.out.println("Hello, "+sb);
}
}
Select 1 option(s)
Hello, How are you?
Hello, How are you?
Hello, StringWrapper@
hashcode
Hello, How are you?
Hello, How are you?
Hello, StringBuilder@
hashcode
Hello, How are you?
Hello, java.lang.StringBuilder@< hashcode >
Hello, StringWrapper@< hashcode >
Hello, java.lang.StringBuilder@< hashcode >
None
22.
Question: Given:
import java.util.*;
class MyStringComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
int s1 = ((String) o1).length();
int s2 = ((String) o2).length();
return s1 - s2;
}
}
and
static String[] sa = { "d", "bbb", "aaaa" };
Select correct statements.
Select 2 option(s)
This is not a valid Comparator implementation.
Arrays.binarySearch(sa, "cc", new MyStringComparator()); will return -2.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will return 0.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will return -1.
Arrays.binarySearch(sa, "c", new MyStringComparator()); will throw an exception.
23.
Question: What can be inserted in the code below so that it will print UP UP UP?
public class Speak {
public static void main(String[] args) {
Speak s = new GoodSpeak();
INSERT CODE HERE
}
}
class GoodSpeak extends Speak implements Tone{
public void up(){
System.out.println("UP UP UP");
}
}
interface Tone{
void up();
}
Select 2 option(s)
((Tone)s).up();
s.up();
((GoodSpeak)s).up();
(GoodSpeak)s.up();
(Tone)(GoodSpeak)s.up();
24.
Question: Consider the following code:
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class MyCache {
private CopyOnWriteArrayList cal = new CopyOnWriteArrayList();
public void addData(List list){
cal.addAll(list);
}
public int getCacheSize(){
return cal.size();
}
}
Given that one thread calls the addData method on an instance of the above class with a List containing 10 Strings and another thread calls the getCacheSize method on the same instance at the same time, which of the following options are correct?
(Assume that no other calls have been made on the MyCache instance.)
Select 1 option(s)
The getCacheSize call may return any value between 0 and 10.
The getCacheSize call may return either 0 or 10.
The call to getCacheSize will be blocked until the call to addData finishes.
One of the threads may get a ConcurrentModificationException.
None
25.
Question: Consider the following code:
class A{
A() { print(); }
void print() { System.out.print("A "); }
}
class B extends A{
int i = 4;
public static void main(String[] args){
A a = new B();
a.print();
}
void print() { System.out.print(i+" "); }
}
What will be the output when class B is run?
Select 1 option(s)
It will print A 4.
It will print A A.
It will print 0 4.
It will print 4 4.
None of the above.
None
26.
Question: Consider the following code:
//INSERT CODE HERE
a[0][0] = 1;
a[0][1] = 2;
a[1][0] = 3;
a[1][1] = 4;
a[1][2] = 5;
a[1][3] = 6;
What can be inserted independently in the above code so that it will compile and run without any error or exception?
Select 2 option(s)
int[][] a = new int[2][];
int[][] a = new int[2][4];
int[][] a = new int[4][2];
int[][] a = new int[2][];
a[0] = new int[2];
a[1] = new int[4];
int[][] a = new int[4][];
a[0] = new int[2];
a[1] = new int[2];
27.
Question: What will the following code print when run?
String[] sa = { "charlie", "bob", "andy", "dave" };
var ls = new ArrayList(Arrays.asList(sa));
ls.sort((var a, var b) -> a.compareTo(b));
System.out.println(sa[0]+" "+ls.get(0));
Select 1 option(s)
charlie andy
andy charlie
charlie charlie
andy andy
It will throw an exception at run time.
It will not compile.
None
28.
Question: You are creating an acme.accounting module that depends on acme.math module and makes its com.acme.accounting package available to all other modules. Which of the following files correctly defines this module?
Select 1 option(s)
//In file module.java:
module acme.accounting{
requires acme.math;
exports com.acme.accounting;
}
//In file module.java:
module acme.accounting{
requires acme.math.*;
exports com.acme.accounting.*;
}
//In file module.java:
module acme.accounting{
requires acme.math;
exports com.acme.accounting.*;
}
//In file module-info.java:
module-info acme.accounting{
requires acme.math;
exports com.acme.accounting;
}
//In file module-info.java:
module acme.accounting{
requires acme.math;
exports com.acme.accounting.*;
}
//In file module-info.java:
module acme.accounting{
requires acme.math;
exports com.acme.accounting;
}
None
29.
Question: Given:
List dList = Arrays.asList(10.0, 12.0);
dList.forEach(x->{ x = x + 10; });
dList.forEach(x->System.out.println(x));
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
30.
Question: 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
31.
Question: Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList("aa", "aaa", "b", "cc", "ccc", "ddd", "a");
//INSERT CODE HERE
System.out.println(count);
}
}
Which of the following options will correctly print the number of elements that will come before the string "c" if the list were sorted alphabetically?
Select 1 option(s)
None
32.
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
33.
Question: Identify the correct statements about the following code -
IntStream is1 = IntStream.of(1, 3, 5); //1
OptionalDouble x = is1.filter(i->i%2 == 0).average(); //2
System.out.println(x); //3
IntStream is2 = IntStream.of(2, 4, 6); //4
int y = is2.filter( i->i%2 != 0 ).sum(); //5
System.out.println(y); //6
Select 1 option(s)
Compilation failure only at //2.
Compilation failure only at //5.
Compilation failure at //2 and //5.
Successful compilation.
None
34.
Question: A programmer has written the following code for Bond class. The programmer intends this class to be immutable.
class Bond {
private final String isin;
private final double coupon;
private final java.util.Date maturityDate;
private Bond(String isin, double coupon, java.util.Date matDate){
this.isin = isin; this.coupon = coupon; this.maturityDate = matDate;
}
public static Bond build(String isin, double coupon, java.util.Date matDate){
return new Bond(isin, coupon, matDate);
}
public String getIsin(){ return isin; }
public double getCoupon(){ return coupon; }
public java.util.Date getMaturityDate(){ return maturityDate; }
}
Identify correct statement about the above code.
Select 2 option(s)
This class implements all Java SE security guideliness for immutable classes.
Bond class should be made final.
The getter methods should be made final.
The getMaturityDate method should return a clone of maturityDate.
The constructor should create a clone of the Date argument and assign the cloned Date object to maturityDate.
35.
Question: Note: java.time API is not mentioned in the exam objectives. However, some candidates have reported getting a similar question that requires a little bit of knowledge about the java.time.LocalDate class. The information given in the explanation should be sufficient to answer such questions.
Given the following code:
public static void main(String[] args) {
LocalDate d1 = LocalDate.now();
d1.plusDays(10);
LocalDate d2 = d1.minusWeeks(1);
d1 = null;
LocalDate d3 = LocalDate.now().plusYears(3).minusMonths(4);
d2.plusWeeks(5);
d1 = d2;
}
How many objects are created/instantiated by the given code?
Select 1 option(s)
4
5
6
7
8
9
None
36.
Question: Identify correct statement(s) regarding the benefit of using PreparedStatement over Statement.
Select 1 option(s)
PreparedStatement offers protection against SQL injection attacks.
PreparedStatement allows transactions to span across multiple databases.
PreparedStatement allows easier customization of joins at run time.
None
37.
Question: Consider the program shown in exhibit and select the right option(s).
public class TestClass
{
static StringBuffer sb1 = new StringBuffer();
static StringBuffer sb2 = new StringBuffer();
public static void main(String[] args)
{
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb1)
{
sb1.append("X");
synchronized(sb2)
{
sb2.append("Y");
}
}
System.out.println(sb1);
}
}
).start();
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb2)
{
sb2.append("Y");
synchronized(sb1)
{
sb1.append("X");
}
}
System.out.println(sb2);
}
}
).start();
}
}
Select 1 option(s)
It will print XX followed by YY.
It will print XY followed by YX T.
The above code may result in a deadlock and so nothing can be said for sure about the output.
None
38.
Question: Which of the given option when inserted in the code below will make the code print true?
List values = Arrays.asList("Alpha A", "Alpha B", "Alpha C");
//INSERT CODE HERE
System.out.println(flag);
Select 1 option(s)
boolean flag = values.stream().allMatch(str->str.equals("Alpha"));
boolean flag = values.stream().findFirst().get().equals("Alpha");
boolean flag = values.stream().findAny().get().equals("Alpha");
boolean flag = values.stream().anyMatch(str->str.equals("Alpha"));
None of the above.
None
39.
Question: Given that listOfWords points to a List of words, which of the following code snippets will create a list of two letter words?
Select 3 option(s)
40.
Question: Given:
public class Counter{
//1
public void increment(){
//2
}
//other valid code
}
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share an instance of this class and call its increment method. What should be inserted at //1 and //2?
Select 1 option(s)
int count; at //1
AtomicInteger.increment(count); at //2
synchronized int count; at //1
count++ at //2
AtomicInteger count = 0; at //1
count++; at //2
AtomicInteger count = new AtomicInteger(0); at //1
count++; at //2
AtomicInteger count = new AtomicInteger(0); at //1
count.incrementAndGet(); at //2
None
41.
Question: Which of the following code fragments will you use to create an ExecutorService?
Select 2 option(s)
ExecutorService
Executor
Executors
.newSingleThreadExecutor();
.createSingleThreadExecutor();
.getSingleThreadExecutor();
42.
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:\\main\\project\\Starter.java");
public static String getData(){
String data = p1.getName(0).toString();
return data;
}
public static void main(String[] args) {
System.out.println(getData());
}
}
Select 1 option(s)
IllegalArgumentException
ArrayIndexOutOfBoundsException
c:\
c:
main
None
43.
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
44.
Question: What will the following code print when compiled and run?
interface Boiler{
public void boil();
private static void log(String msg){ //1
System.out.println(msg);
}
public static void shutdown(){
log("shutting down");
}
}
interface Vaporizer extends Boiler{
public default void vaporize(){
boil();
System.out.println("Vaporized!");
}
}
public class Reactor implements Vaporizer{
public void boil() {
System.out.println("Boiling...");
}
public static void main(String[] args) {
Vaporizer v = new Reactor(); //2
v.vaporize(); //3
v.shutdown(); //4
}
}
Select 1 option(s)
Boiling...
Vaporized!
shutting down
Compilation failure at //1.
Compilation failure at //2.
Compilation failure at //4.
If code at //4 is changed to Vaporizer.shutdown();, it will print
Boiling...
Vaporized!
shutting down
Definition of interface Vaporizer will cause compilation to fail.
None
45.
Question: Given:
//assume appropriate imports
public class Calculator{
public static void main(String[] args) {
double principle = 100;
int interestrate = 5;
double amount = compute(principle, x->x*interestrate);
}
INSERT CODE HERE
}
Which of the following methods can be inserted in the above code so that it will compile and run without any error/exception?
Select 2 option(s)
public static double compute(double base, Function
Integer, Integer
func){
return func.apply((int)base);
}
public static double compute(double base, Function
Integer, Double
func){
return func.apply((int)base);
}
public static double compute(double base, Function
Double, Integer
func){
return func.apply(base);
}
public static double compute(double base, Function
Double, Double
func){
return func.apply(base);
}
public static double compute(double base, Function
Integer, Double
func){
return func.apply(base);
}
46.
Question: What changes, when applied independent of each other, will enable the following code to compile?
//assume appropriate import statements
class TestClass{
public double process(double payment, int rate)
{
double defaultrate = 0.10; //1
if(rate>10) defaultrate = rate; //2
class Implement{
public int apply(double data){
Function f = x->x+(int)(x*defaultrate); //3
return f.apply((int)data); //4
}
}
Implement i = new Implement();
return i.apply(payment);
}
}
Select 2 option(s)
47.
Question: Consider the following code:
public class TestClass {
public static void doStuff() throws Exception{
System.out.println("Doing stuff...");
if(Math.random()>0.4){
throw new Exception("Too high!");
}
System.out.println("Done stuff.");
}
public static void main(String[] args) throws Exception {
doStuff();
System.out.println("Over");
}
}
Which of the following are possible outputs when the above program is compiled and run?
(Assume that Math.random() returns a double between 0.0 and 1.0 not including 1.0.
Further assume that there is no mistake in the line numbers printed in the output shown in the options.)
Select 2 option(s)
Doing stuff...
Exception in thread "main" java.lang.Exception: Too high!
at TestClass.doStuff(TestClass.java:29)
at TestClass.main(TestClass.java:41)
Doing stuff...
Exception in thread "main" java.lang.Exception: Too high!
at TestClass.doStuff(TestClass.java:29)
at TestClass.main(TestClass.java:41)
Over
Doing stuff...
Done stuff.
Over
Doing stuff...
Exception in thread "main" java.lang.Exception: Too high!
at TestClass.doStuff(TestClass.java:29)
at TestClass.main(TestClass.java:41)
Done stuff.
48.
Question: Given:
//creating Book objects using Book(String title, String author) constructor
var books = List.of(new Book("Where the Crawdads Sing", "Dalia Owens" ), new Book("The Outsider", "Stephen King"),
new Book("Elevation", "Stephen King"), new Book("Coffin from Hong Kong", "James Hadley Chase") );
Stream bkStrm = books.stream();
*INSERT CODE HERE*
Assuming Book class has appropriate constructor and accessor methods, which of the following lines of code will get you the first book written by Stephen King from the list of of books?
Select 1 option(s)
None
49.
Question: Which statements about the following code are correct?
interface House{
public default void lockTheGates(){
System.out.println("Locking House");
}
}
interface Office {
public void lockTheGates();
}
class HomeOffice implements House, Office{ //1
public void lockTheGates(){
System.out.println("Locking HomeOffice");
}
}
public class TestClass {
public static void main(String[] args) {
Office off = new HomeOffice(); //2
off.lockTheGates();
}
}
Select 1 option(s)
Code for class HomeOffice will cause compilation to fail.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
The code will compile successfully if the lockTheGates method is removed from class HomeOffice.
It will compile fine and print Locking HomeOffice when run.
None
50.
Question: What will the following code snippet print?
List s1 = new ArrayList( );
try{
while(true){
s1.add("sdfa");
}
}catch(RuntimeException e){
e.printStackTrace();
}
System.out.println(s1.size());
Select 1 option(s)
It will not compile.
It will print a RuntimeException stack trace from the catch clause.
It will throw an error at runtime that will not be caught by the catch block.
It will print a stack trace from the catch clause and a number depending on the memory available in the system.
It will only print a number depending on the memory available in the system.
None
51.
Question: Given the following code:
interface Device {
public abstract void switchOn();
}
abstract class Router /* LOCATION 1 */ {
/* LOCATION 2 */
public void switchOn(){ }
public abstract void reset();
}
class MimoRouter extends Router implements Device{
/* LOCATION 3 */
}
Which code, when inserted at one or more marked locations, would allow classes Router and MimoRouter to compile?
(Consider each option as independent of other options.)
Select 2 option(s)
implements Device //at location 1
@Override //at location 2
public void reset(){ } //at location 3
@Override //at location 2
public void reset() { } //at location 3
@Override //at location 3
void switchOn(){ } //at location 3
@Override //at location 3
public void reset(){ }//at location 3
@Override //at location 2 and 3
public void switchOn(){ } //at location 2 and 3
public void reset(){ }//at location 3
implements Device //at location 1
@Override //at location 2
public void reset(){ }//at location 3
52.
Question: Consider the following method exposed by a utility class:
public static String getOptions(final String propName) {
return AccessController.doPrivileged(
new PrivilegedAction() {
public String run() {
return System.getProperty(propName);
}
}
);
}
It has been decided to give appropriate permission in the security file for this code. Identify correct statements.
Select 2 option(s)
It violates secure coding guidelines for invoking privileged actions.
It violates secure coding guidelines for exposing static methods.
It violates secure coding guidelines for validating inputs.
It violates secure coding guidelines for protecting confidential information.
53.
Question: While reviewing the code for a class that is used by your cloud customers, you notice the following code in one of the methods:
public void invokeService(String srvname, String host, int port){
...
Socket socket = null;
try{
AccessController.doPrivileged( ( PrivilegedExceptionAction ) ()->
socket = new Socket(host, port);
return null;
}
...
}
You also notice the following permission that is given to this code in the security policy file:
permission java.io.SocketPermission "*", "connect";
What security vulnerability does this expose to your cloud customer's code?
Select 1 option(s)
None because the customer's code must also have the same permission.
SQL injection attack against any given host.
XML injection attack against any given host.
SQL and XML injection attacks against the cloud server.
Privilege escalation attack against the machine running this code.
Denial of service attack against any reachable host.
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