Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Java standard test 9 Code 1Z 829
Welcome to your Java Test - 9
Name
Email
Phone
1.
Question: Identify correct statements about the following code:
public class Counter{ //1
T t;
public int count(T[] ta, T t){ //2
this.t = t; //3
int count = 0;
for(T x : ta){
count = x == t ? count+1: count;//4
}
return count;
}
}
Select 1 option(s)
Compilation failure due to //1.
Compilation failure due to //2.
Compilation failure due to //3.
Compilation failure due to //4.
It will compile without any error.
None
2.
Question: You are creating a abc.payroll module that makes its two classes - com.abc.payroll.Hourly and com.abc.payroll.Yearly - available to all other modules for use.
Which of the following files correctly defines this module?
Select 1 option(s)
module abc.payroll{
exports com.abc.payroll.*;
}
module abc.payroll{
exports com.abc.payroll;
}
module abc.payroll{
exports com.abc.payroll to all;
}
module abc.payroll{
exports com.abc.payroll.Hourly, com.abc.payroll.Yearly;
}
module abc.payroll{
exports com.abc.payroll.Hourly;
exports com.abc.payroll.Yearly;
}
None
3.
Question: Consider these two interfaces:
interface I1
{
void m1() throws java.io.IOException;
}
interface I2
{
void m1() throws java.sql.SQLException;
}
What methods have to be implemented by a class that says it implements I1 and I2 ?
Select 1 option(s)
Both, public void m1() throws SQLException; and public void m1() throws IOException;
public void m1() throws Exception
The class cannot implement both the interfaces simultaneously because they have conflicting methods.
public void m1() throws SQLException, IOException;
None of the above.
None
4.
Question: Given:
public static boolean getBool(){
return true;
}
public static String getString(){
return "true";
}
public static void main(String args[]){
switch( getBool() ){
case true -> System.out.println("true");
default -> System.out.println("none");
}
}
What changes can be done so that it will print only true?
Select 1 option(s)
No change is necessary.
Call getString instead of getBool in the switch.
Call getString instead of getBool in the switch and also change the case label from true to "true".
Remove the default section of the switch block.
Add break; after System.out.println("true");
Call getString instead of getBool in the switch, change the case label from true to "true", and also add break; after printing true.
None
5.
Question: Your are modularizing your java application but it depends on commons-dbcp-0.9.jar, which is not modularized. So, you have decided to put this jar on the module-path. What module name will be given to the automatic module created for this jar?
Select 1 option(s)
commons.dbcp.0.9
commons.dbcp.0
commons-dbcp-09
commons.dbcp
commons-dbcp
None
6.
Question: What will be the result when you try to compile and run the following code?
public class TestClass
{
public static void main(String args[] )
{
var out = new Outer();
System.out.println(out.getInner().getOi());
}
}
class Outer
{
private int oi = 20;
class Inner
{
int getOi() { return oi; }
}
Inner getInner() { return new Inner() ; }
}
Select 1 option(s)
The code will fail to compile as the inner class Inner is not defined properly.
The code will fail to compile because the reference of an inner class cannot be passed outside the outer class.
The code will fail to compile, since the method getOi( ) is not visible from the main( ) method in the TestClass.
The code will compile without error and will print 20 when run.
None of the above.
None
7.
Question: What will be the output of the following class.
class Test{
public static void main(String[] args){
int j = 1;
try{
int i = doIt() / (j = 2);
} catch (Exception e){
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new Exception("FORGET IT"); }
}
Select 1 option(s)
It will print j = 1;
It will print j = 2;
The value of j cannot be determined.
It will not compile.
None of the above.
None
8.
Question: Consider the following interface definition:
interface Measurement{
public default int getLength(){
System.out.println("getting length");
return 10;
};
public default int getBreadth(){
System.out.println("getting length");
return 20;
};
}
Several similar default methods need to be added to this interface and each method is supposed to log a message at the start of the method. As of now, the logging is done using just a println statement but it may change later.
What changes can be done in the above interface to make it more maintainable without exposing any non-business functionality to the users of this interface?
Select 1 option(s)
Add a public void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a protected void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a private void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
Add a static void log(String msg) method to write the log message and invoke it from other methods instead of using println statement.
None
9.
Question: Consider the following classes:
class Boo {
public Boo(){ System.out.println("In Boo"); }
}
class BooBoo extends Boo {
public BooBoo(){ System.out.println("In BooBoo"); }
}
class Moo extends BooBoo implements Serializable {
int moo = 10; { System.out.println("moo set to 10"); }
public Moo(){ System.out.println("In Moo"); }
}
First, the following code was executed and the file moo1.ser was created successfully:
Moo moo = new Moo();
moo.moo = 20;
FileOutputStream fos = new FileOutputStream("c:\\temp\\moo1.ser");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(moo);
os.close();
Next, the following code was executed.
FileInputStream fis = new FileInputStream("c:\\temp\\moo1.ser");
ObjectInputStream is = new ObjectInputStream(fis);
Moo moo = (Moo) is.readObject();
is.close();
System.out.println(moo.moo);
Which of the following will be a part of the output of the second piece of code?
Select 3 option(s)
In Boo
In BooBoo
In Moo
10
20
moo set to 10
10.
Question: What can be inserted in the code below so that it will print true when run?
public class TestClass{
public static boolean checkList(List list, Predicate p){
return p.test(list);
}
public static void main(String[] args) {
boolean b = //WRITE CODE HERE
System.out.println(b);
}
}
Select 2 option(s)
checkList(new ArrayList(), al -> al.isEmpty());
checkList(new ArrayList(), ArrayList al -> al.isEmpty());
checkList(new ArrayList(), al -> return al.size() == 0);
checkList(new ArrayList(), al -> al.add("hello"));
checkList(new ArrayList(), (ArrayList al) -> al.isEmpty());
11.
Question: Consider the following method -
public float parseFloat( String s ){
float f = 0.0f;
try{
f = Float.valueOf( s ).floatValue();
return f ;
}
catch(NumberFormatException nfe){
f = Float.NaN ;
return f;
}
finally{
f = 10.0f;
return f;
}
}
What will it return if the method is called with the input "0.0" ?
Select 1 option(s)
It will not compile.
It will return 10.0
It will return Float.Nan
It will return 0.0
None of the above.
None
12.
Question: Given:
class Automobile{
final String getVin(){ return "1234"; }
}
Identify correct statements.
Select 1 option(s)
The following code will not compile because it is missing a zero args constructor:
public final class Car extends Automobile{
}
The following code will not compile because Automobile is final:
class Car{
Automobile a;
}
The following code will not compile because a final class cannot extend any other class:
public final class Car extends Automobile{
}
The following code will compile fine:
final class Car extends Automobile{
}
None
13.
Question: Consider the following class definition:
public class TestClass{
public static void main(String[] args){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); } //2
public void sayHello() { System.out.println("Hello World "); } //3
}
What will be the result of compiling and running the class?
Select 1 option(s)
It will print Hello World.
It will print Static Hello World.
Compilation error at line 2.
Compilation error at line 3.
Runtime Error.
None
14.
Question: Add description herGiven:
import java.io.*;
class TestClass{
public static void main(String[] args) throws Exception{
try(var bfr = new BufferedReader(new InputStreamReader(System.in))){
System.out.println("Enter Number:");
var s = bfr.readLine();
System.out.println("Your Number is : "+s);
}catch(Exception e){
e.printStackTrace();
}
}
}
What will be the output if the above code is executed using the following command:
java TestClass 123
Select 1 option(s)
Enter Number:
(Program is stuck after printing the above)
Enter Number:
Your Number is:123
Enter Number:
Your Number is:TestClass 123
An exception stack trace will be printed.
None
15.
Question: NOTE: Although Class.isArray() and Object.clone() methods are not officially on the exam, you may still see a question or two in the exam that requires you to know about these methods.
Given the following declaration:
int[][] twoD = { { 1, 2, 3} , { 4, 5, 6, 7}, { 8, 9, 10 } };
What will the following lines of code print?
System.out.print(twoD[1].length);
System.out.print(twoD[2].getClass().isArray());
System.out.print(twoD[1][2]);
System.out.print(twoD[0] == twoD.clone()[0]);
Select 1 option(s)
4true6true
3true3false
3false3true
4false6true
4true6false
4false6false
None
16.
Question: For what command line arguments will the following program print true?
class TestClass{
public static void main(String[] args){
Integer i = Integer.parseInt(args[0]);
Integer j = i;
i--;
i++;
System.out.println((i==j));
}
}
Select 3 option(s)
0
-1
127
-256
256
1_00
For all the values between 0 and 255 (both included).
17.
Question: Given:
In file A.java:
package p1;
import java.util.*;
public class A {
public String name = "A";
protected A(){ }
}
In file B.java:
package p2;
import p1.*;
public class B extends A{
public String name = "B";
public B(){ super(); }
}
In file TestClass.java:
import p1.*;
import p2.*;
public class TestClass
{
public static void main(String[] args) {
A a = new B();
System.out.println(a.name);
}
}
What will be the result of compiling and executing Testclass?
Select 1 option(s)
Compilation failure for class B
A
B
Compilation failure for class TestClass
None
18.
Question: Given:
BiFunction bf
= (String s, Integer i) -> { return s.substring(0, i); };
What of the following lambda expressions is equivalent to the one used above?
Select 1 option(s)
(s, i)->s.substring(0, i)
(s, i)->s::substring(0, i)
(s, i)->s:substring(0, i)
s::substring(0, i)
None
19.
Question: What will the following code print when run?
import java.util.function.Predicate;
class Employee{
int age; //1
}
public class TestClass{
public static boolean validateEmployee(Employee e, Predicate p){
return p.test(e);
}
public static void main(String[] args) {
Employee e = new Employee(); //2
System.out.println(validateEmployee(e, e->e.age<10000)); //3
}
}
Select 1 option(s)
It will fail to compile at line marked //1
It will fail to compile at line marked //2
It will fail to compile at line marked //3
It will compile fine and print true when run.
It will compile fine and print false when run.
None
20.
Question: Given:
interface I { }
class A implements I{
public String toString(){ return "in a"; }
}
class B extends A{
public String toString(){ return "in b"; }
}
public class TestClass {
public static void main(String[] args) {
B b = new B();
A a = b;
I i = a;
System.out.println(i);
System.out.println((B)a);
System.out.println(b);
}
}
What will be printed when the above code is compiled and run?
Select 1 option(s)
in i
in a
in b
I
A
in b
in a
in a
in b
in a
in b
in b
in b
in b
in b
None
21.
Question: Given:
var nums = IntStream.range(1, 5);
Which of the following options will compute the average of the numbers in the nums stream?
Select 3 option(s)
double average = nums.collect(Collectors.averagingInt(i->i));
double average = nums.mapToObj(i->i).collect(Collectors.averagingInt(i->i));
double average = nums.average().getAsDouble();
double average = nums.parallelStream().mapToInt(i->i).average();
double average = nums.parallel().mapToDouble(i->i).average().getAsDouble();
22.
Question: Consider the following code:
public class FileCopier {
public static void copy(String records1, String records2) {
try {
InputStream is = new FileInputStream(records1);
OutputStream os = new FileOutputStream(records2);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
System.out.println("Read and written bytes " + bytesRead);
}
} catch (FileNotFoundException | IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
copy("c:\\temp\\test1.txt", "c:\\temp\\test2.txt");
}
}
Assuming appropriate import statements and the existence of both the files, what will happen when the program is compiled and run?
Select 1 option(s)
The program will not compile because it does not handle exceptions correctly.
The program will compile but will throw an exception at run time.
The program will not compile because the catch clause is used incorrectly.
It will compile and run without any error or exception.
None
23.
Question: What will the following code print when compiled and run?
int[][] ab = { {1, 2, 3}, {4, 5} };
for(var i=0; i<ab.length; i++){
for(var j=0; j<ab[i].length; j++){
System.out.print(ab[i][j]+" ");
if(ab[i][j] == 2){
break;
}
}
continue;
}
Select 1 option(s)
1 2 3 4 5
1 2
1 3 4 5
1 2 4 5
2 3 5
It will not compile.
None
24.
Question: Given:
Stream names = Stream.of("Sarah Adams", "Suzy Pinnell", "Paul Basgall");
Stream firstNames = //INSERT CODE HERE
Which of the following options will correctly assign a stream of just first names to firstNames?
Select 1 option(s)
names.map(e->e.split(" ")[0]);
names.reduce(e->e.split(" ")[0]);
names.filter(e->e.split(" ")[0]);
names.forEach(e->e.split(" ")[0]);
None
25.
Question: Which of the following statements can be inserted at // 1 to make the code compile without errors?
public class InitTest{
static int si = 10;
int i;
final boolean bool;
// 1
}
Select 1 option(s)
instance { bool = true; }
InitTest() { si += 10; }
{ si = 5; i = bool ? 1000 : 2000;}
{ i = 1000; }
{ bool = (si > 5); i = 1000; }
None
26.
Question: What will the following code print when run?
public class Noobs {
public void m(int a){
System.out.println("In int ");
}
public void m(char c){
System.out.println("In char ");
}
public static void main(String[] args) {
Noobs n = new Noobs();
int a = 'a';
char c = 6;
n.m(a);
n.m(c);
}
}
Select 1 option(s)
In int
In char
In char
In int
In int
In int
In char
In char
It will not compile.
None
27.
Question: Which of the following sets of interface definitions are valid?
Select 1 option(s)
interface Measurement{
public int getLength(){
return 0;
}
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public default int getLength(){
return 0;
}
public static int getBreadth(){ return 0; }
}
interface Size extends Measurement{
public static final int UNIT = 100;
public static int getLength(){ return 10;}
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private void helper(){ }
}
interface Measurement{
public default final int getUnit(){ return 100; }
private void helper(){ }
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private final int STEP = 10;
}
None
28.
Question: What will the following code print when run?
public class Test {
static String s = "";
public static void m0(int a, int b) {
s += a;
m2();
m1(b);
}
public static void m1(int i) {
s += i;
}
public static void m2() {
throw new NullPointerException("aa");
}
public static void m() {
m0(1, 2);
m1(3);
}
public static void main(String args[]) {
try {
m();
} catch (Exception e) {
}
System.out.println(s);
}
}
Select 1 option(s)
1
12
123
2
It will throw exception at runtime.
None
29.
Question: The following is a partial code listing from an application:
rs.moveToInsertRow();
rs.updateString(1, "111");
rs.updateString(2, "Java in 24 hours");
//INSERT CODE HERE
Assuming that rs is a valid reference to an updatable ResultSet and that the result set contains only two String columns, what can be inserted in the code so that a new row is inserted in the database?
Select 1 option(s)
rs.updateRow();
rs.insertRow();
rs.commit();
rs.insert();
None
30.
Question: Given:
Path p1 = Paths.get("c:\\a\\b\\c.java");
What will p1.getName(2).toString() return?
Select 1 option(s)
a
b
c
c.java
None
31.
Question: Given :
1. The time zone of America/New York is normally 5 hours behind UTC.
2. Day light saving is ON during June in New York. (This means, clocks in New York are 1 hour ahead of the regular time that would have been shown when day light saving is OFF.)
What will the following code print when compiled and run?
LocalDateTime ldt = LocalDateTime.of(2022, 06, 02, 6, 0, 0); //Jun 2nd, 6AM.
ZoneOffset nyOffset = ZoneOffset.ofHoursMinutes(-5, 0);
ZoneId nyZone = ZoneId.of("America/New_York");
OffsetDateTime nyOdt = ldt.atOffset(nyOffset);
ZonedDateTime nyZdt = ldt.atZone(nyZone);
Duration d = Duration.between(nyOdt, nyZdt);
System.out.println(d);
Select 1 option(s)
PT1H
PT0S
PT-1H
PT0H
None
32.
Question: What will be the output of the following code snippet:
Stream ss = Stream.of("a", "b", "c", "d", "e");
Spliterator sit1 = ss.spliterator();
long s0 = sit1.estimateSize();
Spliterator sit2 = sit1.trySplit();
long s1 = sit1.estimateSize();
long s2 = sit2.estimateSize();
System.out.println( s0 - (s1+s2) );
Select 1 option(s)
0
-1
1
The result will be unpredictable.
None
33.
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
34.
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++;
35.
Question: Which statements can be inserted at line 1 in the following code to make the program write x on the standard output when run?
public class AccessTest{
String a = "x";
static char b = 'x';
String c = "x";
class Inner{
String a = "y";
String get(){
String c = "temp";
// Line 1
return c;
}
}
AccessTest() {
System.out.println( new Inner().get() );
}
public static void main(String args[]) { new AccessTest(); }
}
Select 3 option(s)
c = c;
c = this.a;
c = ""+AccessTest.b;
c = AccessTest.this.a;
c = ""+b;
36.
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
37.
Question: Given:
HashMap hm = new HashMap();
hm.put(1, "a"); hm.put(2, "b"); hm.put(3, "c");
Which of the following statements will print the keys as well as values contained in the map?
Select 1 option(s)
hm.forEach((key, entry)->System.out.println(entry));
hm.forEach(System.out.println("%d %s"));
hm.forEach((key, value)->System.out.printf("%d %s ", key, value));
hm.forEach(System.out::println);
hm.forEach(entry->System.out.println(entry));
None
38.
Question: What will the following code print when compiled and run?
public class Test{
static int a = 0;
int b = 5;
public void foo(){
while(b>0){
b--;
a++;
}
}
public static void main(String[] args) {
var p1 = new Test();
p1.foo();
var p2 = new Test();
p2.foo();
System.out.println(p1.a+" "+p2.a);
}
}
Select 1 option(s)
0 10
10 10
10 0
5 5
0 5
5 0
None
39.
Question: Given:
public class TableTest {
static String[][] table;
public static void main(String[] args) {
String[] x = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
String[] y1 = { "1", "2", "3", "4", "5" };
String[] y2 = { "a", "b", "c" };
table = new String[3][];
table[0] = x;
table[1] = y1;
table[2] = y2;
//INSERT CODE HERE
}
}
What can be inserted in the above code to make it print Sun5c?
Select 1 option(s)
for(String[] row : table){
System.out.print(row[row.length]);
}
int i = 0;
for(String[] col : table){
i++;
if(i==col.length){
System.out.print(table[col.length][i]);
}
}
for(var row : table){
System.out.print(row[row.length-1]);
}
for(int i=0; i<table.length-1; i++){
int j = table[i].length-1;
System.out.print(table[i][j]);
}
None
40.
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
41.
Question: Consider the following class :
public class Test{
public static void main(String[] args){
if (args[0].equals("open"))
if (args[1].equals("someone"))
System.out.println("Hello!");
else System.out.println("Go away "+ args[1]);
}
}
Which of the following statements are true if the above program is run with the command line :
java Test closed
Select 1 option(s)
It will throw ArrayIndexOutOfBoundsException at runtime.
It will end without exceptions and will print nothing.
It will print Go away.
It will print Go away and then will throw ArrayIndexOutOfBoundsException.
None of the above.
None
42.
Question: Which lines contain a valid constructor in the following code?
public class TestClass{
public TestClass(int a, int b) { } // 1
public void TestClass(int a) { } // 2
public TestClass(String s); // 3
private TestClass(String s, int a) { } //4
public TestClass(String s1, String s2) { }; //5
}
Select 3 option(s)
Line // 1
Line // 2
Line // 3
Line // 4
Line // 5
43.
Question: What will the following code print when compiled and run?
Select 1 option(s)
null 0
null 1
0
1
0
1
(There is a space before 0 and 1)
null
null
It will throw a RuntimeException at run time.
None
44.
Question: What will be the output of the following code:
Stream ss = Stream.of("a", "b", "a", "b", "c", "b");
Map data = ss.collect( Collectors.groupingBy(Function.identity(),
Collectors.counting()));
System.out.println( data );
Select 1 option(s)
{a=2, b=3, c=1}
[6]
{a=1, b=1, c=1}
Compilation failure.
None
45.
Question: Given the following pairs of method declarations, which of the statements are true?
1.
void perform_work(int time){ }
int perform_work(int time, int speed){ return time*speed ;}
2.
void perform_work(int time){ }
int perform_work(int speed){return speed ;}
3.
void perform_work(int time){ }
void Perform_work(int time){ }
Select 2 option(s)
The first pair of methods will compile correctly and overload the method 'perform_work'.
The second pair of methods will compile correctly and overload the method 'perform_work'.
The third pair of methods will compile correctly and overload the method 'perform_work'.
The second pair of methods will not compile correctly.
The third pair of methods will not compile correctly.
46.
Question: You have a collection which contains objects of a class X. When the collection is sorted using Collections.sort(collectionOfX);, X's compareTo() method is used. Which of the following statements are correct about this class X?
Select 2 option(s)
Class X implements Comparator interface.
Class X implements Comparable interface.
Class X neither implements Comparable nor Comparator. Object of a separate class that implements Comparator is used for sorting.
The mechanism used in this situation allows the Objects of class X to be sorted in only one way (and the reverse of that way).
47.
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;
48.
Question: Given that SomeException is a checked exception, consider the following code:
//in file A.java
public class A{
protected void m() throws SomeException{}
}
//in file B.java
public class B extends A{
public void m(){ }
}
//in file TestClass.java
public class TestClass{
public static void main(String[] args){
//insert code here. //1
}
}
Which of the following options can be inserted at //1 without resulting in any compilation or runtime errors?
Select 1 option(s)
B b = new A();
b.m();
A a = new B();
a.m();
A a = new B();
( ( B) a ).m();
Object o = new B();
o.m();
None of these.
None
49.
Question: Assuming that Book has appropriate constructor and accessor methods, what will the following code print?
List books = Arrays.asList(
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0),
new Book("Midnight Cowboy", 15.0)
);
books.stream()
.filter(b->b.getTitle().startsWith("F"))
.forEach(b->b.setPrice(10.0));
books.stream()
.forEach(b->System.out.println(b.getTitle()+":"+b.getPrice()));
Select 1 option(s)
Freedom at Midnight:5.0
Gone with the wind:5.0
Midnight Cowboy:15.0
Freedom at Midnight:5.0
Gone with the wind:10.0
Midnight Cowboy:10.0
Freedom at Midnight:10.0
Gone with the wind:5.0
Midnight Cowboy:15.0
Freedom at Midnight:10.0
Exception at run time
None
50.
Question: Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){ this.side = length; }
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
double getArea() { return area; }
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
}
}
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 4 option(s)
Add a calculateArea method:
private void calculateArea(){
this.area = this.side*this.side;
}
Make side and area fields private.
Change setSide method to:
public void setSide(double d){
this.side = d;
calculateArea();
}
Make the getArea method public.
Add a setArea() method:
public void setArea(double d){ area = d; }
51.
Question: Encapsulation ensures that ...
Select 1 option(s)
classes are able to inherit functionality from other classes.
classes expose only certain fields and methods to other classes for access.
classes designate certain methods to be abstract and let them be implemented by subclasses.
a method that takes a class X object as a parameter can be passed an object of a subclass of X.
None
52.
Question: Which of the following commands can be used to identify class and module dependencies of a class named test.A of module named moduleA without executing it?
Assume that all module files are stored in out directory.
Note: Although identifying module dependency is not explicitly mentioned in the exam objectives, we have seen questions on the exam that require you to know about the tool that is used to identify module dependencies.
Select 1 option(s)
javac --module-path out --list-dependencies moduleA/test.A
jmod --module-path out --describe test.A
javap --module-path out --show-module-resolution test.A
jdeps --module-path out out\moduleA\test\A.class
jdeps --module-path out moduleA\test.A
None
53.
Question: What will the following code print when compiled and run?
public class ATest {
String global = "111";
public int parse(String arg){
var value = 0;
try{
String global = arg;
value = Integer.parseInt(global);
}
catch(Exception e){
System.out.println(e.getClass());
}
System.out.print(global+" "+value+" ");
return value;
}
public static void main(String[] args) {
ATest ct = new ATest();
System.out.print(ct.parse("333"));
}
}
Select 1 option(s)
111 333 333
333 333 333
java.lang.NumberFormatException
java.lang.Exception
Compilation fails.
None
54.
Question: Consider the following code:
import java.io.*;
public class TestClass {
public static void main(String[] args) throws Exception {
var f = new File("x"); //1
var bfr1 = new BufferedReader(new FileReader(f)); //2
var bfr2 = new BufferedReader( bfr1 ); //3
var pw = new PrintWriter(new FileReader(f)); //4
}
}
Select the correct statements about the above program.
Select 1 option(s)
// 1 will throw an exception at runtime if a file named "x" does not exist.
//2 and //3 will compile without any error.
//4 will compile without any error.
The complete program will compile without any error.
None of these.
None
55.
Question: Consider the following code:
public static void findFiles() throws Exception{
Path dir = Paths.get("c:\\temp");
//INSERT CODE HERE
for(Path p : ds){
System.out.println(p);
}
}
catch(Exception e){
e.printStackTrace();
}
}
What should be inserted in the above code so that it will print all the files with extension gif and jpeg?
Select 1 option(s)
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
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US