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 - 16
Name
Email
Phone
1.
Question: Identify the correct statements about ArrayList?
Select 3 option(s)
Standard JDK provides no subclasses of ArrayList.
An ArrayList cannot store primitives.
It allows constant time access to all its elements.
ArrayList cannot resize dynamically if you add more number of elements than its capacity.
An ArrayList is backed by an array.
2.
Question: When a class, whose members should be accessible only to members of that class, is coded such a way that its members are accessible to other classes as well, this is called ...
Select 1 option(s)
strong coupling
weak coupling
strong typing
weak encapsulation
weak polymorphism
high cohesion
low cohesion
None
3.
Question: Which statements, when inserted in the code below, will cause an exception at run time?
class B {}
class B1 extends B {}
class B2 extends B {}
public class ExtendsTest{
public static void main(String args[]){
B b = new B();
B1 b1 = new B1();
B2 b2 = new B2();
// insert statement here
}
}
Select 1 option(s)
b = b1;
b2 = b;
b1 = (B1) b;
b2 = (B2) b1;
b1 = (B) b1;
None
4.
Question: Given the following RDBMS table information:
STUDENT Table
SID INT Primary Key
NAME VARCHAR(50)
GPA INT
and the following code:
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select SID, NAME, GPA from STUDENT");
while(rs.next()){
System.out.println( INSERT CODE HERE );
}
connection.close();
What can be inserted in the above code so that it will print the GPA value for each student?
(Assume that items not specified such as import statements and try/catch block are all valid.)
Select 2 option(s)
rs.getString(2)
rs.getString(3)
rs.getInt(2)
rs.getInteger(2)
rs.getInt("GPA")
5.
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();
6.
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
7.
Question: Given:
abstract class Vehicle{ }
interface Drivable{ }
class Car extends Vehicle implements Drivable{ }
class SUV extends Car { }
Which of the following options will compile?
Select 2 option(s)
8.
Question: What will the following code print when run?
public class Test{
static String j = "";
public static void method( int i){
try{
if(i == 2){
throw new Exception();
}
j += "1";
}
catch (Exception e){
j += "2";
return;
}
finally{
j += "3";
}
j += "4";
}
public static void main(String args[]){
method(1);
method(2);
System.out.println(j);
}
}
Select 1 option(s)
13432
13423
14324
12434
12342
None
9.
Question: Your finance application invokes a third party analytics libray that takes a list of Bond objects and generates some results. Something like this:
Bond[] bondArray = //prepare an array of Bonds
Report r = BondProcessor.getInstance().analyzeBonds(bondsArray);
Which of the following statements are correct regarding above code from secure coding guidelines perspective?
Select 1 option(s)
These statements should be placed in a synchronized block.
It does not violate any secure coding guideline.
Bond objects should cloned and the clones should be passed on to the analyzeBonds method.
A security manager should be used before calling analyzeBonds method.
None
10.
Question: Consider the following method...
public int setVar(int a, int b, float c) { ...}
Which of the following methods correctly overload the above method?
Select 2 option(s)
public int setVar(int a, float b, int c){
return (int)(a + b + c);
}
public int setVar(int a, float b, int c){
return this(a, c, b);
}
public int setVar(int x, int y, float z){
return x+y;
}
public float setVar(int a, int b, float c){
return c*a;
}
public float setVar(int a){
return a;
}
11.
Question: Which of the following code segments will correctly write the text FINAL TEXT at the end of a file file.txt ?
Select 1 option(s)
RandomAccessFile raf = new RandomAccessFile("file.txt", "a");
raf.writeChars("FINAL TEXT");
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
raf.writeChars("FINAL TEXT");
RandomAccessFile raf = new RandomAccessFile("file.txt", "a");
raf.seek( raf.length() );
raf.writeChars("FINAL TEXT");
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
raf.seek( raf.length() );
raf.writeChars("FINAL TEXT");
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
raf.seek( raf.length() - 1);
raf.writeChars("FINAL TEXT");
None
12.
Question: Which of the lines will cause a compile time error in the following program?
public class MyClass{
public static void main(String args[]){
char c;
int i;
c = 'a';//1
i = c; //2
i++; //3
c = i; //4
c++; //5
}
}
Select 1 option(s)
line 1
line 2
line 3
line 4
line 5
None
13.
Question: What will the following code print?
List names = Arrays.asList(1, 2, 3); //1
names.forEach(x->x=x+1); //2
names.forEach(System.out::println); //3
Select 1 option(s)
1
2
3
2
3
4
It will not compile due to code at //2.
It will not compile due to code at //3.
None
14.
Question: Given the following code:
public class Valuator {
public AtomicInteger status = new AtomicInteger(0);
public void valuate() {
int oldstatus = status.get();
/* valid code here */
int newstatus = //determine new status
//INSERT CODE HERE
}
}
Assuming that an instance of this class is shared among multiple threads, you want to update the status to newstatus only if the oldstatus has not changed. Which of the following lines of code will you use?
Select 1 option(s)
status.compareAndSet(oldstatus, newstatus);
status.compareAndSet(newstatus, oldstatus);
status.setIfUnchanged(oldstatus, newstatus);
status.setIfUnchanged(newstatus, oldstatus);
if(oldstatus == status.get()) status.set(newstatus);
None
15.
Question: Which of the following is a valid module-info for a service provider that provides an Order service defined in OrderServiceAPI module?
Select 1 option(s)
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
requires OrderServiceAPI;
provides com.orderservice.api.Order;
}
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
uses OrderServiceAPI;
provides com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
module OrderServiceProvider{
requires OrderServiceAPI;
exports com.provider;
provides com.orderservice.api.Order;
}
module OrderServiceProvider{
requires OrderServiceAPI;
provides com.orderservice.api.Order with com.provider.OrderServiceImpl;
}
None
16.
Question: Identify the correct statements about the following code:-
List values = Arrays.asList(2, 4, 6, 9); //1
Predicate check = (Integer i) -> {
System.out.println("Checking");
return i == 4; //2
};
Predicate even = (Integer i)-> i%2==0; //3
values.stream().filter(check).filter(even).count(); //4
Select 1 option(s)
It will not compile because of code at //1.
It will not compile because of code at //2.
It will not compile because of code at //3.
It will not compile because of code at //4.
It will compile fine and print Checking four times.
It will compile fine and print Checking three times.
It will compile fine and print Checking one time.
It will compile fine but will print nothing.
None
17.
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
18.
Question: Consider the following code.
import java.time.*;
import java.time.format.*;
public class TestClass
{
public static void main(String[] args) throws Exception
{
LocalDate d = LocalDate.now();
//INSERT CODE HERE
System.out.println(s);
}
}
What should be inserted in the code above so that it will print the date in the following format:
Saturday 1st day of January 2000
Select 1 option(s)
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeeeeeee d'st day of' MMMMMMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeee d"+"st day of"+ "MMMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eee d'st day of' MMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eee d\"st day of\" MMM yyyy");
String s = dtf.format(d);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("eeee d'st day of' MMMM yyyy");
String s = dtf.format(d);
None
19.
Question: Given the following code:
Locale.setDefault(Locale.ITALY);
Locale loc = new Locale.Builder().setLanguage("en").build();
ResourceBundle rb = ResourceBundle.getBundle("mymsgs", loc);
System.out.println(rb.getString("helloMsg"));
and the following properties files:
mymsgs.properties
mymsgs_en_IT.properties
mymsgs_en.properties
mymsgs_IT.properties
Which of the following statements are correct?
Select 2 option(s)
If helloMsg is defined in all the four properties files, the value from mymsgs_en.properties will be displayed.
If helloMsg is defined in all the four properties files, the value from mymsgs_en_IT.properties will be displayed.
If helloMsg is defined only in mymsgs_IT.properties, then that value will be displayed.
If helloMsg is not defined in mymsgs_en.properties file but is defned in mymsgs.properties and mymsgs_en_IT.properties, then the value from mymsgs.properties will be displayed.
A java.util.MissingResourceException will be NOT be thrown if helloMsg is defined in any one of the given four properties files.
20.
Question: Given the following class definitions:
interface MyIface{};
class A {};
class B extends A implements MyIface{};
class C implements MyIface{};
and the following object instantiations:
A a = new A();
B b = new B();
C c = new C();
Which of the following assignments are legal at compile time?
Select 1 option(s)
b = c;
c = b;
MyIface i = c;
c = (C) b;
b = a;
None
21.
Question: Which jdeps option(s) is/are used to include dependent nonmodular jar files?
Note: We have seen some really vague and ill-designed questions without complete information on jdeps in the exam. It is anybody's guess as to what exactly are they testing.
Based on the given options, our guess is that in this question they are just checking whether you know that -cp, -classpath, and --class-path are equivalent options and the nonmodular jars should be put on classpath instead of module-path.
Select 3 option(s)
jdeps -cp file1.jar;file2.jar app.jar
jdeps --upgrade-module-path file1.jar;file2.jar app.jar
jdeps --class-path file1.jar;file2.jar app.jar
jdeps -classpath file1.jar;file2.jar app.jar
jdeps app.jar
jdeps --module-path file1.jar;file2.jar app.jar
jdeps file1.jar;file2.jar app.jar
22.
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
23.
Question: Given:
public class SimpleLoop {
public static void main(String[] args) {
int i=0, j=10;
while (i<=j) {
i++;
j--;
}
System.out.println(i+" "+j);
}
}
What is the result?
Select 1 option(s)
6 4
6 5
6 6
5 3
5 4
5 5
None
24.
Question: The following program will print.
java.lang.ArithmeticException: / by zero
class Test{
public static void main(String[] args){
int d = 0;
try{
int i = 1 / (d* doIt());
} catch (Exception e){
System.out.println(e);
}
}
public static int doIt() throws Exception{
throw new Exception("Forget It");
}
}
Select 1 option(s)
True
False
None
25.
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; }
26.
Question: Which of the options will create and initialize a matrix of ints as shown below?
Â
1
Â
Â
Â
1
Â
Â
Â
1
Â
Â
Â
1
Â
Â
Â
1
Â
Â
Select 1 option(s)
None
27.
Question: What will happen when the following program is compiled and run?
public class SM{
public String checkIt(String s){
if(s.length() == 0 || s == null){
return "EMPTY";
}
else return "NOT EMPTY";
}
public static void main(String[] args){
SM a = new SM();
System.out.println(a.checkIt(null));
}
}
Select 1 option(s)
It will print EMPTY.
It will print NOT EMPTY.
It will throw NullPointerException.
It will print EMPTY if || is replaced with |.
None
28.
Question: Given:
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
ArrayList al = new ArrayList();
//INSERT CODE HERE
}
}
What can be inserted in the above code so that it can compile without any error?
Select 2 option(s)
Al.add(111);
System.out.println(al.indexOf(1.0));
System.out.println(al.contains("string"));
Double d = al.get(al.length);
29.
Question: Given:
String sentence1 = "Carpe diem. Seize the day, boys. Make your lives extraordinary.";
String sentence2 = "Frankly, my dear, I don't give a damn!";
String sentence3 = "Do I look like I give a damn?";
List sentences = Arrays.asList(sentence1, sentence2, sentence3);
Which of the following options will create a stream containing all the words in the three sentences without repetition?
Select 1 option(s)
None
30.
Question: Consider the following program:
import java.util.*;
public class TestClass
{
static String[] sa = { "a", "aa", "aaa", "aaaa" };
static
{
Arrays.sort(sa);
}
public static void main(String[] args)
{
String search = "";
if(args.length != 0) search = args[0];
System.out.println(Arrays.binarySearch(sa, search));
}
}
What are all possible values this program can print when run?
Select 1 option(s)
Any number from -5 to 5.
Any number from -5 to 5 except -1.
Any number from -5 to 3.
Any number from -5 to 3 except -1.
One of a, aa, aaa, or aaaa.
One of a, aa, aaa, aaaa, or null.
None
31.
Question: Given the following lines of code:
int rate = 10;
XXX amount = 1 - rate/100*1 - rate/100;
What can XXX be?
Select 1 option(s)
only int or long.
only long or double.
only double.
double or float.
long or double but not int or float.
int, long, float or double.
None
32.
Question: What will be the output when the following program is run?
public class TestClass{
public static void main(String args[]){
int i;
int j;
for (i = 0, j = 0; j < i; ++j, i++){
System.out.println(i + " " + j);
}
System.out.println(i + " " + j);
}
}
Select 1 option(s)
0 0 will be printed twice.
0 0 will be printed once.
It will keep on printing 0 0.
It will not compile.
It will print 0 0 and then 0 1.
None
33.
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
34.
Question: Given that Book is a valid class with appropriate constructor and getTitle and getPrice methods that return a String and a Double respectively, what will the following code print?
List books = Arrays.asList(
new Book("Gone with the wind", 5.0),
new Book("Gone with the wind", 10.0),
new Book("Atlas Shrugged", 15.0)
);
books.stream().collect(Collectors.toMap((b->b.getTitle()), b->b.getPrice()))
.forEach((a, b)->System.out.println(a+" "+b));
Select 1 option(s)
Gone with the wind 5.0
Atlas Shrugged 15.0
Gone with the wind 10.0
Atlas Shrugged 15.0
Gone with the wind 5.0
Gone with the wind 10.0
Atlas Shrugged 15.0
It will throw an exception at run time.
None
35.
Question: Following is a supposedly robust method to parse an input for a float:
public float parseFloat(String s){
float f = 0.0f;
try{
f = Float.valueOf(s).floatValue();
return f ;
}
catch(NumberFormatException nfe){
System.out.println("Invalid input " + s);
f = Float.NaN ;
return f;
}
finally { System.out.println("finally"); }
return f ;
}
Which of the following statements about the above method is/are true?
Select 1 option(s)
If input is "0.1" then it will return 0.1 and print finally.
If input is "0x.1" then it will return Float.NaN and print Invalid input 0x.1 and finally.
If input is "1" then it will return 1.0 and print finally.
If input is "0x1" then it will return 0.0 and print Invalid input 0x1 and finally.
The code will not compile.
None
36.
Question: Which of the following can be valid declarations of an integer variable?
Select 2 option(s)
private var x = 10;
final int x = 10;
public Int x = 10;
Int x = 10;
static int x = 10;
global int x = 10;
37.
Question: The following are complete contents of ConsoleTest.java:
import java.io.Console;
public class ConsoleTest {
public static void main(String[] args) {
var c = System.console(); //1
char[] line = c.readPassword("Please enter your pwd:"); //2
System.out.println("Pwd is "+new String(line));
}
}
What will happen when it is compiled and run from the command line?
Select 1 option(s)
It will print whatever password is entered by the user.
It will print a garbled version of whatever password is entered by the user.
It will throw an exception at run time.
It will not compile because it does not incorporate exception handling for the readPassword method.
It will not compile because it does not incorporate exception handling for System.console() method.
None
38.
Question: What will the following code print?
int i = 1;
int j = i++;
if( (i==++j) | (i++ == j) ){
i+=j;
}
System.out.println(i);
Select 1 option(s)
3
4
5
2
It will not compile.
None
39.
Question: What will the following program print when run?
public class ChangeTest {
private int myValue = 0;
public void showOne(int myValue){
myValue = myValue;
}
public void showTwo(int myValue){
this.myValue = myValue;
}
public static void main(String[] args) {
var ct = new ChangeTest();
ct.showOne(100);
System.out.println(ct.myValue);
ct.showTwo(200);
System.out.println(ct.myValue);
}
}
Select 1 option(s)
0 followed by 100.
100 followed by 100.
0 followed by 200.
100 followed by 200.
None
40.
Question: Which of these array declarations and initializations are legal?
Select 1 option(s)
var i[][] = { { 1, 2 }, { 1 }, { }, { 1, 2, 3 } } ;
var i[ ] = new int[2] {1, 2} ;
var i = new int[ ][ ] { {1, 2, 3}, {4, 5, 6} } ;
var i = { { 1, 2 }, new int[ 2 ] } ;
var i[4] = new int[]{ 1, 2, 3, 4 } ;
var fa = new Float{ 1.1F, 2.2F, 3.3F };
None
41.
Question: Given:
import java.util.*;
class Data{
int value;
public Data(int x){ this.value = x; }
public String toString(){ return ""+value; }
}
class MyFilter {
public boolean test(Data d){
return d.value == 0;
}
}
public class TestClass{
public static void filterData(ArrayList
dataList, MyFilter f){
Iterator
i = dataList.iterator();
while(i.hasNext()){
if(f.test(i.next())){
i.remove();
}
}
}
public static void main(String[] args) {
ArrayList
al = new ArrayList
();
Data d = new Data(1); al.add(d);
d = new Data(2); al.add(d);
d = new Data(0); al.add(d);
filterData(al, new MyFilter()); //1
System.out.println(al);
}
}
How can you use a lambda expression to achieve the same result?
Select 1 option(s)
None
42.
Question: Given:
List primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17); //1
Stream primeStream = primes.stream(); //2
Predicate test1 = k->k<10; //3
long count1 = primeStream.filter(test1).count();//4
Predicate test2 = k->k>10; //5
long count2 = primeStream.filter(test2).count(); //6
System.out.println(count1+" "+count2); //7
Identify correct statements.
Select 1 option(s)
It will print 4 3 if line at //6 is replaced with:
long count2 = primeStream.reset().filter(test2).count(); //6
It will print 4 3 if types of count1 and count2 are changed to int.
It will print 4 3 if line //4 and //6 are replaced with:
long count1 = IntStream.of(primes).filter(test1).count();//4
and
long count2 = IntStream.of(primes).filter(test2).count();//6
It will print 34 if lines 4 to 7 are replaced with:
primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))
.values().forEach(System.out::print);
None
43.
Question: What will the following program print?
public class TestClass{
public static void main(String[] args){
for : for(var i = 0; i< 10; i++){
for (var j = 0; j< 10; j++){
if ( i+ j > 10 ) break for;
}
System.out.println( "hello");
}
}
}
Select 1 option(s)
It will print hello 6 times.
It will not compile.
It will print hello 2 times.
It will print hello 5 times.
It will print hello 4 times.
None
44.
Question: Consider the following method...
public void ifTest(boolean flag){
if (flag) //1
if (flag) //2
System.out.println("True False");
else // 3
System.out.println("True True");
else // 4
System.out.println("False False");
}
Which of the following statements are correct ?
Select 3 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.
45.
Question: Given:
var bfr = new BufferedReader(new FileReader("c:\\temp\\pathtest\\a.java"));
var bfw = new BufferedWriter(new FileWriter("c:\\temp\\pathtest\\b.java"));
String line = null;
while( (line=bfr.readLine()) != null ){
bfw.append(line);
}
//INSERT CODE HERE
bfw.close();
Which of the following lines is required to be inserted in the code above so that content in b.java will be overwritten with the content in a.java?
Select 1 option(s)
bfr.close();
bfw.close();
bfr.flush();
bfw.flush();
None of the above.
None
46.
Question: What will the following program print?
class Test{
public static void main(String args[]){
int i=0, j=0;
X1: for(i = 0; i < 3; i++){
X2: for(j = 3; j > 0; j--){
if(i < j) continue X1;
else break X2;
}
}
System.out.println(i+" "+j);
}
}
Select 1 option(s)
0 3
0 2
3 0
3 3
2 2
None
47.
Question: The developer of a method that accesses the file system wants to ensure that the caller has appropriate permissions. She has written the following code:
public class FileOps {
public static void doOps() {
return AccessController.doPrivileged(
new PrivilegedAction() {
public String run() {
//do File operations here
}
}, AccessController.getContext()
);
}
}
What, if anything, is wrong with this code from a security perspective?
Select 1 option(s)
This code does not really check the permissions of the caller.
This code violates secure coding guidelines because it does not check the return value of AccessController.getContext() for null.
This code is fine and does not violate secure coding guidelines.
It should use AccessController.getParentContext() instead of AccessController.getContext() as the second argument to doPrivileged.
None
48.
Question: Consider the following code:
import java.util.*;
class Book{ }
class TextBook extends Book{ }
class BookList extends ArrayList
{
public int count = 0;
public boolean add(Object o)
{
if(o instanceof Book ) return super.add((Book) o);
else return count++ == -1;
}
}
//in valid context
BookList list = new BookList();
list.add(new Book());
list.add(new TextBook());
list.add("hello");
System.out.println(list.count);
What will it print?
Select 1 option(s)
0
1
2
It will not compile.
It will throw an exception at runtime.
None
49.
Question: What will be printed when the following code is compiled and run?
class A {
public int getCode(){ return 2;}
}
class AA extends A {
public long getCode(){ return 3;}
}
public class TestClass {
public static void main(String[] args) throws Exception {
A a = new A();
A aa = new AA();
System.out.println(a.getCode()+" "+aa.getCode());
}
public int getCode() {
return 1;
}
}
Select 1 option(s)
2 3
2 2
It will throw an exception at run time.
The code will not compile.
None
50.
Question: What will be the result of attempting to compile and run the following code?
public class Nesting
{
public static void main(String args[])
{
B.C obj = new B( ).new C( );
}
}
class A
{
char c;
A(char c) { this.c = c; }
}
class B extends A
{
char c = 'a';
B( ) { super('b'); }
class C extends A
{
char c = 'c';
C( )
{
super('d');
System.out.println(B.this.c);
System.out.println(C.this.c);
System.out.println(super.c);
}
}
}
Select 1 option(s)
It will not compile.
It will throw an exception at run time.
The program will compile without error, and print a, c and d in that order when run.
The program will compile without error, and print a, b and d in that order when run.
The program will compile without error, and print b, c and a in that order when run.
None
51.
Question: Which of the statements regarding the given code are correct?
public class Test extends Thread
{
static Object obj1 = new Object();
static Object obj2 = new Object();
public void m1()
{
synchronized(obj1)
{
System.out.print("1 ");
synchronized(obj2)
{
System.out.println("2");
}
}
}
public void m2()
{
synchronized(obj2)
{
System.out.print("2 ");
synchronized(obj1)
{
System.out.println("1");
}
}
}
public void run()
{
m1();
m2();
}
public static void main(String[] args)
{
new Test().start();
new Test().start();
}
}
Select 1 option(s)
It may result in a deadlock and the program might get stuck.
There is no potential for deadlock.
Deadlock may occur but the program will not get stuck as the JVM will resolve the deadlock.
The program will always print 1 2, 2 1, 1 2 and 21.
None
52.
Question: Your application uses one modular jar (a.jar), which, in turn, uses one non-modular jar (b.jar). Which of the following commands will cause jdeps to include the non-modular jar in its analysis?
Select 1 option(s)
jdeps -module-path lib\a.jar; -classpath lib\b.jar
jdeps --module-path lib\a.jar; lib\b.jar
jdeps --class-path lib\a.jar; lib\b.jar
jdeps -cp lib\b.jar lib\a.jar
jdeps -cp lib\b.jar;lib\a.jar
None
53.
Question: Consider the following piece of code:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = new Locale("jp", "JP");
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundle files with the following contents:
#In appmessages.properties:
greetings=Hello
#In appmessages_fr_FR.properties:
greetings=bonjour
Given that this code is run on machines all over the world. Which of the following statements are correct?
Select 1 option(s)
It will throw an exception when the default locale of the machine where it is run is different from fr/FR and fr/CA.
It will throw an exception where ever it is run.
It will throw an exception when the default locale of the machine is fr/CA.
It will throw an exception when the default locale of the machine is jp/JP.
It will run without any exception all over the world.
None
54.
Question: Assuming that the following code compiles without any error, identify correct statements.
interface Processor {
A process(String str);
}
class ItemProcessor implements Processor{
@Override
public B process(String str){
return new B(str);
}
}
Select 2 option(s)
B must be a sub type of A.
A must be a sub type of B.
There need not be any type - sub type relation between A and B or B and A.
B must be final.
B must not be final.
A cannot be abstract.
B cannot be abstract.
55.
Question: What will the following code print when run?
public class TestClass {
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "c" : System.out.println( "cat" );
default : System.out.println( "none" );
}
}
public static void main(String[] args) throws Exception {
var tc = new TestClass();
tc.switchString("c");
}
}
Select 1 option(s)
apple
cat
none
apple
cat
cat
none
cat
None
56.
Question: Which of the following statements will evaluate to true?
Select 1 option(s)
"String".replace('g','G') == "String".replace('g','G')
"String".replace('g','g') == new String("String").replace('g','g')
"String".replace('g','G')=="StrinG"
"String".replace('g','g')=="String"
None of these.
None
Time's up
Time is Up!
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Blog
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Blog
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US