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 Unique Java Test - 1
Name
Email
Phone
1.
Question: A developer has written the following code snippet:
Console c = System.console(); //1
String line = c.readLine("Please enter your name:"); //2
System.out.println("Hello, "+line); //3
Which of the following statements are true about this code if it is run in the background by a scheduler?
Select 1 option(s)
Line //1 will throw IOException.
Line //1 will throw NullPointerException.
Line //2 will throw IOException.
Line //2 will throw NullPointerException.
Line //3 will print Hello, null.
None
2.
Question: Identify the correct statements about Java Stream API.
Select 1 option(s)
Streams are reusable.
Elements of a stream are mutable.
Streams support aggregate operations.
All Stream operations are lazy.
None
3.
Question: Given:
List letters = Arrays.asList("j", "a", "v","a");
Which of the following code snippets will print JAVA?
Select 3 option(s)
4.
Question: Which of the following correctly defines a method named stringProcessor that can be called by other programmers as follows: stringProcessor(str1) or stringProcessor(str1, str2) or stringProcessor(str1, str2, str3), where str1, str2, and str3 are references to Strings.
Select 1 option(s)
public void stringProcessor(...String){
}
public void stringProcessor(String... strs){
}
public void stringProcessor(String[] strs){
}
public void stringProcessor(String a, String b, String c){
}
public void stringProcessor(var String a){
}
Three separate methods need to be written.
None
5.
Question: What is wrong with the following code?
class MyException extends Exception {}
public class TestClass{
public static void main(String[] args){
TestClass tc = new TestClass();
try{
tc.m1();
}
catch (MyException e){
tc.m1();
}
finally{
tc.m2();
}
}
public void m1() throws MyException{
throw new MyException();
}
public void m2() throws RuntimeException{
throw new NullPointerException();
}
}
Select 1 option(s)
It will not compile because you cannot throw an exception in finally block.
It will not compile because you cannot throw an exception in catch block.
It will not compile because NullPointerException cannot be created this way.
It will not compile because of unhandled exception.
It will compile but will throw an exception when run.
None
6.
Question: Given:
public class Item{
private String name;
private String category;
private double price;
public Item(String name, String category, double price){
this.name = name;
this.category = category;
this.price = price;
}
//accessors not shown
}
What will the following code print?
List items = Arrays.asList(
new Item("Pen", "Stationery", 3.0),
new Item("Pencil", "Stationery", 2.0),
new Item("Eraser", "Stationery", 1.0),
new Item("Milk", "Food", 2.0),
new Item("Eggs", "Food", 3.0)
);
ToDoubleFunction priceF = Item::getPrice; //1
items.stream()
.collect(Collectors.groupingBy(Item::getCategory)) //2
.forEach((a, b)->{
double av = b.stream().collect(Collectors.averagingDouble(priceF)); //3
System.out.println(a+" : "+av);
});
Select 1 option(s)
Stationery : 2.0
Food : 2.5
[Pen : 3.0, Pencil : 2.0, Eraser : 1.0] : 2.0
[Milk : 2.0, Eggs : 3.0] : 2.5
Pen : 3.0, Pencil : 2.0, Eraser : 1.0 : 2.0
Milk : 2.0, Eggs : 3.0 : 2.5
Stationery : [Pen : 3.0, Pencil : 2.0, Eraser : 1.0] : 2.0
Food : [Milk : 2.0, Eggs : 3.0] : 2.5
Compilation error due to code at //1.
Compilation error due to code at //2.
Compilation error due to code at //3.
None
7.
Question: Which of the statements regarding the following code are correct?
public class TestClass{
static int a;
int b;
public TestClass(){
int c;
c = a;
a++;
b += c;
}
public static void main(String args[]) { new TestClass(); }
}
Select 1 option(s)
The code will fail to compile because the constructor is trying to access static members.
The code will fail to compile because the constructor is trying to use static member variable a before it has been initialized.
The code will fail to compile because the constructor is trying to use member variable b before it has been initialized.
The code will fail to compile because the constructor is trying to use local variable c before it has been initialized.
The code will compile and run without any problem.
None
8.
Question: What will the following code print when compiled and run?
var numA = new Integer[]{1, 2};
var list1 = new ArrayList(List.of(numA));
list1.add(null);
var list2 = Collections.unmodifiableList(list1);
list1.set(2, 3);
List<List> list3 = List.of(list1, list2);
System.out.println(list3);
Select 1 option(s)
[[1, 2, 3], [1, 2, 3]]
[1, 2, 3]
[[1, 2, 3], [1, 2, null]]
[1, 2, null]
[1, 2, 3, null]
It will throw an exception at run time.
None
9.
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
10.
Question: Which is the first line that will cause compilation to fail in the following program?
// Filename: A.java
class A{
public static void main(String args[]){
A a = new A();
B b = new B();
a = b; // 1
b = a; // 2
a = (B) b; // 3
b = (B) a; // 4
}
}
class B extends A { }
Select 1 option(s)
At Line 1.
At Line 2.
At Line 3.
At Line 4.
None of the above.
None
11.
Question: Which of the following are valid declarations inside the FooI interface?
interface AI{
void moo();
}
interface FooI extends AI{
//INSERT CODE HERE
}
Select 2 option(s)
private void foo(){ };
private abstract void foo();
static void foo();
protected void foo();
public final void compute();
final is not allowed.
final void foo(){ }
@Override
void moo();
12.
Question: What will the following code print when compiled and run?
public class TestClass {
public static void main(String[] args) {
String s = "blooper";
StringBuilder sb = new StringBuilder(s);
s.append("whopper");
sb.append("shopper");
System.out.println(s);
System.out.println(sb);
}
}
Select 1 option(s)
Blooper and bloopershopper.
Blooperwhopper and bloopershopper.
Blooper and blooperwhoppershopper.
It will not compile.
None
13.
Question: Which of the following class definitions is/are legal definition(s) of a class that cannot be instantiated?
class Automobile{
abstract void honk(); //(1)
}
abstract class Automobile{
void honk(); //(2)
}
abstract class Automobile{
void honk(){}; //(3)
}
abstract class Automobile{
abstract void honk(){} //(4)
}
abstract class Automobile{
abstract void honk(); //(5)
}
Select 2 option(s)
1
2
3
4
5
14.
Question: What will the following class print when run?
public class Sample{
public static void main(String[] args) {
String s1 = new String("java");
StringBuilder s2 = new StringBuilder("java");
replaceString(s1);
replaceStringBuilder(s2);
System.out.println(s1 + s2);
}
static void replaceString(String s) {
s = s.replace('j', 'l');
}
static void replaceStringBuilder(StringBuilder s) {
s.append("c");
}
}
Select 1 option(s)
javajava
lavajava
javajavac
lavajavac
None of these.
None
15.
Question: Identify correct statements about java.io.Console class?
Select 1 option(s)
You can read character data from a console but not write to it.
You can read both binary and character data from Console object but you cannot write to it.
You can read both binary and character data from Console object but you can only write character data to it.
You can read as well as write only character data from/to it.
None
16.
Question: What will the following code print when run?
public class Test {
static String s = "";
public static void m0(int a, int b) {
s += a;
m2();
m1(b);
}
public static void m1(int i) {
s += i;
}
public static void m2() {
throw new NullPointerException("aa");
}
public static void m() {
m0(1, 2);
m1(3);
}
public static void main(String args[]) {
try {
m();
} catch (Exception e) {
}
System.out.println(s);
}
}
Select 1 option(s)
1
12
123
2
It will throw exception at runtime.
None
17.
Question: Identify the valid enum declarations.
Select 2 option(s)
//in file Pets.java
enum Pets implements java.io.Serializable
{
DOG("D"), CAT("C"), FISH("F");
String name;
Pets(String s) { }
public String getData(){ return name; }
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
static String prefix = "I am ";
String name;
Pets(String s) { name = prefix + s;}
public String getData(){ return name; }
}
//in file Pets.java
public enum Pets
{
DOG(1, "D"),
CAT(2, "C")
{
public String getData(){ return type+name; }
},
FISH(3, "F");
int type;
String name;
Pets(int t, String s) { this.name = s; this.type = t;}
public String getData(){ return name+type; }
}
//in file Pets.java
enum Pets
{
String name;
DOG("D"), CAT("C"), FISH("F");
Pets(String s) { name = s;}
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
String name;
public Pets(String s) { }
public String getData(){ return name; }
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
var name;
Pets(String s) { name = s; }
public String getData(){ return (String) name; }
}
18.
Question: Consider following classes:
//In File Other.java
package other;
public class Other { public static String hello = "Hello"; }
//In File Test.java
package testPackage;
import other.*;
class Test{
public static void main(String[] args){
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " "); //line 1
System.out.print((other.Other.hello == hello) + " "); //line 2
System.out.print((hello == ("Hel"+"lo")) + " "); //line 3
System.out.print((hello == ("Hel"+lo)) + " "); //line 4
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}
class Other { static String hello = "Hello"; }
What will be the output of running class Test?
Select 1 option(s)
False false true false true.
False true true false true.
True true true true true.
True true true false true.
None of the above.
None
19.
Question: Given the following code:
public class TestClass {
int[][] matrix = new int[2][3];
int[] a = new int[]{1, 2, 3};
int[] b = new int[]{4, 5, 6};
public int compute(int x, int y){
//1 : Insert Line of Code here
}
public void loadMatrix(){
for(int x=0; x<matrix.length; x++){
for(int y=0; y<matrix[x].length; y++){
//2: Insert Line of Code here
}
}
}
}
What can be inserted at //1 and //2?
Select 1 option(s)
return a(x)*b(y);
and
matrix(x, y) = compute(x, y);
return a[x]*b[y];
and
matrix[x, y] = compute(x, y);
return a[x]*b[y];
and
matrix[x][y] = compute(x, y);
return a(x)*b(y);
and
matrix(x)(y) = compute(x, y);
return a[x]*b[y];
and
matrix[[x][y]] = compute(x, y);
None
20.
Question: For what command line arguments will the following program print true?
class TestClass{
public static void main(String[] args){
Integer i = Integer.parseInt(args[0]);
Integer j = i;
i--;
i++;
System.out.println((i==j));
}
}
Select 3 option(s)
0
-1
127
-256
256
For all the values between 0 and 255 (both included).
21.
Question: What will the following program print when compiled and run:
public class TestClass {
public static void main(String[] args) {
someMethod();
}
static void someMethod(Object parameter) {
System.out.println("Value is "+parameter);
}
}
Select 1 option(s)
It will not compile.
Value is null
Value is
It will throw a NullPointerException at run time.
None
22.
Question: What will the following code print when compiled and run?
String val1 = "hello";
StringBuilder val2 = new StringBuilder("world");
UnaryOperator uo1 = s1->s1.concat(val1); //1
UnaryOperator uo2 = s->s.toUpperCase(); //2
System.out.println(uo1.apply(uo2.apply(val2))); //3
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
Compilation error at //1 and //3.
It will print WORLDhello.
It will print WORLDHELLO.
It will print HELLOWORLD.
None
23.
Question: Given:
Character[] ca = { 'b', 'c', 'a', 'e', 'd' };
List l = Arrays.asList(ca);
l.parallelStream().peek(System.out::print).forEachOrdered(System.out::print);
Identify the correct statement about the above code.
Select 1 option(s)
The characters printed by peek may be in any order but the characters printed by forEachOrdered will always be in the same order as the original list i.e. bcaed.
The characters printed by forEachOrdered will always be in the same order as the one printed by the peek method.
If forEachOrdered is replaced with forEach, the order of the characters printed by forEach will be the same as the one printed by peek.
Both - peek and forEachOrder - may print the characters in any order.
None
24.
Question: Assuming that the directory /works/ocpjp/code exists but /works/ocpjp/code/sample does not exist, what will the following code output?
Path d1 = Paths.get("/works");
Path d2 = d1.resolve("ocpjp/code"); //1
d1.resolve("ocpjp/code/sample"); //2
d1.toAbsolutePath(); //3
System.out.println(d1);
System.out.println(d2);
Select 1 option(s)
An exception at //2.
An exception at //3.
\works
\works\ocpjp\code
\works
< some path that is system dependent >
None
25.
Question: Consider the following code:
import java.util.*;
class Request { }
class RequestCollector{
//1 : Insert declaration here
public synchronized void addRequest(Request r){
container.add(r);
}
public synchronized Request getRequestToProcess(){
return container.poll();
}
}
What can be inserted at //1?
Select 1 option(s)
Queue
Request
container = new LinkedList
Request
();
LinkedList container = new LinkedList();
Queue container = new PriorityQueue();
Queue
Request
container = new Queue
Request
();
List al = new ArrayList();
None of these.
None
26.
Question: What will the following code print when compiled and run?
public class Data{
int value;
Data(int value){
this.value = value;
}
public String toString(){ return ""+value; }
public static void main(String[] args) {
Data[] dataArr = new Data[]{ new Data(1), new Data(2), new Data(3), new Data(4) };
List
dataList = Arrays.asList(dataArr); //1
for(Data element : dataList){
dataList.removeIf( (Data d) -> { return d.value%2 == 0; } ); //2
System.out.println("Removed "+d+", "); //3
}
}
}
Select 1 option(s)
Removed 2, Removed 4.
It will print Removed 2 and then an exception stack trace.
It will print an exception stack trace.
It will not compile due to //1.
It will not compile due to //2.
It will not compile due to //3.
None
27.
Question: Identify the correct statement(s).
Select 2 option(s)
To customize the behavior of class serialization, the readObject and writeObject methods should be implemented.
To customize the behavior of class serialization, the defaultReadObject and defaultWriteObject methods should be overridden.
Objects of a final class cannot be serialized.
Constructor of the class for an object being deserialized is never invoked.
While serializing an object, only those objects in the object graph that implement Serializable are serialized and the rest are ignored.
28.
Question: Java's Exception mechanism helps in which of the following ways?
Select 2 option(s)
It allows creation of new exceptions that are custom to a particular application domain.
It improves code because error handling code is clearly separated from the main program logic.
It enhances the security of the application by reporting errors in the logs.
It improves the code because the exception is handled right at the place where it occured.
It provides a vast set of standard exceptions that covers all possible exceptions.
29.
Question: What can be inserted in the following code so that it will print exactly 2345 when compiled and run?
public class FlowTest {
static int[] data = {1, 2, 3, 4, 5};
public static void main(String[] args) {
for (var i : data) {
if (i < 2) {
//insert code1 here
}
System.out.print(i);
if (i == 3) {
//insert code2 here
}
}
}
}
Select 2 option(s)
break;
and
//nothing is required
continue;
and
//nothing is required
continue;
and
continue;
break;
and
continue;
break;
and
break;
30.
Question: You want to invoke the overridden method (the method in the base class) from the overriding method (the method in the derived class) named m().
Which of the following constructs which will let you do that?
Select 1 option(s)
super.m();
super.this();
base.m();
parent.m();
super();
None
31.
Question: Which lines contain a valid constructor in the following code?
public class TestClass{
public TestClass(int a, int b) { } // 1
public void TestClass(int a) { } // 2
public TestClass(String s); // 3
private TestClass(String s, int a) { } //4
public TestClass(String s1, String s2) { }; //5
}
Select 3 option(s)
Line // 1.
Line // 2.
Line // 3.
Line // 4.
Line // 5.
32.
Question: Identify correct statements about the module system of Java.
Select 3 option(s)
Every module must reside in a directory of its own.
A module can specify packages as well as services.
Modular JDK is helpful in improving performance of an application.
Modules allow service implementations to be hooked up with service users through dependency injection.
33.
Question: Which of the following declarations is equivalent to var b = 10>11;
Select 2 option(s)
bool b = false;
var b = false;
var b = false|true;
bool b = (10<11);
boolean b = false;
34.
Question: Given:
public class PlaceHolder { //1
private K k;
private V v;
public PlaceHolder(K k, V v){ //2
this.k = k;
this.v = v;
}
public K getK() { return k; }
public static PlaceHolder getDuplicateHolder(X x){ //3
return new PlaceHolder(x, x); //4
}
}
Which line will cause compilation failure?
Select 1 option(s)
1
2
3
4
Some other unnumbered line.
There is no problem with the code.
None
35.
Question: Given:
package strings;
public class StringFromChar {
public static void main(String[] args) {
String myStr = "good";
char[] myCharArr = {'g', 'o', 'o', 'd' };
String newStr = "";
for(char ch : myCharArr){
newStr = newStr + ch;
}
boolean b1 = newStr == myStr;
boolean b2 = newStr.equals(myStr);
System.out.println(b1+ " " + b2);
}
}
What will it print when compiled and run?
Select 1 option(s)
true true
true false
false true
false false
None
36.
Question: Identify the correct statements about the following code:
import java.util.*;
class Person {
private static int count = 0;
private String id = "0"; private String interest;
public Person(String interest){ this.interest = interest; this.id = "" + ++count; }
public String getInterest(){ return interest; }
public void setInterest(String interest){ this.interest = interest; }
public String toString(){ return id; }
}
public class StudyGroup
{
String name = "MATH";
TreeSet set = new TreeSet();
public void add(Person p) {
if(name.equals(p.getInterest())) set.add(p);
}
public static void main(String[] args) {
StudyGroup mathGroup = new StudyGroup();
mathGroup.add(new Person("MATH"));
System.out.println("A");
mathGroup.add(new Person("MATH"));
System.out.println("B");
System.out.println(mathGroup.set);
}
}
Select 1 option(s)
It will print : A, B, and then the contents of mathGroup.set.
It will compile with a warning.
It will NOT throw an exception at runtime.
It will compile without warning but will throw an exception at runtime.
It will only print : A.
It will print : A and B.
None
37.
Question: Given:
class Base{
public List transform(List list)
{
return new ArrayList();
}
}
class Derived extends Base{
*INSERT CODE HERE*
}
What can be inserted in the above code?
Select 2 option(s)
38.
Question: Which of the following method(s) of java.util.stream.Stream interface is/are used for reduction?
Select 2 option(s)
collect
count
distinct
findAny
findFirst
39.
Question: What should be placed in the two blanks so that the following code will compile without errors:
class XXX{
public void m() {
throw new RuntimeException();
}
}
class YYY extends XXX{
public void m() throws Exception{
throw new Exception();
}
}
public class TestClass {
public static void main(String[] args) {
______ obj = new ______();
obj.m();
}
}
Select 1 option(s)
XXX and YYY
XXX and XXX
YYY and YYY
YYY and XXX
None of the options will make the code compile.
None
40.
Question: What will the following code print?
List ls = Arrays.asList(1, 2, 3);
Function func = a->a*a; //1
ls.stream().map(func).peek(System.out::print); //2
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
149
123
It will compile and run fine but will not print anything.
None
41.
Question: Identify the correct statements about ArrayList?
Select 3 option(s)
ArrayList extends java.util.AbstractList.
It allows you to access its elements in random order.
You must specify the class of objects you want to store in ArrayList when you declare a variable of type ArrayList.
ArrayList does not implement RandomAccess.
You can sort its elements using Collections.sort() method.
42.
Question: What is wrong with the following code written in a single file named TestClass.java?
class SomeThrowable extends Throwable { }
class MyThrowable extends SomeThrowable { }
public class TestClass{
public static void main(String args[]) throws SomeThrowable{
try{
m1();
}catch(SomeThrowable e){
throw e;
}finally{
System.out.println("Done");
}
}
public static void m1() throws MyThrowable{
throw new MyThrowable();
}
}
Select 1 option(s)
The main declares that it throws SomeThrowable but throws MyThrowable.
You cannot have more than 2 classes in one file.
The catch block in the main method must declare that it catches MyThrowable rather than SomeThrowable.
There is nothing wrong with the code and Done will be printed.
None
43.
Question: Which of the following statements regarding java.util.HashSet is correct?
Select 1 option(s)
It keeps the elements in a sorted order.
It allows duplicate elements because it is based on HashMap.
It stores name-value pairs.
The order of elements seen while iterating through a HashSet always remains same.
It allows null value to be stored.
None
44.
Question: What will be the result of attempting to compile and run the following code?
class SwitchTest{
public static void main(String args[]){
for ( var i = 0 ; i < 3 ; i++){ //1
var flag = false;
switch (i){ //2
flag = true; //3
}
if ( flag ) System.out.println( i );
}
}
}
Select 1 option(s)
It will print 0, 1 and 2.
It will not print anything.
Runtime error.
Compilation error at line marked //1.
Compilation error at line marked //2.
Compilation error at line marked //3.
None
45.
Question: What will the following code print?
int[] ia1 = { 0, 1, 4, 5};
int[] ia2 = { 0, 1, 1, 5, 6};
int x = Arrays.compare(ia1, ia2);
int y = Arrays.mismatch(ia1, ia2);
System.out.println(x+" "+y);
Select 1 option(s)
1 2
2 2
1 3
-1 2
-1 -2
None
46.
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")
);
Reader r = b->{
System.out.println("Reading book "+b.getTitle());
};
books.forEach(x->r.read(x));
What would be a valid definition of Reader for the above code to compile and run without any error or exception?
Select 2 option(s)
abstract class Reader{
abstract void read(Book b);
}
abstract class Reader{
void read(Book b);
}
@FunctionalInterface
interface Reader{
void read(Book b);
default void unread(Book b){ }
}
interface Reader{
default void read(Book b){ }
void unread(Book b);
private void doSomethingelse(){ }
}
@FunctionalInterface
interface Reader{
default void read(Book b){ System.out.println("Default read");};
}
47.
Question: What will the following code print?
AtomicInteger ai = new AtomicInteger();
Stream stream = Stream.of(11, 11, 22, 33).parallel();
stream.filter( e->{
ai.incrementAndGet();
return e%2==0;
});
System.out.println(ai);
Select 1 option(s)
0
Any number between 1 to 4.
4
Any number between 0 to 3.
None
48.
Question: What will be printed when the following code is compiled and run?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public void open(){
header = "OPENED";
System.out.println("Device Opened");
}
public String read() throws IOException{
throw new IOException("Unknown");
}
public void writeHeader(String str) throws IOException{
System.out.println("Writing : "+str);
header = str;
}
public void close(){
header = null;
System.out.println("Device closed");
}
public static void testDevice(){
try(Device d = new Device()){
d.open();
d.writeHeader("TEST");
d.close();
}catch(IOException e){
System.out.println("Got Exception");
}
}
public static void main(String[] args) {
Device.testDevice();
}
}
Select 1 option(s)
Device Opened
Device closed
Got Exception
Device Opened
Writing : TEST
Device closed
Device closed
Device Opened
Writing : TEST
Device closed
Got Exception
Device Opened
Writing : TEST
Device closed
Device closed
Got Exception
Device Opened
Writing : TEST
Device closed
Device closed
(an exception stack trace)
None
49.
Question: Consider the following class...
public class ParamTest {
public static void printSum(int a, int b){
System.out.println("In int "+(a+b));
}
public static void printSum(Integer a, Integer b){
System.out.println("In Integer "+(a+b));
}
public static void printSum(double a, double b){
System.out.println("In double "+(a+b));
}
public static void main(String[] args) {
printSum(1, 2);
}
}
What will be printed?
Select 1 option(s)
In int 3
In Integer 3
In double 3.0
In double 3
It will not compile.
None
50.
Question: Consider the following method:
static int mx(int s){
for(int i=0; i<3; i++){
s = s + i;
}
return s;
}
and the following code snippet:
int s = 5;
s += s + mx(s) + ++s;
System.out.println(s);
What will it print?
Select 1 option(s)
21
22
23
24
25
26
None
51.
Question: A user thread of a GUI application needs to perform certain security sensitve operations upon receiving system events. For this purpose, a call back handler has been registered with the system by the user thread based upon inputs from the GUI. The operations should be executed only if the user has appropriate permissions as per the security policy.
The following code shows the call back handler:
public class ProtectedCallbackHandler implements Runnable{
final String action;
public ProtectedCallbackHandler(String action){
this.action = action;
}
public void run(){
AccessController.doPrivileged(
new PrivilegedAction() {
public Void run() {
//Do sensitive operations based upon action value
return null;
}
});
}
}
Identify correct statements.
Select 1 option(s)
The call back handler is not coded correctly because it does not check the privileges associated with the user.
The call back handler is not coded correctly because it doesn't check any specific privileges required for the operation.
The call back handler approach will fail because system call back handlers are always executed with full permissions.
The call back handler is coded correctly and will work as expected.
None
52.
Question: What will the following code print when run?
LocalDate d = LocalDate.now();
DateFormat df = new DateFormat(DateFormat.LONG);
System.out.println(df.format(d));
Select 1 option(s)
It will print current date in LONG format.
It will print the number of milliseconds since 1 Jan 1970.
It will not compile.
It will throw an exception at runtime.
None
53.
Question: Consider the following code:
class MyClass { }
public class TestClass{
MyClass getMyClassObject(){
MyClass mc = new MyClass(); //1
return mc; //2
}
public static void main(String[] args){
TestClass tc = new TestClass(); //3
MyClass x = tc.getMyClassObject(); //4
System.out.println("got myclass object"); //5
x = new MyClass(); //6
System.out.println("done"); //7
}
}
After what line the MyClass object created at line 1 will be eligible for garbage collection?
Select 1 option(s)
2
5
6
7
Never till the program ends.
None
54.
Question: Given:
public class TestClass {
static int count = 0;
public static void main(String[] args) throws Exception{
ExecutorService es = Executors.newFixedThreadPool(5);
for(int i=0; i<5; i++){
es.submit( () ->
{
for(int j=0; j<5000; j++){
TestClass.count++;
}
}
);
}
es.awaitTermination(10, TimeUnit.SECONDS);
es.shutdownNow();
System.out.println(count);
}
}
Identify correct statement(s) about the above code.
Select 2 option(s)
The count variable is thread safe.
The count variable should be declared volatile to make it thread safe.
The main method should be declared synchronized to make it thread safe.
The code should increment the count variable inside a synchronized block that synchronizes on a single common object to make it thread safe.
The count variable should be declared synchronized to make it thread safe.
The code should use AtomicInteger instead of int for count variable to make it thread safe.
55.
Question: Given:
Locale locale = new Locale("en", "US");
ResourceBundle rb = ResourceBundle.getBundle("test.MyBundle", locale);
Which of the following are valid lines of code?
(Assume that the ResourceBundle has the values for the given keys.)
Select 2 option(s)
String obj = rb.getObject("key1");
Object obj = rb.getObject("key1");
String[] vals = rb.getStringArray("key2");
Object obj = rb.getValue("key3");
Object obj = rb.getObject(1);
56.
Question: Given :
1. A table has been created in the DB as follows:
CREATE TABLE NAMES (FNAME varchar(20), LNAME varchar(20));
2. A stored procedure has also been created in the DB as follows:
CREATE PROCEDURE insert_name(GIVENNAME IN VARCHAR, SURNAME IN VARCHAR) as
BEGIN
insert into NAMES (FNAME, LNAME) values (SURNAME, GIVENNAME);
END;
Consider the following Java code:
try(Connection c = ds.getConnection();
var stmt = c.prepareCall("{call insert_name(?,?)}") ) { //1
stmt.setObject("surname", "Doe", JDBCType.VARCHAR); //2
stmt.setObject("GIVENNAME", "Jane", JDBCType.VARCHAR); //3
stmt.execute(); //4
}
What will happen when the above code is complied and run?
Select 1 option(s)
It will throw an exception at runtime due to code at //1 because the syntax to invoke a stored procedure is incorrect.
It will fail to compile unless statements at //2 and //3 are replaced with:
stmt.setObject(1, "Jane", java.sql.Types.STRING); //2
stmt.setObject(2, "Doe", java.sql.Types.STRING); //3
It will fail to compile unless stmt.setString and stmt.setDate are used at //2 and //3.
A row with values "Doe", "Jane" will be stored.
A row with values "Jane", "Doe" will be stored.
It will throw an SQL exception at //2 because of a mismatch in parameter name.
It will throw an SQLException at //4 because of a mismatch in parameter name.
It will throw an SQLException at //4 because of the wrong order of parameter names.
None
57.
Question: Given:
public class Book {
private String title;
private LocalDate releaseDate;
public Book(String title, LocalDate releaseDate){
this.title = title; this.releaseDate = releaseDate;
}
//accessors not shown
}
and the following code:
var books = new ArrayList(List.of(new Book("The Outsider", LocalDate.of(2019, 1, 1)),
new Book("Becoming", LocalDate.of(2018, 1, 1)),new Book("Uri", LocalDate.of(2017, 1, 1))));
Predicate p = b->b.getReleaseDate().isAfter(IsoChronology.INSTANCE.date(2018, 1, 1));
Set newBooks = books.stream().
INSERT CODE HERE
What can be inserted in the code above so that newBooks will be assigned a set of books that were released after the date indicated by the predicate p?
Select 3 option(s)
.collect(Collectors.partitioningBy(p))
.get(true).stream().map(Book::getTitle)
.collect(Collectors.toCollection(TreeSet::new));
.collect(Collectors.partitioningBy(p))
.get(true).stream().map(Book::getTitle).collect(Collectors.toSet());
.collect(Collectors.partitioningBy(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
.collect(Collectors.groupingBy(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
.collect(Collectors.filtering(p,
Collectors.mapping(Book::getTitle, Collectors.toSet())));
58.
Question: What will the following code print when compiled and run?
var tickers = List.of("A", "D", "E", "C", "A");
var ratio = List.of(1.0, 1.2, 1.5, 1.8, 2.0);
var map1 = IntStream.range(0, tickers.size())
.boxed()
.collect(Collectors.toMap(
i -> tickers.get(i),
i -> 1.0/ratio.get(i), (x, y) -> x+y)) ; //<<----- LINE 1
var map2 = map1.entrySet().stream().sorted(Map.Entry.comparingByKey())
.collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(x, y) -> x-y,
LinkedHashMap::new)
); //<<----- LINE 2
map2.forEach((var k, var v)->System.out.printf("%s = %.2f\n",k, v));
Select 1 option(s)
A = 1.50
C = 0.56
D = 0.83
E = 0.67
E = 0.67
D = 0.83
C = 0.56
A = 1.50
Exception at line 1.
Exception at line 2.
A = 1.50
D = 0.83
E = 0.67
C = 0.56
A = 1.50
None
59.
Question: Given:
public class TestClass {
static int val = 10;
public static int reduce(int val){
class Inner{
public int reduce(int mval){
return mval-val--;
}
}
val--;
return new Inner().reduce(val);
}
public static void main(String[] args) {
reduce(5);
System.out.println(val);
}
}
Select 1 option(s)
5
10
0
9
Compilation failure.
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