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 3 Code 1Z 829
Welcome to your Java Test - 3
Name
Email
Phone
1.
Question: Consider the standard 'put' method of class HashMap.
public Object put(Object key, Object value);
Select 1 option(s)
It always returns null.
It always returns value ( i.e. the 2nd parameter).
Neither of key or value can be null otherwise a NullPointerException is thrown.
Key cannot be null but value may be null.
It may throw a DuplicateKeyException.
None of these.
None
2.
Question: What will the following code snippet print?
Stream strm1 = Stream.of(2, 3, 5, 7, 11, 13);
double av = strm1
.filter(x->{ if(x>10)return true; else return false;}) //1
.peek() //2
.collect(Collectors.averagingInt(y->y)); //3
System.out.println(av);
Select 1 option(s)
12
12.0
Compilation failure due to code at //1
Compilation failure due to code at //2
Compilation failure due to code at //3
Exception at run time.
None
3.
Question: Which of the following method would you use to get a JDBC connection while using JDBC 4.0 but not while using a previous version of JDBC?
Select 2 option(s)
public Connection getConnection1(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("user", userid);
p.setProperty("password", pwd);
return DriverManager.getConnection(url, p);
}
public Connection getConnection2(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("user", userid);
p.setProperty("password", pwd);
DriverManager.registerDriver("com.xyz.Driver");
return DriverManager.getConnection(url, p);
public Connection getConnection3(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("jdbc.driver", "com.xyz.Driver");
p.setProperty("jdbc.user", userid);
p.setProperty("jdbc.user.password", pwd);
return DriverManager.getConnection(url, p);
}
public Connection getConnection4(String url, String userid, String pwd) throws Exception{
Class.forName("com.xyz.Driver");
return DriverManager.getConnection(url, userid, pwd);
}
public Connection getConnection5(String url, String userid, String pwd) throws SQLException{
return DriverManager.getConnection(url, userid, pwd);
}
4.
Question: What will the following code print?
Path p1 = Paths.get("c:\\temp\\test.txt");
Path p2 = Paths.get("report.pdf");
System.out.println(p1.resolve(p2));
Select 1 option(s)
..\report.pdf
c:\temp\test.txt\report.pdf
c:\temp\report.pdf
It will throw an exception.
None
5.
Question: Given:
class Base{
public Map getMap(T t, Z z)
{
return new HashMap();
}
}
class Derived extends Base{
/* public TreeMap getMap(T t, Z z) {
return new TreeMap();
}; */ //1
/* public Map getMap(Number t, Number z) {
return new TreeMap();
}; */ //2
/* public Map getMap(Number t, Number z) {
return new HashMap();
};*/ //3
}
Identify correct statements about the methods defined in Derived assuming they are uncommented one at a time individually.
Select 1 option(s)
//1 correctly overloads while //2 and //3 correctly override the method in Base.
//1 will not compile while //2 and //3 correctly overload the method in Base.
//1 correctly overloads the method in Base while //2 and //3 will not compile.
//1 correctly overrides while //2 and //3 correctly overloads the method in Base.
//1 and //3 will compile while //2 will not.
//1 and //2 will compile while //3 will not.
None
6.
Question: Which of the following statements are valid?
Select 3 option(s)
String[ ] sa = new String[3]{ "a", "b", "c"};
String sa[ ] = { "a ", " b", "c"};
String sa = new String[ ]{"a", "b", "c"};
String sa[ ] = new String[ ]{"a", "b", "c"};
String sa[ ] = new String[ ] {"a" "b" "c"};
var sa = new String[ ]{"a", "b", "c"};
7.
Question: Given that a table named STOCK exists with nullable columns as follows:
What can be inserted in the above code so that a row with values (1, "APPL", null, null) will be inserted in the STOCK table?
Select 1 option(s)
ps.setNull(3, JDBCType.INTEGER);
ps.setNull(4, JDBCType.STRING);
ps.setNull(3, JDBCType.INTEGER);
ps.setNull(4, JDBCType.VARCHAR);
ps.setNull(3, Types.INTEGER);
ps.setNull(4, Types.STRING);
Integer ltp = null;
ps.setInt(3, ltp);
ps.setString(4, ltp);
ps.setNull(3, Types.INTEGER);
ps.setString(4, null);
None
8.
Question: What two changes can you do, independent of each other, to make the following code compile:
//assume appropriate imports
class PortConnector {
public PortConnector(int port) {
//assume that random() returns a random value
//between 0.0 (inclusive) and 1.0 (exclusive)
if (Math.random() > 0.5) {
throw new IOException();
}
throw new RuntimeException();
}
}
public class TestClass {
public static void main(String[] args) {
try {
PortConnector pc = new PortConnector(10);
} catch (RuntimeException re) {
re.printStackTrace();
}
}
}
Select 2 option(s)
add throws IOException to the main method.
add throws IOException to PortConnector constructor.
add throws IOException to the main method as well as to PortConnector constructor.
Change RuntimeException to java.io.IOException.
add throws Exception to PortConnector constructor and change catch(RuntimeException re) to catch(Exception re) in the main method.
9.
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
10.
Question: Consider the following class...
class TestClass{
int i;
public TestClass(int i) { this.i = i; }
public String toString(){
if(i == 0) return null;
else return ""+i;
}
public static void main(String[ ] args){
TestClass t1 = new TestClass(0);
TestClass t2 = new TestClass(2);
System.out.println(t2);
System.out.println(""+t1);
}
}
What will be the output when the above program is run?
Select 1 option(s)
It will throw NullPointerException when run.
It will not compile.
It will print 2 and then will throw NullPointerException.
It will print 2 and null.
None of the above.
None
11.
Question: What will the following program print?
class Test{
public static void main(String args[]){
var k = 9;
var s = 5;
switch(k){
default :
if( k == 10) { s = s*2; }
else{
s = s+4;
break;
}
case 7 : s = s+3;
}
System.out.println(s);
}
}
Select 1 option(s)
5
9
12
It will not compile.
None
12.
Question: What, if anything, is wrong with the following code?
//Filename: TestClass.java
class TestClass implements T1, T2{
public void m1(){}
}
interface T1{
int VALUE = 1;
void m1();
}
interface T2{
int VALUE = 2;
void m1();
}
Select 1 option(s)
TestClass cannot implement them both because it leads to ambiguity.
There is nothing wrong with the code.
The code will work fine only if VALUE is removed from one of the interfaces.
The code will work fine only if m1() is removed from one of the interfaces.
None of the above.
None
13.
Question: What will be printed when the following code is compiled and run?
package trywithresources;
import java.io.IOException;
public class Device implements AutoCloseable{
String header = null;
public void open(){
header = "OPENED";
System.out.println("Device Opened");
}
public String read() throws IOException{
throw new IOException("Unknown");
}
public void writeHeader(String str) throws IOException{
System.out.println("Writing : "+str);
header = str;
}
public void close(){
header = null;
System.out.println("Device closed");
}
public static void testDevice(){
Device d = new Device();
try(d){
d.open();
d.read();
d.writeHeader("TEST");
d.close();
}catch(IOException e){
System.out.println("Got Exception");
}
}
public static void main(String[] args) {
Device.testDevice();
}
}
Select 1 option(s)
Device Opened
Device closed
Got Exception
Device Opened
Got Exception
Device closed
Device Opened
Got Exception
The code will not compile.
None
14.
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
io
ou
ei
aeiou
Compilation error
None
15.
Question: Which of the following statements are true regarding the try-with-resources statement?
Select 1 option(s)
Resources are closed in the same order of their creation.
Resources may not be closed properly if the code in the try block throws an exception for which there is no catch block.
Resources may not be closed properly if the code in the catch block throws an exception.
catch and finally blocks are executed after the resources opened in the try blocks are closed.
None
16.
Question: What will the following code print?
List names = Arrays.asList("Peter", "Paul", "Pascal");
Optional ops = names.stream()
.parallel()
.allMatch(name->name!=null)
.filter(name->name.length()>6)
.findAny();
System.out.println(ops);
Select 1 option(s)
It may print any name out of the three in the list.
It will print Optional.empty
It will print Optional[Peter]
It will not compile.
None
17.
Question: You are given two modules named enthu.training and enthu.course packaged in training.jar and course.jar. The training module depends on the course module. You want to run a class named com.enthu.training.StartGUI contained in enthu.training module.
Which of the following commands can be used?
Select 1 option(s)
java --module-path training.jar;course.jar --main-class com.enthu.training.StartGUI
java --module-path training.jar;course.jar --main-class enthu.training/com.enthu.training.StartGUI
java --module-path training.jar -classpath course.jar --main-class com.enthu.training.StartGUI
java --module-path training.jar;course.jar --module enthu.training/com.enthu.training.StartGUI
java --module-path training.jar;course.jar --module enthu.training
None
18.
Question: Given:
import java.io.FileNotFoundException;
import java.io.IOException;
public class Scrap {
public static void main(String[] args) {
try{
if(args.length == 0) m2(); else m3();
}
INSERT CODE HERE
}
public static void m2() throws IOException {
throw new FileNotFoundException(); }
public static void m3() throws IndexOutOfBoundsException{
throw new IndexOutOfBoundsException(); }
}
Assuming that the above code is always invoked with at least one argument, what can be inserted in the above code to make it compile?
Select 2 option(s)
catch(IOException e){ }
catch(FileNotFoundException fe){ }
catch(IOException|IndexOutOfBoundsException e){ }
catch(FileNotFoundException|IndexOutOfBoundsException e){ }
catch(RuntimeException re){ }
19.
Question: Which line, if any, will give a compile time error?
void test(byte x){
switch(x){
case 'a': // 1
case 256: // 2
case 0: // 3
default : // 4
case 80: // 5
}
}
Select 1 option(s)
Line 1 as 'a' is not compatible with byte.
Line 2 as 256 cannot fit into a byte.
No compile time error but a run time error at line 2.
Line 4 as the default label must be the last label in the switch statement.
There is nothing wrong with the code.
None
20.
Question: Which of the following expressions will evaluate to true if preceded by the following code?
String a = "java";
char[] b = { 'j', 'a', 'v', 'a' };
String c = new String(b);
String d = a;
Select 3 option(s)
(a == d)
(b == d)
(a == "java")
a.equals(c)
21.
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
22.
Question: What will the following code print when run?
Deque d = new ArrayDeque();
d.push(1);
d.push(2);
d.push(3);
System.out.println(d.remove());
System.out.println(d.remove());
System.out.println(d.remove());
Select 1 option(s)
1
2
3
3
2
1
Compilation error
Exception at run time
None
23.
Question: Complete the following code by filling the two blanks -
class XXX{
public void m() throws Exception{
throw new Exception();
}
}
class YYY extends XXX{
public void m(){ }
public static void main(String[] args) {
________ obj = new ______();
obj.m();
}
}
Select 1 option(s)
XXX XXX
XXX YYY
YYY XXX
YYY YYY
None
24.
Question: Given:
public class Switcher{
public static void main(String[] args){
switch(Integer.parseInt(args[1])) //1
{
case 0 :
var b = false; //2
break;
case 1 :
b = true; // 3
break;
}
if(b) System.out.println(args[2]); //4
}
}
What will the above program print if compiled and run using the following command line:
java Switcher 1 2 3
Select 1 option(s)
It will print 1
It will print 2
It will print 3
It will not print anything.
It will not compile because of //1.
It will not compile because of //2.
It will not compile because of //3.
It will not compile because of //4.
None
25.
Question: Identify the correct statements about the following code -
IntStream is1 = IntStream.of(1, 3, 5); //1
OptionalDouble x = is1.filter(i->i%2 == 0).average(); //2
System.out.println(x); //3
IntStream is2 = IntStream.of(2, 4, 6); //4
int y = is2.filter( i->i%2 != 0 ).sum(); //5
System.out.println(y); //6
Select 1 option(s)
Compilation failure only at //2
Compilation failure only at //5
Compilation failure at //2 and //5
Successful compilation
None
26.
Question: Which of the following code fragments are valid method declarations?
Select 1 option(s)
void method1{ }
void method2( ) { }
void method3(void){ }
var method4{ }
method5(void){ }
String method6(var x){ return ""+x; }
sealed void method7(){ }
None
27.
Question: Given:
String sentence =
"Life is a box of chocolates, Forrest. You never know what you're gonna get."; //1
Optional theword =
Stream.of(sentence.split("[ ,.]")).anyMatch(w->w.startsWith("g")); //2
System.out.println(theword.get()); //3
Which of the following statements are correct?
Select 1 option(s)
It may print either gonna or get.
It will print gonna.
It may print either gonna or get if lines //2 and //3 are changed to:
String theword = Stream.of(sentence.split("[ ,.]"))
.anyMatch(w->w.startsWith("g")); //2
System.out.println(theword.get);//3
It may print either gonna or get if lines //2 and //3 are changed to:
Optional< String > theword =
Stream.of(sentence.split("[ ,.]")).parallel().anyMatch(w->w.startsWith("g")); //2
System.out.println(theword.get()); //3
It will fail to compile.
None
28.
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
29.
Question: What will the following code print?
Path p1 = Paths.get("c:\\temp\\test.txt");
Path p2 = Paths.get("c:\\temp\\report.pdf");
System.out.println(p1.resolve(p2));
Select 1 option(s)
..\report.pdf
temp\report.pdf
report.pdf
c:\temp\report.pdf
None
30.
Question: What will the following code print?
AtomicInteger ai = new AtomicInteger();
Stream stream = Stream.of(11, 11, 22, 33).parallel();
stream.filter( e->{
ai.incrementAndGet();
return e%2==0;
});
System.out.println(ai);
Select 1 option(s)
0
Any number between 1 to 4.
4
Any number between 0 to 3
None
31.
Question: Consider the following classes...
class Teacher{
void teach(String student){
/* lots of code */
}
}
class Prof extends Teacher{
//1
}
Which of the following methods can be inserted at line //1 ?
Select 4 option(s)
public void teach() throws Exception
private void teach(int i) throws Exception
protected void teach(String s)
public final void teach(String s)
public abstract void teach(String s)
32.
Question: Given:
public class Data implements Serializable{
int id;
transient LocalDate ld;
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
ld = LocalDate.of(2020,1,1);
}
}
Identify the correct statements about the above code.
Select 1 option(s)
This class does not perform serialization/deserialization correctly because it does not implement writeObject method.
The readObject method will be invoked after a Data object is deserialized.
The readObject method will be invoked before a Data object is deserialized.
The readObject method will never be invoked.
The readObject method will be invoked after a Data object is serialized.
The readObject method will be invoked before a Data object is serialized.
None
33.
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.
34.
Question: Which of these are valid expressions to create a string of value "hello world" ?
Select 3 option(s)
35.
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
36.
Question: Consider the following method...
public static void ifTest(boolean flag){
if (flag) //1
if (flag) //2
if (flag) //3
System.out.println("False True");
else //4
System.out.println("True False");
else //5
System.out.println("True True");
else //6
System.out.println("False False");
}
Which of the following statements are correct ?
Select 2 option(s)
If run with an argument of 'false', it will print 'False False'
If run with an argument of 'false', it will print 'True True'
If run with an argument of 'true', it will print 'True False'
It will never print 'True True'
It will not compile.
37.
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
38.
Question: What can be inserted in the code below so that it will print UP UP UP?
public class Speak {
public static void main(String[] args) {
Speak s = new GoodSpeak();
INSERT CODE HERE
}
}
class GoodSpeak extends Speak implements Tone{
public void up(){
System.out.println("UP UP UP");
}
}
interface Tone{
void up();
}
Select 2 option(s)
((Tone)s).up();
s.up();
((GoodSpeak)s).up();
(GoodSpeak)s.up();
(Tone)(GoodSpeak)s.up();
39.
Question: Given the following code:
interface Readable{ }
non-sealed class Device implements Readable { }
sealed class DocType implements Readable permits Book, Journal { }
final non-sealed class Book extends DocType{ }
final class Journal extends DocType{ }
Which types will fail compilation?
Select 2 option(s)
Readable
Device
DocType
Book
Journal
40.
Question: What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[]){
int x = 0;
labelA: for (var i=10; i<0; i--){
var j = 0;
labelB:
while (j < 10){
if (j > i) break labelB;
if (i == j){
x++;
continue labelA;
}
j++;
}
x--;
}
System.out.println(x);
}
}
Select 1 option(s)
It will not compile.
It will go in infinite loop when run.
The program will write 10 to the standard output.
The program will write 0 to the standard output.
None of the above.
None
41.
Question: Which of the following statements are true?
Select 1 option(s)
For any non-null reference o1, the expression (o1 instanceof o1) will always yield true.
For any non-null reference o1, the expression (o1 instanceof Object) will always yield true.
For any non-null reference o1, the expression (o1 instanceof o1) will always yield false.
For any non-null reference o1, the expression (o1 instanceof Object) may yield false.
None of the above.
None
42.
Question: What is the result of executing the following fragment of code:
boolean b1 = false;
int i1 = 2;
int i2 = 3;
if (b1 = i1 == i2){
System.out.println("true");
} else{
System.out.println("false");
}
Select 1 option(s)
Compile time error.
It will print true.
It will print false.
Runtime error.
It will print nothing.
None
43.
Question: Although jmod is not on the part exam you might still see it mentioned in one of the incorrect options. You may read about jmod if you have time.
Which of the following options are supported by jmod?
Select 4 option(s)
create
add
delete
list
extract
describe
44.
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
45.
Question: Consider the following code:
interface Flyer{ String getName(); }
class Bird implements Flyer{
public String name;
public Bird(String name){
this.name = name;
}
public String getName(){ return name; }
}
class Eagle extends Bird {
public Eagle(String name){
super(name);
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
Flyer f = new Eagle("American Bald Eagle");
//PRINT NAME HERE
}
}
Which of the following lines of code will print the name of the Eagle object?
Select 3 option(s)
System.out.println(f.name);
System.out.println(f.getName());
System.out.println(((Eagle)f).name);
System.out.println(((Bird)f).getName());
System.out.println(Eagle.name);
System.out.println(Eagle.getName(f));
46.
Question: Given:
interface Book{
public default String getId(){
return "ISBN123456";
}
}
interface Encyclopedia extends Book{
//INSERT CODE HERE
}
Which of the following options can be inserted in Encyclopedia independent of each other?
Select 2 option(s)
static String getId(){
return "AIN8888";
}
String getId();
default String getId(){
return "AIN8888";
};
abstract static String getName();
static String getAuthor();
default String getAuthor();
private String getId(){
return "ISBN123456";
}
47.
Question: Given:
package strings;
public class StringFromChar {
public static void main(String[] args) {
String myStr = "good";
char[] myCharArr = {'g', 'o', 'o', 'd' };
String newStr = "";
for(char ch : myCharArr){
newStr = newStr + ch;
}
boolean b1 = newStr == myStr;
boolean b2 = newStr.equals(myStr);
System.out.println(b1+ " " + b2);
}
}
What will it print when compiled and run?
Select 1 option(s)
true true
true false
false true
false false
None
48.
Question: Which of the following is a valid module-info for a service user module that uses an Order service defined in OrderServiceAPI module and implemented by OrderServiceProvider module?
Select 2 option(s)
module Customer{
requires OrderServiceAPI;
uses com.orderservice.api.Order;
}
module Customer{
requires OrderServiceProvider;
uses com.orderservice.api.Order;
}
module Customer{
requires OrderServiceAPI;
requires OrderServiceProvider;
uses com.orderservice.api.Order;
}
module Customer{
uses OrderServiceAPI;
}
module Customer{
uses OrderServiceAPI;
requires com.orderservice.api.Order;
}
49.
Question: Consider the following method:
public void getLocks(Object a, Object b)
{
synchronized(a)
{
synchronized(b)
{
//do something
}
}
}
and the following instantiations:
Object obj1 = new Object();
Object obj2 = new Object();
obj1 and obj2 are accessible to two different threads and the threads are about to call the getLocks() method. Assume the first thread calls the method getLocks(obj1, obj2). Which of the following options avoids a deadlock?
Select 1 option(s)
The second thread should call getLocks(obj2, obj1)
The second thread should call getLocks(obj1, obj2)
The second thread must call getLocks() only after first thread exits out of it.
The second thread may call getLocks() any time and passing parameters in any order.
None of the above.
None
50.
Question: Given that java.lang.String has two overloaded toUpperCase methods - toUpperCase() and toUpperCase(Locale ), consider the following code:
String name = "bob";
String val = null;
//Insert code here
System.out.print(val);
Which of the following code fragments can be inserted in the above code so that it will print BOB?
Select 2 option(s)
Supplier< String > s = name::toUpperCase;
val = s.get();
Supplier< String > s = name::toUpperCase;
val = s.apply();
Function< String > f = name::toUpperCase;
val = f.get();
Function< String > f = name::toUpperCase;
val = f.apply();
Function< String, Locale > f = name::toUpperCase;
val = f.apply();
Only one of the above is correct.
51.
Question: Consider the following lines of code:
System.out.println(null + true); //1
System.out.println(true + null); //2
System.out.println(null + null); //3
Which of the following statements are correct?
Select 1 option(s)
None of the 3 lines will compile.
All the 3 lines will compile and print nulltrue, truenull and nullnull respectively.
Line 1 and 2 won't compile but line 3 will print nullnull.
Line 3 won't compile but line 1 and 2 will print nulltrue and truenull respectively.
None of the above.
None
52.
Question: Given the following code:
sealed interface Cacheable permits Value, Result{
default void clear(){ System.out.println("clearing cache..."); }
}
Which of the following definition will compile without error?
Select 1 option(s)
non-sealed interface Value extends Cacheable{ }
non-sealed interface Result extends Cacheable{ }
interface Value extends Cacheable{ }
interface Result extends Cacheable{ }
sealed interface Value extends Cacheable{ }
sealed interface Result extends Cacheable{ }
None of the above.
None
53.
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
54.
Question: Given that daylight Savings Time ends on Nov 6 at 2 AM in US/Eastern time zone. (As a result, 2 AM becomes 1 AM. In other words, one minute after 1.59 AM, the clock shows 1 AM instead of 2 AM.), what will the following code print?
LocalDateTime ld1 = LocalDateTime.of(2022, Month.NOVEMBER, 6, 2, 0);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2022, Month.NOVEMBER, 6, 1, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));
long x = ChronoUnit.HOURS.between(zd1, zd2);
System.out.println(x);
Select 1 option(s)
1
-1
0
2
-2
It will not compile.
None
55.
Question: Identify the valid enum declarations.
Select 2 option(s)
//in file Pets.java
enum Pets implements java.io.Serializable
{
DOG("D"), CAT("C"), FISH("F");
String name;
Pets(String s) { }
public String getData(){ return name; }
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
static String prefix = "I am ";
String name;
Pets(String s) { name = prefix + s;}
public String getData(){ return name; }
}
//in file Pets.java
public enum Pets
{
DOG(1, "D"),
CAT(2, "C")
{
public String getData(){ return type+name; }
},
FISH(3, "F");
int type;
String name;
Pets(int t, String s) { this.name = s; this.type = t;}
public String getData(){ return name+type; }
}
//in file Pets.java
enum Pets
{
String name;
DOG("D"), CAT("C"), FISH("F");
Pets(String s) { name = s;}
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
String name;
public Pets(String s) { }
public String getData(){ return name; }
}
//in file Pets.java
enum Pets
{
DOG("D"), CAT("C"), FISH("F");
var name;
Pets(String s) { name = s; }
public String getData(){ return (String) name; }
}
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