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 – 2025
Welcome to your Standard Test 10 - 2025
Name
Email
Phone
Q1. What is the result of executing the following fragment of code:
boolean b1 = false;
boolean b2 = false;
if (b2 != b1 = !b2){
System.out.println("true");
}
else{
System.out.println("false");
}
Select 1 option(s):
Compile time error.
It will print true.
It will print false.
Runtime error.
It will print nothing.
None
Q2. Given the following resource bundle files:
In file msgs.properties:
accountinfo={0} = {1}
In file msgs_en.properties:
accountinfo={0}''s balance is {1}
(Note that an extra ' is used to escape '.)
In file msgs_fr_FR.properties:
accountinfo=Salut {0}, ton solde est de {1}
What will the following code print?
public class TestClass {
public static void showBalance(String ownerName){
Locale.setDefault(Locale.of("en", "GB"));
ResourceBundle rb = ResourceBundle.getBundle("msgs", Locale.of("fr"));
String message = rb.getString("accountinfo");
message = MessageFormat.format(message, ownerName, NumberFormat.getCurrencyInstance().format(100));
System.out.println(message);
}
public static void main(String[] args) {
showBalance("Bob");
}
}
Select 1 option(s):
Bob = 100.00 €
Bob = £100.00
Bob's balance is £100.00
Salut Bob, ton solde est de £100.00
Bob's balance is 100.00 €
Salut Bob, ton solde est de 100.00 €
None
Q3. 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
Q4. 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
Q5. 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
Q6. 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
Q7. 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
Q8. 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
Q9. 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
Q10. 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
Q11. 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
The code will fail to compile.
None
Q12. 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
Q13. 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
Q14. 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
Q15. 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.
Q16. 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.
Q17. 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
Q18. Which of the following statements correctly create a virtual thread?
(Assume that r refers to a Runnable instance.)
Select 1 option(s):
Thread t = new VirtualThread(r);
VirtualThread t = new VirtualThread(r);
VirtualThread t = Thread.ofVirtual();
Thread t = Thread.ofVirtual();
VirtualThread t = VirtualThread.of(r);
Thread t = Thread.ofVirtual(r);
Thread t = Thread.ofVirtual().unstarted(r);
None
Q19. 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 except an empty list.
It may print any combination except: c,
It may print any combination except: a, or b, or a, b, or b, a or an empty list.
It may print any combination except: b, c,
It may print any combination except: a, b,
None
Q20. 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);
Q21. 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
Q22. 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
Q23. 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
Q24. 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;
}
Q25. 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
Q26. 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){
Q27. 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
Q28. 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
Q29. 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
Q30. 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
Q31. 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
Q32. 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;
var f = (float) (1^3);
None
Q33. Assuming 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
Q34. 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));
Q35. 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
Q36. 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(){
Q37. 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
Q38. 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
Q39. 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)));
Q40. 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
Q41. 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() {} }
Q42. 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;
Q43. 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
Q44. Consider 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
Q45. 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
Q46. 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
Q47. 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
Q48. Given:
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
Integer r = i1 + Integer.valueOf(s1.replace("_", ""), 16); //This will throw an exception
System.out.println(r);
Q49. What will the following code print?
List names = Arrays.asList(1, 2, 3); //1
names.forEach(x->x=x+1); //2
names.forEach(System.out::println); //3
Select 1 option(s):
1
2
3
2
3
4
It will not compile due to code at //2
It will not compile due to code at //3
None
Q50. Consider the program shown in exhibit and select the right option(s).
public class TestClass
{
static StringBuffer sb1 = new StringBuffer();
static StringBuffer sb2 = new StringBuffer();
public static void main(String[] args)
{
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb1)
{
sb1.append("X");
synchronized(sb2)
{
sb2.append("Y");
}
}
System.out.println(sb1);
}
}
).start();
new Thread
(
new Runnable()
{
public void run()
{
synchronized(sb2)
{
sb2.append("Y");
synchronized(sb1)
{
sb1.append("X");
}
}
System.out.println(sb2);
}
}
).start();
}
}
Select 1 option(s):
It will print XX followed by YY
It will print YY followed by XX
It will print XY followed by YX
The above code may result in a deadlock and so nothing can be said for sure about the output.
None
Time's 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