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
Articles
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
Articles
Java standard test 10 Code 1Z 829
Welcome to your Java Test - 10
Name
Email
Phone
1.
Question: Given :
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.
See Hint
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
2.
Question: Given:
public class PlaceHolder { //1
private K k;
private V v;
public PlaceHolder(K k, V v){ //2
this.k = k;
this.v = v;
}
public K getK() { return k; }
public static PlaceHolder getDuplicateHolder(X x){ //3
return new PlaceHolder(x, x); //4
}
}
Which line will cause compilation failure?
Select 1 option(s)
1
2
3
4
Some other unnumbered line.
There is no problem with the code.
None
3.
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
4.
Question: Consider the following code:
interface Bar{
void bar();
}
abstract class FooBase{
public static void bar(){
System.out.println("In static bar");
}
}
public class Foo extends FooBase implements Bar {
}
What can be done to the above code so that it will compile without any error?
Select 1 option(s)
Add this method in class Foo -
public void bar(){ };
Make the bar method in Bar interface default like this -
default void bar() { }
Either of the two approaches presented above will work.
Neither of the two approaches presented above will work.
Nothing needs to be done. It will compile as it is.
None
5.
Question: Given:
enum Card
{
HEART, CLUB, SPADE, DIAMOND;
public boolean isRed(){
return switch(this){
case HEART, DIAMOND -> true;
default -> false;
};
}
}
What will the following line of code print?
Arrays.stream(Card.values()).takeWhile(c->c.isRed()).forEach(System.out::print);
Select 1 option(s)
HEARTDIAMOND
HEART
It may print HEART or DIAMOND or even nothing.
It will not print anything.
None
6.
Question: Identify correct statements about following command:
java -p .\dir1 -cp .\dir2 -m a.b/a.b.c.Main
Select 1 option(s)
dir1 should have a directory named a.b or a jar file named a.b.jar.
If classes from a third party non-modular jar are required by Main, then the third party jar file should be present in dir2 directory.
If the a.b module requires any other module, then that module's jar file must be present in dir1 directory.
Main.class should be present in dir1\a.b\a\b\c directory or, if it is inside a jar, then its path should be \a\b\c.
None
7.
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
8.
Question: What will the following code print when compiled and run?
public class Data{
int value;
Data(int value){
this.value = value;
}
public String toString(){ return ""+value; }
public static void main(String[] args) {
Data[] dataArr = new Data[]{ new Data(1),
new Data(2), new Data(3), new Data(4) };
List
dataList = Arrays.asList(dataArr); //1
for(Data element : dataList){
dataList.removeIf( (Data d) -> { return d.value%2 == 0; } ); //2
System.out.println("Removed "+d+", "); //3
}
}
}
Select 1 option(s)
Removed 2, Removed 4
It will print Removed 2 and then an exception stack trace.
It will print an exception stack trace.
It will not compile due to //1
It will not compile due to //2
It will not compile due to //3
None
9.
Question: What would be the result of attempting to compile and run the following code?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[]){
B c = new C();
System.out.println(c.max(10, 20));
}
}
class A{
int max(int x, int y) { if (x>y) return x; else return y; }
}
class B extends A{
int max(int x, int y) { return 2 * super.max(x, y) ; }
}
class C extends B{
int max(int x, int y) { return super.max( 2*x, 2*y); }
}
Select 1 option(s)
The code will fail to compile.
Runtime error.
The code will compile without errors and will print 80 when run.
The code will compile without errors and will print 40 when run.
The code will compile without errors and will print 20 when run.
None
10.
Question: Which of the following are present on the "module-path"?
Select 1 option(s)
only named modules
only unnamed modules
only automatic modules
named, unnamed, and automatic modules
only named and automatic modules
all modules
None
11.
Question: Given:
public class Counter{
//1
public void increment(){
//2
}
//other valid code
}
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share an instance of this class and call its increment method. What should be inserted at //1 and //2?
Select 1 option(s)
int count; at //1
AtomicInteger.increment(count); at //2
synchronized int count; at //1
count++ at //2
AtomicInteger count = 0; at //1
count++; at //2
AtomicInteger count = new AtomicInteger(0); at //1
count++; at //2
AtomicInteger count = new AtomicInteger(0); at //1
count.incrementAndGet(); at //2
None
12.
Question: What is the result of compiling and running this code?
class MyException extends Throwable{}
class MyException1 extends MyException{}
class MyException2 extends MyException{}
class MyException3 extends MyException2{}
public class ExceptionTest{
void myMethod() throws MyException{
throw new MyException3();
}
public static void main(String[] args){
ExceptionTest et = new ExceptionTest();
try{
et.myMethod();
}
catch(MyException me){
System.out.println("MyException thrown");
}
catch(MyException3 me3){
System.out.println("MyException3 thrown");
}
finally{
System.out.println(" Done");
}
}
}
Select 1 option(s)
MyException thrown
MyException3 thrown
MyException thrown Done
MyException3 thrown Done
It fails to compile
None
13.
Question: What will the following code print when compiled and run?
var numA = new Integer[]{1, null, 3}; //1
var list1 = List.of(numA); //2
var list2 = Collections.unmodifiableList(list1); //3
numA[1] = 2; //4
System.out.println(list1+" "+list2);
Select 1 option(s)
It will not compile.
An exception will be thrown at run time.
[1, null, 3] [1, 2, 3]
[1, null, 3] [1, null, 3]
[1, 2, 3] [1, 2, 3]
None
14.
Question: What will the following code print?
int i = 1;
int j = i++;
if( (i==++j) | (i++ == j) ){
i+=j;
}
System.out.println(i);
Select 1 option(s)
3
4
5
2
It will not compile.
None
15.
Question: Which of the following statements are true regarding the try-with-resources statement?
Select 1 option(s)
AutoCloseable's close method throws IOException while Closeable's close method throws Exception.
Resources are closed in the reverse order of their declaration in the try clause (or creation, if they are created in the try clause).
AutoCloseable extends Closeable.
AutoCloseable's close() does not declare any throws clause.
Closeable's close() does not declare any throws clause while AutoCloseable's close() throws Exception.
None
16.
Question: Given the following module-info:
module book{
requires org.pdf;
uses org.pdf.Print;
}
Which of the following statements are correct?
Select 3 option(s)
The module that defines Print service must be present on --module-source-path for book module to compile.
The module that defines Print service must be present on --module-path for book module to compile.
The module that defines Print service must be present on --module-path for book module to execute.
Exactly one module that provides Print service must be present on --module-path for book module to execute.
A module that defines Print service may be added later without requiring book module to recompile.
An implementation of org.pdf.Print can be added to the book module.
17.
Question: Consider the following code:
public class Test extends Thread
{
boolean flag = false;
public Test(boolean f) { flag = f; }
static Object obj1 = new Object();
static Object obj2 = new Object();
public void m1()
{
synchronized(obj1)
{
System.out.print("1 ");
synchronized(obj2)
{
System.out.println("2");
}
}
}
public void m2()
{
synchronized(obj2)
{
System.out.print("2 ");
synchronized(obj1)
{
System.out.println("1");
}
}
}
public void run()
{
if(flag){ m1(); m2(); }
else { m2(); m1(); }
}
public static void main(String[] args)
{
new Test(true).start();
new Test(false).start();
}
}
Which of the following statements are correct?
Select 2 option(s)
It may result in a deadlock and the program may get stuck.
There is no potential for deadlock in the code.
Deadlock may occur but the program will not get stuck as the JVM will resolve the deadlock.
The program will always print: 1 2, 2 1, 1 2 and 2 1.
Nothing can be said for sure.
18.
Question: What will the following code print?
Duration d = Duration.ofHours(25);
System.out.println(d);
Period p = Period.ofDays(1);
System.out.println(p);
Select 1 option(s)
PT25H
P1D
PT1D1H
P1D
PT25H
PT1D
PT1D1H
PT1D
None
19.
Question: Given:
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
public class Cache {
static ConcurrentHashMap chm = new ConcurrentHashMap();
public static void main(String[] args) {
chm.put("a", "aaa");
chm.put("b", "bbb");
chm.put("c", "ccc");
new Thread(){
public void run(){
Iterator<Entry> it = Cache.chm.entrySet().iterator();
while(it.hasNext()){
Entry en = it.next();
if(en.getKey().equals("a") || en.getKey().equals("b")){
it.remove();
}
}
}
}.start();
new Thread(){
public void run(){
Iterator<Entry> it = Cache.chm.entrySet().iterator();
while(it.hasNext()){
Entry en = it.next();
System.out.print(en.getKey()+", ");
}
}
}.start();
}
}
Which of the following are possible outputs when the above program is run?
Select 1 option(s)
It may print any combination of the keys.
It may print any combination except: c,
It may print any combination except: a, or b, or a, b, or b, a
It may print any combination except: b, c,
It may print any combination except: a, b,
None
20.
Question: What changes, when applied independent of each other, will enable the following code to compile?
//assume appropriate import statements
class TestClass{
public double process(double payment, int rate)
{
double defaultrate = 0.10; //1
if(rate>10) defaultrate = rate; //2
class Implement{
public int apply(double data){
Function f = x->x+(int)(x*defaultrate); //3
return f.apply((int)data); //4
}
}
Implement i = new Implement();
return i.apply(payment);
}
}
Select 2 option(s)
Change //1 to
final double defaultrate = 0.10;
Remove code at //2.
Replace lines at //3 and //4 with:
BiFunction< Integer, Double, Integer > f = (m, n)->m+(int)(n*m);
return f.apply((int)data, defaultrate);
Change //3 to:
Function< Integer, Integer > f = x->x+(int)(x*rate);
21.
Question: Consider the following code:
class Super{
static{ System.out.print("super "); }
}
class One{
static { System.out.print("one "); }
}
class Two extends Super{
static { System.out.print("two "); }
}
class Test{
public static void main(String[] args){
One o = null;
Two t = new Two();
}
}
What will be the output when class Test is run ?
Select 1 option(s)
It will print one super two
It will print one two super
It will print super two
It will print two super
None of the above.
None
22.
Question: What will the following class print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) {
TreeSet s = new TreeSet();
TreeSet subs = new TreeSet();
for(int i = 324; i<=328; i++)
{
s.add(i);
}
subs = (TreeSet) s.subSet(326, true, 328, true );
subs.add(329);
System.out.println(s+" "+subs);
}
}
Select 1 option(s)
[324, 325, 326, 327, 328] [326, 327, 329]
[324, 325, 326, 327, 329] [326, 327, 329]
[324, 325, 326, 327, 328] [326, 327]
It will throw an exception at runtime.
It will not compile.
None
23.
Question: What will the following code print when compiled and run?
public static void main(String[] args) {
Stream<List> s1 = Stream.of(
Arrays.asList("a", "b"),
Arrays.asList("a", "c")
);
Stream news = s1.filter(s->s.contains("c"))
.flatMap(olds -> olds.stream());
news.forEach(System.out::print);
}
Select 1 option(s)
ab
ac
[a, b]
[a, c]
[ab]
[ac]
None
24.
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;
}
25.
Question: What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.add(1);
d.addFirst(2);
d.pop();
d.offerFirst(3);
(Assume that in the output, front of deque is on the left side and the end is on the right side.)
Select 1 option(s)
1, 3
3, 1
An exception will be thrown at run time.
Order of elements in the Deque cannot be predicted.
It will not compile.
None
26.
Question: Given:
class Base{
public List getList(int id){
return null;
};
}
class Derived extends Base{
@Override
*INSERT CODE HERE*
//valid code
}
}
What can be inserted in the above code?
Select 2 option(s)
public List< ? extends CharSequence > getList(int id){
public List< String > getList(int id){
public ArrayList< StringBuilder > getList(int id){
public List< ? super Object > getList(int id){
public List< CharSequence > getList(int id){
27.
Question: Given the following class definitions:
interface MyIface{};
class A {};
class B extends A implements MyIface{};
class C implements MyIface{};
and the following object instantiations:
A a = new A();
B b = new B();
C c = new C();
Which of the following assignments are legal at compile time?
Select 1 option(s)
b = c;
c = b;
MyIface i = c;
c = (C) b;
b = a;
None
28.
Question: What will be the output of compiling and running the following program:
class TestClass implements I1, I2{
public void m1() { System.out.println("Hello"); }
public static void main(String[] args){
TestClass tc = new TestClass();
( (I1) tc).m1();
}
}
interface I1{
int VALUE = 1;
void m1();
}
interface I2{
int VALUE = 2;
void m1();
}
Select 1 option(s)
It will print Hello.
There is no way to access any VALUE in TestClass.
The code will work fine only if VALUE is removed from one of the interfaces.
It will not compile.
None of the above.
None
29.
Question: What will the following code print?
String examName = "OCP Java 17";
String uniqueExamName = new String(examName);
String internedExamName = uniqueExamName.intern();
System.out.println(
(examName==uniqueExamName)+" "+
(examName == internedExamName)+" "+
(uniqueExamName == internedExamName) );
Select 1 option(s)
false true true
false false false
true true true
true true false
false true false
true false true
None
30.
Question: What will the following code print when compiled and run?
public class Onion {
private String data = "skin";
private class Layer extends Onion {
String data = "thegoodpart";
public String getData() {
return data;
}
}
public String getData() {
return new Layer().getData();
}
public static void main(String[] args) {
var o = new Onion();
System.out.println(o.getData());
}
}
Select 1 option(s)
It will print an empty String.
skin
thegoodpart
It will not compile.
It will throw an exception at run time.
None
31.
Question: What will the following program print when run without any command line argument?
public class TestClass {
public static void main(String[] args) {
var hasParams = (args == null ? false : true);
if(hasParams){
System.out.println("has params");
}{
System.out.println("no params");
}
}
}
Select 1 option(s)
has params
has params
no params
no params
It will not compile.
None
32.
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
33.
Question: Add description hAssuming that the file module-info.java exists in c:\\temp\\src\\foo.bar but not in c:\\temp\\out\\foo.bar and the folder foo.bar exists in c:\\temp\\out, what will happen when the following code is run?
Path p1 = Paths.get("c:\\temp\\src\\foo.bar\\module-info.java");
Path p2 = Paths.get("c:\\temp\\out\\foo.bar");
Files.move(p1, p2);
Select 1 option(s)
module-info.java will be copied over to out\foo.bar folder.
module-info.java will be moved to out\foo.bar folder.
An exception will be thrown.
module-info.java will be moved to out with the name foo.bar.
None
34.
Question: Which of the following options will print 10?
Select 2 option(s)
IntStream is = IntStream.range(1, 4);
int sum = is.reduce((a, b)->a+b);
System.out.println(sum);
IntStream is = IntStream.range(1, 5);
int sum = is.reduce((a, b)->a+b);
System.out.println(sum);
IntStream is = IntStream.rangeClosed(1, 4);
int sum = is.reduce(0, (a, b)->a+b);
System.out.println(sum);
IntStream is = IntStream.rangeClosed(1, 4);
Optional sum = is.reduce((a, b)->a+b);
System.out.println(sum.getAsInt());
IntStream is = IntStream.range(1, 5);
OptionalInt sum = is.reduce((a, b)->a+b);
System.out.println(sum.orElse(0));
35.
Question: Which of the following correctly defines a method named stringProcessor that can be called by other programmers as follows: stringProcessor(str1) or stringProcessor(str1, str2) or stringProcessor(str1, str2, str3), where str1, str2, and str3 are references to Strings.
Select 1 option(s)
public void stringProcessor(...String){
}
public void stringProcessor(String... strs){
}
public void stringProcessor(String[] strs){
}
public void stringProcessor(String a, String b, String c){
}
public void stringProcessor(var String a){
}
Three separate methods need to be written.
None
36.
Question: Given:
public class Course{
private String id;
private String category;
public Course(String id, String category){
this.id = id; this.category = category;
}
public String toString(){
return id+" "+category;
}
//accessors not shown
}
What will the following code print?
List s1 = Arrays.asList(
new Course("OCAJP", "Java"),
new Course("OCPJP", "Java"),
new Course("C#", "C#"),
new Course("OCEJPA", "Java")
);
s1.stream()
.collect(Collectors.groupingBy(c->c.getCategory()))
.forEach((m, n)->System.out.println(n));
Select 1 option(s)
C# C#
OCAJP Java, OCPJP Java, OCEJPA Java
[C# C#]
[OCAJP Java, OCPJP Java, OCEJPA Java]
[C#]
[OCAJP OCPJP OCEJPA]
C#
OCAJP OCPJP OCEJPA
None
37.
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 5 option(s)
public List< ? extends Integer > getList(){
public List< ? super Integer > getList(){
public ArrayList< ? extends Number > getList(){
public ArrayList< ? extends Integer > getList(){
public ArrayList< Number > getList(){
public ArrayList< Integer > getList(){
38.
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
39.
Question: What will the following program print when run?
public class ChangeTest {
private int myValue = 0;
public void showOne(int myValue){
myValue = myValue;
}
public void showTwo(int myValue){
this.myValue = myValue;
}
public static void main(String[] args) {
var ct = new ChangeTest();
ct.showOne(100);
System.out.println(ct.myValue);
ct.showTwo(200);
System.out.println(ct.myValue);
}
}
Select 1 option(s)
0 followed by 100.
100 followed by 100.
0 followed by 200.
100 followed by 200.
None
40.
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)));
41.
Question: Consider the following program:
class Game {
public void play() throws Exception {
System.out.println("Playing...");
}
}
class Soccer extends Game {
public void play(String ball) {
System.out.println("Playing Soccer with "+ball);
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Game g = new Soccer();
// 1
Soccer s = (Soccer) g;
// 2
}
}
Which of the given options can be inserted at //1 and //2?
Select 2 option(s)
It will not compile as it is.
It will throw an Exception at runtime if it is run as it is.
g.play(); at //1 and s.play("cosco"); at //2
g.play(); at //1 and s.play(); at //2
g.play("cosco"); at //1 and s.play("cosco"); at //2
42.
Question: Given the following class definition:
class A{
protected int i;
A(int i) { this.i = i; }
}
//1 : Insert code here
Which of the following would be a valid class that can be inserted at //1 ?
Select 2 option(s)
class B {}
class B extends A {}
class B extends A { B() { System.out.println("i = " + i); } }
class B { B() {} }
43.
Question: Given:
class Triangle{
public int base;
public int height;
private final double ANGLE;
public void setAngle(double a){ ANGLE = a; }
public static void main(String[] args) {
var t = new Triangle();
t.setAngle(90);
}
}
Identify the correct statement(s).
Select 1 option(s)
the value of ANGLE will not be set to 90 by the setAngle method.
An exception will be thrown at run time.
The code will work as expected setting the value of ANGLE to 90.
The code will not compile.
None
44.
Question: Which of these assignments are valid?
Select 3 option(s)
short s = 12 ;
long g = 012 ;
int i = (int) false;
float f = -123;
float d = 0 * 1.5;
45.
Question: Add description here!What will the following code print when run?
class Baap {
public int h = 4;
public int getH() {
System.out.println("Baap " + h);
return h;
}
}
public class Beta extends Baap {
public int h = 44;
public int getH() {
System.out.println("Beta " + h);
return h;
}
public static void main(String[] args) {
Baap b = new Beta();
System.out.println(b.h + " " + b.getH());
Beta bb = (Beta) b;
System.out.println(bb.h + " " + bb.getH());
}
}
Select 1 option(s)
Beta 44
4 44
Baap 44
44 44
Baap 44
4 44
Beta 44
44 44
Beta 44
4 44
Beta 44
4 44
Beta 44
4 44
Beta 44
44 44
None
46.
Question: Consider the following program...
class Super { }
class Sub extends Super { }
public class TestClass{
public static void main(String[] args){
Super s1 = new Super(); //1
Sub s2 = new Sub(); //2
s1 = (Super) s2; //3
}
}
Which of the following statements are correct?
Select 1 option(s)
It will compile and run without any problems.
It will compile but WILL throw ClassCastException at runtime.
It will compile but MAY throw ClassCastException at runtime.
It will not compile.
None of the above.
None
47.
Question: Add description heConsider the following code:
public class TestClass{
public void method(Object o){
System.out.println("Object Version");
}
public void method(java.io.FileNotFoundException s){
System.out.println("java.io.FileNotFoundException Version");
}
public void method(java.io.IOException s){
System.out.println("IOException Version");
}
public static void main(String args[]){
TestClass tc = new TestClass();
tc.method(null);
}
}
What would be the output when the above program is compiled and run? (Assume that FileNotFoundException is a subclass of IOException, which in turn is a subclass of Exception)
Select 1 option(s)
It will print Object Version
It will print java.io.IOException Version
It will print java.io.FileNotFoundException Version
It will not compile.
It will throw an exception at runtime.
None
48.
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
49.
Question: Which of the following statements are correct regarding synchronization and locks?
Select 1 option(s)
A thread shares the intrinsic lock of an object with other threads between the time the threads enter a synchronized method and exit the method.
When a synchronized method ends with a checked exception, the intrinsic lock held by the thread is released automatically.
A thread will retain the intrinsic lock if the return from a synchronized method is caused due to an uncaught unchecked exception.
Every object has an intrinsic lock associated with it and that lock is automatically acquired by a thread when it executes a method on that object.
None
50.
Question: Given the following code:
public static void main(String[] args) {
LocalDate d1 = LocalDate.now();
d1.plusDays(10);
LocalDate d2 = d1.minusWeeks(1);
d1 = null;
LocalDate d3 = LocalDate.now().plusYears(3).minusMonths(4);
d2.plusWeeks(5);
d1 = d2;
}
How many objects are created/instantiated by the given code?
Select 1 option(s)
4
5
6
7
8
9
None
51.
Question: Add description hereGiven:
Integer i1 = 20_00;
String s1 = "2_0";
Identify correct option(s).
Select 2 option(s)
Integer r = i1+s1;
System.out.println(r); //This will print 20002_0
Integer r = i1+1000;
System.out.println(r); //This will print 3000
Integer r = i1+Integer.parseInt(s1);
System.out.println(r); //This will print 2020
Integer r = 100;
r =+ i1;
System.out.println(r); //This will print 2100
Integer r = 100 + Integer(s1); //This will cause compilation failure
System.out.println(r);
Integer r = i1 + Integer.valueOf(s1);
System.out.println(r); //This will print 2020
52.
Question: Consider the following code:
public class Logger{
private StringBuilder sb = new StringBuilder();
public void logMsg(String location, String message){
sb.append(location);
sb.append("-");
sb.append(message);
}
public void dumpLog(){
System.out.println(sb.toString());
//Empty the contents of sb here
}
}
Which of the following options will empty the contents of the StringBuilder referred to by variable sb in method dumpLog()?
Select 1 option(s)
sb.delete(0, sb.length());
sb.clear();
sb.empty();
sb.removeAll();
sb.deleteAll();
None
53.
Question: What will the following code print when compiled and run?
abstract class Calculator{
abstract void calculate();
public static void main(String[] args){
System.out.println("calculating");
Calculator x = null;
x.calculate();
}
}
Select 1 option(s)
It will not compile.
It will not print anything and will throw NullPointerException
It will print calculating and then throw NullPointerException.
It will print calculating and will throw NoSuchMethodError
It will print calculating and will throw MethodNotImplementedException
None
54.
Question: What will be the output when the following program is run?
package exceptions;
public class TestClass {
public static void main(String[] args) {
try{
doTest();
}
catch(MyException me){
System.out.println(me);
}
}
static void doTest() throws MyException{
int[] array = new int[10];
array[10] = 1000;
doAnotherTest();
}
static void doAnotherTest() throws MyException{
throw new MyException("Exception from doAnotherTest");
}
}
class MyException extends Exception {
public MyException(String msg){
super(msg);
}
}
(Assume that there is no error in the line numbers given in the options.)
Select 1 option(s)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at exceptions.TestClass.doTest(TestClass.java:14)
at exceptions.TestClass.main(TestClass.java:5)
Error in thread "main" java.lang.ArrayIndexOutOfBoundsException
exceptions.MyException: Exception from doAnotherTest
exceptions.MyException: Exception from doAnotherTest
at exceptions.TestClass.doAnotherTest(TestClass.java:29)
at exceptions.TestClass.doTest(TestClass.java:25)
at exceptions.TestClass.main(TestClass.java:14)
None
55.
Question: Identify correct statements about the module system of Java.
Select 2 option(s)
Only an application structured as modular can be run on a modular JDK.
Main goals of the module system are to improve security with strong encapsulation and stability with reliable dependencies.
Code in modules and traditional JARs on the classpath cannot coexist in an application.
Modules have concealed packages for internal use and exported packages for shared code with other modules.
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
Articles
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
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US