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
Standard Unique Test 4
Welcome to your Standard Tests - Unique Test 4 : 2025
Name
Email
Phone
Q1. What happens when you try to compile and run the following program?
public class CastTest{
public static void main(String args[ ] ){
byte b = -128 ;
int i = b ;
b = (byte) i;
System.out.println(i+" "+b);
}
}
Select 1 option(s):
The compiler will refuse to compile it because i and b are of different types cannot be assigned to each other.
The program will compile and will print -128 and -128 when run .
The compiler will refuse to compile it because -128 is outside the range of values for a byte.
The program will compile and will print 128 and -128 when run .
The program will compile and will print 255 and -128 when run .
None
Q2. Given that the test directory contains two files as described below:
File values1.txt contains:
#13
241
35
File values2.txt contains:
23
#50
12
What will be the output of the following code :
Integer sum = Files.list(Path.of("c:\\temp\\test"))
.flatMap( p -> { try{ return Files.lines(p);
}catch(IOException e){
return null;
} } )
.filter(line -> !line.startsWith("#"))
.map(line -> Integer.parseInt(line.substring(1)))
.reduce((i1, i2)->i1+i2)
.get();
System.out.println(sum);
Select 1 option(s):
51
3
0
6
14
63
An exception will be thrown at run time.
None
Q3. Given:
class A extends Thread
{
public void run()
{
System.out.println("Starting loop");
try{
Thread.sleep(10000); //1 sleep for 10 secs
}catch(Exception e){ e.printStackTrace(); }
System.out.println("Ending loop");
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
A a = new A();
a.start();
Thread.sleep(100);
a.interrupt();
}
}
What will be the states of the main thread and the "A" thread created in the above program after the main thread calls a.interrupt()?
Select 1 option(s):
main thread: RUNNABLE
A thread: RUNNABLE
main thread: RUNNABLE
A thread: TERMINATED
main thread: BLOCKED
A thread: RUNNABLE
main thread: WAITING
A thread: TERMINATED
main thread: RUNNABLE
A thread: WAITING
None
Q4. 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();
}
}
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
Q5. Assuming that the following method will always be called with a phone number in the format ddd-ddd-dddd (where d stands for a digit), what can be inserted at //1 so that it will return a String containing "xxx-xxx-"+dddd, where dddd represents the same four digits in the original number?
public static String hidePhone(String fullPhoneNumber){
//1 Insert code here
}
Select 2 option(s):
String mask = "xxx-xxx-";
mask.append(fullPhoneNumber.substring(8));
return mask;
return new StringBuilder("xxx-xxx-")+fullPhoneNumber.substring(8);
return new StringBuilder(fullPhoneNumber).replace(0, 7, "xxx-xxx-").toString();
return "xxx-xxx-"+fullPhoneNumber.substring(8, 12);
Q6. 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?
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
Q7. 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?
Select 2 option(s):
public static double compute(double base, Function<Integer, Integer > func){
return func.apply((int)base);
}
public static double compute(double base, Function<Integer, Double> func){
return func.apply((int)base);
}
public static double compute(double base, Function<Double, Integer> func){
return func.apply(base);
}
public static double compute(double base, Function<Double, Double> func){
return func.apply(base);
}
public static double compute(double base, Function<Integer, Double> func){
return func.apply(base);
}
Q8. 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.)
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);
Q9. Identify correct statements about the modular system of Java.
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.
Q10. 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;
}
}
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
Q11. Given:
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
}
Identify correct statements.
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.
Q12. What will the following line of code print?
System.out.println(LocalDate.of(2022, Month.JANUARY, 01)
.format(DateTimeFormatter.ISO_DATE_TIME));
Select 1 option(s):
01 Jan 2022
01 January 2022 00:00:00
2022-01-01
2022-01-01T00:00:00
Exception at run time.
None
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?
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?
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?
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);
Select 1 option(s):
blorbloo
bloper
bloerper
blooperper
bloo
None
Q17. 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?
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
Q18. Which of the following method implementations will write a boolean value to the underlying stream?
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);
}
Q19. 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
}
Select 4 option(s):
Remove line 3, 6
Remove line 5
Remove line 5, 6
Remove line 7
Remove line 3, 7
Q20. Consider the following code:
import java.util.*;
class Book{ }
class TextBook extends Book{ }
class BookList extends ArrayList
{
public int count = 0;
public boolean add(Object o)
{
if(o instanceof Book b) return super.add(b);
else return count++ == -1;
}
}
//in valid context
BookList list = new BookList();
list.add(new Book());
list.add(new TextBook());
list.add("hello");
System.out.println(list.count);
What will it print?
Select 1 option(s):
0
1
2
It will not compile because the add method does not correctly override the add method from ArrayList.
It will not compile because on incorrect usage of instanceof.
It will throw an exception at runtime.
None
Q21. 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?
Select 1 option(s):
public void process(String name, Double value){
groupedValues.computeIfAbsent(name, (a)->new ArrayList< Double >()).add(value);
}
public void process(String name, Double value){
groupedValues.computeIfAbsent(name, (a, b)->new ArrayList< Double >()).add(value);
}
public void process(String name, Double value){
groupedValues.computeIfPresent(name, (a, b)->new ArrayList< Double >()).add(value);
}
public void process(String name, Double value){
groupedValues.compute(name, (a)->new ArrayList< Double >()).add(value);
}
None
Q22. Given:
module broker{
exports org.broker.api;
provides org.broker.api.Broker with org.broker.api.MyBroker
}
Which of the following statements are correct?
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.
Q23. 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?
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.
Q24. 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?
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
Q25. 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
}
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
Q26. 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.)
Select 1 option(s):
Optional[13]:Optional[13]
< An Optional containing 13, 14, or 15 >:Optional[13]
< An Optional containing 13, 14, or 15 >:< An Optional containing 13, 14, or 15 >
14:13
< 13, 14, or 15 >:13
< 13, 14, or 15 >:< 13, 14, or 15 >
An exception at run time.
None
Q27. 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?
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
Q28. What will the following code print when run without any arguments ...
public class TestClass {
public static int m1(int i){
return ++i;
}
public static void main(String[] args) {
int k = m1(args.length);
k += 3 + ++k;
System.out.println(k);
}
}
Select 1 option(s):
It will throw ArrayIndexOutOfBoundsException.
It will throw NullPointerException.
6
5
7
2
None of these.
None
Q29. 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);
}
}
Select 1 option(s):
10
20
It will not compile.
It will throw an exception at runtime.
None of the above.
None
Q30. 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();
}
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
Q31. 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]);
Select 1 option(s):
charlie
andy
dave
It will throw a NullPointerException
It will not compile.
None
Q32. What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
while(var k = 5; k<7){
System.out.println(k++);
}
}
}
Select 1 option(s):
5
6
5
6
7
It will keep printing 5.
It will not compile.
It will throw an exception at run time.
None
Q33. 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?
Select 1 option(s):
3573
2463
3
2345676
None
Q34. 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);
Select 1 option(s):
Compilation error at //1
Compilation error at //2
Compilation error at //3
3
3.0
3.0f
4
4.0
4.0f
None
Q35. 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?
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.
Q36. 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?
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");};
}
Q37. Which of the following code fragments compile without any error?
Select 3 option(s):
for(;Math.random()<0.5;){
System.out.println("true");
}
for(;;Math.random()<0.5){
System.out.println("true");
}
for(;;Math.random()){
System.out.println("true");
}
for(;;){
Math.random()<.05? break : continue;
}
for(;;){
if(Math.random()<.05) break;
}
Q38. 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?
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 void setF(float f1){ this.f = 2*f1; }
float setF(float f1){ this.f = 2*f1; return f;}
Q39. 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?
Select 1 option(s):
Stream< Integer > strm2 = strm1.filter(i>5).filter(i<15);
Stream< Integer > strm2 = strm1.parallel().filter(i->i>5).filter(i->i<15).sequential();
Stream< Integer > strm2 = strm1.collect(
Collectors.partitioningBy(i->{ return i>5 && i<15; })
).get("true").stream();
Stream< Integer > strm2 = strm1.map(i-> i>5?i<15?i:null:null);
None
Q40. Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList(100, 200, 230, 291, 43);
System.out.println( *INSERT CODE HERE* );
}
}
Which of the following options will correctly print the number of elements that are less than 200?
Select 1 option(s):
al.asStream().reduce((i)->i<200).count();
al.stream().map((i)->i<200, i).count();
al.stream().filter((i)->i<200).list().count();
al.stream().filter((i)->i<200).count();
al.asStream().filter((i)->i<200).count();
None
Q41. 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);
Select 1 option(s):
Compilation failure
i = 5
i = 6
i = 7
None
Q42. 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"));
}
}
Select 1 option(s):
0
-1
4
5
None
Q43. 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()));
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
Q44. Which of the following can be valid declarations of an integer variable?
Select 2 option(s):
Q45. Which of the following statements are true?
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.
Q46. Which of the following implementations of a max() method will correctly return the largest value?
Select 1 option(s):
int max(int x, int y){
return( if(x > y){ x; } else{ y; } );
}
int max(int x, int y){
return( if(x > y){ return x; } else{ return y; } );
}
int max(int x, int y){
switch(x < y){
case true:
return y;
default :
return x;
};
}
int max(int x, int y){
var m = x > y?x :y;
return m;
}
int max(var x, var y){
if(x > y) return x;
return y;
}
int max(int x, int y){
return switch(x < y){
case true -> y;
default -> x;
};
}
None
Q47. Which of the following statements correctly obtains a reference to a Console object?
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
Q48. 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?
Select 1 option(s):
6 4
6 5
6 6
5 3
5 4
5 5
None
Q49. 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?
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
Q50. 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?
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
Q51. What will the following code print?
LongStream ls = LongStream.generate(()->ThreadLocalRandom.current().nextLong()%100);
Long first = ls.sorted().filter(x -> x>-10 && x<10).peek(System.out::println).findFirst().getAsLong();
System.out.println(first);
Select 1 option(s):
-10
It may print any number between -10 and 10 (excluding both).
It will print all the numbers between -10 and 10 (excluding both) followed by -9.
-9
-9
It will throw an exception at run time.
None
Q52.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?
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
Q53. 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
}
Select 1 option(s):
//2
//3
//4
Never in this method.
Cannot be determined.
None
Q54. Given:
record Point(int x, int y){};
record Line(Point p1, Point p2){}
Which of the following are valid method implementations?
Select 3 option(s):
public double getSlope1(Line line){
if(line instanceof Line(Point(int x1, int y1), Point(int x2, int y2))){
return (y2-y1)*1.0/(x2-x1);
}else return 0.0;
}
public double getSlope2(Line line){
return switch(line){
case Line(Point(int x1, int y1), Point(int x2, int y2)) -> (y2-y1)/(x2-x1);
case null, default -> 0.0;
};
}
public double getSlope3(Line line){
return switch(line){
case line instanceof Line(Point(int x1, int y1), Point(int x2, int y2)) -> (y2-y1)*1.0/(x2-x1);
case null, default -> 0.0;
};
}
public double getSlope4(Line line){
return switch(line){
case line instanceof Line(Point(int x1, int y1), Point(int x2, int y2)) -> (y2-y1)*1.0/(x2-x1);
default -> 0.0;
};
}
public double getSlope5(Line line){
return switch(line){
case Line(Point(int x1, int y1), Point(int x2, int y2)) -> (y2-y1)/(x2-x1);
case null -> 0.0;
};
}
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