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 7 – 2025
Welcome to your Standard Test 7 - 2025
Name
Email
Phone
Q1. What will the following code print?
LocalDate ld = LocalDate.parse("2024-06-01");
LocalDateTime ldt1 = ld.atTime(LocalTime.of(10, 10));
LocalDateTime ldt2 = ldt1.plus(Period.ofDays(-1)).withHour(23);
if(ldt1.isAfter(ldt2) &! ldt1.getMonth().equals(ldt2.getMonth())){
System.out.println(ldt1.format(DateTimeFormatter.ofPattern("HHMM")));
}else{
System.out.println(ldt2.format(DateTimeFormatter.ofPattern("HHMM")));
}
Select 1 option(s):
1010
2310
1023
1006
An exception will be thrown at run time.
None
Q2. What will be printed when the following code is compiled and run?
class A {
public int getCode(){ return 2;}
}
class AA extends A {
public long getCode(){ return 3;}
}
public class TestClass {
public static void main(String[] args) throws Exception {
A a = new A();
A aa = new AA();
System.out.println(a.getCode()+" "+aa.getCode());
}
public int getCode() {
return 1;
}
}
Select 1 option(s):
2 3
2 2
It will throw an exception at run time.
The code will not compile.
None
Q3. What will the following expression return?
"""
hello java \
guru
""".strip();
Select 1 option(s):
The line of code will not compile.
"hellojavaguru"
"hello java guru"
"hello java guru "
None of the above
None
Q4. What will be the output of the following program?
class Data{
public volatile int d1 = 0;
public AtomicInteger d2 = new AtomicInteger(0);
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
Data data = new Data();
Runnable r1 = () -> {
Thread t1 = Thread.currentThread();
for(;data.d1<2;){
System.out.print(t1.getName()+" : "+data.d1+" ");
data.d1++;
}
};
Runnable r2 = () -> {
Thread t1 = Thread.currentThread();
for(;data.d2.get()<2;){
System.out.print(t1.getName()+" : "+data.d2.get()+" ");
data.d2.getAndIncrement();
}
};
Thread t1 = new Thread(r1, "T1");
Thread t2 = new Thread(r2, "T2");
t1.start();
t2.start();
}
}
Select 1 option(s):
T1 : 0 T2 : 0 T1 : 1 T2 : 1
Order is underministic.
T1 : 0 T1 : 1 T2 : 0 T2 : 1
or
T2 : 0 T2 : 1 T1 : 0 T1 : 1
T1 : 0 T2 : 0 T1 : 1 T2 : 1
It will not print anything.
None
Q5. Given :
//In Data.java
public class Data{
int value;
Data(int value){
this.value = value;
}
public String toString(){ return ""+value; }
}
and the following code fragments:
public void filterData(ArrayList
dataList, Predicate
p){
Iterator
i = dataList.iterator();
while(i.hasNext()){
if(p.test(i.next())){
i.remove();
}
}
}
....
ArrayList
al = new ArrayList
();
Data d = new Data(1); al.add(d);
d = new Data(2); al.add(d);
d = new Data(3); al.add(d);
//INSERT METHOD CALL HERE
System.out.println(al);
Which of the following options can be inserted above so that it will print [1, 3]?
Select 1 option(s):
filterData(al, d -> d.value%2 == 0 );
filterData(al, (Data x) -> x.value%2 == 0 );
filterData(al, (Data y) -> y.value%2 );
filterData(al, d -> return d.value%2 );
None
Q6. Consider the following program:
public class TestClass extends Thread
{
private static int threadcounter = 0;
public void run()
{
threadcounter++;
System.out.println(threadcounter);
}
public static void main(String[] args) throws Exception
{
for(int i=0; i<10; i++)
{
synchronized(TestClass.class)
{
new TestClass().start();
}
}
}
}
Which of the following is correct regarding the execution of the given program?
Select 2 option(s):
Numbers 1 to 10 will be printed (none repeated or missed) in a serial order.
Numbers 1 to 10 will be printed (none repeated or missed) in any order.
Total of 10 numbers will be printed
The final value of threadcounter just before the program terminates will be 10.
The final value of threadcounter just before the program terminates may be less than 10.
Q7. What should be the return type of the following method?
public RETURNTYPE methodX( byte by){
var d = 10.0;
return (long) by/d*3;
}
Select 1 option(s):
int
long
double
float
byte
None
Q8. What will be result of attempting to compile the following code appearing in TestClass.java file?
import java.util.*;
package test;
public class TestClass{
public OtherClass oc = new OtherClass();
}
class OtherClass{
int value;
}
Select 1 option(s):
TestClass will fail to compile because the class OtherClass is used before it is defined.
There is no problem with the code.
TestClass will fail to compile because the class OtherClass must be defined in a file called OtherClass.java
The code will fail to compile because the order of the package and import statements is incorrect.
The code will fail to compile because of other reason(s).
None
Q9. What will the following code print when compiled and run?
class X{
public X(){
System.out.println("In X");
}
}
class Y extends X{
public Y(){
super();
System.out.println("In Y");
}
}
class Z extends Y{
public Z(){
System.out.println("In Z");
}
}
public class Test {
public static void main(String[] args) {
Y y = new Z();
}
}
Select 1 option(s):
It will not compile.
In X
In Y
In Z
In Z
In Y
In X
In Y
In X
In Z
In Z
In X
In Y
None
Q10. Given:
class Person implements Serializable{
String name;
Person(String name){
this.name = name;
}
}
class Student extends Person{
String school;
public Student(String name, String school){
super(name);
this.school = school;
}
public String toString(){
return name+" "+school;
}
}
public class TestClass {
public static void main(String[] args) {
Person p = new Student("Bob Dylan", "NYU");
try(
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("student.ser"));
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream("student.ser"));
){
oos.writeObject(p);
oos.flush();
System.out.println((Student)ois.readObject());
}
}
}
What can be done so that the above code prints Bob Dylan NYU when run?
Select 1 option(s):
Add implements Serializable clause to Student class.
Add implements Serializable, AutoCloseable clause to Student class.
Add throws IOException clause to the main method.
Add throws IOException, ClassCastException clause to the main method.
Add throws IOException, ClassNotFoundException clause to the main method.
Replace (Student)ois.readObject() with (Person)ois.readObject().
None
Q11. Given:
interface AmazingInterface{
String value = "amazing";
void amazingMethod(String arg);
}
abstract class AmazingClass implements AmazingInterface{
static String value = "awesome";
abstract void amazingMethod(String arg1, String arg2);
}
public class Awesome extends AmazingClass implements AmazingInterface {
public void amazingMethod(String arg1){ }
public void amazingMethod(String arg1, String arg2){ }
public static void main(String[] args){
AmazingInterface ai = new Awesome();
//INSERT CODE HERE
}
}
Identify the options that will cause compilation failure.
Select 3 option(s):
ai.amazingMethod(AmazingInterface.value, AmazingClass.value);
ai.amazingMethod(AmazingInterface.value);
((AmazingClass)ai).amazingMethod("x1", value);
ai.amazingMethod(value);
ai.amazingMethod("x1");
Q12. What will be the output of the following code:
SequencedCollection s1 = new ArrayList( );
s1.addFirst("a");
s1.addFirst("b");
s1.addLast("c");
s1.add("a");
System.out.println(s1.removeFirst()+" "+s1.remove("a")+" "+s1.remove("x"));
Select 1 option(s):
b true false
a true false
a a < exception stack trace >
a false false
true true false
None
Q13. Given:
public class Book{
String isbn;
String title;
public Book(String isbn, String title){
this.isbn = isbn;
this.title = title;
}
public int compareTo(Book b){
return this.isbn.compareTo(b.isbn);
}
//accessors not shown
}
and the following code snippet:
List books = getBooksByAuthor("Ludlum");
Collections.sort(books, (b1, b2)->b1.getTitle().compareTo(b2.getTitle())); //1
Collections.sort(books); //2
Assuming that getBooksByAuthor is a valid method that returns a List of Books, which of the following statements is/are true?
Select 1 option(s):
Compilation failure at //1.
Compilation failure at //2.
Exception at run time because of //1.
Exception at run time because of //2.
Elements in books List will be sorted by title and then by isbn.
None
Q14. Given:
sealed interface Building permits Hospital, Hotel{}
record Hospital(int beds) implements Building{};
record Hotel(int rooms) implements Building{};
public class TestClass {
static Building getBuilding(){
return Math.random()>.05?new Hotel(10): new Hospital(20);
}
public static void main(String[] args) {
Building b = getBuilding();
}
public static void printDetails(Building b){
if(b instanceof Hotel ht){
System.out.println("Hotel has "+ht.rooms()+" rooms");
}else if(b instanceof Hospital hp){
System.out.println("Hospital has "+hp.beds()+" beds");
}
else{
System.out.println("Building not recognized.");
}
}
}
Which of the following code snippets correctly implement the logic contained within the printDetails method?
Select 1 option(s):
return switch(b){
case Hotel(var x) : "Hotel has "+x+" rooms";
case Hospital(var x) : "Hospital has "+x+" beds";
default : "Building not recognized.";
};
return switch(b){
case Hotel(var x) : "Hotel has "+x+" rooms"; break;
case Hospital(var x) : "Hospital has "+x+" beds"; break;
default : "Building not recognized.";
};
return switch(b){
case Hotel(var x) -> "Hotel has "+x+" rooms";
case Hospital(var x) -> "Hospital has "+x+" beds";
default -> "Building not recognized.";
};
String str =
switch(b){
case Hotel(var x) :{ yield "Hotel has "+x+" rooms"; }
case Hospital(var x) : { yield "Hospital has "+x+" beds"; }
case null -> "Building not recognized.";
};
return str;
return switch(b){
case Hotel(var x) -> "Hotel has "+x+" rooms";
case Hospital(var x) -> "Hospital has "+x+" beds";
case null -> "Building not recognized.";
};
None
Q15. Which statements about the following code are correct?
interface House{
public default String getAddress(){
return "101 Main Str";
}
}
interface Bungalow extends House{
public default String getAddress(){
return "101 Smart Str";
}
}
class MyHouse implements Bungalow, House{
}
public class TestClass {
public static void main(String[] args) {
House ci = new MyHouse(); //1
System.out.println(ci.getAddress()); //2
}
}
Select 1 option(s):
Code for interface House will cause compilation to fail.
Code for interface Bungalow will cause compilation to fail.
Code for class MyHouse will cause compilation to fail.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
The code will compile successfully.
None
Q16. What will be written to the standard output when the following program is run?
Select 1 option(s):
25
24
23
22
None of the above.
None
Q17. Given:
char a = 'a', b = 98; //1
int a1 = a; //2
int b1 = (int) b; //3
System.out.println((char)a1+(char)b1); //4
What is the output?
Select 1 option(s):
Compilation error at //1
Compilation error at //2
Compilation error at //3
Compilation error at //4
ab
195
None
Q18. What will be the output of the following lines ?
System.out.println("" +5 + 6); //1
System.out.println(5 + "" +6); // 2
System.out.println(5 + 6 +""); // 3
System.out.println(5 + 6); // 4
Select 1 option(s):
56
56
11
11
11
56
11
11
56
56
56
11
56
56
56
56
56
56
11
56
None
Q19. Which of the following are valid implementations of java.util.Comparator?
Select 3 option(s):
Comparator< Integer > cin = new Comparator< Integer >(){
public int compareTo(Integer i1, Integer i2){
return i1 - i2;
}
};
var cin = new Comparator< Integer >(){
public int compare(Integer i1, Integer i2){
return i1 - i2;
}
};
var cin = new Comparator< Integer >(){
public int compareTo(Integer i1, Integer i2){
return i1 - i2;
}
};
Comparator< Integer > cin = (i1, i2)-> i1-i2;
Comparator< Integer > cin = new Comparator< ? >(){
public int compare(Integer i1, Integer i2){
return i1 - i2;
}
};
var cin = new Comparator< Integer >(){
public int compare(Integer i1, Integer i2){
return i1.compareTo(i2);
}
};
Q20.Given:
class MyProcessor{
public void process(){
System.out.println("Processing ");
}
}
public class TestClass {
public static void main(String[] args) {
process(()->new MyProcessor()); //1 REPLACE THIS LINE OF CODE
}
public static void process(Supplier s){
s.get().process();
}
}
Which of the following options correctly replaces the line marked //1 with code that uses method reference?
Select 1 option(s):
TestClass.process(MyProcessor::new);
TestClass.process(new::MyProcessor);
TestClass.process(MyProcessor::new());
TestClass.process(new::MyProcessor());
TestClass.process(MyProcessor()::new);
None
Q21. Consider the following class...
class Test{
public static void main(String[ ] args){
var a = new int[]{ 1, 2, 3, 4 };
int[] b = { 2, 3, 1, 0 };
System.out.println( a [ (a = b)[3] ] );
}
}
What will it print when compiled and run ?
Select 1 option(s):
It will not compile.
It will throw ArrayIndexOutOfBoundsException when run.
It will print 1.
It will print 3.
It will print 4
None
Q22. What is the effect of compiling and running the code shown below?
public class TestClass{
public static void main (String args []){
var sum = 0;
for (int i = 0, j = 10; sum > 20; ++i, --j) // 1
{
sum = sum+ i + j;
}
System.out.println("Sum = " + sum);
}
}
Select 1 option(s):
Compile time error at line 1.
It will print Sum = 0
It will print Sum = 20
Runtime error.
None of the above.
None
Q23. Consider:
public class Outer
{
int i = 10;
class Inner
{
public void methodA()
{
//line 1.
}
}
}
Which of the following statements are valid at line 1?
Select 2 option(s):
System.out.println(this.i);
System.out.println(i);
System.out.println(Outer.this.i);
'i' cannot be accessed inside the inner class method.
The code cannot be compiled.
Q24. A novice java programmer is unable to get a file named Coffee.java compiled. It contains the following enum definition:
public enum Coffee //1
{
ESPRESSO("Very Strong"), MOCHA, LATTE; //2
public String strength; //3
Coffee(String strength) //4
{
this.strength = strength; //5
}
public String toString(){ return strength + ordinal(); } //6
}
Which line is causing the problem?
Select 1 option(s):
1
2
3
4
5
6
None
Q25. You are trying to modularize an existing application that uses a few Apache open source jar files. Some of those jar files have been modularized but some have not. Details of such jar files are as follows:
commons-beanutils-1.9.jar
commons-collections4-4.0.jar
(Automatic-Module-Name: org.apache.commons.collections4)
commons-lang3-3.6.jar
(Automatic-Module-Name: org.apache.commons.lang3)
commons-text-1.2.jar
(Automatic-Module-Name: org.apache.commons.text)
What should the module-info file for your application contain?
Select 1 option(s):
module myapp{
requires commons.beanutils-1.9;
requires commons.collections4-4.0;
requires commons.lang3-3.6;
requires commons.text-1.2;
}
module myapp{
requires org.apache.commons.beanutils;
requires org.apache.commons.collections4;
requires org.apache.commons.lang3;
requires org.apache.commons.text;
}
module myapp {
requires commons.beanutils;
requires commons.collections4;
requires commons.lang3;
requires commons.text;
}
module myapp{
requires commons.beanutils;
requires org.apache.commons.collections4;
requires org.apache.commons.lang3;
requires org.apache.commons.text;
}
None
Q26. Given:
String s1 = "Hello World";
String s2 = """
Hello World""";
System.out.println((s1 == s2)+" "+s1.equals(s2));
What is the result?
Select 1 option(s):
true true
true false
false false
false true
None
Q27. Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 3 option(s):
public List< ? extends Integer > getList(){
public List< ? super Number > getList(){
public List< ? extends Number > getList(){
public ArrayList< ? extends Integer > getList(){
public ArrayList< Number > getList(){
public ArrayList< Integer > getList(){
Q28. Which of the lines will cause a compile time error in the following program?
public class MyClass{
public static void main(String args[]){
char c;
int i;
c = 'a';//1
i = c; //2
i++; //3
c = i; //4
c++; //5
}
}
Select 1 option(s):
line 1
line 2
line 3
line 4
line 5
None
Q29. Which of the following is/are a valid functional interface(s)?
Select 3 option(s):
@FunctionalInterface
public interface FI{
int m1();
boolean equals(Object o);
}
@FunctionalInterface
public interface FI{
String toString = "VALUE";
int m1();
String m2(String s);
}
public interface FI{
int m1();
String toString();
}
@FunctionalInterface
public interface FI{
int m1();
default int m2(){ return 10; }
String toString();
}
@FunctionalInterface
public interface FI{
String toString = "VALUE";
boolean equals(Object o);
}
@FunctionalInterface
public interface FI{
String toString();
}
Q30. What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.add(1);
d.push(2);
d.pop();
d.offerFirst(3);
d.remove();
System.out.println(d);
Select 1 option(s):
1
2
3
Exception at run time.
It will not compile.
None
Q31. Identify correct statement(s) about the following code:
public class FunWithOptional{
public static String getValue(){
return null;
}
public static void main(String[] args) {
Optional stro = Optional.of(getValue());//1
System.out.println(stro.isPresent());//2
System.out.println(stro.get());//3
System.out.println(stro.orElse(null));//4
}
}
Select 1 option(s):
It will throw a NullPointerException at //1
It will throw a NullPointerException at //3
It will throw a NoSuchElementException at //3
It will throw a NullPointerException at //4
It will print:
false
null
null
None
Q32. Given that the file test.txt contains :
12345678
What will the following code print when compiled and run?
public static void main(String[] args) throws Exception{
try(var fis = new FileInputStream("c:\\temp\\test.txt");
var isr = new InputStreamReader(fis)){
while(isr.ready()){
isr.skip(1);
int i = isr.read();
char c = (char) i;
System.out.print(c);
}
}
}
Select 1 option(s):
It will not compile.
It will throw an exeception when run.
It will print just 2
It will run without any exception but will not print anything.
It will print 2468
None
Q33. Given the following contents of module-info.java,
module enthu.finance{
exports com.enthu.Reports;
requires enthu.utils;
}
Select correct statements.
Select 1 option(s):
Module name is finance.
com.enthu.Reports is the name of the class that this module exports.
This module depends on enthu.utils package.
This file must be present in enthu.finance directory if the source code is to be compiled using the --module-source-path option.
Other modules that depend on this module will be able to access com.enthu.Reports package as well as enthu.utils package.
None
Q34. Consider the following class :
class Test{
public static void main(String[] args){
for (var i = 0; i < 10; i++) System.out.print(i + " "); //1
for (var i = 10; i > 0; i--) System.out.print(i + " "); //2
var i = 20; //3
System.out.print(i + " "); //4
}
}
Which of the following statements are true?
Select 4 option(s):
As such, the class will compile and print "20 " (without quotes) at the end of its output.
It will not compile if line 3 is removed.
It will not compile if line 3 is removed and placed before line 1.
It will not compile if line 4 is removed and placed before line 3.
Only Option 2, 3, and 4 are correct.
Q35. Given the following method:
public static void copy(String fileName1, String fileName2) throws Exception{
try (
InputStream is = new FileInputStream(fileName1);
OutputStream os = new FileOutputStream(fileName2); ) {
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
System.out.println("Read and written bytes " + bytesRead);
}
}
}
What will happen fileName1 contains only 100 bytes and fileName2 contains 200 bytes?
Select 1 option(s):
An exception will be thrown while reading from the file.
An exception will be thrown while writing to the file.
fileName2 will end up with 300 bytes.
fileName2 will end up with 200 bytes.
fileName2 will end up with 100 bytes.
None
Q36. Given:
interface Instrument{
default void reset(){
System.out.println("In Instrument");
}
}
class Debt implements Instrument{
}
class Bond extends Debt{
public void reset(){
super.reset();
System.out.println("In Bond");
}
}
class ZCBond extends Bond{
ZCBond(){
reset();
}
public void reset(){
super.reset();
System.out.println("In ZCBond");
}
public static void main(String args[]){
Instrument i = new ZCBond();
}
}
What is the output?
Select 1 option(s):
The Bond class will fail to compile.
The Debt class will fail to compile.
In Instrument
In Bond
In ZCBond
In ZCBond
In Bond
In Instrument
In Bond
In ZCBond
In ZCBond
In Bond
None
Q37. Given the following code:
public class Valuator {
public AtomicInteger status = new AtomicInteger(0);
public void valuate() {
int oldstatus = status.get();
/* valid code here */
int newstatus = //determine new status
//INSERT CODE HERE
}
}
Assuming that an instance of this class is shared among multiple threads, you want to update the status to newstatus only if the oldstatus has not changed. Which of the following lines of code will you use?
Select 1 option(s):
status.compareAndSet(oldstatus, newstatus);
status.compareAndSet(newstatus, oldstatus);
status.setIfUnchanged(oldstatus, newstatus);
status.setIfUnchanged(newstatus, oldstatus);
if(oldstatus == status.get()) status.set(newstatus);
None
Q38. Assume that the following directory exists:
c:\a\b\c
A File object is created as follows:
var f = new File("c:\\a\\b\\c\\d\\e");
Given that directories d and e do not exist under c, which of the following statements are correct?
Select 2 option(s):
The given line of code will throw an exception at run time.
f.mkdir (); will create directory d under c and directory e under d.
f.mkdirs (); will create directory d under c and directory e under d.
f.getParentFile () will return a File Object representing c:\a\b\c\d
None of these.
Q39. Consider the following class :
public class Parser{
public static void main( String[] args){
try{
int i = 0;
i = Integer.parseInt( args[0] );
}
catch(NumberFormatException e){
System.out.println("Problem in " + i );
}
}
}
What will happen if it is run with the following command line:
java Parser 1_00
Select 1 option(s):
It will print Problem in 0
It will throw an exception and end without printing anything.
It will not even compile.
It will not print anything if the argument is 100 instead of 1_00.
None of the above.
None
Q40. 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:\\main\\project\\Starter.java");
public static String getRoot(){
String root = p1.getRoot().toString();
return root;
}
public static void main(String[] args) {
System.out.println(getRoot());
}
}
Select 1 option(s):
\
c:
c:\
It will print an empty string.
None
Q41. Which of the following declarations are valid?
Select 4 option(s):
float f1 = 1.0;
float f = 43e1;
float f = -1;
float f = 0x0123;
float f = 4;
var f1 = 1.0;
float f2 = f1;
var f = 4f;
void m(float x){
var x = 20;
}
Q42. Given:
class Base{
public Collection transform(Collection list)
{
return new ArrayList();
}
}
class Derived extends Base{
/* public Collection transform(Collection list) {
return new HashSet();
}; */ //1
/* public Collection transform(Stream list) {
return new HashSet();
}; */ //2
/* public List transform(Collection list) {
return new ArrayList();
}; */ //3
/*public Collection transform(Collection list) {
return new HashSet();
}; */ //4
/* public Collection transform(Collection list) {
return new HashSet();
}; */ //5
}
Identify correct statements about the methods defined in Derived assuming they are uncommented one at a time individually.
Select 2 option(s):
//1 correctly overrides the method in Base
//1 will cause compilation failure.
//2 correctly overrides the method in Base
//3 correctly overrides the method in Base
//4 will cause compilation failure.
//5 correctly overrides the method in Base
//5 correctly overloads the method in Base
Q43. Consider the following class:
class TestClass{
void probe(int... x) { System.out.println("In ..."); } //1
void probe(Integer x) { System.out.println("In Integer"); } //2
void probe(long x) { System.out.println("In long"); } //3
void probe(Long x) { System.out.println("In LONG"); } //4
public static void main(String[] args){
Integer a = 4; new TestClass().probe(a); //5
int b = 4; new TestClass().probe(b); //6
}
}
What will it print when compiled and run?
Select 2 option(s):
In Integer and In long
In ... and In LONG, if //2 and //3 are commented out.
In Integer and In ..., if //4 is commented out.
It will not compile, if //1, //2, and //3 are commented out.
In LONG and In long, if //1 and //2 are commented out.
Q44. Which of the options will create and initialize a matrix of ints as shown below?
1
1
1
1
1
Select 1 option(s):
int[][] matrix = new int[5][4];
for(int i=1;i<=5; i++) matrix[i][1] = 1;
int[][] matrix = new int[5][4];
for(var i=0;i<5; i++) matrix[i][1] = 1;
int[][] matrix = new int[4][5];
for(var i=1;i<=5; i++) matrix[i][1] = 1;
int[][] matrix = new int[5][4];
for(var i=1;i<=5; i++) matrix[i][2] = 1;
None
Q45. What will the following code print when compiled and run?
Select 1 option(s):
Input value must be smaller than X and larger than 0
Input value must be smaller than 10 and larger than 0
Input value must be smaller than X
Input value must be smaller than 10
None
Q46. What will the following code print?
int i = 0;
int j = 1;
if( (i++ == 0) & (j++ == 2) ){
i = 12;
}
System.out.println(i+" "+j);
Select 1 option(s):
1 2
2 3
12 2
12 1
It will not compile.
None
Q47. Identify the correct statement(s).
Select 2 option(s):
To customize the behavior of class serialization, the readObject and writeObject methods should be implemented.
To customize the behavior of class serialization, the defaultReadObject and defaultWriteObject methods should be overridden.
Objects of a final class cannot be serialized.
Constructor of the class for an object being deserialized is never invoked except for record classes.
While serializing an object, only those objects in the object graph that implement Serializable are serialized and the rest are ignored.
Q48. Given:
public class Buddy {
Buddy upper;
String name;
public Buddy(){ }
public Buddy(String name){
this.name = name;
}
public Buddy(String name, Buddy upper){
this.name = name;
Buddy b = new Buddy(upper.name);//1
upper = b; //2
}
public static void main(String[] args) {
Buddy b1 = new Buddy("A"); //3
Buddy b2 = new Buddy("B", b1); //4
System.out.println(b1); //5
}
}
Identify correct statements.
Select 2 option(s):
Object created at line //1 will be eligible for garbage collection after line //2.
Object created at line //1 will be eligible for garbage collection after line //5.
Object created at line //3 will be eligible for garbage collection after line //4.
Object created at line //3 will be eligible for garbage collection only after line //5.
Q49. Which of the given options if put at //1 will correctly instantiate objects of various classes defined in the following code?
public class TestClass
{
public class A{
}
public static class B {
}
public static void main(String args[]){
class C{
}
//1
}
}
Select 2 option(s):
new TestClass().new A();
new TestClass().new B();
new TestClass.A();
new C();
new TestClass.C();
Q50. What will the following code print when compiled and run?
var numA = new Integer[]{1, 2};
var list1 = new ArrayList(List.of(numA));
list1.add(null);
var list2 = Collections.unmodifiableList(list1);
list1.set(2, 3);
List<List> list3 = List.of(list1, list2);
System.out.println(list3);
Select 1 option(s):
[[1, 2, 3], [1, 2, 3]]
[1, 2, 3]
[[1, 2, 3], [1, 2, null]]
[1, 2, null]
[1, 2, 3, null]
It will throw an exception at run time.
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