Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Blog
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Blog
Welcome to your Standard Java Test - 9
Name
Email
Phone
1.
Question: What will the following code print when compiled and run?
IntStream is1 = IntStream.range(1, 3);
IntStream is2 = IntStream.rangeClosed(1, 3);
IntStream is3 = IntStream.concat(is1, is2);
Object val = is3.boxed().collect(Collectors.groupingBy(k->k)).get(3);
System.out.println(val);
Select 1 option(s)
[1]
[3]
[3, 3]
[2]
[1, 2]
None
2.
Question: Given:
Map hm = new ConcurrentHashMap();
hm.put(null, "asdf"); //1
hm.put("aaa", null); //2
hm = new HashMap();
hm.put(null, "asdf"); //3
hm.put("aaa", null); //4
List list = new ArrayList();
list.add(null); //5
list.add(null); //6
list = new CopyOnWriteArrayList();
list.add(null); //7
Which of the above lines will throw NullPointerException?
(Assume that each of the put and add calls are executed as if they are wrapped inside a try/catch block i.e. an exception thrown at //1 will not prevent the execution of //2.)
Select 2 option(s)
//1
//2
//3
//4
//5
//6
//7
3.
Question: What will the following code print when run without any arguments ...
public class TestClass {
public static int m1(int i){
return ++i;
}
public static void main(String[] args) {
int k = m1(args.length);
k += 3 + ++k;
System.out.println(k);
}
}
Select 1 option(s)
It will throw ArrayIndexOutOfBoundsException.
It will throw NullPointerException.
6
5
7
2
None of these.
None
4.
Question: Which of the following are valid declarations inside an interface independent of each other?
Select 2 option(s)
void compute();
public void compute();
public final void compute();
static void compute();
protected void compute();
5.
Question: Given:
public class ValueHolder{
final int value;
*INSERT CODE HERE*
}
Which of the following options can be inserted in the above code independent of each other?
Select 2 option(s)
public ValueHolder() { value = 10; }
public void ValueHolder(int x) { value = x; }
public int ValueHolder(String s) { value = Integer.parseInt(s); }
public ValueHolder(){ this("10"); }
public ValueHolder(String x) { value = Integer.parseInt(x, 2); }
public ValueHolder(int x) { value = x; }
6.
Question: Which of the following statements will print /test.txt when executed on a *nix system?
Select 1 option(s)
System.out.println(Path.get("/test.txt"));
System.out.println(new Path("/test.txt"));
System.out.println(Paths.get("/", "test.txt"));
System.out.println(Path.toPath("/test.txt"));
System.out.println(Paths.toPath("/test.txt"));
None
7.
Question: Which of the following are valid code fragments:
Select 2 option(s)
new Object[]{ "aaa", new Object(), new ArrayList(), 10};
new Object[]{ "aaa", new Object(), new ArrayList(), {} };
new Object[]{ "aaa", new Object(), new ArrayList(), new String[]{""} };
new Object[1]{ new Object() };
8.
Question: Given:
public class Student {
public static enum Grade{ A, B , C, D, F}
private String name;
private Grade grade;
public Student(String name, Grade grade){
this.name = name;
this.grade = grade;
}
public String toString(){
return name+":"+grade;
}
//getters and setters not shown
}
What can be inserted in the code below so that it will print:
{C=[S3:C], A=[S1:A, S2:A]}
List ls = Arrays.asList(new Student("S1", Student.Grade.A), new Student("S2", Student.Grade.A), new Student("S3", Student.Grade.C));
//INSERT CODE HERE
System.out.println(grouping);
Select 1 option(s)
None
9.
Question: Which of the following expressions will evaluate to true if preceded by the following code?
String a = "java";
char[] b = { 'j', 'a', 'v', 'a' };
String c = new String(b);
String d = a;
Select 3 option(s)
(a == d)
(b == d)
(a == "java")
a.equals(c)
10.
Question: Assuming that the following method will always be called with a phone number in the format ddd-ddd-dddd (where d stands for a digit), what can be inserted at //1 so that it will return a String containing "xxx-xxx-"+dddd, where dddd represents the same four digits in the original number?
public static String hidePhone(String fullPhoneNumber){
//1 Insert code here
}
Select 2 option(s)
String mask = "xxx-xxx-";
mask.append(fullPhoneNumber.substring(8));
return mask;
return new StringBuilder("xxx-xxx-")+fullPhoneNumber.substring(8);
return new StringBuilder(fullPhoneNumber).replace(0, 7, "xxx-xxx-").toString();
return "xxx-xxx-"+fullPhoneNumber.substring(8, 12);
11.
Question: What will the following program print?
public class TestClass{
public static void main(String[] args){
var str = "111";
boolean[] bA = new boolean[1];
if( bA[0] ) str = "222";
System.out.println(str);
}
}
Select 1 option(s)
111
222
It will not compile as bA[0] is uninitialized.
It will throw an exception at runtime.
None of the above.
None
12.
Question: The following method will compile and run without any problems.
public void switchTest(byte x){
switch(x){
case 'b': // 1
default : // 2
case -2: // 3
case 80: // 4
}
}
Select 1 option(s)
True
False
None
13.
Question: What will the following code snippet print?
int count = 0, sum = 0;
do{
if(count % 3 == 0) continue;
sum+=count;
}
while(count++ < 11);
System.out.println(sum);
Select 1 option(s)
49
48
37
36
38
None
14.
Question: Given:
var nums = List.of(1, 2, 3, 4, 5, 6, 7).stream();
Predicate p = //a predicate goes here
Optional value = nums.filter(p).reduce((a, b)->a+b);
value.ifPresent(System.out::println);
Select 2 option(s)
setting p to a-> a <0; will produce no output.
setting p to a-> a <0; will generate a NullPointerException.
setting p to a-> a <0; will generate a NoSuchElementException.
setting p to a->a%2==0; will produce 12.
setting p to a->a%2==0; will produce 16.
15.
Question: Which of the following command line options can be used to find out all the dependencies of a module while execution?
Note: Although identifying module dependency is not explicitly mentioned in the exam objectives, we have seen questions on the exam that require you to know about this.
Select 1 option(s)
--show-module-resolution
--show-module-dependencies
--list-dependencies
--list-deps
--describe
--describe-module
None
16.
Question: Consider the following class...
import java.awt.*;
import java.awt.event.*;
class TestFrame extends Frame
{
String s="Message";
public static void main(String args[])
{
var t = new TestFrame();
var b = new Button("press me");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Message is " +s);
}
}
);
t.add(b);
}
}
What will happen when you attempt to compile and run the program?
NOTE: Although this question uses classes from the AWT package, it is not about those class. You may see exam questions referring to classes that are not on the exam objectives. If you see such classes, you can safely assume that the question is not about them.
Select 1 option(s)
It will not compile because the variable s is not accessible from the inner class.
It will compile but not show anything when run.
It will compile and show a very small Frame.
It will compile and show a frame big enough to display the button.
It will not compile because of incorrect usage of var.
None
17.
Question: What will the following code print when compiled and run?
List names = Arrays.asList("charles", "chuk", "cynthia", "cho", "cici");
int x = names.stream().filter(name->name.length()>4).collect(Collectors.counting());
System.out.println(x);
Select 1 option(s)
2
3
Exception at run time.
Compilation failure.
None
18.
Question: The following code snippet will print true.
String str1 = "one";
String str2 = "two";
System.out.println( str1.equals(str1=str2) );
Select 1 option(s)
True
False
None
19.
Question: Which of the following are valid JDBC URLs?
Select 3 option(s)
jdbc.derby.localhost/sample
jdbc://mysql.com/sample
http://jdbc.mysql/sample
jdbc:oracle:thin:@localhost:1521:mydb
jdbc:mysql://192.168.1.10:3306/sample
jdbc:xderby:1106:sample
20.
Question: Which line will print the string "MUM"?
public class TestClass{
public static void main(String args []){
String s = "MINIMUM";
System.out.println(s.substring(4, 7)); //1
System.out.println(s.substring(5)); //2
System.out.println(s.substring(s.indexOf('I', 3))); //3
System.out.println(s.substring(s.indexOf('I', 4))); //4
}
}
Select 1 option(s)
1
2
3
4
None of these.
None
21.
Question: What will be printed when the following program is compiled and run?
class Super{
public int getNumber( int a){
return 2;
}
}
public class SubClass extends Super{
public int getNumber( int a, char ch){
return 4;
}
public static void main(String[] args){
System.out.println( new SubClass().getNumber(4) );
}
}
What will be printed?
Select 1 option(s)
4
2
It will not compile.
It will throw an exception at runtime.
None of the above.
None
22.
Question: Assuming that a valid integer will be passed in the command line as first argument, which statements regarding the following code are correct?
public class TestClass{
public static void main(String args[]){
var x = Integer.parseInt(args[0]);
switch(x){
case x < 5 : System.out.println("BIG"); break;
case x > 5 : System.out.println("SMALL");
default : System.out.println("CORRECT"); break;
}
}
}
Select 1 option(s)
BIG will never be followed by SMALL.
SMALL will never follow anything else.
SMALL will always be followed by CORRECT.
It will not compile.
It will throw an exception at runtime.
None
23.
Question: Identify correct statements about the following code:
public class Counter{ //1
T t;
public int count(T[] ta, T t){ //2
this.t = t; //3
int count = 0;
for(T x : ta){
count = x == t ? count+1: count;//4
}
return count;
}
}
Select 1 option(s)
Compilation failure due to //1.
Compilation failure due to //2.
Compilation failure due to //3.
Compilation failure due to //4.
It will compile without any error.
None
24.
Question: Given:
public class Book{
private String title;
private Double price;
public Book(String title, Double price){
this.title = title;
this.price = price;
}
//accessor methods not shown
What will the following code print when compiled and run?
Book b1 = new Book("Java in 24 hrs", null);
DoubleSupplier ds1 = b1::getPrice;
System.out.println(b1.getTitle()+" "+ds1.getAsDouble());
Select 1 option(s)
Java in 24 hrs null.
Java in 24 hrs 0.0
Java in 24 hrs.
It will throw a NullPointerException.
It will not compile.
None
25.
Question: Identify correct statements about the following code:
interface Processor {
Iterable process();
}
interface ItemProcessor extends Processor{
Collection process();
}
interface WordProcessor extends Processor{
String process();
}
interface GenericProcessor extends ItemProcessor, WordProcessor{
}
Select 2 option(s)
ItemProcessor fails compilation because it does not override the process method correctly.
WordProcessor fails compilation because it does not override the process method correctly.
GenericProcessor fails compilation because it inherits two process methods with incompatible return types.
GenericProcessor fails compilation because it extends from more than one interface.
WordProcessor will compile without errors if @Override annotation is applied on its process method.
26.
Question: Which statement regarding the following code is correct?
class A{
public int i = 10;
private int j = 20;
}
class B extends A{
private int i = 30; //1
public int k = 40;
}
class C extends B{
}
public class TestClass{
public static void main(String args[]){
C c = new C();
System.out.println(c.i); //2
System.out.println(c.j); //3
System.out.println(c.k);
}
}
Select 1 option(s)
The code will print 10 and 40 if //3 is commented out.
The code will print 40 if //2 and //3 are commented out.
The code will not compile because of //1.
The code will compile if the line marked //2 is commented out.
None of these.
None
27.
Question: Given:
public class Book{
String isbn;
String title;
public Book(String isbn, String title){
this.isbn = isbn;
this.title = title;
}
public int compareTo(Book b){
return this.isbn.compareTo(b.isbn);
}
//accessors not shown
}
and the following code snippet:
List books = getBooksByAuthor("Ludlum");
Collections.sort(books, (b1, b2)->b1.getTitle().compareTo(b2.getTitle())); //1
Collections.sort(books); //2
Assuming that getBooksByAuthor is a valid method that returns a List of Books, which of the following statements is/are true?
Select 1 option(s)
Compilation failure at //1.
Compilation failure at //2.
Exception at run time because of //1.
Exception at run time because of //2.
Elements in books List will be sorted by title and then by isbn.
None
28.
Question: What will the following program print when run?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[] ){ A b = new B("good bye"); }
}
class A{
A() { this("hello", " world"); }
A(String s) { System.out.println(s); }
A(String s1, String s2){ this(s1 + s2); }
}
class B extends A{
B(){ super("good bye"); };
B(String s){ super(s, " world"); }
B(String s1, String s2){ this(s1 + s2 + " ! "); }
}
Select 1 option(s)
It will print "good bye".
It will print "hello world".
It will print "good bye world".
It will print "good bye" followed by "hello world".
It will print "hello world" followed by "good bye".
None
29.
Question: Given that your code is being run in a locale where the language code is fr and country code is CA, which of the following file names represents a valid resource bundle file name?
Select 1 option(s)
MyResource_fr_CA.xml
MyResource_fr_CA.properties
MyResource_fr_CA.java
MyResource_fr_CA.profile
None
30.
Question: Which of the following are valid module definitions?
Select 1 option(s)
//In file module.java:
module autos{
}
//In file autos.java:
module autos{
}
//In file module-info.java:
module autos{
}
//In file module-info.java:
module cars{
exports com.car;
}
module trucks{
requires cars;
}
//In file module-info.java:
module-info autos{
}
None
31.
Question: What will the following code print when run?
Deque d = new ArrayDeque();
d.push(1);
d.push(2);
d.push(3);
System.out.println(d.remove());
System.out.println(d.remove());
System.out.println(d.remove());
Select 1 option(s)
1
2
3
3
2
1
Compilation error.
Exception at run time.
None
32.
Question: Replace XXX with a declaration such that the following code will compile without any error or warning.
public void m1(XXX list)
{
Number n = list.get(0);
}
Select 1 option(s)
List< ? super Number >
List
?
List
? extends Number
List
Number extends ?
List< Number super ? >
None
33.
Question: Consider the following classes:
class A {
public int getCode(){ return 2;}
}
class AA extends A {
public void doStuff() {
}
}
Given the following two declarations, which of the options will compile?
A a = null;
AA aa = null;
Select 4 option(s)
a = (AA)aa;
a = new AA();
aa = new A();
aa = (AA) a;
aa = a;
((AA)a).doStuff();
34.
Question: Which code fragments will print the last argument given on the command line to the standard output, and exit without any output or exception stack trace if no arguments are given?
1.
public static void main(String args[ ]){
if (args.length != 0) System.out.println(args[args.length-1]);
}
2.
public static void main(String args[ ]){
try { System.out.println(args[args.length-1]); }
catch (ArrayIndexOutOfBoundsException e) { }
}
3.
public static void main(String args[ ]){
int i = args.length;
if (i != 0) System.out.println(args[i-1]);
}
4.
public static void main(String args[ ]){
int i = args.length-1;
if (i > 0) System.out.println(args[i]);
}
5.
public static void main(String args[ ]){
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}
}
Select 3 option(s)
1
2
3
4
6
35.
Question: Which of the following are valid at line 1?
public class X{
//line 1: insert code here.
}
Select 2 option(s)
Var s;
String s = 'asdf';
String s = 'a';
String s = this.toString();
String s = asdf;
String s;
Var al;
al = new ArrayList<>();
36.
Question: Which of the following are correct definitions of a repeatable annotation?
Select 1 option(s)
public @interface Meal{
String value();
}
@Repeatable(Meals.class)
public @interface Meal {
int id() default 0;
}
public @interface Meals{
Meal[] meals();
}
public @interface Meals{
Meal[] value();
String course() default "maincourse";
}
@Repeatable(Meals.class)
public @interface Meal{
int id() default 0;
String name();
}
public @interface Meals{
Meal[] value();
String course();
}
@Repeatable(Meals.class)
public @interface Meal{
int id() default 0;
String value();
}
None
37.
Question: You are creating an enthu.questionbank module that depends on enthu.internal.db and enthu.external.feeds modules. Which of the following files correctly defines this module?
Select 1 option(s)
//In file module-info.java:
module enthu.questionbank{
requires enthu.internal.db, enthu.external.feeds;
}
//In file module-info.java:
module enthu.questionbank{
uses enthu.internal.db, enthu.external.feeds;
}
//In file module-info.java:
module enthu.questionbank{
import enthu.internal.db;
import enthu.external.feeds;
}
//In file module-info.java:
module enthu.questionbank{
require enthu.internal.db;
require enthu.external.feeds;
}
None of the above are valid.
None
38.
Question: Identify correct statements about the following code:
List vals = Arrays.asList("a", "b");
String join = vals.parallelStream()
.reduce("_",
(a, b)->a.concat(b)
);
System.out.println(join);
Select 1 option(s)
It will always print _ab
It will always print either _ab or _ba
It will print either _ab or _a_b
It will print any of the following:
_ab, _ba, _a_b,_b_a
None
39.
Question: Consider the standard 'put' method of class HashMap.
public Object put(Object key, Object value);
Select 1 option(s)
It always returns null.
It always returns value ( i.e. the 2nd parameter).
Neither of key or value can be null otherwise a NullPointerException is thrown.
Key cannot be null but value may be null.
It may throw a DuplicateKeyException.
None of these.
None
40.
Question: Which of the following method(s) of java.util.stream.Stream interface is/are used for reduction?
Select 2 option(s)
filter
reduce
sum
max
add
41.
Question: Assuming the following enum declaration and a variable s of type Switch, identify valid code fragments.
public enum Switch{ ON, OFF }
Select 3 option(s)
if( s == Switch.OFF) { System.out.println("It is off!"); }
if( s.equals(Switch.OFF)) { System.out.println("It is off!"); }
switch(s)
{
case Switch.OFF : System.out.println("It is off!"); break;
}
switch(s)
{
case OFF : System.out.println("It is off!"); break;
}
while(s)
{
System.out.println("It is off!");
}
switch(s)
{
case Switch.OFF.valueOf() : System.out.println("It is off!"); break;
}
switch(s)
{
case OFF.toString() : System.out.println("It is off!"); break;
}
42.
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){
// 1 INSERT CODE HERE
try{
marksObtained.put(subject, marks);
}finally{
// 2 INSERT CODE HERE
}
}
public double getAverageMarks(){
// valid code that computes average
}
}
What should be inserted at //1 and //2?
Select 1 option(s)
lock.writeLock().acquire();
and
lock.writeLock().release();
lock.writeLock().lock();
and
lock.writeLock().unlock();
lock.acquire();
and
lock.release();
lock.readLock().lock();
and
lock.readLock().unlock();
None
43.
Question: What will be the result of compiling and running the following program?
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String[] args) throws Exception{
try{
m2();
}
finally{
m3();
}
catch (NewException e){}
}
public static void m2() throws NewException { throw new NewException(); }
public static void m3() throws AnotherException{ throw new AnotherException(); }
}
Select 1 option(s)
It will compile but will throw AnotherException when run.
It will compile but will throw NewException when run.
It will compile and run without throwing any exceptions.
It will not compile.
None of the above.
None
44.
Question: Given:
interface IHello
{
public int hello(int x, int y);
public long hello(long x, long y);
}
Which of the following options are valid definitions in a different file assuming that the above definition is already available?
Select 3 option(s)
interface IHello2 extends IHello{
private static void print(){ };
}
interface iHello2 implements IHello{ }
abstract class Hello implements IHello{}
abstract class Hello implements IHello{
public short hello(short a, short b){ return 0; } }
abstract class Hello implements IHello{
public short hello(int a, int b){ return 0; } }
45.
Question: In which sequence will the characters a, b, and, c be printed by the following program?
import java.util.* ;
public class ListTest{
public static void main(String args[]){
List s1 = new ArrayList( );
s1.add("a");
s1.add("b");
s1.add(1, "c");
List s2 = new ArrayList( s1.subList(1, 1) );
s1.addAll(s2);
System.out.println(s1);
}
}
Select 1 option(s)
The sequence a, b, c is printed.
The sequence a, b, c, b is printed.
The sequence a, c, b, c is printed.
The sequence a, c, b is printed.
None of the above.
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")
);
List genreList = new ArrayList();
//INSERT CODE HERE
System.out.println(genreList);
Which of the following options will correctly make genreList refer to a List containing the genres of the books present in books List?
Select 4 option(s)
books.stream().map(Book::getGenre).forEach(s->genreList.add(s));
genreList = books.stream().map(Book::getGenre).collect(Collectors.toList());
books.stream().map(Book::getGenre).collect(Collectors.toList(genreList));
books.stream().map(Book::getGenre).forEach(genreList::add);
books.stream().map(b->b.getGenre()).forEach(genreList::add);
books.stream().flatMap(b->b.getGenre()).forEach(g->genreList.add(g));
47.
Question: Which of these expressions will obtain the substring "456" from a string defined by String str = "01234567"?
Select 1 option(s)
str.substring(4, 7)
str.substring(4)
str.substring(3, 6)
str.substring(4, 6)
str.substring(4, 3)
None
48.
Question: Which of the following declarations are valid?
Select 4 option(s)
float f1 = 1.0;
float f = 43e1;
float f = -1;
float f = 0x0123;
float f = 4;
var f1 = 1.0;
float f2 = f1;
var f = 4f;
49.
Question: Consider the following classes:
class A{
public static void sM1() { System.out.println("In base static"); }
}
class B extends A{
Line 1 --> // public static void sM1() { System.out.println("In sub static"); }
Line 2 --> // public void sM1() { System.out.println("In sub non-static"); }
}
Which of the following statements are true?
Select 2 option(s)
Class B will not compile if line 1 is uncommented.
Class B will not compile if line 2 is uncommented.
Class B will not compile if line 1 and 2 are both uncommented.
Only the second option is correct.
Only the third option is correct.
50.
Question: Which of the following interface definitions can use Lambda expressions?
Select 1 option(s)
interface A{
}
interface A{
default void m(){};
}
interface A{
void m(){};
}
interface A{
default void m1(){};
void m2();
}
interface A{
void m1();
void m2();
}
None
51.
Question: A programmer is writing a small component that processes a file line by line. The following is the code:
public class LineByLineProcessor {
public void processLines(String fullFilePath) throws Exception
{
// declare and initialize "handle" here
String str = null;
while( (str = handle.readLine()) != null)
{
System.out.println("Processing line : "+str);
}
handle.close();
}
}
Which of the given options will declare and initialize handle appropriately?
Select 2 option(s)
Reader handle = new FileReader(fullFilePath);
BufferedReader handle = new BufferedReader(fullFilePath);
BufferedReader handle = new BufferedReader(new File(fullFilePath));
BufferedReader handle = new BufferedReader(new FileReader(fullFilePath));
BufferedReader handle = new BufferedReader(new FileReader( new File(fullFilePath)));
52.
Question: What can you do to make the following code compile?
public class TestClass {
public static void main(String[] args) {
int[] values = { 10, 20, 30 };
for( /* put code here */ ){
}
}
}
Select 2 option(s)
int k : values
int k in values
var k; k<0; k++
; ;
; k<values.length;k++
53.
Question: Identify correct statements about the following code:
public String[] getDataForUser(String userid) throws ServerException{
try{
String dbdata = loadFromDB(userid);
String filedata = loadFromFile(userid);
return new String[]{dbdata, filedata};
}catch(SQLException|IOException se){
ServerException e = new ServerException("Unable to load data");
e.setCause(se);
throw e;
}
}
NOTE: Some candidates have reported seeing the usage of ServerException in the exam. It is not known what ServerException does it refer to. There is one java.rmi.ServerException class but it does not have any setCause method. ServerException does have a ServerException(String s, Exception ex) constructor, which can be used to store the actual exception. This exception can then be retrieved using the getCause() method.
Our suggestion is to answer it assuming that it refers to java.rmi.ServerException and that it has a setCause method.
Select 1 option(s)
This is a good approach to exception handling because it can handle new exceptions without affecting caller code.
This is not a good approach to exception handling because the actual cause of exception is lost.
This is not a good approach to exception handling because it leaks memory by holding on to an exception while creating a new exception.
This is not a good approach to exception handling because resources cannot be closed correctly in this approach.
None
54.
Question: Given:
public class TestClass
{
public static void main(String[] args) throws IOException {
final Reader reader = new FileReader("aaa.a"); //1
try(reader){
reader.read(); //2
}finally{
reader.read(); //3
}
reader.read(); //4
}
}
Assuming that the fle named aaa.a does not exist, what will be the outcome?
Select 1 option(s)
An exception will be thrown at line marked //1.
An exception will be thrown at line marked //2.
An exception will be thrown at line marked //3.
An exception will be thrown at line marked //4.
It will fail to compile.
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