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 - 14
Name
Email
Phone
1.
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
2.
Question: Which of the following statements are correct regarding synchronization and locks?
Select 2 option(s)
A thread exclusively owns the intrinsic lock between the time it has acquired the lock and released the lock.
A thread can acquire a lock on the class.
A thread will release the intrinsic lock if the synchronized method calls a non-synchronized method and then reacquire the lock upon returning from that method.
Java allows a thread to acquire the intrinsic lock of only one object at a time to prevent deadlocks.
3.
Question: What will be printed by the following code if it is run with command line: java TestClass -0.50 ?
public class TestClass{
public static double getSwitch(String str){
return Double.parseDouble(str.substring(1, str.length()-1) );
}
public static void main(String args []){
switch(getSwitch(args[0])){
case 0.0 : System.out.println("Hello");
case 1.0 : System.out.println("World"); break;
default : System.out.println("Good Bye");
}
}
}
Select 1 option(s)
Hello
World
Hello World
Hello World Good Bye
None of the above.
None
4.
Question: Given the following method code:
public void myMethod() throws MyException {
//method code
}
Select 1 option(s)
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be an unchecked exception.
If the throws MyException clause is removed from the method and if the method fails to compile, then MyException must be extending RuntimeException.
A method that calls myMethod must wrap the call in a try block.
The code in myMethod can throw only MyException.
If MyException class is made to extend RuntimeException, there would be no impact on myMethod.
None
5.
Question: Which of the following are valid implementations of java.util.Comparator?
Select 3 option(s)
6.
Question: Which statements regarding the following code are correct?
class Outer
{
private void Outer() { }
protected class Inner
{
}
}
Select 1 option(s)
This code will not compile.
Constructor for Outer is public.
Constructor for Outer is private.
Constructor for Inner is public.
Constructor for Inner is protected.
None
7.
Question: What will be the output of the following program?
class Test
{
static int i1, i2, i3;
public static void main(String[] args)
{
try
{
test(i1 = 1, oops(i2=2), i3 = 3);
} catch (Exception e)
{
System.out.println(i1+" "+i2+" "+i3);
}
}
static int oops(int i) throws Exception
{
throw new Exception("oops");
}
static int test(int a, int b, int c) {
return a + b + c;
}
}
Select 1 option(s)
1 0 0
1 2 0
1 2 3
0 0 0
It will not compile.
None
8.
Question: Given:
class Course{
private String id;
private String name;
public Course(String id, String name){
this.id = id; this.name = name;
}
//accessors not shows
}
What will the following code print?
List cList = Arrays.asList(
new Course("803", "OCAJP 7"),
new Course("808", "OCAJP 8"),
new Course("809", "OCPJP 8")
);
cList.stream().filter(c->c.getName().indexOf("8")>-1)
.map(c->c.getId())
.collect(Collectors.joining("1Z0-"));
cList.stream().forEach(c->System.out.println(c.getId()));
Select 1 option(s)
803
808
809
803
1Z0-808
1Z0-809
1Z0-808
1Z0-809
It will throw an exception at run time.
It will not compile.
None
9.
Question: What will the following code print when compiled and run?
List ls = Arrays.asList(1, 2, 3);
ls.stream().forEach(System.out::print)
.map(a->a*2)
.forEach(System.out::print);
Select 1 option(s)
123
246
Compilation failure.
Exception at run time.
None
10.
Question: Which of the following statements are true?
Select 2 option(s)
Method length() of String class is a final method.
You can make mutable subclasses of the String class.
StringBuilder extends String.
StringBuilder is a final class.
String class is not final.
11.
Question: What will be printed when the following code is compiled and run?
public class LoadTest{
public static void main(String[] args) throws Exception {
LoadTest t = new LoadTest();
int i = t.getLoad();
double d = t.getLoad();
System.out.println( i + d );
}
public int getLoad() {
return 1;
}
public double getLoad(){
return 3.0;
}
}
Select 1 option(s)
13.0
4.0
4
The code will not compile.
None
12.
Question: Given the following code:
class M { }
class N{
private M m = new M();
public void makeItNull(M pM){
pM = null;
}
public void makeThisNull(){
makeItNull(m);
}
public static void main(String[] args){
N n = new N();
n.makeThisNull();
}
}
Which of the following statements are correct?
Select 1 option(s)
There are no instances of M to be garbage collected till the program ends.
A call to n.makeThisNull() marks the private instance of M for garbage collection.
Setting pM = null; in makeItNull(), marks the private instance of M for garbage collection.
Private members of a class become eligible for garbage collection only when the instance of the class itself becomes eligible for garbage collection.
None
13.
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
14.
Question: What would be the result of attempting to compile and run the following program?
class TestClass{
static TestClass ref;
String[] arguments;
public static void main(String args[]){
ref = new TestClass();
ref.func(args);
}
public void func(String[] args){
ref.arguments = args;
}
}
Select 1 option(s)
The program will fail to compile, since the static method main is trying to call the non-static method func.
The program will fail to compile, since the non-static method func cannot access the static member variable ref.
The program will fail to compile, since the argument args passed to the static method main cannot be passed on to the non-static method func.
The program will fail to compile, since method func is trying to assign to the non-static member variable 'arguments' through the static member variable ref.
The program will compile and run successfully.
None
15.
Question: Given that classes B1 and B2 extend class A and classes C1, C2 are subclasses of B1.
Further, assume that method public void m1(){ ... } is defined in all of these classes EXCEPT B1 and C1.
class A{
public void m1(){ }
}
class B1 extends A{
}
class B2 extends A{
public void m1(){ }
}
class C1 extends B1{
}
class C2 extends B1{
public void m1(){ }
}
Assume that "objectOfXX" means a variable that points to an object of class XX. So, objectOfC1 means a reference variable that is pointing to an object of class C1.
Which of the following statements are correct?
Select 1 option(s)
ObjectOfC1.m1(); will cause a compilation error.
ObjectOfC2.m1(); will cause A's m1() to be called.
ObjectOfC1.m1(); will cause A's m1() to be called.
ObjectOfB1.m1(); will cause an exception at runtime.
ObjectOfB2.m1(); will cause an exception at runtime.
None
16.
Question: What will the following code print when compiled and run?
List iList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
Predicate p = x->x%2==0;
List newList = iList.stream().filter(p).filter(x->x>3).collect(Collectors.toList());
System.out.println(newList);
Select 1 option(s)
It will fail to compile.
Null.
[1]
[2]
[5, 7]
[4, 6]
None
17.
Question: Identify correct statement about the following code -
class X{
int val = 10;
}
class Y extends X{
Y val = null; //1
}
public class TestClass extends X{
public static void main(String[] args){
Y y = new Y();
int k = (X) y.val ; //2
System.out.println(k);
}
}
Select 1 option(s)
It will compile and print 10 when run.
It will fail to compile due to line marked //1.
It will fail to compile due to line marked //2.
It will compile but will throw a NullPointerException at line marked //2.
None
18.
Question: What can be inserted in the following code at //1 so that it will print the number of lines present in the given file?
public void countLines(String filePath) throws Exception{
//1
System.out.println(ref.count());
}
Select 1 option(s)
Stream
String
ref = new BufferedReader(new FileReader("c:\\temp\\test.txt")).
lines();
Stream
String
ref = new BufferedReader(
new FileReader(Paths.get("c:\\temp\\test.txt"))).lines();
Stream
String
ref = new BufferedReader(new FileReader("c:\\temp\\test.txt"))
.readLines();
Stream< String > ref = Files.lines("c:\\temp\\test.txt");
None
19.
Question: Given the following declarations, identify which statements will return true:
Integer i1 = 1;
Integer i2 = new Integer(1);
int i3 = 1;
Byte b1 = 1;
Long g1 = 1L;
Double d = 1.0;
Select 2 option(s)
i1 == i2
i1 == i3
i1 == b1
i1.equals(i2)
i1.equals(g1)
i1.equals(b1)
d > 1L
20.
Question: What will the following program print?
public class TestClass{
public static void main(String[] args){
int x = 1;
int y = 0;
if( x/y ) System.out.println("Good");
else System.out.println("Bad");
}
}
Select 1 option(s)
Good
Bad
Exception at runtime saying division by Zero.
It will not compile.
None of the above.
None
21.
Question: What will the following code print when compiled and run?
class Base{
void methodA(){
System.out.println("base - MethodA");
}
}
class Sub extends Base{
public void methodA(){
System.out.println("sub - MethodA");
}
public void methodB(){
System.out.println("sub - MethodB");
}
public static void main(String args[]){
Base b=new Sub(); //1
b.methodA(); //2
b.methodB(); //3
}
}
Select 1 option(s)
Sub - MethodA and sub - MethodB.
Base - MethodA and sub - MethodB.
Compile time error at //1.
Compile time error at //2.
Compile time error at //3.
None
22.
Question: Which of the following code snippets will compile without any errors?
(Assume that the statement int x = 0; exists prior to the statements below.)
Select 3 option(s)
While (false) { x=3; }
If (false) { x=3; }
Do{ x = 3; } while(false);
For( var i = 0; i< 0; i++) x = 3;
23.
Question: Given:
public static void createFile(String name) throws Exception{
try (
OutputStream os = new FileOutputStream(name); ) {
//INSERT CODE HERE
//flush and close the streams that are open
}
}
Which of the following combinations of the lines of code and their outcome when inserted above, are correct?
Select 2 option(s)
var pw = new PrintWriter(os);
pw.write(1);
Size of the file depends on default character encoding.
os.write(99);
A file of size 1 byte will be created.
var bos = new BufferedOutputStream(os);
var pw = new PrintWriter(bos);
pw.print(99);
A file of size 1 byte will be created.
os.writeInt(99);
A file of size 4 bytes will be created.
var pw = new PrintWriter(os);
pw.writeInt(1);
A file of size 4 bytes will be created.
24.
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
25.
Question: What will the following program print?
public class TestClass{
static int someInt = 10;
public static void changeIt(int a){
a = 20;
}
public static void main(String[] args){
changeIt(someInt);
System.out.println(someInt);
}
}
Select 1 option(s)
10
20
It will not compile.
It will throw an exception at runtime.
None of the above.
None
26.
Question: Given:
public class Course{
private String id;
private String category;
public Course(String id, String category){
this.id = id; this.category = category;
}
public String toString(){
return id+" "+category;
}
//accessors not shown
}
What will the following code print?
List s1 = Arrays.asList(
new Course("OCAJP", "Java"),
new Course("OCPJP", "Java"),
new Course("C#", "C#"),
new Course("OCEJPA", "Java")
);
s1.stream()
.collect(Collectors.groupingBy(c->c.getCategory()))
.forEach((m, n)->System.out.println(n));
Select 1 option(s)
C# C#
OCAJP Java, OCPJP Java, OCEJPA Java
[C# C#]
[OCAJP Java, OCPJP Java, OCEJPA Java]
[C#]
[OCAJP OCPJP OCEJPA]
C#
OCAJP OCPJP OCEJPA
None
27.
Question: Given the following classes, what will be the output of compiling and running the class Truck?
class Automobile{
public void drive() { System.out.println("Automobile: drive"); }
}
public class Truck extends Automobile{
public void drive() { System.out.println("Truck: drive"); }
public static void main (String args [ ]){
Automobile a = new Automobile();
Truck t = new Truck();
a.drive(); //1
t.drive(); //2
a = t; //3
a.drive(); //4
}
}
//End of Code
Select 1 option(s)
Compiler error at line 3.
Runtime error at line 3.
It will print:
Automobile: drive
Truck: drive
Automobile: drive
in that order.
It will print:
Automobile: drive
Truck: drive
Truck: drive
in that order.
It will print:
Automobile: drive
Automobile: drive
Automobile: drive
in that order.
None
28.
Question: What will the following code print?
List s1 = new ArrayList();
String s = null;
s1.add("a");
s1.add(s); //1
s1.add("b");
s1.remove(s); //2
System.out.println(s1); //3
Select 1 option(s)
A NullPointerException will be thrown at line marked //1.
A NullPointerException will be thrown at line marked //2.
A NullPointerException will be thrown at line marked //3.
[a, b]
[a, null, b]
[]
None
29.
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
30.
Question: Which of the following method implementations will write a boolean value to the underlying stream?
Select 3 option(s)
public void usePrintWriter(PrintWriter pw){
boolean bval = true;
pw.writeBoolean(bval);
}
public void usePrintWriter(PrintWriter pw) throws IOException{
boolean bval = true;
pw.write(bval);
}
public void usePrintWriter(PrintWriter pw) throws IOException{
boolean bval = true;
pw.print(bval);
}
public void usePrintWriter(PrintWriter pw) {
boolean bval = true;
pw.print(bval);
}
public void usePrintWriter(PrintWriter pw) {
boolean bval = true;
pw.println(bval);
}
31.
Question: Consider the following code written to generate a report containing customer data where each line is a pipe separated list of values.
String qr = "select EMAILID, NAME, PHONE from CUSTOMER order by EMAILID";
PreparedStatement stmt = connection.prepareStatement(qr);
ResultSet rs = stmt.executeQuery(); //LINE 10
while(rs.next()){
System.out.println(rs.getString(0)+"|"+rs.getString(1)+"|"+rs.getString(3));
}
connection.close();
Identify the correct statement about this code.
(Assume that items not specified such as import statements and try/catch block are all valid.)
Select 1 option(s)
It will throw an exception when run if there is at least 1 record in the table.
It will throw an exception when run if there are no records in the table.
It will print the data as expected.
It will not compile.
None
32.
Question: The signature of a method in a class is as follows:
public static List doIt(List nums)
This method is being called in the following code:
result = doIt(in);
Given that String implements CharSequence interface, what should be the reference type of 'in' and 'result' variables?
Select 1 option(s)
ArrayList< String > in;
List< CharSequence > result;
List
String
in;
List
Object
result;
ArrayList
String
in;
List result;
List
CharSequence
in;
List
CharSequence
result;
ArrayList< Object > in;
List< CharSequence > result;
None of these.
None
33.
Question: Given:
@Retention(RetentionPolicy.RUNTIME)
public @interface DebugInfo {
String[] params() default {""};
String date() default "";
int depth() default 10;
String value() ;
}
Which of the following options correctly uses the above annotation?
Select 3 option(s)
34.
Question: Consider the following class hierarchy.
class A{
public void m1() { }
}
class B extends A{
public void m1() { }
}
class C extends B{
public void m1(){
/* //1
... lot of code.
*/
}
}
Select 2 option(s)
You cannot access class A's m1() from class C for the same object ( i.e. this).
You can access class B's m1() using super.m1() from class C.
You can access class A's m1() using ( (A) this ).m1() from class C.
You can access class A's m1() using super.super.m1() from class C.
35.
Question: Consider the following code:
Statement stmt = null;
try(Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app"))
{
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from STUDENT");
while(rs.next()){
System.out.println(rs.getString(1));
}
}
catch(SQLException e){
System.out.println("Exception "+e);
}
Which objects can be successfully used to query the database after the try block ends without any exception?
Select 1 option(s)
Stmt
c
rs
Stmt as well c.
None of them.
None
36.
Question: Given:
public class Book{
private int id;
private String title;
//constructors and accessors not shown
}
Assuming that book is a reference to a valid Book object, which of the following code fragments correctly prints the details of the Book?
Select 1 option(s)
None
37.
Question: What will be the output when the following class is compiled and run?
class ScopeTest{
static int x = 5;
public static void main(String[] args){
int x = ( x=3 ) * 4; // 1
System.out.println(x);
}
}
Select 1 option(s)
It will not compile because line //1 cannot be parsed correctly.
It will not compile because x is used before initialization.
It will not compile because there is an ambiguous reference to x.
It will print 12.
It will print 3.
None
38.
Question: Given that the file test.txt contains:
12345678
What will the following code print when compiled and run?
public static void main(String[] args) throws Exception{
try(var fis = new FileInputStream("c:\\temp\\test.txt");
var isr = new InputStreamReader(fis)){
while(isr.ready()){
isr.skip(1);
int i = isr.read();
char c = (char) i;
System.out.print(c);
}
}
}
Select 1 option(s)
It will not compile.
It will throw an exeception when run.
It will print just 2.
It will run without any exception but will not print anything.
It will print 2468.
None
39.
Question: Identify correct statements about the following code:
import java.util.*;
class Student{
int marks;
}
class TestClass {
var k = new Student(); //1
public static void main(String[] args) {
var s = new Student(){ //2
@Override
public String toString(){ return "student obj"; };
};
var slist = Set.of(new Student()); //3
for(var i : slist){ //4
System.out.println(i);
}
slist.removeIf((var s1) -> s1.marks<0); //5
}
}
Select 1 option(s)
It will compile without any error.
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
Compilation error at //4.
Compilation error at //5.
None
40.
Question: What will the following code print when compiled and run?
HashSet keys = new HashSet(List.of("a", "b", "c"));
ArrayList values = new ArrayList(Set.of("1", "2", "3"));
Map m = new HashMap();
int i = 0;
for(var key : keys){
m.put(key, values.get(i++));
}
keys.clear(); //2
values.clear();
System.out.println(m.keySet().size()+" "+m.values().size());
Select 1 option(s)
It will throw an java.lang.UnsupportedOperationException.
0 0
3 3
It will not compile.
None
41.
Question: Given:
public static void createFile(String name) throws Exception{
try (
OutputStream os = new FileOutputStream(name); ) {
//INSERT CODE HERE
//flush and close the streams that are open
}
}
Which of the following combinations of the lines of code and their outcome when inserted above, are correct?
Select 2 option(s)
DataOutputStream dos = new DataOutputStream(os);
dos.write(1);
A file of size 4 bytes will be created.
Os.write(1);
A file of size 1 byte will be created.
BufferedOutputStream bos = new BufferedOutputStream(os);
DataOutputStream dos = new DataOutputStream(bos);
dos.write(1);
A file of size 1 byte will be created.
Os.writeInt(1);
A file of size 4 bytes will be created.
42.
Question: Given:
var qr = "insert into USERINFO values( ?, ?, ?)";
try(PreparedStatement ps = c.prepareStatement(qr);)
{
ps.setObject(1, 1, JDBCType.INTEGER);
ps.setObject(2, "Ally A", JDBCType.VARCHAR);
ps.setObject(3, "101 main str", JDBCType.VARCHAR);
var i = ps.executeUpdate(); //1
ps.setObject(1, 2, JDBCType.INTEGER);
ps.setObject(2, "Bob B", JDBCType.VARCHAR);
i = ps.executeUpdate(); //2
}
What will be the result?
Select 1 option(s)
An exception will be thrown at //1.
An exception will be thrown at //2.
Two rows with the following values will be inserted in the USERINFO table:
1, Ally A, 101 main str
2, Bob B, null
Two rows with the following values will be inserted in the USERINFO table:
1, Ally A, 101 main str
2, Bob B, 101 main str
One row with the following values will be inserted in the USERINFO table:
1, Ally A, 101 main str
and an exception will be thrown at //2.
None
43.
Question: What will the following program print when compiled and run?
class Boo implements Serializable {
transient int ti = 10;
static int si = 20;
}
public class TestClass
{
public static void main(String[] args) throws Exception
{
Boo boo = new Boo();
boo.si++;
System.out.println(boo.ti+" "+boo.si);
var fos = new FileOutputStream("c:\\temp\\boo.ser");
var os = new ObjectOutputStream(fos);
os.writeObject(boo);
os.close();
var fis = new FileInputStream("c:\\temp\\boo.ser");
var is = new ObjectInputStream(fis);
boo = (Boo) is.readObject();
is.close();
System.out.println(boo.ti+" "+boo.si);
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at run time.
10 21
10 21
10 21
10 20
10 21
0 20
10 21
0 21
None
44.
Question: Given the following code that appears inside a method:
var values = new ArrayList();
//INSERT CODE HERE
What can be inserted at the given location without causing any compilation error?
Select 2 option(s)
45.
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 2 option(s)
Make setSide() method private.
Make getArea() method private.
Make side and area fields private.
Make the side field private and remove the area field.
Change getArea method to:
public double getArea(){ return side*side; }
Add a setArea() method.
46.
Question: You have a file named customers.dat in c:\company\records directory. You want to copy all the lines in this file to another file named clients.dat in the same directory and you have the following code to do it:
public static void writeData() {
Path p1 = Paths.get("c:\\company\\records\\customers.dat");
//LINE 20 - INSERT CODE HERE
try (
var br = new BufferedReader(new FileReader(p1.toFile()));
var bw = new BufferedWriter(new FileWriter(p2.toFile()))) {
String line = null;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
}catch(Exception e){
e.printStackTrace();
}
}
Which of the following options can be inserted independent of each other at //LINE 20 to make it work?
Assume that the current directory for the program when it runs is c:\code.
Select 2 option(s)
Path p2 = p1.resolveSibling("\\clients.dat");
Path p2 = p1.resolveSibling("clients.dat");
Path p2 = p1.relativize("clients.dat");
Path p2 = Paths.get("c:", p1.subpath(0, 2).toString(), "clients.dat");
Path p2 = Paths.get("c:", p1.subpath(1, 2).toString(), "clients.dat");
47.
Question: Given:
public class TestClass {
public void myMethod(String... params) {
var a = params;
var b = params[0];
}
}
What are the types of the variables a and b?
Select 1 option(s)
Object[] and Object
String[] and Object
String[] and String
List and Object
List< String > and String
None
48.
Question: Given:
module abc.print{
requires org.pdf;
provides org.pdf.Print with com.abc.print.PrintImpl;
}
Identify correct statements about the above module.
Select 1 option(s)
org.pdf.Print must be an interface.
org.pdf.Print must be an interface or an abstract class.
com.abc.print.PrintImpl must have a no-args constructor.
com.abc.print.PrintImpl must implement (or extend) org.pdf.Print.
None of the above are correct.
None
49.
Question: Given:
package loops;
public class JustLooping {
private int j;
void showJ(){
while(j<=5){
for(int j=1; j <= 5;){
System.out.print(j+" ");
j++;
}
j++;
}
}
public static void main(String[] args) {
new JustLooping().showJ();
}
}
What is the result?
Select 1 option(s)
It will not compile.
It will print 1 2 3 4 5 five times.
It will print 1 3 5 five times.
It will print 1 2 3 4 5 once.
It will print 1 2 3 4 5 six times.
None
50.
Question: Which statements about the following code contained in BankAccount.java are correct?
interface Account{
public default String getId(){
return "0000";
}
}
interface PremiumAccount extends Account{
public String getId();
}
public class BankAccount implements PremiumAccount{
public static void main(String[] args) {
Account acct = new BankAccount();
System.out.println(acct.getId());
}
}
Select 1 option(s)
It will print 0000 when run.
It will compile if class BankAccount provides an implementation for getId method.
It will not compile unless interface PremiumAccount is marked abstract.
It will compile if getId method in PremiumAccount is replaced with:
public String getId(){ super.getId(); }
It will compile if getId method in PremiumAccount is replaced with:
public default String getId(){ super.getId(); }
It will compile if getId method in PremiumAccount is replaced with:
public default String getId(){ super(); }
None
51.
Question: Which of the following method definitions will prevent overriding of that method?
Select 4 option(s)
public final void m1()
public static void m1()
public static final void m1()
public abstract void m1()
private void m1()
52.
Question: Consider the following class...
class TestClass{
void probe(Object x) { System.out.println("In Object"); } //3
void probe(Number x) { System.out.println("In Number"); } //2
void probe(Integer x) { System.out.println("In Integer"); } //2
void probe(Long x) { System.out.println("In Long"); } //4
public static void main(String[] args){
double a = 10;
new TestClass().probe(a);
}
}
What will be printed?
Select 1 option(s)
In Number
In Object
In Long
In Integer
It will not compile.
None
53.
Question: Which of the following lines will cause the compilation to fail?
interface I { }
public enum EnumA implements I, Serializable { A, AA, AAA}; //1
class TestClass
{
public enum EnumB{ B, BB, BBB;
public Object clone(){ return B; } //2
}
public static enum EnumC{ C, CC, CCC };
public static enum EnumD extends EnumC{ DDD }; //3
public TestClass()
{
System.out.println(EnumC.CC.index()); //4
}
public static void main(String[] args)
{
System.out.println(EnumC.valueOf("ccc")); //5
System.out.println(EnumC.CCC.name()); //6
}
}
Select 3 option(s)
1
2
3
4
5
6
54.
Question: Given:
module broker{
exports org.broker.api;
}
The broker module contains org.broker.api.Installer interface, which is implemented by com.foo.AppInstaller class of com.foo module.
Which of the following is a valid module definition for com.foo module?
Select 1 option(s)
module com.foo{
exports broker;
}
module com.foo{
provider broker;
}
module com.foo{
requires broker;
provides org.broker.api;
}
module com.foo{
requires broker;
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
module com.foo{
exports com.foo;
provides org.broker.api.Installer with com.foo.AppInstaller;
}
None
55.
Question: Given:
interface Process{
public void process(int a, int b);
}
public class Data{
int value;
Data(int value){
this.value = value;
}
}
and the following code fragments:
public void processList(ArrayList
dataList, Process p){
for(Data d: dataList){
p.process(d.value, d.value);
}
}
....
ArrayList
al = new ArrayList
();
al.add(new Data(1));al.add(new Data(2));al.add(new Data(3));
//INSERT METHOD CALL HERE
Which of the following options can be inserted above so that it will print 1 4 9?
Select 3 option(s)
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