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 12 – 2025
Welcome to your Standard Test 12 - 2025
Name
Email
Phone
Q1. Given:
byte b = 1;
char c = 1;
short s = 1;
int i = 1;
which of the following expressions are valid?
Select 4 option(s):
s = b * b ;
i = b + b ;
s *= b ;
c = c + b ;
s += i ;
float f = 2%s+c;
Q2. Given:
String presentPastOrFuture(Object obj){
LocalDate now = LocalDate.now();
return switch(obj){
case null -> "no idea";
case LocalDate d
when d.isBefore(now) -> "past";
case LocalDate d
when d.isAfter(now) -> "future";
case LocalDate d
when !d.isBefore(now) && !d.isAfter(now) -> "present";
};
}
What must be done to fix the above code?
Select 1 option(s):
Replace case null with default.
Add default -> "no idea"; at the end of the switch block.
Remove case null -> "no idea"; and add default -> "no idea"; at the end of the switch block.
Shift case null -> "no idea"; at the end of the switch block.
Add default -> "no idea"; at the end of the switch block and move case null -> "no idea"; just above default.
Add case !(LocalDate d) -> "no idea"; at the end of the switch.
None
Q3. Identify correct statements.
In the given statements, it is not clear what is meant by number? Does it mean integer or double? Unfortunately, the real exam does have such vaguely worded questions on Math.random. Our suggestion is to answer the question assuming that numbers mean integers and doubles both.
So, when they say "number between 1 and 10", it means any integer or a double between 1 and 10.
Further, it is not clear whether both the numbers in the given range are inclusive or exclusive. Since, Math.random() returns a double between 0.0 (inclusive) and 1.0 (exclusive), our suggestion is to use the same convention. i.e. when they say "number between 1 and 10", it means >=1 and <10.
Select 2 option(s):
1 + Math.random()*9 will return a random number between 1 and 10.
Math.random()*10 will return a random number between 1 and 10.
Math.round(Math.random()*9) will return a random number between 1 and 10.
1 + Math.round(Math.random()*9) will return a random number between 1 and 10.
Math.round(Math.random()*10) will return a random number between 1 and 10.
Q4. What will the following code print?
public class Test{
public static void stringTest(String s){
s.replace("h", "s");
}
public static void stringBuilderTest(StringBuilder s){
s.append("o");
}
public static void main(String[] args){
String s = "hell";
StringBuilder sb = new StringBuilder("well");
stringTest(s);
stringBuilderTest(sb);
System.out.println(s + sb);
}
}
Select 1 option(s):
sellwello
hellwello
hellwell
sellwell
None of these.
None
Q5. What will be the output when the following program is run?
public class TestClass{
char c;
public void m1(){
char[ ] cA = { 'a' , 'b'};
m2(c, cA);
System.out.println( ( (int)c) + "," + cA[1] );
}
public void m2(char c, char[ ] cA){
c = 'b';
cA[1] = cA[0] = 'm';
}
public static void main(String args[]){
new TestClass().m1();
}
}
Select 1 option(s):
Compile time error.
,m
0,m
b,b
b,m
None
Q6. Which of the following are valid code snippets appearing in a method:
Select 3 option(s):
var a = b = c = 100;
var a = 100, b = 10;
var a = b;
int a, b, c=100;
int a=100, b, c;
int a = 100 = b = c;
int a = b = c = 100;
int a, b, c; a = b = c = 100;
Integer x = 10d;
Q7. What will the following code print when compiled and run?
List values = Arrays.asList("Java EE", "C#", "Python");
boolean flag = values.stream().allMatch(str->{
System.out.println("Testing: "+str);
return str.equals("Java");
});
System.out.println(flag);
Select 1 option(s):
Testing: Java EE
false
Testing: Java EE
Testing: C#
Testing: Python
false
Testing: Java EE
true
It will not compile because lambda expression is built incorrectly.
None
Q8. Which of the following lines will cause the compilation to fail?
interface I { }
public enum EnumA implements I, Serializable { A, AA, AAA}; //1
class TestClass
{
public enum EnumB{ B, BB, BBB;
public Object clone(){ return B; } //2
}
public static enum EnumC{ C, CC, CCC };
public static enum EnumD extends EnumC{ DDD }; //3
public TestClass()
{
System.out.println(EnumC.CC.index()); //4
}
public static void main(String[] args)
{
System.out.println(EnumC.valueOf("ccc")); //5
System.out.println(EnumC.CCC.name()); //6
System.out.println(EnumC.CCC.ordinal()); //7
}
}
Select 3 option(s):
1
2
3
4
5
6
7
Q9. Given:
class Buddy {
public Buddy(){ }
}
public class GCTest
public static void initBuddies(Buddy[] ba){
ba[0] = new Buddy(); //1
ba[1] = new Buddy(); //2
ba[0] = ba[1]; //3
ba[1] = ba[2]; //4
}
public static void main(String[] args) {
Buddy[] ba = new Buddy[3]; //5
initBuddies(ba); //6
//7
}
}
How many Buddy objects will be eligible for garbage collection at line marked //7?
Select 1 option(s):
1
2
3
4
5
0
None
Q10. Your application consists of two jar files produced by two different teams - accounting-3.2.jar and reporting-5.6.jar. Classes in reporting-5.6.jar use the class com.abc.account.Account in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.
The accounting team has decided to modularize their jar. Which of the following would be a valid module-info.java for the new accounting-3.3.jar?
Select 1 option(s):
module accounting{
requires com.abc.account;
}
module accounting{
export com.abc.account.*;
}
module accounting{
exports com.abc.account;
}
module accounting{
export com.abc.account;
}
module accounting{
export com.abc.account.Account;
}
module accounting{
provides com.abc.account;
}
None
Q11. Consider the following piece of code:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = new Locale("jp", "JP");
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundle files with the following contents:
#In appmessages.properties:
greetings=Hello
#In appmessages_fr_FR.properties:
greetings=bonjour
Given that this code is run on machines all over the world. Which of the following statements are correct?
Select 1 option(s):
It will throw an exception when the default locale of the machine where it is run is different from fr/FR and fr/CA.
It will throw an exception where ever it is run.
It will throw an exception when the default locale of the machine is fr/CA.
It will throw an exception when the default locale of the machine is jp/JP.
It will run without any exception all over the world.
None
Q12. Given the following module definitions:
module m${
requires _n;
exports o;
}
module _n{
requires m$;
exports p;
}
Identify the correct statements.
Select 1 option(s):
The definitions are invalid because of circular dependency.
The definitions are invalid because the package names in the export clauses are invalid.
The definitions are invalid because the modules names are invalid.
The definitions are invalid because they don't declare dependency on java.base module.
The definitions are invalid because of circular dependency as well as ommission of requires java.base;.
None
Q13. What will the following code print?
public static void main(String[] args) {
Integer x = 3;
switch(x){
case 1, 2 -> System.out.println("A");
case 3, 4 -> System.out.println("B");
default -> System.out.println("C");
}
}
Select 1 option(s):
B
B
C
C
It will not compile.
It will compile but will not print anything.
None
Q14. Which of the statements regarding the given code are correct?
public class Test extends Thread
{
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()
{
m1();
m2();
}
public static void main(String[] args)
{
new Test().start();
new Test().start();
}
}
Select 1 option(s):
It may result in a deadlock and the program might get stuck.
There is no potential for deadlock.
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 21
None
Q15. What will the following code print when compiled and run?
interface Eatable{
int types = 10;
}
class Food implements Eatable {
public static int types = 20;
}
public class Fruit extends Food implements Eatable{ //LINE1
public static void main(String[] args) {
types = 30; //LINE 2
System.out.println(types); //LINE 3
}
}
Select 1 option(s):
Compilation failure at //LINE 1.
Compilation failure at //LINE 2.
Compilation failure at //LINE 3.
10
20
30
Compilation failure at //LINE 2 as well as at //LINE 3
None
Q16. Consider the following code:
interface Classic {
int version = 1;
public void read() ;
}
class MediaReader implements Classic{
int version = 2;
public void read() {
//Insert code here
}
}
public class ReaderTest{
public static void main(String[] args) {
MediaReader mr = new MediaReader();
mr.read();
}
}
What can be inserted in the code above so that it will print 1 when run?
Select 1 option(s):
System.out.println(version);
System.out.println((Classic)version);
System.out.println(((Classic)this).version);
System.out.println(this.Classic.version);
System.out.println(MediaReader.version);
None
Q17. Given:
public class TestClass {
public void myMethod(String... params) {
var a = params;
var b = params[0];
}
}
What are the types of the variables a and b?
Select 1 option(s):
Object[] and Object
String[] and Object
String[] and String
List and Object
List< String > and String
None
Q18. What will the following code print when run?
public class TestClass
{
public static void main(String args[])
{
A a = new B();
if( a instanceof B b){
b.b();
}
System.out.println(b);
}
}
class A {
void a(){ System.out.println("a"); }
}
class B extends A {
void b(){ System.out.println("b"); }
}
Select 1 option(s):
Compilation failure
b
null
b
null
None
Q19. Identify correct statements about Java platform module system.
Select 2 option(s):
A module is a set of packages that make sense being grouped together and is designed for reuse.
The module system ensures that code that is internal to a platform implementation is not accessible from outside the implementation.
The module system uses only two phases - compile time and run time - for building an application.
All classes in a module are concealed and cannot be accessed by code from other modules. Only interfaces are visibile outside the package.
Q20. Which of the following classes have a default constructor?
class A{ }
class B { B(){ } }
class C{ C(String s){ } }
Select 1 option(s):
A
A and B
B
C
B and C
None
Q21. You want to print the date that represents upcoming Tuesday from now even if the current day is a Tuesday. Which of the following lines of code accomplishe(s) this?
Note: It is not clear if TemporalAdjusters is on the exam or not. You should read about it if you have time.
Select 2 option(s):
System.out.println(LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY)));
System.out.println(new LocalDate().with(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(new LocalDate().adjust(TemporalAdjusters.next(DayOfWeek.TUESDAY)));
System.out.println(TemporalAdjusters.next(DayOfWeek.TUESDAY).adjustInto(LocalDate.now()));
Q22. Which of the following lines of code that, when inserted at line 1, will make the overriding method in SubClass invoke the overridden method in BaseClass on the current object with the same parameter.
class BaseClass{
public void print(String s) { System.out.println("BaseClass :"+s); }
}
class SubClass extends BaseClass{
public void print(String s){
System.out.println("SubClass :"+s);
// Line 1
}
public static void main(String args[]){
SubClass sc = new SubClass();
sc.print("location");
}
}
Select 1 option(s):
this.print(s);
super.print(s);
print(s);
BaseClass.print(s);
None
Q23. Consider the directory structure and its contents shown in the figure.
(c:\temp is a directory that contains two text files - test1.txt and text2.txt)
What should be inserted at //LINE 10 in the following code so that it will write "hello" to text2.txt?
public static void writeData() throws Exception{
var p1 = Paths.get("c:\\temp\\test1.txt");
var p2 = //LINE 10 - INSERT CODE HERE
var bw = new BufferedWriter(new FileWriter(p2.toFile()));
bw.write("hello");
bw.close();
}
Select 1 option(s):
p1.resolve("text2.txt");
p1.relativize("c:\\temp\\text2.txt");
p1.resolveSibling("text2.txt");
p1.relativize(Paths.get("text2.txt"));
None
Q24. What will the following code print when compiled and run?
var numA = new Integer[]{1, 2};
var list1 = List.of(numA);
numA[0] = 2;
var list2 = List.copyOf(list1);
System.out.println(list1+" "+list2);
Select 1 option(s):
It will not compile.
[1, 2] [1, 2]
[2, 2] [1, 2]
[2, 2] [2, 2]
None
Q25. Given that the user account under which the following code is run does not have the permission to access a.java, what will the the following code print when run?
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;
public class IOTest {
public static void main(String[] args) {
try(BufferedReader bfr = new BufferedReader(
new FileReader("c:\\works\\a.java"))){
String line = null;
while( (line = bfr.readLine()) != null){
System.out.println(line);
}
}catch(NoSuchFileException|IOException|AccessDeniedException e){
e.printStackTrace();
}
}
}
Select 1 option(s):
It will run without any exception and without any output.
It will print a stack trace for AccessDeniedException.
It will print a stack trace for IOException.
It will print a stack trace for NoSuchFileException.
It will not compile because the catch clause is invalid.
It will not compile because AccessDeniedException is not a valid exception class in java.nio.file package.
None
Q26. Given:
abstract class AmazingClass{
void amazingMethod(Collection c){
System.out.println("Got collection");
};
}
public class SpecialAmazingClass extends AmazingClass{
void amazingMethod(List l){
System.out.println("Got list");
};
public static void main(String[] args) {
List al = new ArrayList();
Collection c = al;
AmazingClass ac = new SpecialAmazingClass();
ac.amazingMethod(c);
}
}
What is the output?
Select 1 option(s):
Compilation error
Exception at run time.
Got collection
Got list
None
Q27. Given:
String s1 = "Hello World";
String s2 = """
Hello World""";
String s3 = """
Hello World
""";
System.out.println((s1 == s2)+" "+s2.equals(s3)+" "+s2.intern().equals(s3.intern()));
What is the result?
Select 1 option(s):
true false true
true true true
false true false
true false false
false false false
None
Q28. Consider the following code:
class A
{
byte getStatusCode(Object obj) throws NullPointerException
{
if(obj != null ) return 128;
else return -1;
}
}
class B extends A
{
//override getStatusCode method.
}
Which of the following statements are valid?
Select 3 option(s):
Overriding method cannot throw IOException
Overriding method can throw Throwable
class A will not compile as it is.
Overriding method can throw any exception
Overriding method may choose not to throw any exception.
Q29. What letters will be printed by this program?
public class ForSwitch{
public static void main(String args[]){
char i;
LOOP: for (i=0;i<5;i++){
switch(i++){
case '0': System.out.println("A");
case 1: System.out.println("B"); break LOOP;
case 2: System.out.println("C"); break;
case 3: System.out.println("D"); break;
case 4: System.out.println("E");
case 'E' : System.out.println("F");
}
}
}
}
Select 2 option(s):
A
B
C
D
F
Q30. Which of the following are valid method implementations?
Select 2 option(s):
public void outputText(PrintWriter pw, String text){
try{
pw.write(text);
}catch(IOException e){
System.out.println("exception in writing");
}
}
public void outputText(PrintWriter pw, String text){
pw.write(text);
if(pw.checkError()) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
boolean flag = pw.write(text);
if(!flag) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
pw.printf(text).print("success");
}
public void outputText(PrintWriter pw, String text){
pw.println(text).println("success");
}
Q31. What will the following code print when run?
import java.nio.file.Path;
import java.nio.file.Paths;
public class PathTest {
static Path p1 = Paths.get("c:\\finance\\data\\reports\\daily\\pnl.txt");
public static void main(String[] args) {
System.out.println(p1.subpath(0, 2));
}
}
Select 1 option(s):
finance\data
finance\data\
\finance\data\reports
c:\finance\data
c:\finance
None
Q32. Given:
Path p = Paths.get("c:\\temp\\out");
try{
var b = Files.deleteIfExists(p);
System.out.println(b);
}catch(Exception e){
e.printStackTrace();
}
Identify correct statements.
Select 1 option(s):
It will print "c:\temp\out" if the file referred to by p is not deleted for any reason.
It will print an exception stack trace if p refers to a directory instead of a file.
It will print an exception stack trace if p refers to an empty file or a non-empty directory.
It will print an exception stack trace the file referred to by p does not exist.
It will print true if p refers to an empty directory.
None
Q33. What will the following code print when compiled and run?
List countries = List.of("US", "UK", "India", "Argentina");
List capitals = List.of("Washington DC", "London", "New Delhi" );
Stream is = IntStream
.range(0, Math.min(countries.size(), capitals.size()))
.mapToObj(i->countries.get(i)+" "+capitals.get(i));
is.forEach(System.out::println);
Select 1 option(s):
It will not compile.
It will throw an exception at run time.
It will not print anything.
US Washington DC
UK London
India New Delhi
US Washington DC
UK London
None
Q34. Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){ this.side = length; }
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
double getArea() { return area; }
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
}
}
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 2 option(s):
Make setSide() method private.
Make getArea() method private.
Make side and area fields private.
Make the side field private and remove the area field.
Change getArea method to:
public double getArea(){ return side*side; }
Add a setArea() method.
Q35. What will the following code print when compiled and run?
SequencedCollection als = new ArrayList(List.of("a", "b", "c"));
Set ss = new HashSet();
ss.addAll(als); //1
als.clear(); //2
System.out.println(ss.size());
Select 1 option(s):
It will throw an java.lang.UnsupportedOperationException at //1.
It will throw an java.lang.UnsupportedOperationException at //2.
0
3
None
Q36. Which of the changes given in options can be done (independent of each other) to let the following code compile and run without errors when its generateReport method is called?
class SomeClass{
String s1 = "green mile"; // 0
public void generateReport( int n ){
String local; // 1
if( n > 0 ) local = "good"; //2
System.out.println( s1+" = " + local ); //3
}
}
Select 2 option(s):
Replace String at //0 with var.
Insert after line 2 : if(n <= 0) local = "bad";
Move line 1 and place it after line 0.
change line 1 to : final String local = "rocky";
Insert after line 2 : else local = "bad";
The program already is without any errors.
Q37. Given:
public record Book (String title, String genre){}
and the following code:
List books = Arrays.asList(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
List genreList = new ArrayList();
//INSERT CODE HERE
System.out.println(genreList);
Which of the following options will correctly make genreList refer to a List containing the genres of the books present in books List?
Select 4 option(s):
books.stream().map(Book::genre).forEach(s->genreList.add(s));
genreList = books.stream().map(Book::genre).collect(Collectors.toList());
books.stream().map(Book::genre).collect(Collectors.toList(genreList));
books.stream().map(Book::genre).forEach(genreList::add);
books.stream().map(b->b.genre()).forEach(genreList::add);
books.stream().flatMap(b->b.genre()).forEach(g->genreList.add(g));
Q38. Given:
record Student (String name, Grade grade){
public static enum Grade{ A, B , C, D, F}
public String toString(){
return name+":"+grade;
}
}
What can be inserted in the code below so that it will print:
{C=[S3], A=[S1, S2]}
List ls = Arrays.asList( new Student("S1", Student.Grade.A),
new Student("S2", Student.Grade.A),
new Student("S3", Student.Grade.C));
//INSERT CODE HERE
System.out.println(grouping);
Select 1 option(s):
Map< Student.Grade, List< Student > > grouping = ls.stream().collect(
Collectors.groupingBy(Student::grade),
Collectors.groupingBy(Student::name, Collectors.toList())));
Map< Student.Grade, List< String > > grouping = ls.stream().collect(
Collectors.groupingBy(Student::grade,
Collectors.groupingBy(Student::name, Collectors.toList())));
Map< Student.Grade, List< String > > grouping = ls.stream().collect(
Collectors.groupingBy(Student::grade,
Collectors.mapping(Student::name, Collectors.toList())));
Map< Student.Grade, List< String > > grouping = ls.stream().collect(
Collectors.groupingBy(Student::grade,
Collectors.mapping(Student::name)));
None
Q39. What will the following class print when compiled and run?
class Holder{
int value = 1;
Holder link;
public Holder(int val){ this.value = val; }
public static void main(String[] args){
final var a = new Holder(5);
var b = new Holder(10);
a.link = b;
b.link = setIt(a, b);
System.out.println(a.link.value+" "+b.link.value);
}
public static Holder setIt(final Holder x, final Holder y){
x.link = y.link;
return x;
}
}
Select 1 option(s):
It will not compile because 'a' is final.
It will not compile because method setIt() cannot change x.link.
It will print 5, 10.
It will print 10, 10.
It will throw an exception when run.
None
Q40. Which of the following code snippet will print 10 random double values?
Select 3 option(s):
new Random().doubles(10).forEach(System.out::print);
Random r = new Random();
DoubleStream rDoubles = r.generate().limit(10);
rDoubles.forEach(System.out::print);
Random r = new Random();
DoubleStream rDoubles = r.doubles().limit(10);
rDoubles.forEach(System.out::print);
Random r = new Random();
DoubleStream.generate(()->r.nextDouble()).limit(10).forEach(System.out::print);
DoubleStream.generate(Random::nextDouble).limit(10).forEach(System.out::print);
Q41. What will the following code print when compiled and run?
public class Paper {
public String title;
public int id;
public Paper(String title, int id){
this.title = title;
this.id = id;
}
public static void main(String[] args) {
var papers = new Paper[]{
new Paper("T1", 1),
new Paper("T2", 2),
new Paper("T3", 3)
};
System.out.println(papers);
System.out.println(papers[1]);
System.out.println(papers[1].id);
}
}
Select 1 option(s):
papers
Paper
2
papers
T2,2
2
[LPaper;@< hashcode >
Paper
2
[LPaper;@< hashcode >
Paper@< hashcode >
2
It will not compile.
None
Q42. What will the following code print when compiled and run?
class Base{
void methodA(){
System.out.println("base - MethodA");
}
}
class Sub extends Base{
public void methodA(){
System.out.println("sub - MethodA");
}
public void methodB(){
System.out.println("sub - MethodB");
}
public static void main(String args[]){
Base b=new Sub(); //1
b.methodA(); //2
b.methodB(); //3
}
}
Select 1 option(s):
sub - MethodA and sub - MethodB
base - MethodA and sub - MethodB
Compile time error at //1
Compile time error at //2
Compile time error at //3
None
Q43. What will the following program print when compiled and run?
class Boo implements Serializable {
transient int ti = 10;
static int si = 20;
}
public class TestClass
{
public static void main(String[] args) throws Exception
{
Boo boo = new Boo();
boo.si++;
System.out.println(boo.ti+" "+boo.si);
var fos = new FileOutputStream("c:\\temp\\boo.ser");
var os = new ObjectOutputStream(fos);
os.writeObject(boo);
os.close();
var fis = new FileInputStream("c:\\temp\\boo.ser");
var is = new ObjectInputStream(fis);
boo = (Boo) is.readObject();
is.close();
System.out.println(boo.ti+" "+boo.si);
}
}
Select 1 option(s):
It will not compile.
It will throw an exception at run time.
10 21
10 21
10 21
10 20
10 21
0 20
10 21
0 21
None
Q44. Consider the following code.
LocalDate d = LocalDate.now();
Locale loc = new Locale("fr", "FR");
// 1 insert code here.
What should be inserted at //1 above so that it will print the date in French format?
Select 1 option(s):
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy", loc);
System.out.println(df.format(d));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d, loc));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
df.setLocale(loc);
System.out.println(df.format(d));
d.setLocale(loc);
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d));
None
Q45. What would be the result of compiling and running the following program?
class SomeClass{
public static void main(String args[]){
var size = 10;
var arr = new int[size];
for (var i = 0 ; i < size ; ++i) System.out.println(arr[i]);
}
}
Select 1 option(s):
The code will fail to compile, because the int[] array declaration is incorrect.
The program will compile, but will throw an IndexArrayOutOfBoundsException when run.
The program will compile and run without error, and will print nothing.
The program will compile and run without error and will print null ten times.
The program will compile and run without error and will print 0 ten times.
The code will fail to compile, because the array elements are being accessed without being initialized first.
None
Q46. Consider the following code appearing in the same file:
class Data {
int x = 0, y = 0;
public Data(int x, int y){
this.x = x; this.y = y;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d = new Data(1, 1);
//add code here
}
}
Which of the following options when applied individually will change the Data object currently referred to by the variable d to contain 2, 2 as values for its data fields?
Select 2 option(s):
Add the following two statements:
d.x = 2;
d.y = 2;
Add the following statement:
d = new Data(2, 2);
Add the following two statements:
d.x += 1;
d.y += 1;
Add the following statement:
d = d + 1;
Q47. Your application consists of two jar files produced by two different teams - accounting-3.2.jar and reporting-5.6.jar. Classes in reporting-5.6.jar uses classes from com.abc.accounts package in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.
The application is currently launched using the following command:
java -classpath accounting-3.2.jar;reporting-5.6.jar com.abc.reporting.Main
The accounting team has decided to modularize the new version of their jar but the reporting team hasn't.
Which of the following commands can be used to launch the reporting application using the new version of accounting jar?
Select 2 option(s):
java -classpath accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java -classpath reporting-5.6.jar --module-path accounting-3.3.jar; com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar
--add-modules accounting
--module reporting/com.abc.reporting.Main
(Assume that the module name in accounting-3.3.jar is accounting.)
Q48. Consider the following code snippet:
//INSERT LINE OF CODE HERE
switch( condition ){
case 1 -> System.out.println("1");
case 2 -> System.out.println("2");
case 3 -> System.out.println("3");
}
What type can be inserted in the code above so that the above code compiles and runs as expected ?
Select 2 option(s):
int condition;
long condition = 2;
var condition = Integer.valueOf("1");
String condition = "1";
var condition = Short.valueOf(1);
Byte condition = 1;
Q49. Given:
class InternalException extends RuntimeException {
public InternalException(String message) {
super (message);
}
}
class ExternalException extends Exception{
public ExternalException (String message) {
super (message);
}
}
class MicroService implements AutoCloseable{
private String name;
public MicroService(String name){
this.name = name;
System.out.println(name+" started");
}
public void availService(String name) {
if (!this.name.equals(name)) {
throw new InternalException ("Unknown service "+name);
}
}
@Override
public void close() throws ExternalException {
if (name.equals("X")) {
throw new ExternalException("Can't close X service");
}
System.out.println(name+" closed");
}
public static void main(String[] args) {
try(MicroService ms = new MicroService("X")){
ms.availService("test");
}
catch(InternalException|ExternalException e){
System.out.println(e);
for(Throwable t : e.getSuppressed()) System.out.println(t);
}
}
}
What will be the result?
Select 1 option(s):
X started
InternalException: Unknown service test
X started
ExternalException: Can't close X service
X started
InternalException: Unknown service test
ExternalException: Can't close X service
X started
ExternalException: Can't close X service
InternalException: Unknown service test
None
Q50. What will be the result of attempting to compile and run the following code?
public class InitClass{
public static void main(String args[ ] ){
InitClass obj = new InitClass(5);
}
int m;
static int i1 = 5;
static int i2 ;
int j = 100;
int x;
public InitClass(int m){
System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m);
}
{ j = 30; i2 = 40; } // Instance Initializer
static { i1++; } // Static Initializer
}
Select 1 option(s):
The code will fail to compile since the instance initializer tries to assign a value to a static member.
The code will fail to compile since the member variable x will be uninitialized when it is used.
The code will compile without error and will print 6 40 0 30 5 when run.
The code will compile without error and will print 5, 0, 0, 100, 5 when run.
The code will compile without error and will print 5, 40, 0, 30, 0 when run.
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