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 - 3
Name
Email
Phone
1.
Question: Given that SomeException is a checked exception, consider the following code:
//in file A.java
public class A{
protected void m() throws SomeException{}
}
//in file B.java
public class B extends A{
public void m(){ }
}
//in file TestClass.java
public class TestClass{
public static void main(String[] args){
//insert code here. //1
}
}
Which of the following options can be inserted at //1 without resulting in any compilation or runtime errors?
Select 1 option(s)
B b = new A();
b.m();
A a = new B();
a.m();
A a = new B();
( ( B) a ).m();
Object o = new B();
o.m();
None of these.
None
2.
Question: What is the result of executing the following fragment of code:
var b1 = false;
var b2 = false;
if (b2 = b1 != b2){
System.out.println("true");
} else{
System.out.println("false");
}
Select 1 option(s)
Compile time error.
It will print true;
It will print false;
Runtime error.
It will print nothing.
None
3.
Question: Given:
class Base{
public Collection getCollection(T t, Integer n)
{
return new ArrayList();
}
}
class Derived extends Base{
//public List getCollection(T t, Integer m) { return new ArrayList(); }; //1
//public Stream getCollection(T t, Integer m) { return new ArrayList(); }; //2
//public void getCollection(T t, Integer m) { return new ArrayList(); }; //3
//public List getCollection(String t, Integer m) { return new ArrayList(); }; //4
}
Identify correct statements about the methods defined in Derived assuming they are uncommented one at a time individually.
Select 1 option(s)
//1, //2, and //3 correctly override the method in Base.
//2, //3, and //4 correctly overload the method in Base.
//2 and //3 correctly override the method in Base.
//1 correctly overloads while //4 correctly overrides the method in Base.
//1 correctly overrides the method in Base.
//1 and //4 cannot be inserted in the code at the same time.
None
4.
Question: Which of the following statements are valid?
Select 3 option(s)
String[ ] sa = new String[3]{ "a", "b", "c"};
String sa[ ] = { "a ", " b", "c"};
String sa = new String[ ]{"a", "b", "c"};
String sa[ ] = new String[ ]{"a", "b", "c"};
String sa[ ] = new String[ ] {"a" "b" "c"};
Var sa = new String[ ]{"a", "b", "c"};
5.
Question: Which of the following are correct about "encapsulation"?
Select 2 option(s)
Encapsulation is same as polymorphism.
It helps make sure that clients have no accidental dependence on the choice of representation
It helps avoiding name clashes as internal variables are not visible outside.
Encapsulation makes sure that messages are sent to the right object at run time.
Encapsulation helps you inherit the properties of another class.
6.
Question: An application program collects a bunch of tasks in an list and submits this list to a task execution service. This service keeps running in the background as a system process and executes the tasks by launching a thread for the list of tasks. The following code shows how the execution service processes the tasks:
public class BackgroundExecutionService {
public void submitTask(final List tasks, final AccessControlContext acc){
new Thread(){ public void run(){
AccessController.doPrivileged(
new PrivilegedAction() {
public Void run() {
for(Task t : tasks){
// process task t
}
}
}, acc);
}.start();
...other irrelevant code
}
Identify correct statements.
Select 1 option(s)
This approach correctly follows secure coding guidelines for executing code by checking user permissions using user's AccessControlContext.
This approach violates secure coding guidelines by transferring AccessControlContext accross thread boundaries.
This approach violates secure coding guidelines by executing application code in a system thread.
The approach used for executing code by checking user permissions using user's AccessControlContext is correct but it is implemented incorrectly.
None
7.
Question: Consider the following code:
public class TestClass {
//define tester method here
public static void main(String[] args) throws Exception {
var tc = new TestClass();
while(tc.tester()){
System.out.println("running...");
}
}
}
Which of the following options would be a valid implementation of tester() method?
Select 2 option(s)
public var tester(){
return false;
}
public Boolean tester(){
return false;
}
public tester(){
return false;
}
public int tester(){
return 0;
}
public String tester(){
return "false";
}
public boolean tester(){
return false;
}
8.
Question: Which of the following are good practices from security perspective?
Select 3 option(s)
Validate input using well tested libraries instead of ad hoc code.
Always use dynamic SQL through java.sql.Statement.
Use XML or HTML to output untrusted data because it is not executable.
Any data that needs to be passed to a new process should be passed either as encoded arguments (e.g., Base64), in a temporary file, or through a inherited channel.
A secure sandbox must be constructed to run it untrusted code.
9.
Question: What will the following code print when run?
class A{
String value = "test";
A(String val){
this.value = val;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
new A("new test").print();
}
}
Select 1 option(s)
Test
New test
It will not compile.
It will throw an exception at run time.
None
10.
Question: What will the following code print?
DateTimeFormatter df = DateTimeFormatter.ofPattern("eeee");
LocalDate d = LocalDate.of(2000, 1, 1); //assume that it was Saturday on this date
System.out.println(df.format(d));
Select 1 option(s)
Satu
Saturday
Sat
0007
7
None
11.
Question: Given:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DebugInfo {
String value();
String[] params();
String date();
int depth();
}
Which of the following options correctly uses the above annotation?
Select 1 option(s)
@DebugInfo(value="applyLogic", date = "2019", depth = 10, params = "index" )
void applyLogic(int index){
}
@DebugInfo(value="applyLogic", date = "01/01/2019", depth = "10", params = "index" )
void applyLogic(int index){
}
@DebugInfo(value="applyLogic", date = "01/01/2019", depth = "10", params = {"index"})
void applyLogic(int index){
}
@DebugInfo(value="applyLogic", date = "01/01/2019")
@DebugInfo(depth = 10, params = {"index"})
void applyLogic(int index){
}
None
12.
Question: What will the following code print if file test1.txt exists but test2.txt doesn't exist?
public class FileCopier {
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
}
public static void main(String[] args) throws Exception {
var p1 = Paths.get("c:\\temp\\test1.txt");
var p2 = Paths.get("c:\\temp\\test2.txt");
copy1(p1, p2);
if(Files.isSameFile(p1, p2)){
System.out.println("file copied");
}else{
System.out.println("unable to copy file");
}
}
}
Select 1 option(s)
An exception at run time if either of p1 or p1 is a symbolic link.
It will print file copied and test2.txt will contains the same data as test1.txt.
It will print file copied but test2.txt will NOT contain the same data as test1.txt.
It will print unable to copy file but test2.txt will contain the same data as test1.txt.
It will print unable to copy file and test2.txt will not be created.
None
13.
Question: Which of the following options will print 10?
Select 2 option(s)
14.
Question: What will the following code print when run?
import java.nio.file.Path;
import java.nio.file.Paths;
public class PathTest {
public static void main(String[] args) {
var p1 = Paths.get("c:\\code\\java\\PathTest.java");
System.out.println(p1.getName(3).toString());
}
}
Select 1 option(s)
It will throw NullPointerException.
It will throw IllegalArgumentException.
It will throw InvalidArgumentException.
It will throw ArrayIndexOutOfBoundsException.
None
15.
Question: Assuming that a file named "a.java" exists in c:\pathtest\ as well as in c:\pathtest\dir2, what will happen when the following code is compiled and run?
//imports not shown
public class MoveTest {
public static void main(String[] args) throws IOException {
Path p1 = Paths.get("c:\\pathtest\\a.java");
Path p2 = Paths.get("c:\\pathtest\\dir2\\a.java");
Files.move(p1, p2, StandardCopyOption.ATOMIC_MOVE);
Files.delete(p1);
System.out.println(p1.toFile().exists()+" "+
p2.toFile().exists());
}
}
Select 1 option(s)
It will not compile.
It will terminate cleanly after printing false true.
It will terminate cleanly after printing true true.
It will terminate cleanly after printing true false.
It will terminate cleanly after printing false false.
It will throw an exception at run time.
The outcome is JVM/platform dependent.
None
16.
Question: Consider the following class:
public class Parser{
public static void main( String[] args){
try{
int i = 0;
i = Integer.parseInt( args[0] );
}
catch(NumberFormatException e){
System.out.println("Problem in " + i );
}
}
}
What will happen if it is run with the following command line:
java Parser one
Select 1 option(s)
It will print Problem in 0.
It will throw an exception and end without printing anything.
It will not even compile.
It will not print anything if the argument is '1' instead of 'one'.
None of the above.
None
17.
Question: Consider the following code:
class A
{
}
public class TestClass
{
public class A
{
public void m() { }
}
class B extends A
{
B(){ m(); }
}
public static void main(String args[])
{
new TestClass().new A() { public void m() { } }; //1
var tc = new TestClass();
//insert call to A's m() here
}
}
Select 4 option(s)
This program will not compile.
Class created inside the main method at //1 is static.
Class created inside the main method at //1 is final.
Objects of class B cannot be created inside the main method just by doing "new B()"
New TestClass().new A().m(); can be inserted in main to invoke A's m().
New A().m(); can be inserted in main to invoke A's m().
Tc.new A().m(); can be inserted in main to invoke A's m().
18.
Question: Given:
public List getList(){
*INSERT CODE HERE*
}
What can be inserted in the above code?
Select 3 option(s)
return new ArrayList
Integer
();
return new ArrayList
Number
();
return new ArrayList
Object
();
return new ArrayList();
return new ArrayList
? Super Number
();
return new ArrayList
? extends Number
();
19.
Question: Given:
public class Data implements Serializable{
int id;
transient LocalDate ld;
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
ld = LocalDate.of(2020,1,1);
}
}
Identify the correct statements about the above code.
Select 1 option(s)
This class does not perform serialization/deserialization correctly because it does not implement writeObject method.
The readObject method will be invoked after a Data object is deserialized.
The readObject method will be invoked before a Data object is deserialized.
The readObject method will never be invoked.
The readObject method will be invoked after a Data object is serialized.
The readObject method will be invoked before a Data object is serialized.
None
20.
Question: What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.add(1);
d.push(2);
d.pop();
d.offerFirst(3);
d.remove();
System.out.println(d);
Select 1 option(s)
1
2
3
Exception at run time.
It will not compile.
None
21.
Question: Given:
abstract class Vehicle{ }
interface Drivable{ }
class Car extends Vehicle implements Drivable{ }
class SUV extends Car { }
Which of the following options will fail to compile?
Select 1 option(s)
None
22.
Question: Consider the following code:
static void printElements(List... la) { //1
for(List l : la){ //2
System.out.println(l);
}
}
Select 1 option(s)
Line //1 will cause the compile to generate a warning.
Line //2 will cause the compile to generate a warning.
Both the lines //1 and //2 will cause the compile to generate a warning.
Neither of the lines //1 and //2 will cause the compile to generate a warning.
None
23.
Question: Consider the following code snippet:
void m1() throws Exception{
try{
// line1
}
catch (IOException e){
throw new SQLException();
}
catch(SQLException e){
throw new InstantiationException();
}
finally{
throw new CloneNotSupportedException(); // CloneNotSupportedException is a checked exception.
}
}
Which of the following statements are true?
Select 2 option(s)
If IOException gets thrown at line1, then the whole method will end up throwing SQLException.
If IOException gets thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
If IOException gets thrown at line1, then the whole method will end up throwing InstantiationException.
If no exception is thrown at line1, then the whole method will end up throwing CloneNotSupportedException.
If SQLException gets thrown at line1, then the whole method will end up throwing InstantiationException.
24.
Question: What will the following code print when run?
public class TestClass {
public static void main(String[] args) throws Exception {
var sa = new String[]{"a", "b", "c"};
for(String s : sa){
if("b".equals(s)) continue;
System.out.println(s);
if("b".equals(s)) break;
System.out.println(s+" again");
}
}
}
Select 1 option(s)
a
a again
c
c again
a
a again
b
a
a again
b
b again
c
c again
None
25.
Question: Given that Book is a valid class with appropriate constructor and getPrice method that returns a double, what can be inserted at //1 so that it will sum the price of all the books that are priced greater than 5.0?
List books = Arrays.asList(
new Book("Gone with the wind", 10.0),
new Book("Atlas Shrugged", 10.0),
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0)
);
//1 INSERT CODE HERE
System.out.println(sum);
Select 2 option(s)
26.
Question: You are creating an inventory module. This module contains a com.inventory.Queries class that uses a com.acme.DB class. This com.acme.DB class is contained in acme.db module. Which of the following files correctly defines the inventory module?
Select 1 option(s)
module inventory{
requires com.acme.db.*;
}
module inventory{
requires acme.db;
}
module inventory{
requires acme.db/com.acme.DB;
}
module inventory{
uses com.acme.DB;
}
module inventory{
requires com.acme.DB;
}
module inventory{
requires com.acme.DB transitively;
}
None
27.
Question: What will the following code snippet print?
Stream strm1 = Stream.of(2, 3, 5, 7, 11, 13);
double av = strm1
.filter(x->{ if(x>10)return true; else return false;}) //1
.peek() //2
.collect(Collectors.averagingInt(y->y)); //3
System.out.println(av);
Select 1 option(s)
12
12.0
Compilation failure due to code at //1.
Compilation failure due to code at //2.
Compilation failure due to code at //3.
Exception at run time.
None
28.
Question: Given:
public class FastDataProcessor{
public static int[] key = {1, 2, 3, 4, 5};
public native byte[] transform(byte[] input, int start, int end);
}
Identify correct statements from secure coding guidelines perspective about the above code?
Select 1 option(s)
Native methods should be avoided.
Static fields should be avoided.
The code will be fine if key is made final.
Usage of public arrays should be avoided.
The code will be fine if transform method is made final.
None
29.
Question: You are given two modules named enthu.training and enthu.course packaged in training.jar and course.jar. The training module depends on the course module. You want to run a class named com.enthu.training.StartGUI contained in enthu.training module.
Which of the following commands can be used?
Select 1 option(s)
Java --module-path training.jar;course.jar --main-class com.enthu.training.StartGUI.
Java --module-path training.jar;course.jar
--main-class enthu.training/com.enthu.training.StartGUI.
Java --module-path training.jar -classpath course.jar
--main-class com.enthu.training.StartGUI.
Java --module-path training.jar;course.jar
--module enthu.training/com.enthu.training.StartGUI.
Java --module-path training.jar;course.jar --module enthu.training.
None
30.
Question: Given:
public class PlaceHolder {
private K k;
private V v;
public PlaceHolder(K k, V v){
this.k = k;
this.v = v;
}
public K getK() { return k; }
public static PlaceHolder getDuplicateHolder(X x){
return new PlaceHolder(x, x);
}
public static void main(String[] args) {
PlaceHolder ph1 = PlaceHolder.getDuplicateHolder("b"); //1
PlaceHolder ph2 = PlaceHolder.getDuplicateHolder("b"); //2
PlaceHolder ph3 = PlaceHolder.getDuplicateHolder("b"); //3
PlaceHolder ph4 = new PlaceHolder("a", "b"); //4
PlaceHolder ph5 = new PlaceHolder(10, 10); //5
}
}
Which lines will fail compilation?
Select 3 option(s)
//1
//2
//3
//4
//5
31.
Question: What will the following code print when run?
import java.util.function.Predicate;
class Employee{
int age; //1
}
public class TestClass{
public static boolean validateEmployee(Employee e, Predicate p){
return p.test(e);
}
public static void main(String[] args) {
Employee e = new Employee(); //2
System.out.println(validateEmployee(e, e->e.age<10000)); //3
}
}
Select 1 option(s)
It will fail to compile at line marked //1.
It will fail to compile at line marked //2.
It will fail to compile at line marked //3.
It will compile fine and print true when run.
It will compile fine and print false when run.
None
32.
Question: Consider the following class:
class Test{
public static void main(String[] args){
for (var i = 0; i < 10; i++) System.out.print(i + " "); //1
for (var i = 10; i > 0; i--) System.out.print(i + " "); //2
var i = 20; //3
System.out.print(i + " "); //4
}
}
Which of the following statements are true?
Select 4 option(s)
As such, the class will compile and print "20 " (without quotes) at the end of its output.
It will not compile if line 3 is removed.
It will not compile if line 3 is removed and placed before line 1.
It will not compile if line 4 is removed and placed before line 3.
Only Option 2, 3, and 4 are correct.
33.
Question: Given the following code, which statements can be placed at the indicated position without causing compile and run time errors?
public class Test{
int i1;
static int i2;
public void method1(){
int i;
// ... insert statements here
}
}
Select 3 option(s)
i = this.i1;
i = this.i2;
this = new Test( );
this.i = 4;
this.i1 = i2;
34.
Question: Which of the following is/are valid instantiations and initializations of a multi dimensional array?
Select 2 option(s)
var array2D = { { 0, 1, 2, 4}, {5, 6}};
int[][][] array3D = {{0, 1}, {2, 3}, {4, 5}};
int[] array2D[] = new int [2] [2];
array2D[0] [0] = 1;
array2D[0] [1] = 2;
array2D[1] [0] = 3;
int[][] array2D = new int[][]{0, 1};
int[] arr = {1, 2};
int[][] arr2 = {arr, {1, 2}, arr};
int[][][] arr3 = {arr2};
int[][] array2D = new int[][] { { 0, 1, 2, 4} {5, 6}};
35.
Question: What will be the contents of s1 and s2 at the time of the println statement in the main method of the following program?
import java.util.*;
public class TestClass{
public static void main(String args[]){
Stack s1 = new Stack ();
Stack s2 = new Stack ();
processStacks (s1, s2);
System.out.println (s1 + " "+ s2);
}
public static void processStacks(Stack x1, Stack x2){
x1.push (new Integer ("100")); //assume that the method push adds the passed object to the stack.
x2 = x1;
}
}
Note:[] is used in the options below to denote each element of the Stack.
Select 1 option(s)
[100] [100]
[100] []
[] [100]
[] []
None
36.
Question: What will the following program print?
class Test{
public static void main(String[] args){
var i = 4;
int ia[][][] = new int[i][i = 3][i];
System.out.println( ia.length + ", " + ia[0].length+", "+ ia[0][0].length);
}
}
Select 1 option(s)
It will not compile.
3, 4, 3
3, 3, 3
4, 3, 4
4, 3, 3
None
37.
Question: What will be the output when the following code is compiled and run?
//in file Test.java
class E1 extends Exception{ }
class E2 extends E1 { }
class Test{
public static void main(String[] args){
try{
throw new E2();
}
catch(E1 e){
System.out.println("E1");
}
catch(Exception e){
System.out.println("E");
}
finally{
System.out.println("Finally");
}
}
}
Select 1 option(s)
It will not compile.
It will print E1 and Finally.
It will print E1, E and Finally.
It will print E and Finally.
It will print Finally.
None
38.
Question: Which of the following illustrates a good coding practice given that the database connection is to be reused?
Select 1 option(s)
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); )
{
while(rs.next()){
//do something with the row
}
}
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); ) {
while(rs.next()){
//do something with the row
}
}
finally{
rs.close();
stmt.close();
}
try(Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT"); ) {
while(rs.next()){
//do something with the row
}
}
catch(SQLException e){
}
Statement stmt = null;
ResultSet rs = null;
try{
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
//do something with the row
}
}
finally{
rs.close(); stmt.close();
}
None
39.
Question: What will the following code print when run?
public class Noobs {
public void m(int a){
System.out.println("In int ");
}
public void m(char c){
System.out.println("In char ");
}
public static void main(String[] args) {
Noobs n = new Noobs();
int a = 'a';
char c = 6;
n.m(a);
n.m(c);
}
}
Select 1 option(s)
In int
In char
In char
In int
In int
In int
In char
In char
It will not compile.
None
40.
Question: What will the following code print when compiled and run?
var strList1 = new ArrayList();
strList1.add("A");
var strList2 = Collections.unmodifiableList(strList1);
strList1.add(null);
System.out.println(strList1+" "+strList2);
strList2.add(null);
System.out.println(strList1+" "+strList2);
Select 2 option(s)
[A, null] [A, null]
[A, null] [A]
It will throw a java.lang.UnsupportedOperationException at run time.
It will throw a java.lang.NullPointerException at run time.
It will not generate any output other than an exception stack trace.
41.
Question: Given:
Map<String , List> stateCitiesMap = new HashMap<String, List>();
Which of the following options correctly achieves the same or compatible declaration using type inference?
Select 2 option(s)
42.
Question: Given:
class Booby{
}
class Dooby extends Booby{
}
class Tooby extends Dooby{
}
and the following declarations:
var bL = new ArrayList();
var tL = new ArrayList();
List bV = //code for initialization
List dV = //code for initialization
Which of the following statements are valid?
Select 4 option(s)
dV.add(new Dooby(){ });
bV = bL;
dV = bL;
bV = tL;
dV = tL;
bV.add(new Dooby(){ });
43.
Question: What will be the result of compiling and running the following code?
class Base{
public Object getValue(){ return new Object(); } //1
}
class Base2 extends Base{
public String getValue(){ return "hello"; } //2
}
public class TestClass{
public static void main(String[] args){
Base b = new Base2();
System.out.println(b.getValue()); //3
}
}
Select 1 option(s)
It will print the hash code of the object.
It will print hello.
Compile time error at //1.
Compile time error at //2.
Compile time error at //3.
None
44.
Question: Which of the following statements will compile without any error?
Select 3 option(s)
45.
Question: Given:
class OverloadingTest{
void m1(int x){
System.out.println("m1 int");
}
void m1(double x){
System.out.println("m1 double");
}
void m1(String x){
System.out.println("m1 String");
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
OverloadingTest ot = new OverloadingTest();
ot.m1(1.0);
}
}
What will be the output?
Select 1 option(s)
It will fail to compile.
m1 int
m1 double
m1 String
None
46.
Question: Which of the following lines will cause the compilation to fail?
public enum EnumA{ A, AA, AAA}; //1
public class TestClass //2
{
public enum EnumB{ B, BB, BBB }; //3
public static enum EnumC{ C, CC, CCC }; //4
public TestClass()
{
enum EnumD{ D, DD, DDD } //5
}
public void methodX()
{
public enum EnumE{ E, EE, EEE } //6
}
public static void main(String[] args) //7
{
enum EnumF{ F, FF, FFF}; //8
}
}
Select 4 option(s)
1, 2, or both depending on the file name.
3
4
5
6
7
8
47.
Question: What would be the result of compiling and running the following program?
class SomeClass{
public static void main(String args[]){
var size = 10;
var arr = new int[size];
for (var i = 0 ; i < size ; ++i) System.out.println(arr[i]);
}
}
Select 1 option(s)
The code will fail to compile, because the int[] array declaration is incorrect.
The program will compile, but will throw an IndexArrayOutOfBoundsException when run.
The program will compile and run without error, and will print nothing.
The program will compile and run without error and will print null ten times.
The program will compile and run without error and will print 0 ten times.
The code will fail to compile, because the array elements are being accessed without being initialized first.
None
48.
Question: What will the following code print when compiled and run?
public class OrderTest {
public void initData(String[] arr){
int ind = 0;
for(String str : arr){
str.concat(str+" "+ind);
ind++;
}
}
public void printData(String[] arr){
for(var str : arr){
System.out.println(str);
}
}
public static void main(String[] args) {
var ot = new OrderTest();
String[] arr = new String[2];
ot.initData(arr);
ot.printData(arr);
}
}
Select 1 option(s)
null 0
null 1
0
1
0
1
(There is a space before 0 and 1)
null
null
It will throw a RuntimeException at run time.
None
49.
Question: What will the following code print when compiled and run?
class Names{
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public void printNames(){
System.out.println(getList());
}
public static void main(String[] args) {
List list = Arrays.asList(
"Bob Hope",
"Bob Dole",
"Bob Brown"
);
Names n = new Names();
n.setList(list.stream().collect(Collectors.toList()));
n.getList().forEach(Names::printNames);
}
}
Select 1 option(s)
[Bob Hope, Bob Dole, Bob Brown]
Bob HopeBob DoleBob Brown.
[null, null, null]
Compilation error.
An exception will be thrown at run time.
None
50.
Question: Given:
public static boolean getBool(){
return true;
}
public static String getString(){
return "true";
}
public static void main(String args[]){
switch( getBool() ){
case true :
System.out.println("true");
break;
default :
System.out.println("none");
break;
}
}
What changes can be done so that it will print only true?
Select 1 option(s)
No change is necessary.
Call getString instead of getBool in the switch.
Call getString instead of getBool in the switch and also change the case label from true to "true".
Remove the default section of the switch block.
None
51.
Question: What will the following program print when run?
public class ChangeTest {
private int myValue = 0;
public void showOne(int myValue){
myValue = myValue;
System.out.println(this.myValue);
}
public void showTwo(int myValue){
this.myValue = myValue;
System.out.println(this.myValue);
}
public static void main(String[] args) {
var ct = new ChangeTest();
ct.showOne(100);
ct.showTwo(200);
}
}
Select 1 option(s)
0 followed by 100.
100 followed by 100.
0 followed by 200.
100 followed by 200.
None
52.
Question: Consider the following classes...
class Car{
public int gearRatio = 8;
public String accelerate() { return "Accelerate : Car"; }
}
class SportsCar extends Car{
public int gearRatio = 9;
public String accelerate() { return "Accelerate : SportsCar"; }
public static void main(String[] args){
Car c = new SportsCar();
System.out.println( c.gearRatio+" "+c.accelerate() );
}
}
What will be printed when SportsCar is run?
Select 1 option(s)
8 Accelerate : Car
9 Accelerate : Car
8 Accelerate : SportsCar
9 Accelerate : SportsCar
None of the above.
None
53.
Question: Given:
class MyException extends Exception {
private final int code;
public MyException(int code, Throwable actualEx){
super(actualEx);
this.code = code;
}
public MyException(int code, String message, Throwable actualEx){
super(message, actualEx);//1
this.code = code;
}
public String getMessage(){
return String.format("Exception - Code=%d, Msg=%s, OrigMsg=%s", code, super.getMessage(), this.getCause().getMessage()); //2
}
}
public class TestClass {
public static void main(String[] args) {
try{
throw new MyException(404, "NOT FOUND", new IOException("FILE UNREADABLE")); //3
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What is the result?
Select 1 option(s)
Compilation failure at //1.
Compilation failure at //2.
It will print:
Exception - Code=404, Msg=NOT FOUND, OrigMsg=FILE UNREADABLE
It will print:
Exception - Code=404, Msg=, OrigMsg=FILE UNREADABLE
It will print:
Exception - Code=404, Msg=, OrigMsg=
It will print:
Exception - Code=404, Msg=FILE UNREADABLE, OrigMsg=NOT FOUND
It will print:
Exception - Code=404, Msg=null, OrigMsg=null
None
54.
Question: Consider the following lines of code:
System.out.println(null + true); //1
System.out.println(true + null); //2
System.out.println(null + null); //3
Which of the following statements are correct?
Select 1 option(s)
None of the 3 lines will compile.
All the 3 lines will compile and print nulltrue, truenull and nullnull respectively.
Line 1 and 2 won't compile but line 3 will print nullnull.
Line 3 won't compile but line 1 and 2 will print nulltrue and truenull respectively.
None of the above.
None
55.
Question: Identify correct statements about -classpath and --module-path options while executing a java program.
Select 3 option(s)
A modular jar placed on the classpath results in a named application module.
A non-modular jar placed on the classpath results in an automatic module.
A non-modular jar placed on the module-path results in an automatic module.
A modular jar placed on the module-path results in a named application module.
If a package is available in a jar on the classpath as well as in another jar on the module-path, the one on the classpath is ignored.
Classpath or module-path are mutually exclusive i.e. only one of them should be used.
56.
Question: Given:
interface Instrument{
default void reset(){
System.out.println("In Instrument");
}
}
class Debt implements Instrument{
}
class Bond extends Debt{
public void reset(){
super.reset();
System.out.println("In Bond");
}
}
class ZCBond extends Bond{
ZCBond(){
reset();
}
public void reset(){
super.reset();
System.out.println("In ZCBond");
}
public static void main(String args[]){
Instrument i = new ZCBond();
}
}
What is the output?
Select 1 option(s)
The Bond class will fail to compile.
The Debt class will fail to compile.
In Instrument
In Bond
In ZCBond
In ZCBond
In Bond
In Instrument
In Bond
In ZCBond
In ZCBond
In Bond
None
57.
Question: Assume that a stored procedure named generateDailyGainsReport exists in your database. It takes two parameters - portfolioId and a date and returns a result set with several rows of data.
Consider the following Java code:
try(Connection c = ds.getConnection();
var stmt = c.prepareCall("{call generateDailyGainsReport(?,?)}") ) { //1
stmt.setObject("PORTFOLIOID", portfolioId, JDBCType.VARCHAR); //2
stmt.setObject("VALUEDATE", date, JDBCType.DATE); //3
boolean hasResult = stmt.execute(); //4
if(hasResult){
ResultSet rs = stmt.getResultSet(); //5
//code to process result
}
}
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, portfolioId, java.sql.Types.STRING); //2
stmt.setObject(2, date, java.sql.Types.DATE); //3
It will fail to compile unless stmt.setString and stmt.setDate are used at //2 and //3.
It will cause a compilation error at //4 because stmt.execute() returns void.
It will throw an exception at runtime at //5 because the stmt.execute was called instead of stmt.executeQuery.
It is a valid usage of CallableStatement and there is no problem with the code.
None
58.
Question: Consider the following code:
public class Student {
private Map marksObtained = new HashMap();
private ReadWriteLock lock = new ReentrantReadWriteLock();
public void setMarksInSubject(String subject, Integer marks){
// valid code to set marks for a given subject
}
public double getAverageMarks(){
//1 - INSERT CODE HERE
var sum = 0.0;
try{
for(Integer mark : marksObtained.values()){
sum = sum + mark;
}
return sum/marksObtained.size();
}finally{
//2 - INSERT CODE HERE
}
}
}
What should be inserted at //1 and //2?
Select 1 option(s)
lock.lock();
and
lock.unlock();
lock.readLock();
and
lock.readUnlock();
lock.read();
and
lock.unlock();
lock.readLock().lock();
and
lock.readLock().unlock();
None
59.
Question: Given the following two files in /user/home directory:
In file messages.properties:
message=hi {0}, thanks {1}
In file messages_fr_FR.properties:
message=salut {0}, merci {1}
and the following class in /user/home directory:
public class TestClass
{
public static void main(String[] args) {
//INSERT CODE HERE
System.out.println(message);
}
}
Which of the following options when inserted in TestClass will print salut Amy, merci Adams?
Select 2 option(s)
ResourceBundle msg = ResourceBundle.getBundle("/user/home/messages", new Locale("fr", "FR"));
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
ResourceBundle msg = ResourceBundle.getBundle("messages.messages", Locale.FRANCE);
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
ResourceBundle msg = ResourceBundle.getBundle("messages", new Locale("fr", "FR"));
Object[] names = { "Amy", "Adams" };
String message = MessageFormat.format(msg.getString("message") , names);
Locale.setDefault(Locale.FRANCE);
ResourceBundle msg = ResourceBundle.getBundle("messages");
String message = MessageFormat.format(msg.getString("message") , "Amy", "Adams");
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