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 - 12
Name
Email
Phone
1.
Question: What will the following program print?
class LoopTest{
public static void main(String args[]) {
var counter = 0;
outer:
for (var i = 0; i < 3; i++) {
middle:
for (var j = 0; j < 3; j++) {
inner:
for (var k = 0; k < 3; k++) {
if (k - j > 0) {
break middle;
}
counter++;
}
}
}
System.out.println(counter);
}
}
Select 1 option(s)
2
3
6
7
9
None
2.
Question: What will the following code print when compiled and run?
public class Device implements AutoCloseable{
boolean open = false;
int index;
public Device(int index){
this.index = index;
open = true;
}
public void write() throws IOException{
throw new RuntimeException("Can't write!");
}
public void close(){
open = false;
System.out.println("Device closed "+index);
}
public static void main(String[] args) {
Device d1 = new Device(1);
try(d1;
Device d2 = new Device(2);
Device d3 = new Device(3)){
d2.write();
d1.close();
}catch(Exception e){
System.out.println("Got Exception "+e.getMessage());
}
}
}
Select 1 option(s)
Device closed 3
Device closed 2
Got Exception Can't write!
Device closed 2
Device closed 3
Got Exception Can't write!
Device closed 1
Device closed 2
Device closed 3
Got Exception Can't write!
Device closed 1
Device closed 3
Device closed 2
Got Exception Can't write!
Device closed 3
Device closed 2
Device closed 1
Got Exception Can't write!
None
3.
Question: Which of the following are valid approaches for input validation from security perspective?
Select 2 option(s)
Validate input from client side.
Integral values should be validated by using appropriate constraints in the database.
Input validation should be done using trusted domain specific libraries.
Accept only valid character and input values.
Modify input values to make sure they pass validation.
4.
Question: How many times will the line marked //1 be called in the following code?
var x = 10;
do{
x--;
System.out.println(x); // 1
}while(x<10);
Select 1 option(s)
0
1
9
10
None of these.
None
5.
Question:Â Identify correct statements above the following code:
var myES = Executors.newSingleThreadExecutor();
myES.submit(() -> {}); //1
myES.submit(() -> 100);//2
Select 2 option(s)
//1 will not compile.
//2 will not compile.
The lambda expression used at //1 implements java.util.concurrent.Callable.
The lambda expression used at //1 implements java.lang.Runnable.
The lambda expression used at //2 implements java.util.concurrent.Callable.
The lambda expression used at //2 implements java.lang.Runnable.
The code will compile but will throw an exception at runtime.
6.
Question: Given:
String qr = "insert into STOCK ( ID, TICKER, LTP, EXCHANGE ) values( ?, ?, ?, ?)";
String[] tickers = {"AA", "BB", "CC", "DD" };
You are trying to initialize the STOCK table and for that you need to insert one row for each of the ticker value in the tickers array. Each row has to be initialized with the same values except the ID and TICKER columns, which are different for each row. The ID column is defined as AUTO_INCREMENT and so you need to pass only 0 for this column.
Which of the following code snippets would you use?
Select 1 option(s)
for(String ticker : tickers)
try(PreparedStatement ps = c.prepareStatement(qr);)
{
ps.setInt(1, 0);
ps.setString(2, ticker);
ps.setDouble(3, 0.0);
ps.setString(4, "NYSE");
ps.executeUpdate();
}
try(PreparedStatement ps = c.prepareStatement(qr);)
{
for(String ticker : tickers) {
ps.setInt(1, 0);
ps.setString(2, ticker);
ps.setDouble(3, 0.0);
ps.setString(4, "NYSE");
ps.executeUpdate();
}
}
try(PreparedStatement ps = c.prepareStatement(qr);)
{
ps.setInt(1, 0);
ps.setDouble(3, 0.0);
ps.setString(4, "NYSE");
for(String ticker : tickers) {
ps.setString(2, ticker);
ps.executeUpdate();
}
}
for(String ticker : tickers)
try(Statement s = c.createStatement(qr);)
{
s.executeUpdate("insert into STOCK ( ID, TICKER, LTP, EXCHANGE ) values( 0, '"+ticker+"', 0.0, 'NYSE')");
}
None
7.
Question: Given:
public static void main(String[] args) {
Device d1 = new Device(1);
try(d1){
//do some thing with d1
}
}
Identify correct statement(s).
Select 1 option(s)
Device should extend AutoCloseable and override close() method.
Device should implement Closeable and override close() method.
Device should implement Closeable and override autoClose() method.
Device should implement AutoCloseable and override autoClose() method.
Device should implement AutoCloseable and override close() method.
Device should extend AutoCloseable and override autoClose() method.
None
8.
Question: Which digits and in what order will be printed when the following program is run?
public class TestClass{
public static void main(String args[]){
int k = 0;
try{
int i = 5/k;
}
catch (ArithmeticException e){
System.out.println("1");
}
catch (RuntimeException e){
System.out.println("2");
return ;
}
catch (Exception e){
System.out.println("3");
}
finally{
System.out.println("4");
}
System.out.println("5");
}
}
Select 1 option(s)
The program will print 5.
The program will print 1 and 4, in that order.
The program will print 1, 2 and 4, in that order.
The program will print 1, 4 and 5, in that order.
The program will print 1,2, 4 and 5, in that order.
None
9.
Question: What can be inserted in the following code so that it will print [21, 32, 43] ?
List ls = Arrays.asList(11, 22, 33);
//INSERT CODE HERE
ls.replaceAll(func);
System.out.println(ls);
Select 1 option(s)
None
10.
Question: Which of the following commands can be used to identify class and module dependencies?
Select 1 option(s)
jar -describe
java --describe
jmod describe
jmod --describe
jmod --show-module-resolutionx`
None
11.
Question: You have been given an array of objects and you need to process this array as follows -
1. Call a method on each object from first to last one by one.
2. Call a method on each object from last to first one by one.
3. Call a method on only those objects at even index (0, 2, 4, 6, etc.)
Which of the following are correct?
Select 1 option(s)
Enhanced for loops can be used for all the three tasks.
Enhanced for loop can be used for only the first task. For the rest, standard for loops can be used.
Standard for loops can be used for tasks 1 and 2 but not 3.
All the tasks can be performed either by using only standard for loops or by using only enhanced for loops.
Neither standard for loops nor enhanced for loops can be used for all three tasks.
None
12.
Question: Consider the following code:
class Outsider
{
public class Insider{ }
}
public class TestClass
{
public static void main(String[] args)
{
var os = new Outsider();
// 1 insert line here
}
}
Which of the following options can be inserted at //1?
Select 1 option(s)
Insider in = os.new Insider();
Os.Insider in = os.new Insider();
Outsider.Insider in = os.new Insider();
Insider in = Outsider.new Insider();
None
13.
Question: Consider the following code:
import java.util.ArrayList;
public class Student{
ArrayList scores;
private double average;
public ArrayList getScores(){ return scores; }
public double getAverage(){ return average; }
private void computeAverage(){
//valid code to compute average
average =//update average value
}
public Student(){
computeAverage();
}
//other code irrelavant to this question not shown
}
What can be done to improve the encapsulation of this class?
Select 2 option(s)
Make the class private.
Make the scores instance field private.
Make getScores() protected.
Make computeAverage() public.
Change getScores to return a copy of the scores list:
public ArrayList
Integer
getScores(){
return new ArrayList(scores);
}
14.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
String s = "hello";
StringBuilder sb = new StringBuilder( "hello" );
sb.reverse();
s.reverse();
if( s == sb.toString() ) System.out.println( "Equal" );
else System.out.println( "Not Equal" );
}
}
Select 1 option(s)
Compilation error.
It will print 'Equal'.
It will print 'Not Equal'.
Runtime error.
None of the above.
None
15.
Question: What will the following program print?
public class InitTest{
public InitTest(){
s1 = sM1("1");
}
static String s1 = sM1("a");
String s3 = sM1("2");{
s1 = sM1("3");
}
static{
s1 = sM1("b");
}
static String s2 = sM1("c");
String s4 = sM1("4");
public static void main(String args[]){
InitTest it = new InitTest();
}
private static String sM1(String s){
System.out.println(s); return s;
}
}
Select 1 option(s)
The program will not compile.
It will print : a b c 2 3 4 1
It will print : 2 3 4 1 a b c
It will print : 1 a 2 3 b c 4
It will print : 1 a b c 2 3 4
None
16.
Question: What will be the result of attempting to compile and run the following class?
public class InitTest{
static String s1 = sM1("a");{
s1 = sM1("b");
}
static{
s1 = sM1("c");
}
public static void main(String args[]){
InitTest it = new InitTest();
}
private static String sM1(String s){
System.out.println(s); return s;
}
}
Select 1 option(s)
The program will fail to compile.
The program will compile without error and will print a, c and b in that order when run.
The program will compile without error and will print a, b and c in that order when run.
The program will compile without error and will print c, a and b in that order when run.
The program will compile without error and will print b, c and a in that order when run.
None
17.
Question: Given:
StringBuilder sb = new StringBuilder("abcdef");
//INSERT CODE HERE
for(int i = 0, k = sb.length(); i<k; i++){
sb.replace(i, i+1, f.apply(sb.charAt(i)));
}
System.out.println(sb);
Which of the following statements can be inserted in the above code?
Select 1 option(s)
None
18.
Question: Consider the following code:
class Test{
public static void main(String[] args){
for (int i = 0; i < args.length; i++) System.out.print(i == 0 ? args[i] : " " + args[i]);
}
}
What will be the output when it is run using the following command:
java Test good bye friend!
Select 1 option(s)
good bye friend!
good good good
goodgoodgood
good bye
None of the above.
None
19.
Question: How can you declare 'i' so that it is not visible outside the package test.
package test;
public class Test{
XXX int i;
/* irrelevant code */
}
Select 2 option(s)
Private
Public
Protected
No access modifier.
Friend
20.
Question: Given that a class named com.xyz.fx.Main is part of a module named xyz.fx packaged in fx.jar, which of the following commands can be used to execute this class?
(Assume that the jar file is located in the current directory.)
Select 2 option(s)
java -classpath fx.jar --m xyz.fx/com.xyz.fx.Main
java --p fx.jar --m xyz.fx/com.xyz.fx.Main
java -p fx.jar --module xyz.fx/com.xyz.fx.Main
java --module-path fx.jar --module com.xyz.fx.Main
java -classpath fx.jar com.xyz.fx.Main
21.
Question: You want to execute a task that returns a result without blocking. Which of the following types from java.util.concurrent package will be required to achieve this?
Select 4 option(s)
Executor
ExecutorService
Executors
Runnable
Callable
Future
22.
Question: Consider the following class and interface definitions (in separate files):
public class Sample implements IInt{
public static void main(String[] args){
Sample s = new Sample(); //1
int j = s.thevalue; //2
int k = IInt.thevalue; //3
int l = thevalue; //4
}
}
public interface IInt{
int thevalue = 0;
}
What will happen when the above code is compiled and run?
Select 1 option(s)
It will give an error at compile time at line //1.
It will give an error at compile time at line //2.
It will give an error at compile time at line //3.
It will give an error at compile time at line //4.
It will compile and run without any problem.
None
23.
Question: Given:
interface Account{
public default String getId(){
return "0000";
}
}
interface PremiumAccount extends Account{
//INSERT CODE HERE
}
Which of the following options can be inserted in PremiumAccount independent of each other?
Select 2 option(s)
static String getId(){
return "1111";
}
String getId();
default String getId(){
return "1111";
}
abstract static String getName();
static String getName();
default String getName();
24.
Question: Given:
public static void reader(String fileName1) throws Exception{
try (var fr = new FileReader(fileName1);) {
int charRead = 0;
while ((charRead = fr.read()) != -1) {
System.out.println("Read char " + charRead);
}
}
}
What can be done to the above code to make it read Strings instead of chars?
Select 1 option(s)
Chain fr to a StringReader and use its readString method.
Use fr.readString instead of fr.read.
Chain fr to a BufferedReader use its readLine method.
Chain fr to a DataReader and use its readLine method.
None
25.
Question: Which of the following lambda expressions can be used to invoke a method that accepts a java.util.function.Predicate as an argument?
Select 2 option(s)
x -> System.out.println(x)
x -> System.out.println(x);
x -> x == null
() -> true
x->true
26.
Question: Consider the following code:
var s = "hello";
byte i = 100;
var fos = new FileOutputStream("c:\\temp\\data.bin");
var dos = new DataOutputStream(fos);
//WRITE s to file
//WRITE i to file
dos.flush(); dos.close(); fos.close();
var dis = new DataInputStream(new FileInputStream("c:\\temp\\data.bin"));
//READ s from file
//READ i from file
Which methods should be used to write and read s and i to/from the data.bin file?
Select 1 option(s)
writeString, writeByte and readString, readByte
writeString, writeInt and readString, readInt
writeChars, writeByte and readChars, readByte
writeUTF, writeByte and readUTF, readByte
writeUTF, writeInt and readUTF, readInt
None
27.
Question: Given:
@Retention(RetentionPolicy.RUNTIME)
public @interface DebugInfo {
String value() default "";
String[] params();
String date();
int depth() default 10;
}
Which of the following options correctly uses the above annotation?
Select 2 option(s)
@DebugInfo(date = "2019", params = "index")
void applyLogic(int index){
}
@DebugInfo(date = "2019-1-1", params = { null })
void applyLogic(int index){
}
@DebugInfo(depth = 10, date = "01/01/2019",
params = {"index"}, value="applyLogic")
static final String s = null;
@DebugInfo({"index"}, "01/01/2019")
void applyLogic(int index){
}
@DebugInfo("value", params={"index"}, date="01/01/2019")
void applyLogic(int index){
}
28.
Question: What will the following code print when compiled and run?
abstract class Calculator{
abstract void calculate();
public static void main(String[] args){
System.out.println("calculating");
Calculator x = null;
x.calculate();
}
}
Select 1 option(s)
It will not compile.
It will not print anything and will throw NullPointerException.
It will print calculating and then throw NullPointerException.
It will print calculating and will throw NoSuchMethodError.
It will print calculating and will throw MethodNotImplementedException.
None
29.
Question: Consider the following code:
import java.util.*;
public class TestClass {
public static void main(String[] args)
{
// put declaration here
m.put("1", new ArrayList()); //1
m.put(1, new Object()); //2
m.put(1.0, "Hello"); //3
System.out.println(m);
}
}
How can 'm' be declared such that the above code will compile and run without errors?
Select 2 option(s)
Map m = new TreeMap();
Map< Object, Object > m = new TreeMap<Object, Object>();
Map< Object, ? > m = new LinkedHashMap< Object, Object >();
Map
Object, ? super ArrayList
m = new LinkedHashMap
Object, ArrayList
(); will work if lines //2 and //3 are commented out.
Map
Object, ? super ArrayList
m = new LinkedHashMap
Object, ArrayList
(); will work if lines //1 and //3 are commented out.
Map m = new HashMap();
30.
Question: What will the following code print?
Path p1 = Paths.get("\\photos\\vacation");
Path p2 = Paths.get("\\yellowstone");
System.out.println(p1.resolve(p2)+" "+p1.relativize(p2));
Select 1 option(s)
yellowstone ..\..\yellowstone
\yellowstone ..\..\yellowstone
\yellowstone \yellowstone
\yellowstone yellowstone
None
31.
Question: Which of the following classes have a default constructor?
class A{ }
class B { B(){ } }
class C{ C(String s){ } }
Select 1 option(s)
A
A and B
B
C
B and C
None
32.
Question: Which of the following are valid method implementations?
Select 2 option(s)
public void outputText(PrintWriter pw, String text){
try{
pw.write(text);
}catch(IOException e){
System.out.println("exception in writing");
}
}
public void outputText(PrintWriter pw, String text){
pw.write(text);
if(pw.checkError()) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
boolean flag = pw.write(text);
if(!flag) System.out.println("exception in writing");
}
public void outputText(PrintWriter pw, String text){
pw.printf(text).print("success");
}
public void outputText(PrintWriter pw, String text){
pw.println(text).println("success");
}
33.
Question: Given:
class Person{
String name;
String dob;
public Person(String name, String dob){
this.name = name; this.dob = dob;
}
}
class MySorter {
public int compare(Person p1, Person p2){
return p1.dob.compareTo(p2.dob);
}
}
public class SortTest {
public static int diff(Person p1, Person p2){
return p1.dob.compareTo(p2.dob);
}
public static int diff(Date d1, Date d2){
return d1.compareTo(d2);
}
public static void main(String[] args) {
ArrayList al = new ArrayList();
al.add(new Person("Paul", "01012000"));
al.add(new Person("Peter", "01011990"));
al.add(new Person("Patrick", "01012002"));
INSERT CODE HERE
}
}
and the following lines of code:
I java.util.Collections.sort(al, (p1, p2)->p1.dob.compareTo(p2.dob));
II java.util.Collections.sort(al, SortTest::diff);
III java.util.Collections.sort(al, new MySorter()::compare);
IV java.util.Arrays.sort(al, SortTest::diff);
How many of the above lines can be inserted into the given code, independent of each other, to sort the list referred to by al?
Select 1 option(s)
1
2
3
4
None of these
None
34.
Question: Identify correct statements about following command:
java -p .\dir1 -cp .\dir2 -m a.b/a.b.c.Main
Select 1 option(s)
Dir1 should have a directory named a.b or a jar file named a.b.jar.
If classes from a third party non-modular jar are required by Main, then the third party jar file should be present in dir2 directory.
If the a.b module requires any other module, then that module's jar file must be present in dir1 directory.
Main.class should be present in dir1\a.b\a\b\c directory or, if it is inside a jar, then its path should be \a\b\c.
None
35.
Question: Consider the following piece of code, which is run in an environment where the default locale is English - US:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = new Locale("jp", "JP");
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundles for appmessages, with the following contents:
#In English US resource bundle file
greetings=Hello
#In French CA resource bundle file
greetings=bonjour
What will be the output?
Select 1 option(s)
Hello
Bonjour
An exception at run time.
No message will be printed.
None
36.
Question: After which line will the object created at line XXX be eligible for garbage collection?
public Object getObject(Object a) //0
{
Object b = new Object(); //XXX
Object c, d = new Object(); //1
c = b; //2
b = a = null; //3
return c; //4
}
Select 1 option(s)
//2
//3
//4
Never in this method.
Cannot be determined.
None
37.
Question: Identify correct statements about the module system of Java.
Select 2 option(s)
Only an application structured as modular can be run on a modular JDK.
Main goals of the module system are to improve security with strong encapsulation and stability with reliable dependencies.
Code in modules and traditional JARs on the classpath cannot coexist in an application.
Modules have concealed packages for internal use and exported packages for shared code with other modules.
38.
Question: 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 1 option(s)
public List< Integer > getList(){
public List
Object
getList(){
public ArrayList
Number
getList(){
public ArrayList
Integer
getList(){
public ArrayList< Object > getList(){
None
39.
Question: Consider that you are writing a set of classes related to a new Data Transmission Protocol and have created your own exception hierarchy derived from java.lang.Exception as follows:
enthu.trans.ChannelException
+-- enthu.trans.DataFloodingException,
enthu.trans.FrameCollisionException
You have a TransSocket class that has the following method:
long connect(String ipAddr) throws ChannelException
Now, you also want to write another "AdvancedTransSocket" class, derived from "TransSocket" which overrides the above mentioned method. Which of the following are valid declaration of the overriding method?
Select 2 option(s)
int connect(String ipAddr) throws DataFloodingException
int connect(String ipAddr) throws ChannelException
long connect(String ipAddr) throws FrameCollisionException
long connect(String ipAddr) throws Exception
long connect(String str)
40.
Question: 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.
41.
Question: What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
var k = 2;
do{
System.out.println(k);
}while(--k>0);
}
}
Select 1 option(s)
1
1
0
2
1
2
1
0
It will keeping printing numbers in an infinite loop.
It will not compile.
None
42.
Question: What will the following code fragment print when compiled and run?
Locale myloc = new Locale.Builder().setLanguage("en").setRegion("UK").build(); //L1
ResourceBundle msgs = ResourceBundle.getBundle("mymsgs", myloc);
Enumeration en = msgs.getKeys();
while(en.hasMoreElements()){
String key = en.nextElement();
String val = msgs.getString(key);
System.out.println(key+" : "+val);
}
Assume that only the following two properties files (contents of the file is shown below the name of the file) are accessible to the code.
1. mymsgs.properties
okLabel=OK
cancelLabel=Cancel
2. mymsgs_en_UK.properties
okLabel=YES
noLabel=NO
Select 1 option(s)
It will not compile due to line L1.
It will not print anything.
okLabel=OK
cancelLabel=Cancel
okLabel=YES
noLabel=NO
noLabel : NO
okLabel : YES
cancelLabel : Cancel
noLabel : NO
okLabel : OK
cancelLabel : Cancel
None
43.
Question: Given:
class NewException extends Exception {}
class AnotherException extends Exception {}
public class ExceptionTest{
public static void main(String[] args) {
try{
if(args.length == 0) m2(); else m3();
}
*INSERT CODE HERE*
}
public static void m2() throws NewException { throw new NewException(); }
public static void m3() throws AnotherException{ throw new AnotherException(); }
}
Which of the following options can be inserted in the above code to make it compile?
Select 3 option(s)
catch(NewException|Exception ne){ }
catch(Exception|AnotherException ne){ }
catch(NewException|AnotherException ne){ }
catch(NewException ne){ }
catch(AnotherException ne){ }
catch(AnotherException ne){ }
catch(NewException ne){ }
44.
Question: What will the following code print?
public class Test{
public int luckyNumber(int seed){
if(seed > 10) return seed%10;
int x = 0;
try{
if(seed%2 == 0) throw new Exception("No Even no.");
else return x;
}
catch(Exception e){
return 3;
}
finally{
return 7;
}
}
public static void main(String args[]){
int amount = 100, seed = 6;
switch( new Test().luckyNumber(6) ){
case 3: amount = amount * 2;
case 7: amount = amount * 2;
case 6: amount = amount + amount;
default :
}
System.out.println(amount);
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at runtime.
800
200
400
None
45.
Question: 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.
46.
Question: Consider the following code:
public class Test extends Thread
{
boolean flag = false;
public Test(boolean f) { flag = f; }
static Object obj1 = new Object();
static Object obj2 = new Object();
public void m1()
{
synchronized(obj1)
{
System.out.print("1 ");
synchronized(obj2)
{
System.out.println("2");
}
}
}
public void m2()
{
synchronized(obj2)
{
System.out.print("2 ");
synchronized(obj1)
{
System.out.println("1");
}
}
}
public void run()
{
if(flag){ m1(); m2(); }
else { m2(); m1(); }
}
public static void main(String[] args)
{
new Test(true).start();
new Test(false).start();
}
}
Which of the following statements are correct?
Select 2 option(s)
It may result in a deadlock and the program may get stuck.
There is no potential for deadlock in the code.
Deadlock may occur but the program will not get stuck as the JVM will resolve the deadlock.
The program will always print: 1 2, 2 1, 1 2 and 2 1.
Nothing can be said for sure.
47.
Question: Given the following program, which statements are true?
// Filename: TestClass.java
public class TestClass{
public static void main(String args[]){
A[] a, a1;
B[] b;
a = new A[10]; a1 = a;
b = new B[20];
a = b; // 1
b = (B[]) a; // 2
b = (B[]) a1; // 3
}
}
class A { }
class B extends A { }
Select 2 option(s)
Compile time error at line 3.
The program will throw a java.lang.ClassCastException at the line labelled 2 when run.
The program will throw a java.lang.ClassCastException at the line labelled 3 when run.
The program will compile and run if the (B[ ] ) cast in the line 2 and the whole line 3 is removed.
The cast at line 2 is needed.
48.
Question: Consider the classes shown below:
class A{
public A() { }
public A(int i) { System.out.println(i ); }
}
class B{
static A s1 = new A(1);
A a = new A(2);
public static void main(String[] args){
var b = new B();
var a = new A(3);
}
static A s2 = new A(4);
}
Which is the correct sequence of the digits that will be printed when B is run?
Select 1 option(s)
1 ,2 ,3 4.
1 ,4, 2 ,3
3, 1, 2, 4
2, 1, 4, 3
2, 3, 1, 4
None
49.
Question: What will the following code print when compiled and run?
List list1 = List.of("A", "B");
List list2 = List.copyOf(list1);
list1.add("C"); //1
list2.add("D"); //2
System.out.println(list1+" "+list2);
Select 1 option(s)
[A, B] [A, B]
[A, B, C] [A, B]
[A, B, C] [A, B, C, D]
[A, B, C, D] [A, B, C, D]
Line marked //1 will cause an exception at run time.
Both the lines marked //1 and //2 will cause an exception at run time.
None
50.
Question: What will the following code print when compiled and run:
class Data {
int intVal = 0;
String strVal = "default";
public Data(int k){
this.intVal = k;
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Data d1 = new Data(10);
d1.strVal = "D1";
Data d2 = d1;
d2.intVal = 20;
System.out.println("d2 val = "+d2.strVal);
}
}
Select 1 option(s)
d2 val =
d2 val = default
d2 val = D1
Exception at run time.
None
51.
Question: 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
52.
Question: What will the following code print when compiled and run?
public class TestClass{
public static void main(String[] args) {
int value = 0;
Supplier valueS = ()->value++; //1
value++;//2
System.out.println(value+" "+valueS.get()); //3
}
}
Select 1 option(s)
1 1
2 1
2 2
Compilation error at //1.
Compilation error at //2.
None
53.
Question: Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?
abstract class Bang{
// abstract void f(); // LINE 0
final void g(){}
// final void h(){} // LINE 1
protected static int i;
private int j;
}
final class BigBang extends Bang{
// BigBang(int n) { m = n; } // LINE 2
public static void main(String args[]){
Bang mc = new BigBang();
}
// @Override // LINE 3
void h(){}
// void k(){ i++; } // LINE 4
// void l(){ j++; } // LINE 5
int m;
}
Consider each line independently.
Select 1 option(s)
abstract void f( ) ; //(0)
final void h( ) { } //(1)
BigBang(int n) { m = n; } //(2)
@Override //(3)
void k( ) { i++; } //(4)
void l( ) { j++; } //(5)
None
54.
Question: What will the following code print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
List al = new ArrayList(); //1
al.add(111); //2
System.out.println(al.get(al.size())); //3
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at run time because of line //1.
It will throw an exception at run time because of line //2
It will throw an exception at run time because of line //3.
Null.
None
55.
Question: Given:
public class Bandwidth{
public int available = 0;
public int getAvailable(){
return available;
}
public Bandwidth(int quota){
this.available = quota;
}
public void addMore(int more){
available += more;
}
}
and a piece of code from another class:
Bandwidth bw = new Bandwidth(100);
//INSERT CODE HERE
System.out.println(bw.getAvailable());
What can be inserted in the code above so that it will print 0?
Select 2 option(s)
bw(0);
bw.available = 0;
bw.setAvailable(0);
bw = new Bandwidth();
bw.addMore(-bw.getAvailable());
--bw.available;
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