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 - 2
Name
Email
Phone
1.
Question: You are creating an acme.db module. This module contains a com.acme.DB class that will be used by other modules of your application. Which of the following files correctly defines the acme.db module?
Select 1 option(s)
module acme.db{
exports com.acme/DB;
}
module acme.db{
exports com.acme.*;
}
module acme.db{
public com.acme;
}
module acme.db{
exports com.acme.DB;
}
module acme.db{
exports com.acme;
}
module acme.db{
exports com.acme to *;
}
None
2.
Question: Which of the following code fragments is/are appropriate usage(s) of generics?
Select 2 option(s)
3.
Question: Which of the following options correctly create an ExecutorService instance?
Select 1 option(s)
var es = ExecutorService.getInstance();
var es = new ExecutorService();
var es = Executors.newFixedThreadPool(2);
var es = Executor.getSingleThreadExecutor();
var es = Executors.getSingleThreadExecutor();
None
4.
Question: What will the following code print when compiled and run?
public class TestClass{
public static void main(String[] args) {
System.out.println(getMsg((char)10));
}
public static String getMsg(char x){
String msg = "Input value must be ";
msg = msg.concat("smaller than X");
msg.replace('X', x);
String rest = " and larger than 0";
msg.concat(rest);
return msg;
}
}
Select 1 option(s)
Input value must be smaller than X and larger than 0.
Input value must be smaller than 10 and larger than 0.
Input value must be smaller than X.
Input value must be smaller than 10.
None
5.
Question: What will the following program print when compiled and run?
class Game{
public void play() throws Exception{
System.out.println("Playing...");
}
}
public class Soccer extends Game{
public void play(){
System.out.println("Playing Soccer...");
}
public static void main(String[] args){
Game g = new Soccer();
g.play();
}
}
Select 1 option(s)
It will not compile.
It will throw an Exception at runtime.
Playing Soccer...
Playing...
None of these.
None
6.
Question: How will you initialize a SimpleDateFormat object so that the following code will print the full text time zone of the given date?
System.out.println(sdf.format(new Date()));
Select 1 option(s)
None
7.
Question: A java source file contains the following code:
interface I {
int getI(int a, int b);
}
interface J{
int getJ(int a, int b, int c);
}
abstract class MyIJ implements J , I { }
class MyI{
int getI(int x, int y){ return x+y; }
}
interface K extends J{
int getJ(int a, int b, int c, int d);
}
Identify the correct statements:
Select 1 option(s)
It will fail to compile because of MyIJ.
It will fail to compile because of MyIJ and K.
It will fail to compile because of K.
It will fail to compile because of MyI and K.
It will fail to compile because of MyIJ, K, and MyI.
It will compile without any error.
None
8.
Question: Which of the following commands can be used to run a class named com.foo.Bar, which is part of a module named foo.bar packaged in foobar.jar.
(Assume that the jar file is located in the current directory.)
Select 1 option(s)
java --classpath foobar.jar --module foo.bar/com.foo.Bar
java --module foobar.jar foo.bar/com.foo.Bar
java --classpath foobar.jar --module-path foo.bar/com.foo.Bar
java --module-path foobar.jar com.foo.Bar
java --module-path foobar.jar --module foo.bar/com.foo.Bar
None
9.
Question: Checked exceptions are meant for...
Select 1 option(s)
Exceptional conditions external to an application that a well written application should anticipate and from which it can recover.
Exceptional conditions external to the program that a well written program cannot anticipate but should recover from.
Exceptional conditions from which recovery is difficult or impossible.
Exceptional situations internal to an application that the application can anticipate but cannot recover from.
None
10.
Question: Which of the given statements are correct for a method that overrides the following method:
public Set getSet(int a) {...}
Assume that Set is an interface and HashSet is a class that implements Set.
Select 3 option(s)
Its return type must be declared as Set.
It may return HashSet.
It can declare any Exception in throws clause
It can declare any RuntimeException in throws clause.
It can be abstract.
11.
Question: What will the following code print?
public class Test{
public static void stringTest(String s){
s.replace('h', 's');
}
public static void stringBuilderTest(StringBuilder s){
s.append("o");
}
public static void main(String[] args){
String s = "hell";
StringBuilder sb = new StringBuilder("well");
stringTest(s);
stringBuilderTest(sb);
System.out.println(s + sb);
}
}
Select 1 option(s)
sellwello
hellwello
hellwell
sellwell
None of these.
None
12.
Question: Given:
//1
public class TestClass {
//2
public static void main(String... args) throws Exception{
List al = new ArrayList();
printElements(al);
}
//3
static void printElements(List... la) {
for(List l : la){
System.out.println(l);
}
}
}
Which option will get rid of compilation warnings for the above code?
Select 1 option(s)
Apply @SafeVarargs at //1.
Apply @SafeVarargs at //2.
Apply @SafeVarargs at //3.
Apply @SafeVarargs at //2 as well as //3.
None of the above.
None
13.
Question: Consider the following program:
class Test{
public static void main(String[] args){
short s = 10; // 1
char c = s; // 2
s = c; // 3
}
}
Identify the correct statements.
Select 2 option(s)
Line 3 is not valid.
Line 2 is not valid.
It will compile because both short and char can hold 10.
None of the lines 1, 2 and 3 is valid.
14.
Question: Identify correct statements regarding Java module system.
Select 1 option(s)
The file in which module information is specified must be named moduleinfo.java.
Module information can also be specified using @Module annotation.
Every class of a module must specify which module it belongs to either using @Module annotation or using a command line option.
Module-info.java must list all packages that you want to add to that module.
The only information required in the file that specifies module information is the module name.
None
15.
Question: What can be inserted in the code below so that it will print true when run?
public class TestClass{
public static boolean checkList(List list, Predicate p){
return p.test(list);
}
public static void main(String[] args) {
boolean b = //WRITE CODE HERE
System.out.println(b);
}
}
Select 2 option(s)
checkList(new ArrayList(), al -> al.isEmpty());
checkList(new ArrayList(), ArrayList al -> al.isEmpty());
checkList(new ArrayList(), al -> return al.size() == 0);
checkList(new ArrayList(), al -> al.add("hello"));
checkList(new ArrayList(), (ArrayList al) -> al.isEmpty());
16.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
Object a, b, c ;
a = new String("A");
b = new String("B");
c = a;
a = b;
System.out.println(""+c);
}
}
Select 1 option(s)
The program will print java.lang.String@XXX, where XXX is the memory location of the object a.
The program will print A.
The program will print B.
The program will not compile because the type of a, b, and c is Object.
The program will print java.lang.String@XXX, where XXX is the hash code of the object a.
None
17.
Question: Given the following class:
public class SpecialPicker{
public K pickOne(K k1, K k2){
return k1.hashCode()>k2.hashCode()?k1:k2;
}
}
what will be the result of running the following lines of code:
SpecialPicker sp = new SpecialPicker(); //1
System.out.println(sp.pickOne(1, 2).intValue()+1); //2
Select 1 option(s)
The first line of code will not compile.
The second line of code will not compile.
It will throw an exception at run time.
It will print 3.
None
18.
Question: Given the following class:
public class Food{ // LINE 1
String name;
int caloriesPerServing;
public Food(String name, int calories){
this.name = name; this.caloriesPerServing = calories;
}
//accessors not shown
//LINE 2
}
This class is used in an application as follows -
ArrayList al = new ArrayList();
//code that adds Food objects to al not shown
Collections.sort(al);
What changes must be done to Food class so that the call to Collections.sort(al) will work as expected?
Select 2 option(s)
Replace line 1 with :
public class Food implements Comparable
Food
{
Replace line 1 with :
public class Food implements Comparator
Food
{
Replace line 1 with :
public class Food extends Comparator
Food
{
Replace line 1 with :
public class Food extends Comparable< Food >{
Add the following a line 2 :
public int compareTo(Food f){
return this.name.compareTo(f.name);
}
Add the following a line 2 :
public boolean compare(Food f){
return this.name.compare(f.name);
}
Add the following a line 2 :
public int compare(Food f){
return this.name.compare(f.name);
}
19.
Question: What will the following code print?
var flag = true;
if(flag = false){
System.out.println("1");
}else if(flag){
System.out.println("2");
}else if(!flag){
System.out.println("3");
}else System.out.println("4");
Select 1 option(s)
1
2
3
4
Compilation error.
None
20.
Question: What will the following code print?
List s1 = new ArrayList( );
s1.add("a");
s1.add("b");
s1.add("c");
s1.add("a");
if(s1.remove("a")){
if(s1.remove("a")){
s1.remove("b");
}else{
s1.remove("c");
}
}
System.out.println(s1);
Select 1 option(s)
[b]
[c]
[b, c, a]
[a, b, c, a]
Exception at runtime
None
21.
Question: You are writing a class named Bandwidth for an internet service provider that keeps track of number of bytes consumed by a user. The following code illustrates the expected usage of this class -
class User{
Bandwidth bw = new Bandwidth();
public void consume(int bytesUsed){
bw.addUsage(bytesUsed);
}
... other irrelevant code
}
class Bandwidth{
private int totalUsage;
private double totalBill;
private double costPerByte;
//add your code here
...other irrelevant code
}
Your goal is to implement a method addUsage (and other methods, if required) in Bandwidth class such that all the bandwidth used by a User is reflected by the totalUsage field and totalBill is always equal to totalUsage*costPerByte. Further, that a User should not be able to tamper with the totalBill value and is also not able to reduce it.
Which of the following implementation(s) accomplishes the above?
Select 1 option(s)
None
22.
Question: Assuming that STOCK table exists and is empty, what will the following code snippet print?
String qr = "insert into STOCK ( ID, TICKER, LTP, EXCHANGE ) values( ?, ?, ?, ?)";
try(PreparedStatement ps = c.prepareStatement(qr);)
{
ps.setInt(1, 111);
ps.setString(2, "APPL");
ps.setDouble(3, 0.0);
ps.setNull(4, java.sql.Types.VARCHAR);
int i = ps.executeUpdate(); //1
System.out.println(i);
}
Assume that EXCHANGE column allows null values.
Select 1 option(s)
It will not compile due to error at //1.
It will print 0.
It will print 1.
It will print 4.
It will print -1.
It will throw an exception at run time.
None
23.
Question: Given the following code, which of the constructors shown in the options can be added to class B without causing a compilation to fail (independent of each other)?
class A{
int i;
public A(int x) { this.i = x; }
}
class B extends A{
int j;
public B(int x, int y) { super(x); this.j = y; }
}
Select 2 option(s)
B( ) { }
B(int y ) { j = y; }
B(int y ) { super(y*2 ); j = y; }
B(int y ) { i = y; j = y*2; }
B(int z ) { this(z, z); }
24.
Question: Given the following code:
interface Movable{
int offset = 100;
public void move(int dx);
}
interface Growable{
public void grow(int dy);
}
class Animal implements Movable, Growable{
public void move(int dx){ }
public void grow(int dy){ }
}
Select 1 option(s)
Animal class illustrates Java's support for multiple inheritance of type.
Animal class illustrates Java's support for multiple inheritance of state.
Animal class illustrates Java's support for multiple inheritance of type as well as state.
Animal class illustrates Java's support for multiple implementation inheritance.
None
25.
Question: What will the following program print?
class Test{
public static void main(String args[]){
int var = 20, i=0;
do{
while(true){
if( i++ > var) break;
}
}while(i<var--);
System.out.println(var);
}
}
Select 1 option(s)
19
20
21
22
It will enter an infinite loop.
It will not compile due to the variable named var.
None
26.
Question: A novice java programmer is unable to get a file named Coffee.java compiled. It contains the following enum definition:
public enum Coffee //1
{
ESPRESSO("Very Strong"), MOCHA, LATTE; //2
public String strength; //3
Coffee(String strength) //4
{
this.strength = strength; //5
}
public String toString(){ return strength; } //6
}
Which line is causing the problem?
Select 1 option(s)
1
2
3
4
5
6
None
27.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
A o1 = new C( );
B o2 = (B) o1;
System.out.println(o1.m1( ) );
System.out.println(o2.i );
}
}
class A { int i = 10; int m1( ) { return i; } }
class B extends A { int i = 20; int m1() { return i; } }
class C extends B { int i = 30; int m1() { return i; } }
Select 1 option(s)
The program will fail to compile.
Class cast exception at runtime.
It will print 30, 20.
It will print 30, 30.
It will print 20, 20.
None
28.
Question: What will be the result of compilation and execution of the following code?
IntStream is1 = IntStream.range(0, 5); //1
OptionalDouble x = is1.average(); //2
System.out.println(x); //3
Select 1 option(s)
It will print 2.5
It will print 2.0
It will print OptionalDouble[2.0]
It will print OptionalDouble[3.0]
It will print 2.0 if line at //2 is replaced with double x = is1.average();
It will print 2.5 if line at //2 is replaced with double x = is1.average();
None
29.
Question: Given:
PERSON table in the database with the following data:
ID(int) NAME(varchar) TAXID(varchar)
--------------------
1 Ally 111
2 Bob 222
and the following code:
Connection c = ds.getConnection(); //assume that ds refers to a DataSource
Statement stmt = c.createStatement();
String qr = "select * from PERSON";
try(ResultSet rs = stmt.executeQuery(qr);
PreparedStatement ps1 = c.prepareStatement("update PERSON set taxid = 'NNNN' where id=?");
)
{
while(rs.next()){
int id = rs.getInt(1);
ps1.setInt(1, id);
ps1.executeUpdate(); //1
System.out.println("Updated "+rs.getString(3)); //2
}
}
Identify correct statements.
Note: In the options below, the word "query" refers to all kinds of SQL queries (select/update/insert) and not just the "select" query.
Select 2 option(s)
It will execute one query on the database.
It will execute two querries on the database.
It will execute three querries on the database.
It will throw an exception at //1
It will print:
Updated NNNN
Updated NNNN
It will print:
Updated 111
Updated 222
30.
Question: What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
int i = 0;
loop : // 1
{
System.out.println("Loop Lable line");
try{
for ( ; true ; i++ ){
if( i >5) break loop; // 2
}
}
catch(Exception e){
System.out.println("Exception in loop.");
}
finally{
System.out.println("In Finally"); // 3
}
}
}
}
Select 1 option(s)
Compilation error at line 1 as this is an invalid syntax for defining a label.
Compilation error at line 2 as 'loop' is not visible here.
No compilation error and line 3 will be executed.
No compilation error and line 3 will NOT be executed.
Only the line with the label loop will be printed.
None
31.
Question: Given the class.
// Filename: Test.java
public class Test{
public static void main(String args[]){
for(int i = 0; i< args.length; i++){
System.out.print(" "+args[i]);
}
}
}
Now consider the following 3 options for running the program:
a: java Test
b: java Test param1
c: java Test param1 param2
Which of the following statements are true?
Select 2 option(s)
The program will throw java.lang.ArrayIndexOutOfBoundsException on option a.
The program will throw java.lang.NullPointerException on option a.
The program will print Test param1 on option b.
It will print param1 param2 on option c.
It will not print anything on option a.
32.
Question: What will be printed when the following code is compiled and run?
package trywithresources;
import java.io.IOException;
public class Device{
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.read();
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
Got Exception
Device closed
Device Opened
Got Exception
The code will not compile.
None
33.
Question: What two changes can you do, independent of each other, to make the following code compile:
//assume appropriate imports
class PortConnector {
public PortConnector(int port) {
if (Math.random() > 0.5) { //assume that random() returns a random value between 0.0 and 1.0)
throw new IOException();
}
throw new RuntimeException();
}
}
public class TestClass {
public static void main(String[] args) {
try {
PortConnector pc = new PortConnector(10);
} catch (RuntimeException re) {
re.printStackTrace();
}
}
}
Select 2 option(s)
Add throws IOException to the main method.
Add throws IOException to PortConnector constructor.
Add throws IOException to the main method as well as to PortConnector constructor.
Change RuntimeException to java.io.IOException.
Add throws Exception to PortConnector constructor and change catch(RuntimeException re) to catch(Exception re) in the main method.
34.
Question: What will the following code print?
List names = Arrays.asList("Peter", "Paul", "Pascal");
Optional ops = names.stream()
.parallel()
.allMatch(name->name!=null)
.filter(name->name.length()>6)
.findAny();
System.out.println(ops);
Select 1 option(s)
It may print any name out of the three in the list.
It will print Optional.empty.
It will print Optional[Peter].
It will not compile.
None
35.
Question: Which of the following statements will compile without any error?
Select 4 option(s)
System.out.println("a"+'b'+63);
System.out.println("a"+63);
System.out.println('b'+new Integer(63));
String s = 'b'+63+"a";
String s = 63 + new Integer(10);
36.
Question: What will the following program print?
public class TestClass{
static String str;
public static void main(String[] args){
System.out.println(str);
}
}
Select 1 option(s)
It will not compile.
It will compile but throw an exception at runtime.
It will print 'null' (without quotes).
It will print nothing.
None of the above.
None
37.
Question: Identify valid methods:
Assume that Shape is a valid non-final class.
Select 2 option(s)
38.
Question: What will be the output when the following program is run?
package exceptions;
public class TestClass{
public static void main(String[] args) {
try{
hello();
}
catch(MyException me){
System.out.println(me);
}
}
static void hello() throws MyException{
int[] dear = new int[7];
dear[0] = 747;
foo();
}
static void foo() throws MyException{
throw new MyException("Exception from foo");
}
}
class MyException extends Exception {
public MyException(String msg){
super(msg);
}
}
(Assume that line numbers printed in the messages given below are correct.)
Select 1 option(s)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at exceptions.TestClass.doTest(TestClass.java:24)
at exceptions.TestClass.main(TestClass.java:14)
Error in thread "main" java.lang.ArrayIndexOutOfBoundsException
Exceptions.MyException: Exception from foo
Exceptions.MyException: Exception from foo
at exceptions.TestClass.foo(TestClass.java:29)
at exceptions.TestClass.hello(TestClass.java:25)
at exceptions.TestClass.main(TestClass.java:14)
None
39.
Question: What is the effect of compiling and running the code shown in exhibit?
public class TestClass{
public static void main (String args []){
var sum = 0;
for (int i = 0, j = 10; sum > 20; ++i, --j) // 1
{
sum = sum+ i + j;
}
System.out.println("Sum = " + sum);
}
}
Select 1 option(s)
Compile time error at line 1.
It will print Sum = 0.
It will print Sum = 20.
Runtime error.
None of the above.
None
40.
Question: What will the following program print?
public class TestClass{
static boolean b;
static int[] ia = new int[1];
static char ch;
static boolean[] ba = new boolean[1];
public static void main(String args[]) throws Exception{
var x = false;
if( b ){
x = ( ch == ia[ch]);
}
else x = ( ba[ch] = b );
System.out.println(x+" "+ba[ch]);
}
}
Select 1 option(s)
true true
true false
false true
false false
It will not compile.
None
41.
Question: Given that a class named mywids.Widget is part of a module named mod.wids packaged in mywidgets.jar, which of the following commands can be used to execute this class?
(Assume that the jar file is located in the current directory and the jar file does not have any entry in its manifest.)
Select 1 option(s)
java --module-path mywidgets.jar --module mywids.Widget
java --module-path mywidgets.jar --module mod.wids/mywids.Widget
java --module-path mywidgets.jar --module mod.wids --main-class mywids.Widget
java --module-path mywidgets.jar --module mod.wids mywids.Widget
None
42.
Question: What will be the output of the following lines?
System.out.println("" +5 + 6); //1
System.out.println(5 + "" +6); // 2
System.out.println(5 + 6 +""); // 3
System.out.println(5 + 6); // 4
Select 1 option(s)
56
56
11
11
11
56
11
11
56
56
56
11
56
56
56
56
56
56
11
56
None
43.
Question: Given:
interface Carnivore{
default int calories(List food){
return food.size()*100;
}
int eat(List foods);
}
class Tiger implements Carnivore{
public int eat(List foods){
System.out.println("Eating "+foods);
return foods.size()*200;
}
}
public class TestClass {
public static int size(List names){
return names.size()*2;
}
public static void process(List names, Carnivore c){
c.eat(names);
}
public static void main(String[] args) {
List fnames = Arrays.asList("a", "b", "c");
Tiger t = new Tiger();
INSERT CODE HERE
}
}
Which of the following options can be inserted independent of each other in the code above without any compilation error?
Select 3 option(s)
process(fnames, t::eat);
process(fnames, t::calories);
process(fnames, TestClass::size);
process(fnames, Carnivore::calories);
process(fnames, Tiger::eat);
44.
Question: Which of the following code fragments compile without any error?
Select 3 option(s)
45.
Question: Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 3 option(s)
public List
? extends Integer
getList(){
public List
? super Number
getList(){
public List
? extends Number
getList(){
public ArrayList
? extends Integer
getList(){
public ArrayList
Number
getList(){
public ArrayList
Integer
getList(){
46.
Question: Given the following classes and declarations, which of these statements about //1 and //2 are true?
class A{
private int i = 10;
public void f(){}
public void g(){}
}
class B extends A{
public int i = 20;
public void g(){}
}
public class C{
A a = new A();//1
A b = new B();//2
}
Select 1 option(s)
System.out.println(b.i); will print 10.
The statement b.f( ); will cause compile time error.
System.out.println(b.i); will print 20.
All of the above are correct.
None of the above statements is correct.
None
47.
Question: Given:
class Book{
private String title;
private double price;
public Book(String title, double price){
this.title = title;
this.price = price;
}
//getters/setters not shown
}
What will the following code print?
List books = Arrays.asList(new Book("Thinking in Java", 30.0),
new Book("Java in 24 hrs", 20.0),
new Book("Java Recipies", 10.0));
double averagePrice = books.stream().filter(b->b.getPrice()>10)
.mapToDouble(b->b.getPrice())
.average().getAsDouble();
System.out.println(averagePrice);
Select 1 option(s)
It will not compile.
It will throw an exception at runtime.
0.0
25.0
10.0
None
48.
Question: Given:
var data = new ArrayList();
data.add("A");
data.add(100); //1
data.add("C");
data.set(0, 200); //2
data.remove(2); //3
data.set(2, 101L);//4
System.out.println(data);
What will be the output?
Select 1 option(s)
It will not compile.
Exception at run time on line marked //1.
Exception at run time on line marked //2.
Exception at run time on line marked //3.
Exception at run time on line marked //4.
[200, 100, 101]
None
49.
Question: You have created a module named mycompany.smartschool packaged in smartschool.jar. This module uses a third party non-modular java library packaged as utils.jar.
How will you execute your module's main class named mycompany.smartschool.Main?
(Assume that the jar files are located in the current directory.)
Select 1 option(s)
Java --module-path smartschool.jar;utils.jar
--module mycompany.smartschool/mycompany.smartschool.Main.
Java -classpath utils.jar --module-path smartschool.jar
--module mycompany.smartschool/mycompany.smartschool.Main.
Java -cp utils.jar;smartschool.jar
--module mycompany.smartschool/mycompany.smartschool.Main.
Java -classpath utils.jar --module-jar smartschool.jar
-main-class mycompany.smartschool/mycompany.smartschool.Main.
None
50.
Question: Consider these two interfaces:
interface I1
{
void m1() throws java.io.IOException;
}
interface I2
{
void m1() throws java.sql.SQLException;
}
What methods have to be implemented by a class that says it implements I1 and I2 ?
Select 1 option(s)
Both, public void m1() throws SQLException; and public void m1() throws IOException;
Public void m1() throws Exception.
The class cannot implement both the interfaces simultaneously because they have conflicting methods.
Public void m1() throws SQLException, IOException;
None of the above.
None
51.
Question: What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
while(var k = 5; k<7){
System.out.println(k++);
}
}
}
Select 1 option(s)
5
6
5
6
7
It will keep printing 5.
It will not compile.
It will throw an exception at run time.
None
52.
Question: Given:
class TestClass{
public static void main(String[] args) throws Exception {
List list = new CopyOnWriteArrayList();
ExecutorService es = Executors.newFixedThreadPool(5);
CyclicBarrier cb = new CyclicBarrier(2, ()->System.out.print("All Done"));
IntStream.range(0, 5).forEach(n->es.execute(
()->{
try{
list.add(n);
cb.await();
}catch(InterruptedException|BrokenBarrierException e){
System.out.println("Exception");
}
}
));
es.shutdown();
}
}
What will the above program print?
Select 2 option(s)
It will print "All Done" once.
It will print "All Done" twice.
It will never print "All Done".
It will print "All Done" once and end.
It may print "All Done" once or twice.
The program will not end.
The program will end.
53.
Question: What should be inserted in the following code so that it works as expected?
String token = "xyz";
String output = null;
String processedValueCall = "{call reconciler(?,?)}";
CallableStatement callableStatement = dbConnection.prepareCall(processedValueCall);
*INSERT CODE HERE*
callableStatement.executeUpdate();
String value = callableStatement.getString(2);
Assume that the token variable is the first parameter to be passed.
Select 1 option(s)
callableStatement.registerInParameter(1, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.setString(2, output);
callableStatement.setString(1, token);
callableStatement.setString(2, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.setString(1, token);
callableStatement.registerOutParameter(2, output);
None
54.
Question: Which of the following is illegal?
Select 1 option(s)
char c = 320;
float f = 320;
double d = 320;
byte b = 320;
float f = 22.0f/7.0f;
None of the above is illegal.
None
55.
Question: Complete the following code by filling the two blanks -
class XXX{
public void m() throws Exception{
throw new Exception();
}
}
class YYY extends XXX{
public void m(){ }
public static void main(String[] args) {
________ obj = new ______();
obj.m();
}
}
Select 1 option(s)
XXX XXX
XXX YYY
YYY XXX
YYY YYY
None
56.
Question: Given:
//using title, price constructor to create Book instances
var books = List.of(new Book("The Outsider", 2.99), new Book("Where the Crawdads Sing", 4.99 ),
new Book("Elevation", 2.99), new Book("Coffin from Hong Kong", 1.99) );
Stream bkStrm = books.stream();//
double total = bkStrm.map(b->b.getPrice()).reduce(0.0, (a, b)->{ return a+b;}); //1
Assuming appropriate constructor and methods, which of the following options are equivalent to the statement at //1 of the above code?
Select 1 option(s)
None
57.
Question: Given the following code:
class TestClass{
public static void main(String args[]){
java.sql.Timestamp ts = new java.sql.Timestamp(1);
java.awt.Label lb = new java.awt.Label("Time is "+ts);
System.out.println(lb);
}
}
and the following commands:
javac TestClass.java
jdeps -summary TestClass.class
What will be the output?
Select 1 option(s)
None
58.
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(new IOException("NOT FOUND")); //3
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What is the result?
Select 1 option(s)
Compilation failure at //3.
It will print:
Exception - Code=0, Msg=null, OrigMsg=NOT FOUND
It will print:
Exception - Code=0, Msg=NOT FOUND, OrigMsg=null
It will print:
Exception - Code=0, Msg=, OrigMsg=null
None
59.
Question: Given:
public class Movie{
private String title;
private String genre;
public Movie(String title, String genre){
this.title = title;
this.genre = genre;
}
//accessors not shown
}
and
Stream sm = Stream.of(new Movie("a1", "a"), new Movie("a2", "a"), new Movie("b1", "b"), new Movie("c1", null));
Which of the following code fragments will get you the map of all the genres and the number of movies belonging to each genre?
Select 1 option(s)
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