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 - 3
Name
Email
Phone
1.
Question: What will the following code print?
List vowels = new ArrayList();
vowels.add("a");
vowels.add("e");
vowels.add("i");
vowels.add("o");
vowels.add("u");
Function<List, List> f = list->list.subList(2, 4);
f.apply(vowels);
vowels.forEach(System.out::print);
Select 1 option(s)
iou
ou
ei
aeiou
Compilation error.
None
2.
Question: Consider the following code:
static void doElements(List l) {
l.add("string"); //1
System.out.println(l.get(0)); //2
}
Select 1 option(s)
Line //1 will cause the compile to generate "unchecked or unsafe" warning, which can be removed using@SuppressWarnings("unchecked")
Line //2 will cause the compile to generate "unchecked or unsafe" warning, which can be removed using @SuppressWarnings("unsafe")
Both the lines //1 and //2 will cause the compile to generate "unchecked or unsafe" warning, which can be removed using @SuppressWarnings()
Neither of the lines //1 and //2 will cause the compile to generate "unchecked or unsafe" warning.
None
3.
Question: Consider the following code appearing in a module-info.java.
module com.amazing.movies{
requires transitive com.amazing.customer;
}
Identify correct statements.
Select 1 option(s)
Any module that requires the com.amazing.movies module must also require the com.amazing.customer module.
Any module that requires the com.amazing.movies module can use the com.amazing.customer module without requiring it.
Only a module that requires the com.amazing.movies module can use the com.amazing.customer module.
Any module that requires the com.amazing.customer module must also require the com.amazing.movies module.
Any module that requires the com.amazing.movies module must require the com.amazing.customer module instead of com.amazing.movies.
None
4.
Question: Identify correct statements about the following code:
class Writer{
private static final int LOOPSIZE = 5;
public synchronized void write(Data... da){
for(int i=0; i<LOOPSIZE; i++){
while(!da[0].own(this));
while(!da[1].own(this));
da[0].write(i); da[1].write(i);
da[1].release();
da[0].release();
}
}
}
class Data{
Writer writer; int id;
public Data(int id){ this.id = id; }
public synchronized boolean own(Writer w){
if(writer == null){
writer = w; return true;
}
else return false;
}
public synchronized void release(){ writer = null; }
public void write(int i){
System.out.println("data written W"+i+" D"+id);
}
}
public class TestClass {
public static void main(String[] args) {
var w1 = new Writer();
var w2 = new Writer();
var d1 = new Data(1);
var d2 = new Data(2);
new Thread(()->{w1.write(d1, d2);}).start();
new Thread(()->{w2.write(d1, d2);}).start();
}
}
Select 1 option(s)
It is subject to a deadlock.
It is subject to a livelock.
This code will compile and run fine.
This code will not compile.
It will throw an IllegalMonitorStateException at run time.
None
5.
Question: Which of the following statements about starvation is correct?
Select 1 option(s)
Starvation occurs when threads become so busy in responding to each other that they are unable to perform any real work.
Starvation occurs when a thread is frequently unable to get access to a resource because the resource is hogged by other threads most of the time.
Starvation is a symptom of live lock in the threads.
Starvation is a symptom of deadlock in the threads.
None
6.
Question: Given a Course class with appropriate constructor and methods and the following code:
List s1 = //create a list with a few Course objects
String testCategory = "Java";
Integer comparisonCode = 0;
long l = s1.stream()
.peek(new Consumer(){
public void accept(Course c){
c.printPassPercent();
}})
.map(c -> testCategory.compareToIgnoreCase(c.getCategory()))
.filter(a->a == 0)
.count();
System.out.println(l);
Which of the method arguments can be changed to use method references?
Select 2 option(s)
Course::printPassPercent
testCategory::compareToIgnoreCase
comparisonCode::equals
comparisonCode::equals(0)
Integer::equals(comparisonCode)
Course::getId == comparisonCode
7.
Question: Given:
List letters = Arrays.asList("j", "a", "v","a");
String word = INSERT CODE HERE
System.out.println(word);
Which of the following code fragments when inserted in the above code independent of each other will cause it to print java?
Select 1 option(s)
letters.stream().reduce("", (a, b)->a.concat(b)).get();
letters.stream().collect(Collectors.joining());
letters.stream().collect(Collectors.groupingBy(a->a)).toString();
letters.stream().collect(Collectors.groupingBy(a->"")).toString();
None
8.
Question: Which of the following interface definitions can be implemented using Lambda expressions?
@FunctionalInterface
interface A{
static void m1(){};
}
interface AA extends A{
void m2();
private void mp(){ }
}
interface AAA extends AA{
void m3();
}
interface B {
default void m1(){ }
}
interface BB extends B {
static void m2(){ };
}
interface C extends BB{
void m3();
}
Select 2 option(s)
A
AA
AAA
B
BB
C
9.
Question: Given:
public @interface Authors{
Author[] value();
}
@Repeatable(Authors.class)
public @interface Author {
int id() default 0;
String value();
}
Identify correct usages of the above annotations.
Select 2 option(s)
@Author(1, "bob")
@Author(2, "alice")
public class Sample{
}
@Authors(@Author("bob"))
void someMethod(int index){
}
@Authors(@Author("bob"))
@Authors(@Author("alice"))
void someMethod(int index){
}
@Author("bob")
@Authors(@Author("alice"))
void someMethod(int index){
}
@Author("bob")
@Author(1)
void someMethod(int index){
}
@Author("bob")
@Author(id=1, value=null)
void someMethod(int index){
}
10.
Question: What can be the return type of method getSwitch so that this program compiles and runs without any problems?
public class TestClass{
public static XXX getSwitch(int x){
return x - 20/x + x*x;
}
public static void main(String args[]){
switch( getSwitch(10) ){
case 1 :
case 2 :
case 3 :
default : break;
}
}
}
Select 1 option(s)
int
float
long
double
char
byte
short
None
11.
Question: Given:
public void processUploads(String listOfFilesFile) throws IOException{
//1
File f = new File(listOfFilesFile);
List al = new ArrayList();
try(var bfr = new BufferedReader(new FileReader(f))){
//2
String uploadedFileName = null;
while( (uploadedFileName=bfr.readLine()) != null ){
var fbfr = new BufferedReader(new FileReader(uploadedFileName));
al.add(fbfr);
//3
loadXML(fbfr);
//4
}
}finally{
for(var openReader : al){
try{ openReader.close(); }catch(Exception e)
{ e.printStackTrace();}
}
}
}
Which of the following actions will limit a potential denial of service attack on the above code?
Select 2 option(s)
Check whether listOfFilesFile refers to a valid file at //1.
Make sure that the number of lines in the file referred to by listOfFilesFile at //2 is within acceptable limit before proceeding to open the files.
Limit the size of the input file at //3 before loading XML from it.
Close fbfr at //4 and instead of closing it later in the finally block.
Remove the call to e.printStackTrace() from the finally block.
12.
Question: Given:
public class Counter{
static AtomicInteger ai = new AtomicInteger(0);
public static void increment(){
//1
}
//other valid code
}
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share this class and call its increment method. What should be inserted at //1 ?
Select 2 option(s)
ai.increment();
ai.incrementAndGet();
ai.set(ai.get()+1);
ai.addAndGet(1);
ai.add(1);
ai++;
13.
Question: 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
14.
Question: What is the result of compiling and running the following program?
public class Learner {
public static void main(String[] args) {
var dataArr = new String[4];
dataArr[1] = "Bill";
dataArr[2] = "Steve";
dataArr[3] = "Larry";
try{
for(String data : dataArr){
System.out.print(data+" ");
}
}catch(Exception e){
System.out.println(e.getClass());
}
}
}
Select 1 option(s)
Bill Steve Larry null.
Bill Steve Larry class java.lang.NullPointerException.
class java.lang.Exception Bill Steve Larry.
Bill Steve Larry class java.lang.Exception.
Null Bill Steve Larry.
None
15.
Question: Which of the following statements are correct about --jdk-internals option of jdeps tool when run on a jar file or a class file?
Select 2 option(s)
It analyzes all classes of the given jar file for class level dependence on Java API.
It analyzes all classes of the given jar file for class level dependence on jdk's deprecated API. If any such dependence is found, it is printed with a suggestion for replacement.
It analyzes all classes of the given jar file for class level dependence on jdk's internal API. If any such dependence is found, it is printed with a suggestion for replacement.
It analyzes all input modules and list all jdk internal modules on which the input modules depend. If any such dependence is found, it is printed with a suggestion for replacement.
It can only be used with -summary or -verbose options.
It performs static analysis.
16.
Question: Which of the following code snippets will print exactly 10?
1. Object t = new Integer(106);
int k = ((Integer) t).intValue()/10;
System.out.println(k);
2. System.out.println(100/9.9);
3. System.out.println(100/10.0);
4. System.out.println(100/10);
5. System.out.println(3 + 100/10*2-13);
Select 3 option(s)
1
2
3
4
5
17.
Question: What will the following code print when run?
Deque d = new ArrayDeque();
d.add(1);
d.add(2);
d.addFirst(3);
System.out.println(d.pollLast());
System.out.println(d.pollLast());
System.out.println(d.pollLast());
Select 1 option(s)
1
2
3
3
2
1
3
1
2
2
1
3
Exception at run time.
It will not compile.
None
18.
Question: You want to change the default locale for formatting numbers, currency, and percentages. Which of the following statements will achieve that?
Select 2 option(s)
Locale.setDefault(Locale.EN_US);
Locale.setDefault("en_US");
Locale.setDefault("en", "US");
Locale.setDefault(Locale.Category.FORMAT, Locale.US);
Locale.setDefault(Locale.Category.FORMAT, "en_US");
Locale.setDefault(Locale.US);
19.
Question: Given the following code snippet:
int rate = 10;
int t = 5;
XXX amount = 1000.0;
for(int i=0; i<t; i++){
amount = amount*(1 - rate/100);
}
What can XXX be?
Select 1 option(s)
int
long
only double
double or float
float
None
20.
Question: Consider the following code:
public class ArrayTest {
static int[][] table = new int[2][3];
public static void init() {
for (var x = 0; x < table.length; x++) {
for (var y = 0; y < table[x].length; y++) {
//insert code to initialize
}
}
}
public static void multiply() {
for (var x = 0; x < table.length; x++) {
for (var y = 0; y < table[x].length; y++) {
//insert code to multiply
}
}
}
}
Which of the following options can be used in the code above so that the init method initializes each table element to the sum of its row and column number and the multiply method just multiplies the element value by 2?
Select 1 option(s)
table[x, y] = x+y;
and
table[x, y] = table[x, y]*2;
table[x][y] = x+y;
and
table[x][y] = table[x][y]*2;
table[[x] [y]] = x+y;
and
table[[x] [y]] = table[[x] [y]]*2;
table(x, y) = x+y;
and
table(x, y) = table(x, y)*2;
None
21.
Question: 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 cannot be deleted due to lack of appropriate file permissions.
It will print true if p refers to an empty directory.
None
22.
Question: The following class will print 'index = 2' when compiled and run.
class Test{
public static int[ ] getArray() { return null; }
public static void main(String[] args){
var index = 1;
try{
getArray()[index=2]++;
}
catch (Exception e){ } //empty catch
System.out.println("index = " + index);
}
}
Select 1 option(s)
True
False
None
23.
Question: Given:
public List getList(){
*INSERT CODE HERE*
}
What can be inserted in the above code?
Select 3 option(s)
return new ArrayList
Integer
();
return new ArrayList
Number
();
return new ArrayList
Object
();
return new ArrayList();
return new List
Number
();
24.
Question: Which statements about the output of the following programs are true?
public class TestClass{
public static void main(String args[ ] ){
int i = 0 ;
boolean bool1 = true;
boolean bool2 = false;
boolean bool = false;
bool = (bool2 & method1("1")); //1
bool = (bool2 && method1("2")); //2
bool = (bool1 | method1("3")); //3
bool = (bool1 || method1("4")); //4
}
public static boolean method1(String str){
System.out.println(str);
return true;
}
}
Select 2 option(s)
1 will be the part of the output.
2 will be the part of the output.
3 will be the part of the output.
4 will be the part of the output.
None of the above
25.
Question: Which of the following statements are correct regarding synchronization and locks?
Select 1 option(s)
A thread shares the intrinsic lock of an object with other threads between the time the threads enter a synchronized method and exit the method.
When a synchronized method ends with a checked exception, the intrinsic lock held by the thread is released automatically.
A thread will retain the intrinsic lock if the return from a synchronized method is caused due to an uncaught unchecked exception.
Every object has an intrinsic lock associated with it and that lock is automatically acquired by a thread when it executes a method on that object.
None
26.
Question: What will be the output of the following program:
public class TestClass{
public static void main(String args[]){
try{
m1();
}catch(IndexOutOfBoundsException e){
System.out.println("1");
throw new NullPointerException();
}catch(NullPointerException e){
System.out.println("2");
return;
}catch (Exception e) {
System.out.println("3");
}finally{
System.out.println("4");
}
System.out.println("END");
}
static void m1(){
System.out.println("m1 Starts");
throw new IndexOutOfBoundsException( "Big Bang " );
}
}
Select 3 option(s)
The program will print m1 Starts.
The program will print m1 Starts, 1 and 4, in that order.
The program will print m1 Starts, 1 and 2, in that order.
The program will print m1 Starts, 1, 2 and 4 in that order.
END will not be printed.
27.
Question: What will be the output when the following program is run?
package exceptions;
public class TestClass {
public static void main(String[] args) {
try{
doTest();
}
catch(MyException me){
System.out.println(me);
}
}
static void doTest() throws MyException{
int[] array = new int[10];
array[10] = 1000;
doAnotherTest();
}
static void doAnotherTest() throws MyException{
throw new MyException("Exception from doAnotherTest");
}
}
class MyException extends Exception {
public MyException(String msg){
super(msg);
}
}
(Assume that there is no error in the line numbers given in the options.)
Select 1 option(s)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at exceptions.TestClass.doTest(TestClass.java:14)
at exceptions.TestClass.main(TestClass.java:5)
Error in thread "main" java.lang.ArrayIndexOutOfBoundsException
Exceptions.MyException: Exception from doAnotherTest
Exceptions.MyException: Exception from doAnotherTest
at exceptions.TestClass.doAnotherTest(TestClass.java:29)
at exceptions.TestClass.doTest(TestClass.java:25)
at exceptions.TestClass.main(TestClass.java:14)
None
28.
Question: Given that test1.txt exists but test2.txt doesn't exist, consider the following code?
public class FileCopier {
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.COPY_ATTRIBUTES);
}
public static void main(String[] args) throws Exception {
Path p1 = Paths.get("c:\\temp\\test1.txt");
Path p2 = Paths.get("c:\\temp\\test2.txt");
copy1(p1, p2);
}
}
Which file attributes will be copied over to test2.txt?
Select 1 option(s)
Hidden
Readonly
Archive
Copying of the attributes is platform and system dependent.
It will print unable to copy file and test2.txt will not be created.
None
29.
Question: What will be the result of attempting to compile and run the following code?
class TestClass{
public static void main(String args[] ){
String str1 = "str1";
String str2 = "str2";
System.out.println( str1.concat(str2) );
System.out.println(str1);
}
}
Select 1 option(s)
The code will fail to compile.
The program will print str1 and str1.
The program will print str1 and str1str2.
The program will print str1str2 and str1.
The program will print str1str2 and str1str2.
None
30.
Question: Consider the following code snippet:
public void readData(String fileName) throws Exception {
try(FileReader fr1 = new FileReader(fileName)){
Connection c = getConnection();
//...other valid code
}
}
Given that the call to getConnection method in the above code throws a ClassNotFoundException and that an IOException is thrown while closing fr1, which exception will be received by the caller of readData() method?
Select 1 option(s)
java.lang.Exception
java.lang.ClassNotFoundException
java.io.IOException
java.lang.RuntimeException
None
31.
Question: What can be inserted into the following code at //1 so that it will print "Oldboy"?
//imports not shown
class Movie{
static enum Genre {DRAMA, THRILLER, HORROR, ACTION };
private Genre genre;
private String name;
Movie(String name, Genre genre){
this.name = name; this.genre = genre;
}
//accessors not shown
}
public class FilteringStuff {
public static void main(String[] args) {
List movies = Arrays.asList(
new Movie("On the Waterfront", Movie.Genre.DRAMA),
new Movie("Psycho", Movie.Genre.THRILLER),
new Movie("Oldboy", Movie.Genre.THRILLER),
new Movie("Shining", Movie.Genre.HORROR)
);
Predicate horror = mov->mov.getGenre() == Movie.Genre.THRILLER;
Predicate name = mov->mov.getName().startsWith("O");
//1 INSERT CODE HERE
.forEach(mov->System.out.println(mov.getName()));
}
}
Select 1 option(s)
movies.stream().filter(horror, name)
movies.filter({horror, name})
movies.stream().filter({horror, name})
movies.stream().filter(horror).filter(name)
movies.filter(horror).filter(name)
None
32.
Question: Given the following code:
var raf = new RandomAccessFile("c:\\temp\\test.txt", "rwd");
raf.writeChars("hello");
raf.close();
Which of the following statements are correct?
(Assume that the code has appropriate security permissions.)
Select 1 option(s)
If the file test.txt does not exist, an attempt will be made to create it.
If the file test.txt does not exist, an exception will be thrown.
If the file test.txt exists, an exception will be thrown.
If the file test.txt exists, it will be overwritten and all the existing data will be lost.
If the file test.txt exists, the given characters will be appended to the end of the existing data.
None
33.
Question: What can be inserted at //1 and //2 in the code below so that it can compile without errors:
class Doll{
String name;
Doll(String nm){
this.name = nm;
}
}
class Barbie extends Doll{
Barbie(){
//1
}
Barbie(String nm){
//2
}
}
public class TestClass {
public static void main(String[] args) {
Barbie b = new Barbie("mydoll");
}
}
Select 2 option(s)
this("unknown"); at 1 and super(nm); at 2
super("unknown"); at 1 and super(nm); at 2
super(); at 1 and super(nm); at 2
super(); at 1 and Doll(nm); at 2
super("unknown"); at 1 and this(nm); at 2
Doll(); at 1 and Doll(nm); at 2
34.
Question: You want to use a module built by another team in your company. The name of the module is abc.math.utils and the module is packaged as a jar file named mathutils.jar. The module contains a class named abc.utils.Main.
You want to run this class from the command line. Which of the following commands can be used?
(Assume that the jar file is located in the current directory.)
Select 1 option(s)
java --module-source-path mathutils.jar --module abc.math.utils/abc.utils.Main
java --module-path mathutils.jar --module abc.math.utils/abc.utils.Main
java --module-path mathutils.jar --main-module abc.math.utils
java --module-source-path mathutils.jar --main-class abc.utils.Main
None
35.
Question: Identify the correct statements regarding the following program?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public Device(String name) throws IOException{
header = name;
if("D2".equals(name)) throw new IOException("Unknown");
System.out.println(header + " Opened");
}
public String read() throws IOException{
return "";
}
public void close(){
System.out.println("Closing device "+header);
throw new RuntimeException("RTE while closing "+header);
}
public static void main(String[] args) throws Exception {
try(Device d1 = new Device("D1");
Device d2 = new Device("D2")){
throw new Exception("test");
}
}
}
Select 1 option(s)
It will end up with an Exception containing message "test".
It will end up with a RuntimeException containing message "RTE while closing D1".
It will end up with an IOException containing message "Unknown".
It will end up with a RuntimeException containing message "RTE while closing D1" and a suppressed IOException containing message "Unknown".
It will end up with an IOException containing message "Unknown" and a suppressed RuntimeException containing message "RTE while closing D1".
None
36.
Question: What can be inserted in the code below so that it will print {a=x, b=xy, c=y}?
Map map1 = new HashMap();
map1.put("a", "x");
map1.put("b", "x");
//INSERT CODE HERE
map1.merge("b", "y", f);
map1.merge("c", "y", f);
System.out.println(map1);
Select 1 option(s)
BiFunction
String, String
f = String::concat;
Function
String
f = String::concat;
BiFunction
String, String, String
f = String::concat;
Function
String, String
f = String::concat;
None
37.
Question: Given:
//creating Book objects using Book(String title, String author) constructor
var books = List.of(new Book("The Outsider", "Stephen King"),
new Book("The Shining", "Stephen King" ), new Book("Uri", "India"));
Stream bkStrm = books.stream();//
long count = *INSERT CODE HERE*;
System.out.println(count);
Assuming Book class has appropriate constructor and accessor methods, which of the following statements will correctly print the number of unique authors in the list of Books?
Select 1 option(s)
bkStrm.map(Book::getAuthor).collect(Collectors.toSet()).count()
bkStrm.map(b->b.getAuthor()).distinct().count()
bkStrm.filter(b->b.getAuthor()).count()
bkStrm.map(b->b.getAuthor()).count()
None
38.
Question: Given:
interface Runner {
public void run();
}
Which of the following is/are valid lambda expression(s) that capture(s) the above interface?
Select 2 option(s)
-> System.out.println("running...");
void -> System.out.println("running...")
() -> System.out.println("running...")
() -> { System.out.println("running..."); return; }
(void) -> System.out.println("running...")
-> System.out.println("running...")
39.
Question: What will the following code print when compiled and run?
class ABCD{
int x = 10;
static int y = 20;
}
class MNOP extends ABCD{
int x = 30;
static int y = 40;
}
public class TestClass {
public static void main(String[] args) {
System.out.println(new MNOP().x+", "+new MNOP().y);
}
}
Select 1 option(s)
10, 40
30, 20
10, 20
30, 40
20, 30
Compilation error.
None
40.
Question: Consider the following code for the main() method:
public static void main(String[] args) throws Exception{
int i = 1, j = 10;
do {
if (i++ > --j) continue;
} while (i < 5);
System.out.println("i=" + i + " j=" + j);
}
What will be the output when the above code is executed?
Select 1 option(s)
i=6 j=6
i=5 j=6
i=5 j=5
i=6 j=5
None of these.
None
41.
Question: Identify correct statement(s) about the following code:
public double getTotal(String file) throws IOException{
if(!checkFile(file)) throw new IllegalArgumentException("Invalid file : " +file);
var f = new File(file);
var bfr = new BufferedReader(new FileReader(f));
String line = null;
var sum = 0.0;
while( (line = bfr.readLine()) != null ){
sum = sum + Double.parseDouble(line.trim());
}
bfr.close();
return sum;
}
Select 1 option(s)
It violates secure coding guidelines for input validation by delegating input file name validation to another method.
It violates secure coding guidelines for protecting sensitive information by dumping file name in an Exception object.
It violates secure coding guidelines for preventing denial of service attacks.
It violates secure coding guidelines for Accessibility and Extensibility by making the method overridable.
None
42.
Question: Given:
List ls = Arrays.asList(3,4,6,9,2,5,7);
System.out.println(ls.stream().reduce(Integer.MIN_VALUE, (a, b)->a>b?a:b)); //1
System.out.println(ls.stream().max(Integer::max).get()); //2
System.out.println(ls.stream().max(Integer::compare).get()); //3
System.out.println(ls.stream().max((a, b)->a>b?a:b)); //4
Which of the above statements will print 9?
Select 1 option(s)
1 and 4
2 and 3
1 and 3
2, 3, and 4
All of them.
None of them.
None
43.
Question: Given:
class StaticTest{
void m1(){
StaticTest.m2(); // 1
m4(); // 2
StaticTest.m3(); // 3
}
static void m2(){ } // 4
void m3(){
m1(); // 5
m2(); // 6
StaticTest.m1(); // 7
}
static void m4(){ }
}
Which of the lines will fail to compile?
Select 2 option(s)
1
2
3
4
5
6
7
44.
Question: Given:
public class Shape {
Point[] vertices;
public Shape(Point[] verts){ this.vertices = verts; }
public Point[] getVertices(){ return vertices; }
public void setVertices(Point[] vertices){ this.vertices = vertices; }
}
Which actions implement Java SE security guidelines?
Select 3 option(s)
Change getVertices to _getVertices.
Make get and set Vertices methods synchronized.
Make the vertices field volatile.
Change getVertices to return vertices.clone().
Change setVertices to this.vertices = vertices.clone();.
Make vertices field private.
Make vertices field private and final.
45.
Question: What will the following code print when compiled and run?
import java.util.*;
interface Birdie {
void fly();
}
class Dino implements Birdie {
public void fly(){ System.out.println("Dino flies"); }
public void eat(){ System.out.println("Dino eats");}
}
class Bino extends Dino {
public void fly(){ System.out.println("Bino flies"); }
public void eat(){ System.out.println("Bino eats");}
}
public class TestClass {
public static void main(String[] args) {
List m = new ArrayList();
m.add(new Dino());
m.add(new Bino());
for(Birdie b : m) {
b.fly();
b.eat();
}
}
}
Select 1 option(s)
Dino flies
Dino eats
Bino flies
Bino eats
Bino flies
Bino eats
Dino flies
Bino eats
The code will not compile.
Exception at run time.
None
46.
Question: What will be a part of the output when the following code is compiled and run?
class Boo {
int boo = 10;
public Boo(int k){ System.out.println("In Boo k = "+k); boo = k;}
}
class BooBoo extends Boo {
public BooBoo(int k ){ super(k); System.out.println("In BooBoo k = "+k); }
}
class Moo extends BooBoo implements Serializable {
int moo = 10;
public Moo(){ super(5); System.out.println("In Moo"); }
}
public class TestClass {
public static void main(String[] args) throws Exception{
var moo = new Moo();
var fos = new FileOutputStream("c:\\temp\\moo1.ser");
var os = new ObjectOutputStream(fos);
os.writeObject(moo);
os.close();
var fis = new FileInputStream("c:\\temp\\moo1.ser");
var is = new ObjectInputStream(fis);
moo = (Moo) is.readObject();
is.close();
}
}
Select 3 option(s)
In Boo k = 5
In BooBoo k = 5
In Boo k = 0
In BooBoo k = 0
In Moo
It will throw an exception at runtime.
It will not compile.
47.
Question: Given:
Connection con = DriverManager.getConnection(dbURL);
con.setAutoCommit(false);
String updateString =
"update SALES " +
"set T_AMOUNT = 100 where T_NAME = 'BOB'";
Statement stmt = con.createStatement();
stmt.executeUpdate(updateString);
//INSERT CODE HERE
What statement can be added to the above code so that the update is committed to the database?
Select 1 option(s)
con.setAutoCommit(true);
con.commit(true);
stmt.commit();
con.setRollbackOnly(false);
No code is necessary.
None
48.
Question: 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
49.
Question: Given:
List ls = Arrays.asList(10, 47, 33, 23);
int max = //INSERT code HERE
System.out.println(max); //1
Which of the following options can be inserted above so that it will print the largest number in the input stream?
Select 1 option(s)
None
50.
Question: Given:
@Target(ElementType.TYPE)
public @interface DBTable {
public String value();
public String[] primarykey();
public String surrogateKey() default "id";
}
Identify correct usages of the above annotation.
Select 2 option(s)
@DBTable("person", primarykey={"name"})
interface Person{
}
@DBTable(value="person", primarykey={"name"})
interface Person{
}
@DBTable("person", {"name"}, "pid")
class Person{
}
@DBTable(value="DAYS", primarykey="name")
enum DAYS{
MON, TUE, WED, THU, FRI, SAT, SUN;
}
@DBTable("DAYS", {"name"})
enum DAYS{
MON, TUE, WED, THU, FRI, SAT, SUN;
}
51.
Question: Given:
class TestClass{
public static void main(String[] args) throws IOException {
final InputStream fis = new FileInputStream("c:\\temp\\test.txt");
long l = 0;
try(fis){
l = fis.read();//1
}finally{
l = fis.read();//2
}
l = fis.read();//3
System.out.println(l);//4
}
}
What will be the output?
Select 1 option(s)
Compilation failure.
Exception at //1.
Exception at //2.
Exception at //3.
Value of the first byte in the file will be printed.
Value of the second byte in the file will be printed.
None
52.
Question: What will the following code print?
public class TestClass{
int x = 5;
int getX(){ return x; }
public static void main(String args[]) throws Exception{
TestClass tc = new TestClass();
tc.looper();
System.out.println(tc.x);
}
public void looper(){
var x = 0;
while( (x = getX()) != 0 ){
for(int m = 10; m>=0; m--){
x = m;
}
}
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at runtime.
It will print 0.
It will print 5.
None of these.
None
53.
Question: 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
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