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
Blog
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
Blog
Welcome to your Standard Java Test - 1
Name
Email
Phone
1.
Question: Consider the following code:
interface Flyer{ String getName(); }
class Bird implements Flyer{
public String name;
public Bird(String name){
this.name = name;
}
public String getName(){ return name; }
}
class Eagle extends Bird {
public Eagle(String name){
super(name);
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Flyer f = new Eagle("American Bald Eagle");
//PRINT NAME HERE
}
}
Which of the following lines of code will print the name of the Eagle object?
Select 3 option(s)
System.out.println(f.name);
System.out.println(f.getName());
System.out.println(((Eagle)f).name);
System.out.println(((Bird)f).getName());
System.out.println(Eagle.name);
System.out.println(Eagle.getName(f));
2.
Question: 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 = //code to create the list goes here
Comparator c1 = (b1, b2)->b1.getGenre().compareTo(b2.getGenre()); //1
books.stream().sorted(c1.thenComparing(Book::getTitle)); //2
System.out.println(books);
Identify the correct statements.
Select 1 option(s)
It will print the list that is sorted by genre and then sorted by title within.
It will print the list that is sorted by title and then sorted by genre within.
It will print the list as it is.
Code will fail to compile because of code at //1.
Code will fail to compile because of code at //2.
None
3.
Question: What will be the result of attempting to compile and run the following class?
public class TestClass{
public static void main(String args[ ] ){
int i, j, k;
i = j = k = 9;
System.out.println(i);
}
}
Select 2 option(s)
The code will not compile because unlike in c++, operator '=' cannot be chained i.e. a = b = c = d is invalid.
The code will not compile as 'j' is being used before getting initialized.
The code will compile correctly and will display '9' when run.
The code will not compile as 'j' and 'i' are being used before getting initialized.
All the variables will get a value of 9.
4.
Question: Given the following method code appearing in an application that manages files on a server machine:
List dir; //initialize dir somehow
public List executeFunction(Function fun){
List l = new ArrayList();
for(File f : dir){
l.add(fun.apply(f));
}
return l;
}
The caller of this method passes in a Function that takes a java.io.File object and performs whatever operation is need to be done on that file. It is required that the above code must ensure that the caller only reads a file and is not able to overwrite or delete it irrespective of what level of permission the caller has. How can this be done?
Select 1 option(s)
Change the code inside the for loop as follows:
AccessController.doPrivileged(new PrivilegedAction
Void
() {
public Void run() {
l.add(fun.apply(f));
return null;
}}
);
Change the code inside the for loop as follows: Â Â Â Â
Permission perm = new java.io.FilePermission(f.getPath(), "read");
    PermissionCollection perms = perm.newPermissionCollection();
    perms.add(perm);          Â
AccessController.doPrivileged(new PrivilegedAction
Void
() { Â Â Â Â Â Â Â
 public Void run() {           Â
 l.add(fun.apply(f));           Â
 return null;     Â
   }},        Â
new AccessControlContext( Â Â Â Â Â Â Â Â Â Â Â
 new ProtectionDomain[] {               Â
 new ProtectionDomain(null, perms)         Â
   }   Â
     )  Â
  );
Change the code inside the for loop as follows: Â Â
  Permission perm = new java.io.FilePermission(f.getPath(), "read");
    AccessController.checkPermission(perm);    Â
    AccessController.doPrivileged(new PrivilegedAction
Void
() { Â Â Â Â
    public Void run() {        Â
    l.add(fun.apply(f));        Â
    return null;      Â
  }}   Â
 );
No code change is required. Modify the policy file to have only read permission to the given files.
None
5.
Question: What exception will be thrown out of the main method when the following program is run?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public void open() throws IOException{
header = "OPENED";
System.out.println("Device Opened");
throw new IOException("Unknown");
}
public String read() throws IOException{
return "";
}
public void close(){
System.out.println("Closing device");
header = null;
throw new RuntimeException("rte");
}
public static void main(String[] args) throws Exception {
try(Device d = new Device()){
throw new Exception("test");
}
}
}
Select 1 option(s)
java.lang.Exception
java.lang.RuntimeException
java.io.IOException
The given code will not compile.
None
6.
Question: What will the following code print when run?
import java.io.Reader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class MarkTest {
public static void main(String[] args) {
try (Reader r = new BufferedReader(new FileReader("c:\\temp\\test.txt"))) {
if (r.markSupported()) {
BufferedReader in = (BufferedReader) r;
System.out.print(in.readLine());
in.mark(100);
System.out.print(in.readLine());
System.out.print(in.readLine());
in.reset();
System.out.print(in.readLine());
in.reset();
System.out.println(in.readLine());
}else{
System.out.println("Mark Not Supported");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Assume that the file test.txt contains:
A
B
C
D
E
Select 1 option(s)
Mark Not Supported
ABCB
<exception stack trace>
ABC
<exception stack trace>
ABCBB
ABCBD
None
7.
Question: What changes can be made to the following code so that it will print:
Old Rating A
New Rating R
List ratings = Arrays.asList('U', 'R', 'A');
ratings.stream()
.filter(x->x=='A') //1
.peek(x->System.out.println("Old Rating "+x)) //2
.map(x->x=='A'?'R':x) //3
.peek(x->System.out.println("New Rating "+x)); //4
Select 1 option(s)
None
8.
Question: Consider the following code:
public class SubClass extends SuperClass{
int i, j, k;
public SubClass( int m, int n ) { i = m ; j = m ; } //1
public SubClass( int m ) { super(m ); } //2
}
Which of the following constructors MUST exist in SuperClass for SubClass to compile correctly?
Select 2 option(s)
It is ok even if no explicit constructor is defined in SuperClass.
public SuperClass(int a, int b)
public SuperClass(int a)
public SuperClass()
only public SuperClass(int a) is required.
9.
Question: Given:
//Insert code here
public abstract void draw();
}
//Insert code here
public void draw(){ System.out.println("in draw..."); }
}
Which of the following lines of code can be used to complete the above code?
Select 2 option(s)
class Shape {
and
class Circle extends Shape {
public class Shape {
and
class Circle extends Shape {
abstract Shape {
and
public class Circle extends Shape {
public abstract class Shape {
and
class Circle extends Shape {
@Override
public abstract class Shape {
and
class Circle implements Shape {
public interface Shape {
and
class Circle implements Shape {
@Override
10.
Question: Which of the following expressions can be used to implement a Function ?
Select 3 option(s)
(a)-> Integer.toHexString(a)
a -> Integer::toHexString
Integer::toHexString
i::toHexString
toHexString
val -> val + 1
(Integer a)-> Integer.toHexString(a)
Integer a-> Integer.toHexString(a)
11.
Question: 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
12.
Question: 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)
None
13.
Question: Which of the following code fragments correctly loads a service provider that implements api.BloggerService?
Select 1 option(s)
Iterable
api.BloggerService
bsLoader = ServiceLoader.load(api.BloggerService.class);
Remember that java.util.ServiceLoader implements java.util.Iterable.
api.BloggerService bloggerServiceRef =
ServiceLoader.load(api.BloggerService.class);
api.BloggerService bloggerServiceRef =
ServiceLoader<api.BloggerService>.load(api.BloggerService.class);
ServiceLoader<api.BloggerService> bsLoader = new ServiceLoader<>(api.BloggerService.class);
api.BloggerService bloggerServiceRef =
java.util.service.Provider.getProvider(api.BloggerService.class);
None
14.
Question: Identify the right declaration for 'box' for the following code.
import java.util.*;
class Dumper {
// declaration for box
public void dumpStuff(){
for(List l : box.values()){
System.out.println(l);
}
}
}
Select 2 option(s)
15.
Question: 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
16.
Question: Consider the following classes:
interface I{
}
class A implements I{
}
class B extends A {
}
class C extends B{
}
And the following declarations:
A a = new A();
B b = new B();
Identify options that will compile and run without error.
Select 1 option(s)
a = (B)(I)b;
b = (B)(I) a;
a = (I) b;
I i = (C) a;
None
17.
Question: Given:
ConcurrentMap cache = new ConcurrentHashMap();
cache.put("111", student1);
(Assume that student1 and student2 are references to a valid objects.)
Which of the following statements are legal but will NOT modify the Map referenced by cache?
Select 1 option(s)
cache.put("111", student2);
cache.putIfAbsent("111", student2);
cache.checkAndPut("111", student2);
cache.putIfNotLocked("111", student2);
None
18.
Question: What will the following code print when run?
public class TestClass{
public static Integer wiggler(Integer x){
Integer y = x + 10;
x++;
System.out.println(x);
return y;
}
public static void main(String[] args){
Integer dataWrapper = new Integer(5);
Integer value = wiggler(dataWrapper);
System.out.println(dataWrapper+value);
}
}
Select 1 option(s)
5 and 20
6 and 515
6 and 20
6 and 615
It will not compile.
None
19.
Question: Which of the following code snippets appearing in a method are valid.
Select 1 option(s)
for(var x : System.getProperties().entrySet()){
var m = x.getKey();
}
for(var x : System.getProperties().keySet()){
System.out.println(x.length());
}
var obj = null;
var k = System.out::println;
var _ = new ArrayList<>();
var _ = 10;
None
20.
Question: Which of the following statements are correct regarding the module system of Java.
Select 1 option(s)
A module can access all public classes of another module.
A module can access all public classes of another module if it declares that it requires the other module.
A module can access all public classes of another module if those classes are exported by the other module.
A module can access public classes of only those packages of another module that the other module exports.
A module can access another module if both are in the same folder.
None
21.
Question: Given:
module foo.filter{
requires api;
provides api.Filter with foo.DoNothingFilter;
}
Assuming that api.Filter is an interface with just a single method List filter(List l), which of the following is a valid implementation of foo.DoNothingFilter class?
Answered Incorrectly
Select 1 option(s)
package foo;
import api.*;
import java.util.*;
public class DoNothingFilter{
public List<String> filter(List<String> l) { return l; }
}
package foo;
import api.*;
import java.util.*;
public class DoNothingFilter implements Filter{
public DoNothingFilter(int a){ }
public List
String
filter(List
String
l) { return l; }
}
package foo;
import api.*;
import java.util.*;
public class DoNothingFilter {
public DoNothingFilter(int a){ }
public static Filter provider(){
return new Filter(){
public List
String
filter(List
String
l) { return l; }
};
}
}
package foo;
import api.*;
import java.util.*;
public class DoNothingFilter implements Filter {
public DoNothingFilter(){ }
public static Filter provider(){
return new Filter(){
public List<String> filter(List<String> l) { return l; }
};
}
}
None
22.
Question: What will the following code print?
public class BreakTest{
public static void main(String[] args){
int i = 0, j = 5;
lab1 : for( ; ; i++){
for( ; ; --j) if( i >j ) break lab1;
}
System.out.println(" i = "+i+", j = "+j);
}
}
Select 1 option(s)
i = 1, j = -1
i = 1, j = 4
i = 0, j = 4
i = 0, j = -1
It will not compile.
None
23.
Question: Given that your module named foo.bar contains the following two source files: src/foo.bar/f/b/Baz1.java and src/foo.bar/f/c/Caz1.java.
Which of the following options can be used to compile this module?
(Assume that all directory paths are relative to the current directory.)
Select 1 option(s)
javac --module-source-path src src/*/*.java
javac --module-source-path src -d out src/foo.bar/*/*.java
javac --module-source-path src -d out src/foo.bar
javac --module-source-path src -d out --module foo.bar
javac --module-source-path src -module foo.bar
None
24.
Question: What will the following code print when compiled and run?
int [] [] array = {{0}, {0, 1}, {0, 1, 2}, {0, 1, 2, 3}, {0, 1, 2, 3, 4}};
var arr1 = array[4];
System.out.println (arr1[4][1]);
System.out.println (array[4][1]);
Select 1 option(s)
1
1
1
4
4
1
It will not compile.
It will throw ArrayIndexOutOfBoundsException at run time.
It will throw IllegalArgumentException at run time.
None
25.
Question: 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
26.
Question: What will the following code print?
AtomicInteger ai = new AtomicInteger();
Stream stream = Stream.of("old", "king", "cole", "was", "a", "merry", "old", "soul").parallel();
stream.filter( e->{
ai.incrementAndGet();
return e.contains("o");
}).allMatch(x->x.indexOf("o")>0);
System.out.println("AI = "+ai);
Select 1 option(s)
Any number between 1 to 8.
Any number between 0 to 7.
Any number between 1 to 6.
8
4
None
27.
Question: What will the following code fragment print when compiled and run?
Statement stmt = null;
Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
try(stmt = c.createStatement();)
{
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
System.out.println(rs.getString(0));
}
}
catch(SQLException e){
System.out.println("Exception ");
}
(Assume that items not specified such as import statements and try/catch block are all valid.)
Select 1 option(s)
It will throw an exception if the first column of the result is not a String.
It will throw an exception every time it is run irrespective of what the query returns.
It will print the values for the first column of the result and if there is no row in STUDENT table, it will not print anything.
It will not compile.
None
28.
Question: You are the maintainer of a library packaged as bondanalytics.jar, which is used by several groups in your company. It has the following two packages that are used by other applications:
com.abc.bonds
com.abc.bonds.analytics
You want to modularize this jar with least impact to others. What will you do?
Select 1 option(s)
Split the jar into two modules - one exporting com.abc.bonds package and another exporting com.abc.bonds.analytics package.
Just add module-info to the jar with export clauses for both the packages.
Just add an empty module-info.java to the jar.
It cannot be modularized without impacting existing non-modular applications that use it.
None
29.
Question: 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
30.
Question: Given the following module-info:
module book{
requires org.pdf;
uses org.pdf.Print;
}
Which of the following statements are correct?
Select 3 option(s)
The module that defines Print service must be present on --module-source-path for book module to compile.
The module that defines Print service must be present on --module-path for book module to compile.
The module that defines Print service must be present on --module-path for book module to execute.
Exactly one module that provides Print service must be present on --module-path for book module to execute.
A module that defines Print service may be added later without requiring book module to recompile.
An implementation of org.pdf.Print can be added to the book module.
31.
Question: What is the result of executing the following fragment of code:
boolean b1 = false;
int i1 = 2;
int i2 = 3;
if (b1 = i1 == i2){
System.out.println("true");
} else{
System.out.println("false");
}
Select 1 option(s)
Compile time error.
It will print true.
It will print false.
Runtime error.
It will print nothing.
None
32.
Question: What will the following code print when run?
import java.util.function.*;
class Employee{
int age;
}
public class TestClass{
public static void main(String[] args) {
Employee e = new Employee();
Supplier se = ()->{ e.age = 40; return e; }; //1
e.age = 50;//2
System.out.println(se.get().age); //3
}
}
Select 1 option(s)
It will fail to compile at line marked //1.
It will fail to compile at line marked //3.
It will print 40.
It will print 50.
It will throw an exception at run time.
None
33.
Question: Consider the following code:
package mypack;
public class TestOuter
{
public static class TestInner
{
public void sayIt(){ System.out.println("hello"); }
}
public static void main(String[] args){
//call here
}
}
Which of the following options are correct?
Select 2 option(s)
An instance of the nested class can be created from any class using: new TestOuter.TestInner().
(Assuming appropriate imports).
An instance of the nested class can be created only from classes of package mypack.
An instance of the nested class can be created from a class of package mypack using: new TestInner().
(Assuming appropriate imports).
It will not compile.
TestInner.sayIt(); can be inserted in main.
34.
Question: What will the following code print when compiled and run?
var numA = new Integer[]{1, null, 3}; //1
var list1 = List.of(numA); //2
var list2 = Collections.unmodifiableList(list1); //3
numA[1] = 2; //4
System.out.println(list1+" "+list2);
Select 1 option(s)
It will not compile.
An exception will be thrown at run time.
[1, null, 3] [1, 2, 3]
[1, null, 3] [1, null, 3]
[1, 2, 3] [1, 2, 3]
None
35.
Question: Given:
static boolean validateInput(String str){
return INSERT CODE HERE;
}
Which of the following expressions can be inserted in the above code so that the validateInput method will return true if and only if the input string contains non-whitespace data?
Select 1 option(s)
!str.isBlank()
!str.isEmpty()
str.strip() != ""
!str.equalsIgnoreBlanks("")
str.compareTo("") != 0
None
36.
Question: A new Java programmer has written the following method that takes an array of ints and sums up all the integers that are less than 100.
public void processArray(int[] values){
int sum = 0;
int i = 0;
try{
while(values[i]<100){
sum = sum +values[i];
i++;
}
}
catch(ExceUse flow control to terminate the loop.
ption e){ }
System.out.println("sum = "+sum);
}
Which of the following are best practices to improve this code?
Select 2 option(s)
Use ArrayIndexOutOfBoundsException for the catch argument.
Use ArrayIndexOutOfBoundsException for the catch argument and add code in the catch block to log or print the exception.
Add code in the catch block to handle the exception.
Use flow control to terminate the loop.
37.
Question: Consider the following class:
public class PortConnector{
public PortConnector(int port) throws IOException{
...lot of valid code.
}
...other valid code.
}
You want to write another class CleanConnector that extends from PortConnector. Which of the following statements should hold true for CleanConnector class?
Select 1 option(s)
It is not possible to define CleanConnector that does not throw IOException at instantiation.
PortConnector class itself is not valid because you cannot throw any exception from a constructor.
CleanConnector's constructor cannot throw any exception other than IOException.
CleanConnector's constructor cannot throw any exception other than subclass of IOException.
CleanConnector's constructor cannot throw any exception other than superclass of IOException.
None of these.
None
38.
Question: Which of the following options correctly makes use of java.util.concurrent.Callable?
Select 1 option(s)
public static class MyTask implements Callable
String
{
public String call(){
try {
//do something
} catch (Exception ex) {
ex.printStackTrace();
} return new Future("Data from callable");
}
}
public static class MyTask implements Callable
String
{
public String call() throws Exception {
//do something
return "Data from callable";
}
}
public static class MyTask extends Callable
String
{
public String call(){
return "Data from callable";
}
}
public class MyTask implements Callable{
Future result;
public void call(){
result = new Future<String>("Data from callable");
}
}
None
39.
Question: Consider the following code:
import java.io.*;
public class Test
{
public static void main(String[] args) throws Exception
{
var fw = new FileWriter("text.txt");
// fw.write("hello"); //1
fw.close();
}
}
Which of the following statements are correct?
Select 1 option(s)
It will throw an exception if text.txt does not exist.
It will create text.txt file in the filesystem if it does not exist.
It will not throw an exception if text.txt does not exist and it will not create a file either because nothing is being written to the file.
It will throw an exception if //1 is uncommented and if text.txt does not exist.
It will throw an exception if text.txt already exists.
None
40.
Question: Consider the following code appearing in the same file:
class Data {
private 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 1 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 method to Data class:
public void setValues(int x, int y){
this.x.setInt(x); this.y.setInt(y);
}
Then add the following statement:
d.setValues(2, 2);
Add the following method to Data class:
public void setValues(int x, int y){
this.x = x; this.y = y;
}
Then add the following statement:
d.setValues(2, 2);
None
41.
Question: What will the following code print when run?
Deque d = new ArrayDeque();
d.push(1);
d.push(2);
d.push(3);
System.out.println(d.pollFirst());
System.out.println(d.poll());
System.out.println(d.pollLast());
Select 1 option(s)
1
2
3
3
2
1
Compilation error.
Exception at run time.
None
42.
Question: What will the following code print?
Map map1 = new HashMap();
map1.put("a", 1);
map1.put("b", 1);
map1.merge("b", 1, (i1, i2)->i1+i2);
map1.merge("c", 3, (i1, i2)->i1+i2);
System.out.println(map1);
Select 1 option(s)
{a=1, b=2, c=3}
{a=1, b=1, c=3}
{a=1, b=2}
A NullPointerException will be thrown at run time.
None
43.
Question: 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.
44.
Question: Which of these for statements are valid when present in a method?
1. for (var i=5; i=0; i--) { }
2. var j=5;
for(int i=0, j+=5; i<j ; i++) { j--; }
3. int i, j;
for (j=10; i<j; j--) { i += 2; }
4. var i=10;
for ( ; i>0 ; i--) { }
5. for (int i=0, j=10; i<j; i++, --j) {;}
6. for (var i=0, j=10; i<j; i++, --j) {;}
Select 1 option(s)
1, 2
3, 4
1, 5
4, 5
5
4, 5, 6
None
45.
Question: What will the following code fragment print?
Path p1 = Paths.get("photos/goa");
Path p2 = Paths.get("/index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);
Select 1 option(s)
..\index.html
\index.html
\photos\index.html
\photos\goa\index.html
java.lang.IllegalArgumentException will be thrown
None
46.
Question: 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
47.
Question: Given the following code:
class TestClass{
public static void main(String args[]){
int time = 100;
java.sql.Timestamp ts = new java.sql.Timestamp(time);
java.util.Date d = new java.util.Date();
ts = new java.sql.Timestamp(d.getTime());
System.out.println(ts);
}
}
and the following commands:
javac TestClass.java
jdeps -summary TestClass.class
What will be the output?
Select 1 option(s)
None
48.
Question: Your application is packaged in myapp.jar and depends on a jar named datalayer.jar, which in turn depends on mysql-connector-java-8.0.11.jar.
You have modularized myapp without waiting for datalayer and mysql driver to be modularized and the following are the contents of myapp's module-info:
module abc.myapp{
requires datalayer;
}
Assming that com.abc.myapp.Main is the main class of your application that you want to execute, which of the following commands will successfully launch your application?
Select 3 option(s)
java -classpath
mysql-connector-java-8.0.11.jar;datalayer.jar;myapp.jar com.abc.myapp.Main
java -module-path
mysql-connector-java-8.0.11.jar;datalayer.jar;myapp.jar com.abc.myapp.Main
java -p mysql-connector-java-8.0.11.jar;datalayer.jar;myapp.jar
-m com.abc.myapp.Main
java -p mysql-connector-java-8.0.11.jar;datalayer.jar;myapp.jar
-m abc.myapp/com.abc.myapp.Main
java -cp mysql-connector-java-8.0.11.jar -p datalayer.jar;myapp.jar
-m abc.myapp/com.abc.myapp.Main
49.
Question: 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 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");
50.
Question: Given:
enum Title
{
MR("Mr."), MS1("Ms."), MS2("Ms.");
private String title;
private Title(String s){
title = s;
}
}
public class TestClass{
public static void main(String[] args)
{
var ts = new TreeSet
Title
();
ts.add(Title.MS2);
ts.add(Title.MR);
ts.add(Title.MS1);
for(Title t : ts){
System.out.println(t);
}
}
}
What will be the output when TestClass is compiled and run?
Select 1 option(s)
It will print MR, MS1, MS2, but the order is unpredictable.
MS2, MR, MS1,
MR, MS1, MS2,
It will not compile.
None
51.
Question: What will the following program print when compiled and run?
class Data {
private int x = 0;
private String y = "Y";
public Data(int k){
this.x = k;
}
public Data(String k){
this.y = k;
}
public void showMe(){
System.out.println(x+y);
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
new Data(10).showMe();
new Data("Z").showMe();
}
}
Select 1 option(s)
0Z
10Y
10Y
0Z
It will not compile.
It will throw an exception at run time.
None
52.
Question: Which of the following are benefits of the Java module system?
Select 1 option(s)
It saves application developers from Jar hell.
It improves security and maintainability.
It makes it easier to expose implementation details.
It eliminates the need of making custom runtime linked applications.
None
53.
Question: Which of the following code fragments correctly executes the blog(String data) method of a blogging service that implements api.Blogger interface assuming that you already have a reference to the loader for this service?
Assume that data refers to the data that needs to be blogged.
Select 2 option(s)
try{
Iterator
Blogger
bi = loader.iterator();
while(bi.hasNext()){
Blogger b = bi.next();
b.blog(data);
}
}catch(ServiceConfigurationError e){ }
try{
Iterator
Blogger
bi = loader.services();
while(bi.hasNext()){
Blogger b = bi.next();
b.blog(data);
}
}catch(ServiceConfigurationError e){ }
for(Blogger b : loader.services()){
b.blog(data);
}
try{
Blogger b = loader.getService();
b.blog(data);
}catch(ServiceConfigurationError e){ }
loader.blog(data);
for (Blogger b : loader){
b.blog("Hello from textbook");
}
Time's up
Time is Up!
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Blog
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
Blog
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US