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 Test 24 – 2024
Welcome to your Java Test 24 - 2024
Name
Email
Phone
Q1. What should be placed in the two blanks so that the following code will compile without errors:
class XXX{
public void m() {
throw new RuntimeException();
}
}
class YYY extends XXX{
public void m() throws Exception{
throw new Exception();
}
}
public class TestClass {
public static void main(String[] args) {
______ obj = new ______();
obj.m();
}
}
You had to select 1 option(s)
XXX and YYY
XXX and XXX
YYY and YYY
YYY and XXX
None of the options will make the code compile.
None
Q2. What will the following code fragment print when compiled and run?
Locale myloc = new Locale.Builder().setLanguage("hinglish")
.setRegion("IN").build(); //L1
ResourceBundle msgs = ResourceBundle.getBundle("mymsgs", myloc);
Enumeration en = msgs.getKeys();
while(en.hasMoreElements()){
String key = en.nextElement();
String val = msgs.getString(key);
System.out.println(key+"="+val);
}
Assume that only the following two properties files (contents of the file is shown below the name of the file) are accessible to the code.
1. mymsgs_hinglish_US.properties
okLabel=OK
cancelLabel=Cancel
2. mymsgs_hinglish_UK.properties
okLabel=YES
noLabel=NO
You had to select 1 option(s)
It will not compile due to line L1.
It will not print anything.
okLabel=OK
cancelLabel=Cancel
okLabel=YES
noLabel=NO
It will throw an exception at run time.
None
Q3. Given:
class Item{
private int id;
private String name;
public Item(int id, String name){
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return name;
}
}
public class Test {
public static void main(String[] args) {
List l = Arrays.asList(
new Item(1, "Screw"),
new Item(2, "Nail"),
new Item(3, "Bolt")
);
l.stream()
//INSERT CODE HERE
.forEach(System.out::print);
}
}
Which of the following options can be inserted in the above code independent of each other, so that the code will print BoltNailScrew?
You had to select 2 option(s)
Q4. Given the following code:
//in WeekDay.java
package days;
public sealed class WeekDay permits Monday {
}
Which of the following is a valid declaration of Monday?
You had to select 1 option(s)
package calendar;
final class Monday extends WeekDay{
}
package days;
final class Monday {
}
package days;
class Monday extends WeekDay{
}
package days;
non-sealed class Monday extends WeekDay{
}
package days;
sealed class Monday extends WeekDay{
}
None
Q5. Given:
//assume appropriate imports
public class Calculator{
public static void main(String[] args) {
double principle = 100;
int interestrate = 5;
double amount = compute(principle, x->x*interestrate);
}
INSERT CODE HERE
}
Which of the following methods can be inserted in the above code so that it will compile and run without any error/exception?
You had to select 2 option(s)
Q6. Given:
Locale locale = new Locale("en", "US");
ResourceBundle rb = ResourceBundle.getBundle("test.MyBundle", locale);
Which of the following are valid lines of code?
(Assume that the ResourceBundle has the values for the given keys.)
You had to select 2 option(s)
String obj = rb.getObject("key1");
Object obj = rb.getObject("key1");
String[] vals = rb.getStringArray("key2");
Object obj = rb.getValue("key3");
Object obj = rb.getObject(1);
Q7. Identify correct statements about the modular system of Java.
You had to select 3 option(s)
A module can allow other modules to access all its types and members of its type through reflection.
By default, a module exhibits strong encapsulation by preventing reflective access to it types.
A module can be used by non-modular code by putting that module on the classpath.
An application can either use module-path or classpath but not both.
A sealed class belonging to a module may list classes belonging to other modules in its permits clause.
Q8. What will happen when the following code is compiled and run?
class AX{
static int[] x = new int[0];
static{
x[0] = 10;
}
public static void main(String[] args){
var ax = new AX();
}
}
You had to select 1 option(s)
It will throw NullPointerException at runtime.
It will throw ArrayIndexOutOfBoundsException at runtime.
It will throw ExceptionInInitializerError at runtime.
It will not compile.
None
Q9. Which of the following are valid declarations inside an interface independent of each other?
You had to select 3 option(s)
default void compute();
public void compute();
static void compute(){
System.out.println("computing...");
}
static void compute();
default static void compute(){
System.out.println("computing...");
};
interface I {
sealed class Inner { }
final class IC extends Inner{ }
}
Q10. What will the following code print when run?
public class TestClass{
public static Integer wiggler(Integer x){
Integer y = x + 10;
x++;
System.out.println(x);
return y;
}
public static void main(String[] args){
Integer dataWrapper = Integer.valueOf(5);
Integer value = wiggler(dataWrapper);
System.out.println(dataWrapper+value);
}
}
You had to select 1 option(s)
5 and 20
6 and 515
6 and 20
6 and 615
It will not compile.
None
Q11. What will be the result of attempting to compile and run the following class?
public class InitTest{
static String s1 = sM1("a");{
s1 = sM1("b");
}
static{
s1 = sM1("c");
}
public static void main(String args[]){
InitTest it = new InitTest();
}
private static String sM1(String s){
System.out.println(s); return s;
}
}
You had to select 1 option(s)
The program will fail to compile.
The program will compile without error and will print a, c and b in that order when run.
The program will compile without error and will print a, b and c in that order when run.
The program will compile without error and will print c, a and b in that order when run.
The program will compile without error and will print b, c and a in that order when run.
None
Q12. Given:
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
}
Identify correct statements.
You had to select 2 option(s)
An exception will be thrown at runtime if p2 is a symbolic link.
If p2 is a symbolic link, then that link, and not the target of that link, will be replaced .
If p1 is a symbolic link, then the final target of the link is copied to p2.
An exception will be thrown at runtime if either of p1 or p2 is a symbolic link.
Result is OS dependent if either of p1 or p2 is a symbolic link.
Q13. Consider the following code:
class Account{
private String id; private double balance;
ReentrantLock lock = new ReentrantLock();
public void withdraw(double amt){
try{
lock.lock();
if(balance > amt) balance = balance - amt;
}finally{
lock.unlock();
}
}
}
What can be done to make the above code thread safe?
You had to select 1 option(s)
Change new ReentrantLock() to new ReentrantLock(true).
Move the call to lock.lock(); to before the try block.
Declare lock variable as private and final.
Make the lock variable private, final, and static.
Make the lock variable static.
No change is required.
None
Q14. Given the following code:
package com.auto.vehicles;
public interface Drivable{
void drive();
}
and
package com.auto.vehicles.electric;
public class ECar implements Drivable{
private int maxSpeed;
public ECar(){
this(120);
}
public ECar(int maxSpeed){
this.maxSpeed = maxSpeed;
}
@Override
public void drive(){
System.out.println("driving ecar");
}
}
Which statements should be present in the module-info for it to represent a service provider?
You had to select 2 option(s)
requires com.auto.vehicles.Drivable;
requires com.auto.vehicles.electric.ECar;
exports com.auto.vehicles.Drivable;
exports com.auto.vehicles;
provides com.auto.vehicles.Drivable;
provides com.auto.vehicles.Drivable to com.auto.vehicles.electric;
provides com.auto.vehicles.Drivable with com.auto.vehicles.electric.ECar;
provides com.auto.vehicles.electric.ECar;
Q15. Consider the following class...
public class ParamTest {
public static void printSum(double a, double b){
System.out.println("In double "+(a+b));
}
public static void printSum(float a, float b){
System.out.println("In float "+(a+b));
}
public static void main(String[] args) {
printSum(1, 2.0);
printSum(1, 2);
printSum(1.0, 2.0);
}
}
What will be printed?
You had to select 1 option(s)
In float 3.0
In float 3.0
In float 3.0
In double 3.0
In double 3.0
In double 3.0
In double 3.0
In float 3.0
In double 3.0
In float 3.0
In double 3.0
In float 3.0
It will not compile.
None
Q16. What will the following code print?
String s = "blooper";
StringBuilder sb = new StringBuilder(s);
sb.append(s.substring(4)).delete(3, 5);
System.out.println(sb);
You had to select 1 option(s)
blorbloo
bloper
bloerper
blooperper
bloo
None
Q17. Consider the following method:
public void setSQLMode(Connection c, String mode) throws Exception{
Statement stmt = c.createStatement();
String qr = "SET SESSION sql_mode = '"+mode+"';";
stmt.execute(qr);
}
Identify the correct statement about the above code.
You had to select 1 option(s)
mode should enquoted like this:
String qr = "SET SESSION sql_mode = "+stmt.enquoteLiteral(mode)+";";
because enquoting values provided by the calling code prevents SQL injection attacks.
There is no need to enquote mode because identifiers need not be enquoted.
There is no need to enquote mode because the calling code would have enquoted it already.
Enquoting mode would make no difference because it is functionally equivalent to the current statement.
mode should be enquoted using the encodeIdentifier method.
None
Q18. Given:
public class CrazyMath {
public static void main(String[] args) {
int x = 10, y = 20;
int dx, dy;
try{
dx = x % 5;
dy = y/dx;
}catch(ArithmeticException ae){
System.out.println("Caught AE");
dx = 2;
dy = y/dx;
}
x = x/dx;
y = y/dy;
System.out.println(dx+" "+dy);
System.out.println(x+" "+y);
}
}
What is the output?
You had to select 1 option(s)
Caught AE
2 10
5 5
Caught AE
2 10
5 2
2 10
5 2
It will not compile.
None
Q19. Identify correct statement(s) regarding the benefit of using PreparedStatement over Statement.
You had to select 2 option(s)
PreparedStatement offers better performance.
PreparedStatement offers better performance when the same query is to be run multiple times with different parameter values.
PreparedStatement supports multiple transactions.
PreparedStatement allows several additional SQL types such as BLOB and CLOB.
Q20. Which of the following method implementations will write a boolean value to the underlying stream?
You had to select 3 option(s)
public void usePrintWriter(PrintWriter pw){
boolean bval = true;
pw.writeBoolean(bval);
}
public void usePrintWriter(PrintWriter pw) throws IOException{
boolean bval = true;
pw.write(bval);
}
public void usePrintWriter(PrintWriter pw) throws IOException{
boolean bval = true;
pw.print(bval);
}
public void usePrintWriter(PrintWriter pw) {
boolean bval = true;
pw.print(bval);
}
public void usePrintWriter(PrintWriter pw) {
boolean bval = true;
pw.println(bval);
}
Q21. Consider the following code snippet :
public void readData(String fileName) throws Exception {
try(FileReader fr1 = new FileReader(fileName)){
Connection c = getConnection();
//...other valid code
}
}
Given that the call to getConnection method in the above code throws a ClassNotFoundException and that an IOException is thrown while closing fr1, which exception will be received by the caller of readData() method?
You had to select 1 option(s)
java.lang.Exception
java.lang.ClassNotFoundException
java.io.IOException
java.lang.RuntimeException
None
Q22. What letters, and in what order, will be printed when the following program is compiled and run?
public class FinallyTest{
public static void main(String args[]) throws Exception{
try{
m1();
System.out.println("A");
}
finally{
System.out.println("B");
}
System.out.println("C");
}
public static void m1() throws Exception { throw new Exception(); }
}
You had to select 1 option(s)
It will print C and B, in that order.
It will print A and B, in that order.
It will print B and throw Exception.
It will print A, B and C in that order.
Compile time error.
None
Q23. What can be done to get the following code to compile and run? (Assume that the options are independent of each other.)
public float parseFloat( String s ){
float f = 0.0f; // 1
try{
f = Float.valueOf( s ).floatValue(); // 2
return f ; // 3
}
catch(NumberFormatException nfe){
f = Float.NaN ; // 4
return f; // 5
}
finally {
return f; // 6
}
return f ; // 7
}
You had to select 4 option(s)
Remove line 3, 6
Remove line 5
Remove line 5, 6
Remove line 7
Remove line 3, 7
Q24. The following code was written for Java 7:
Map<String, List> groupedValues = new HashMap();
public void process(String name, Double value){
List values = groupedValues.get(name);
if(values == null){
values = new ArrayList();
groupedValues.put(name, values);
}
values.add(value);
}
Which of the following implementations correctly makes use of the functional interfaces available in the Java standard library to achieve the same?
You had to select 1 option(s)
None
Q25. Given:
module broker{
exports org.broker.api;
provides org.broker.api.Broker with org.broker.api.MyBroker
}
Which of the following statements are correct?
You had to select 3 option(s)
This is not a valid service definition module because it provides the service instead of defining it.
This is not a valid service provider module because it does not contain appropriate requires clause for service definition.
Other modules can also provide implementations for org.broker.api.Broker service.
Placing the org.broker.api package in a separate module named brokerapi would make it easy to install multiple provider modules.
It is not a good idea to include MyBroker and Broker in the same module because that allows the user of the service to inadvertantly depend on the implementation class.
Q26. Consider the following hierarchy of Exception classes :
java.lang.RuntimeException
+----- IndexOutOfBoundsException
+----ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
Which of the following statements are correct for a method that can throw ArrayIndexOutOfBounds as well as StringIndexOutOfBounds Exceptions but does not have try catch blocks to catch the same?
You had to select 3 option(s)
The method calling this method will either have to catch these 2 exceptions or declare them in its throws clause.
It is ok if it declares just throws ArrayIndexOutOfBoundsException
It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
It is ok if it declares just throws IndexOutOfBoundsException
It does not need to declare any throws clause.
Q27. A modularized application has been packaged in graphs.jar file with module name as com.xcomp.graphs. The entry point of the application is a class named Main in package com.xcomp.graphs.
Which two options can be used to execute this application?
You had to select 2 option(s)
java --module-path graphs.jar --module com.xcomp.graphs.Main
java --module-path graphs.jar --module com.xcomp.graphs/com.xcomp.graphs.Main
java -classpath graphs.jar --module com.xcomp.graphs/com.xcomp.graphs.Main
java --module-path graphs.jar com.xcomp.graphs.Main
java -classpath graphs.jar com.xcomp.graphs.Main
java --module-path graphs.jar --main-class com.xcomp.graphs.Main
Q28. Identify correct statements about the following code -
interface Drink{
default double getAlcoholPercent(){
return 0.0;
}
static double computeAlcoholPercent(){
return 0.0;
}
}
interface ColdDrink extends Drink{
String getName();
}
class CrazyDrink implements ColdDrink{
// INSERT CODE HERE
}
You had to select 1 option(s)
CrazyDrink must either implement getName or be marked abstract.
CrazyDrink must either implement getName as well as computeAlcoholPercent or be marked abstract.
CrazyDrink must either implement getName as well as getAlcoholPercent or be marked abstract.
CrazyDrink must either implement getName or be marked abstract. Further, computeAlcoholPercent must be removed from Drink.
None
Q29. What will the following code print?
Object v1 = IntStream.rangeClosed(10, 15)
.boxed()
.filter(x->x>12)
.parallel()
.findAny();
Object v2 = IntStream.rangeClosed(10, 15)
.boxed()
.filter(x->x>12)
.sequential()
.findAny();
System.out.println(v1+":"+v2);
(Note: in the options below denote the possible output and not the sign themselves.)
You had to select 1 option(s)
None
Q30. Given the following code :
public class TestClass {
int[][] matrix = new int[2][3];
int[] a = new int[]{1, 2, 3};
int[] b = new int[]{4, 5, 6};
public int compute(int x, int y){
//1 : Insert Line of Code here
}
public void loadMatrix(){
for(int x=0; x<matrix.length; x++){
for(int y=0; y<matrix[x].length; y++){
//2: Insert Line of Code here
}
}
}
}
What can be inserted at //1 and //2?
You had to select 1 option(s)
return a(x)*b(y);
and
matrix(x, y) = compute(x, y);
return a[x]*b[y];
and
matrix[x, y] = compute(x, y);
return a[x]*b[y];
and
matrix[x][y] = compute(x, y);
return a(x)*b(y);
and
matrix(x)(y) = compute(x, y);
return a[x]*b[y];
and
matrix[[x][y]] = compute(x, y);
None
Q31. 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);
}
}
You had to select 1 option(s)
It will throw ArrayIndexOutOfBoundsException.
It will throw NullPointerException.
6
5
7
2
None of these.
None
Q32. What will the following program print?
public class TestClass{
static int someInt = 10;
public static void changeIt(int a){
a = 20;
}
public static void main(String[] args){
changeIt(someInt);
System.out.println(someInt);
}
}
You had to select 1 option(s)
10
20
It will not compile.
It will throw an exception at runtime.
None of the above.
None
Q33. Given:
public class ItemProcessor implements Runnable{ //LINE 1
CyclicBarrier cb;
public ItemProcessor(CyclicBarrier cb){
this.cb = cb;
}
public void run(){
System.out.println("processed");
try {
cb.await();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public class Merger implements Runnable{ //LINE 2
public void run(){
System.out.println("Value Merged");
}
}
What should be inserted in the following code such that run method of Merger will be executed only after the thread started at 4 and the main thread have both invoked await?
public static void main(String[] args) throws Exception{
var m = new Merger();
//LINE 3
var ip = new ItemProcessor(cb);
ip.start(); //LINE 4
cb.await();
}
You had to select 1 option(s)
Make ItemProcessor extend Thread instead of implementing Runnable and add CyclicBarrier cb = new CyclicBarrier(1, m); to //LINE 3
Make ItemProcessor extend Thread instead of implementing Runnable and add CyclicBarrier cb = new CyclicBarrier(2, m); to //LINE 3
Make Merger extend Thread instead of implementing Runnable and add CyclicBarrier cb = new CyclicBarrier(1, m); to //LINE 3
Make Merger extend Thread instead of implementing Runnable and add CyclicBarrier cb = new CyclicBarrier(2, m); to //LINE 3
Just add CyclicBarrier cb = new CyclicBarrier(1, m); to //LINE 3
Just add CyclicBarrier cb = new CyclicBarrier(2, m); to //LINE 3
None
Q34. What will the following code print when run?
String[] sa = { "charlie", "bob", "andy", "dave" };
Collections.sort(Arrays.asList(sa), null);
System.out.println(sa[0]);
You had to select 1 option(s)
charlie
andy
dave
It will throw a NullPointerException
It will not compile.
None
Q35. What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
while(var k = 5; k<7){
System.out.println(k++);
}
}
}
You had to select 1 option(s)
5
6
5
6
7
It will keep printing 5.
It will not compile.
It will throw an exception at run time.
None
Q36. Given:
int[][] iaa = { {1, 2}, {3, 4}, { 5, 6} };
long count = Stream.of(iaa).flatMapToInt(IntStream::of)
.map(i->i+1).filter(i->i%2 != 0).peek(System.out::print).count();
System.out.println(count);
What will be the output?
You had to select 1 option(s)
3573
2463
3
2345676
None
Q37. What will be the result of compiling and running the following code:
float foo = 2, bar = 3, baz = 4; //1
float mod1 = foo % baz, mod2 = baz % foo; //2
float val = mod1>mod2? bar : baz; //3
System.out.println(val);
You had to select 1 option(s)
Compilation error at //1
Compilation error at //2
Compilation error at //3
3.0
3.0f
4
4.0
4.0f
None
Q38. Given the following code:
Locale.setDefault(Locale.ITALY);
Locale loc = new Locale.Builder().setLanguage("en").build();
ResourceBundle rb = ResourceBundle.getBundle("mymsgs", loc);
System.out.println(rb.getString("helloMsg"));
and the following properties files:
mymsgs.properties
mymsgs_en_IT.properties
mymsgs_en.properties
mymsgs_IT.properties
Which of the following statements are correct?
You had to select 2 option(s)
If helloMsg is defined in all the four properties files, the value from mymsgs_en.properties will be displayed.
If helloMsg is defined in all the four properties files, the value from mymsgs_en_IT.properties will be displayed.
If helloMsg is defined only in mymsgs_IT.properties, then that value will be displayed.
If helloMsg is not defined in mymsgs_en.properties file but is defned in mymsgs.properties and mymsgs_en_IT.properties, then the value from mymsgs.properties will be displayed.
A java.util.MissingResourceException will be NOT be thrown if helloMsg is defined in any one of the given four properties files.
Q39. 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 = List.of(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
Reader r = b->{
System.out.println("Reading book "+b.getTitle());
};
books.forEach(x->r.read(x));
What would be a valid definition of Reader for the above code to compile and run without any error or exception?
You had to select 2 option(s)
abstract class Reader{
abstract void read(Book b);
}
abstract class Reader{
void read(Book b);
}
interface Reader{
void read(Book b);
default void unread(Book b){ }
}
interface Reader{
default void read(Book b){ }
void unread(Book b);
interface Reader{
default void read(Book b){ System.out.println("Default read");};
}
Q40. Which of the following code fragments compile without any error?
You had to select 3 option(s)
Q41. Consider the following code:
class Base{
private float f = 1.0f;
void setF(float f1){ this.f = f1; }
}
class Base2 extends Base{
private float f = 2.0f;
//1
}
Which of the following options is/are valid example(s) of overriding?
You had to select 2 option(s)
protected void setF(float f1){ this.f = 2*f1; }
public void setF(double f1){ this.f = (float) ( 2*f1); }
public void setF(float f1){ this.f = 2*f1; }
private is more restrictive than default, so it is NOT valid.
float setF(float f1){ this.f = 2*f1; return f;}
Q42. Given:
Stream strm1 = Stream.of(2, 3, 5, 7, 11, 13, 17, 19); //1
Stream strm2 = strm1.filter(i->{ return i>5 && i<15; }); //2
strm2.forEach(System.out::print); //3
Which of the following options can be used to replace line at //2 and still print the same elements of the stream?
You had to select 1 option(s)
None
Q43. What will be the output?
var ca = new char[]{'a', 'b', 'c', 'd'};
var i = 0;
for(var c : ca){
switch(c){
case 'a' : i++;
case 'b' : ++i;
case 'c'|'d' : i++;
}
}
System.out.println("i = "+i);
You had to select 1 option(s)
Compilation failure
i = 5
i = 6
i = 7
None
Q44. What will the following class print when run?
public class Sample{
public static void main(String[] args) {
String s1 = """
java \
java\
""";
StringBuilder s2 = new StringBuilder("news");
s1.replace("java", "");
s2.append(s1);
System.out.println(s2.indexOf("java"));
}
}
You had to select 1 option(s)
0
-1
4
5
None
Q45. How will you initialize a DateTimeFormatter object so that the following code will print the number of the month (i.e. 02 for Feb, 12 for Dec, and so on) and a two digit calendar year of any given date?
System.out.println(dtf.format(LocalDate.now()));
You had to select 1 option(s)
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("mm/yy");
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("MM/yy");
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("mm/YY");
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("MM/YY");
None
Q46. Which of the following can be valid declarations of an integer variable?
You had to select 2 option(s)
private var x = 10;
final int x = 10;
public Int x = 10;
Int x = 10;
static int x = 10;
global int x = 10;
Q47. Which of the following statements are true?
You had to select 2 option(s)
System.out.println(1 + 2 + "3"); will print 33.
System.out.println("1" + 2 + 3); will print 15.
System.out.println(4 + 1.0f); will print 5.0
System.out.println(5/4); will print 1.25
System.out.println('a' + 1 ); will print b.
Q48. Which of the following implementations of a max() method will correctly return the largest value?
You had to select 1 option(s)
None
Q49. Which of the following statements correctly obtains a reference to a Console object?
You had to select 1 option(s)
Console c = Console.getInstance();
Console c = new Console();
Console c = new Console(System.in);
Console c = new Console(new InputStreamReader(System.in));
Console c = System.console();
None
Q50. Given:
public class SimpleLoop {
public static void main(String[] args) {
int i=0, j=10;
while (i<=j) {
i++;
j--;
}
System.out.println(i+" "+j);
}
}
What is the result?
You had to select 1 option(s)
6 4
6 5
6 6
5 3
5 4
5 5
None
Q51. Given:
sealed interface Member permits Student, Person{ //LINE A
String role();
}
record Person(String role) implements Member{ //LINE B
}
record Student(int id, Person person) //LINE C
implements Member //LINE D
{
public String role(){ return person.role(); } //LINE E
}
Which lines will cause compilation issues?
You had to select 1 option(s)
LINE A
LINE B
LINE C
LINE D
LINE E
There is no problem with any of the marked lines but the given code will not compile.
The given code will compile without any problem.
None
Q52. Given:
class T extends Thread
{
static Lock lock = new ReentrantLock();
public T(String name){ super(name); }
public void run()
{
for(int i=0; i<2; i++){
if(lock.tryLock()){
System.out.println(getName()+" got lock. "+getState());
}else{
System.out.println(getName()+" could not get lock. "+getState());
}
}
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
T t1 = new T("T1");
t1.start();
T t2 = new T("T2");
t2.start();
Thread.sleep(1000);
}
}
What is a possible output?
You had to select 1 option(s)
T2 could not get lock. RUNNABLE
T1 got lock. RUNNABLE
T2 could not get lock. RUNNABLE
T1 got lock. RUNNABLE
T2 could not get lock. WAITING
T1 got lock. RUNNABLE
T2 could not get lock. WAITING
T1 got lock. RUNNABLE
T2 could not get lock. WAITING
T1 got lock. RUNNABLE
T2 could not get lock. WAITING
T1 could not get lock. WAITING
T2 could not get lock. RUNNABLE
T1 got lock. RUNNABLE
T2 could not get lock. RUNNABLE
T1 could not get lock. RUNNABLE
None
Q53. Consider the following code :
String id = c.readLine("%s", "Enter UserId:"); //1
System.out.println("userid is " + id); //2
String pwd = c.readPassword("%s", "Enter Password :"); //3
System.out.println("password is " + pwd); //4
Assuming that c is a valid reference to java.io.Console and that a user types jack as userid and jj123 as password, what will be the output on the console?
You had to select 1 option(s)
Enter UserId:jack
userid is jack
Enter Password :
password is jj123
Enter UserId:jack
userid is jack
Enter Password :*****
password is jj123
Enter UserId:jack
userid is jack
Enter Password :
password is ****
Enter UserId:jack
userid is jack
Enter Password : password is jj123
It will not compile.
None
Q54. What is the result of executing the following code when the value of i is 5:
switch (i){
default:
case 1:
System.out.println(1);
case 0:
System.out.println(0);
case 2:
System.out.println(2);
break;
case 3:
System.out.println(3);
}
You had to select 1 option(s)
It will print 1 0 2
It will print 1 0 2 3
It will print 1 0
It will print 1
Nothing will be printed.
None
Q55. After which line will the object created at line XXX be eligible for garbage collection?
public Object getObject(Object a) //0
{
Object b = new Object(); //XXX
Object c, d = new Object(); //1
c = b; //2
b = a = null; //3
return c; //4
}
You had to select 1 option(s)
//2
//3
//4
Never in this method.
Cannot be determined.
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
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