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 - 6
Name
Email
Phone
1.
Question: Given:
public class Buddy {
Buddy upper;
String name;
public Buddy(){ }
public Buddy(String name){
this.name = name;
}
public Buddy(String name, Buddy upper){
this.name = name;
Buddy b = new Buddy(upper.name);//1
upper = b; //2
}
public static void main(String[] args) {
Buddy b1 = new Buddy("A"); //3
Buddy b2 = new Buddy("B", b1); //4
System.out.println(b1); //5
}
}
Identify correct statements.
Select 2 option(s)
Object created at line //1 will be eligible for garbage collection after line //2.
Object created at line //1 will be eligible for garbage collection after line //5.
Object created at line //3 will be eligible for garbage collection after line //4.
Object created at line //3 will be eligible for garbage collection after line //5.
2.
Question: Given:
enum Coffee
{
ESPRESSO("Very Strong"), MOCHA("Bold"), LATTE("Mild");
public String strength;
Coffee(String strength)
{
this.strength = strength;
}
}
and the statement
System.out.println(Coffee.ESPRESSO);
What can be done so that the above statement will print Very Strong?
Select 1 option(s)
Insert the following in Coffee:
public String toString(){ return Coffee.values()[0]; }
Insert the following in Coffee:
String toString(){ return "Very Strong"; }
Insert the following in Coffee:
public String toString(){ return String.valueOf(Coffee.ESPRESSO);}
Insert the following in Coffee:
public String toString(){ return String.valueOf(strength);}
None
3.
Question: You have just taken over as the build manager for your development team and while go through all the build steps you notice that one of the steps of your build involves running a tool over your java files for preprocessing. This tool runs with a security file containing the following code:
grant codeBase "file:${toolhome}/tool.jar", {
permission java.security.AllPermission;
};
What should you do?
Note: Although security policy file is not mentioned in the exam objectives explicitly, we have seen similar question in the exam.
Select 1 option(s)
Replace the AllPermission line and replace it with the actual permissions that are required.
Stop using the tool.
File a security complain with the tool vendor.
Not do anything because listing just the required permissions would be a maintenance challenge.
Not do anything because it is an internal development step and does not affect final classes.
None
4.
Question: Consider the following piece of code, which is run in an environment where the default locale is English - US:
Locale.setDefault(new Locale("fr", "CA")); //Set default to French Canada
Locale l = Locale.getDefault();
ResourceBundle rb = ResourceBundle.getBundle("appmessages", l);
String msg = rb.getString("greetings");
System.out.println(msg);
You have created two resource bundles for appmessages, with the following contents:
#In English US resource bundle file
greetings=Hello
#In French CA resource bundle file
greetings=bonjour
What will be the output?
Select 1 option(s)
Hello
bonjour
An exception at run time.
No message will be printed.
None
5.
Question: Given:
List dList = Arrays.asList(10.0, 12.0);
DoubleFunction df = x->x+10;
dList.stream().forEach(df);
dList.stream().forEach(d->System.out.println(d));
What will it print when compiled and run?
Select 1 option(s)
A compilation error will occur.
10.0
12.0
20.0
22.0
It will compile but throw an exception at run time.
None
6.
Question: Given:
char a = 'a', b = 98; //1
int a1 = a; //2
int b1 = (int) b; //3
System.out.println((char)a1+(char)b1); //4
What is the output?
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
Compilation error at //4.
ab
195
None
7.
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";
}
8.
Question: Given:
List names = Arrays.asList(1, 2, 3);
How many of the following lines will print exactly 6?
1. System.out.println(names.stream().mapToInt(x->x).sum());
2. System.out.println(names.stream().forEach((sum, x)->sum = sum + x));
3. System.out.println(names.stream().reduce(0, (a, b)->a+b));
4. System.out.println(names.stream().collect(Collectors.mapping(x->x, Collectors.summarizingInt(x->x))).getSum());
5. System.out.println(names.stream().collect(Collectors.summarizingInt(x->x)).getSum());
Select 1 option(s)
1
2
3
4
5
None
9.
Question: Consider the following code appearing in a file named TestClass.java:
class Test{ } // 1
public class TestClass {
var v1; // 2
public int main(String[] args) { // 3
var v2; //4
double x=10, double y; // 5
System.out.println[]; // 6
for(var k=0; k<x; k++){ } //7
return 0;
}
}
Which of the lines are valid?
Select 3 option(s)
// 1
// 2
// 3
// 4
// 5
// 6
// 7
10.
Question: Given:
import java.util.*;
class Student{
int marks;
}
public class TestClass {
static var getHighest(var students){
int highest = 0;
for(var student : students){
if(highest <student.marks) highest = student.marks;
}
return highest;
}
public static void main(String[] args) {
var student = new Student();
var allStudents = new ArrayList();
allStudents.add(student);
var h = getHighest(allStudents);
System.out.println(h);
}
}
Identify correct statements about the above code.
Select 1 option(s)
It will compile if the getHighest method declaration is changed to:
static var getHighest(ArrayList< Student > students)
It will compile if the getHighest method declaration is changed to:
static int getHighest(var students)
It will compile if allStudents type is changed from var to ArrayList< Student >.
It will compile if the type of h is changed from var to int.
None of the above.
None
11.
Question: What will the following class print ?
class InitTest{
public static void main(String[] args){
int a = 10;
int b = 20;
a += (a = 4);
b = b + (b = 5);
System.out.println(a+ ", "+b);
}
}
Select 1 option(s)
It will print 8, 25
It will print 4, 5
It will print 14, 5
It will print 4, 25
It will print 14, 25
None
12.
Question: What should be the return type of the following method?
public RETURNTYPE methodX( byte by){
var d = 10.0;
return (long) by/d*3;
}
Select 1 option(s)
int
long
double
float
byte
None
13.
Question: What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
var i = 0;
for (i=1 ; i<5 ; i++) continue; //(1)
for (i=0 ; ; i++) break; //(2)
for ( ; i<5?false:true ; ); //(3)
}
}
Select 1 option(s)
The code will compile without error and will terminate without problem when run.
The code will fail to compile, since the continue can't be used this way.
The code will fail to compile, since the break can't be used this way.
The code will fail to compile, since the for statement in line 2 is invalid.
The code will compile without error but will never terminate.
None
14.
Question: Given the following code:
import java.util.Arrays;
import java.util.List;
public class TestClass {
public static void main(String[] args) {
List al = Arrays.asList(100, 200, 230, 291, 43);
System.out.println( *INSERT CODE HERE* );
}
}
Which of the following options will correctly print the number of elements that are less than 200?
Select 1 option(s)
None
15.
Question: Which secure programming guideline does the following code violate?
public void saveUserCredentials(String data, String file) throws Exception {
FileWriter fw = null;
try{
fw = new FileWriter(file);
fw.write(data);
fw.close();
}catch(Exception e){
System.err.println("Unable to save user data "+data+" to "+file);
e.printStackTrace();
throw e;
}finally{
if(fw != null) fw.close();
}
}
Select 3 option(s)
It exposes sensitive information by logging confidential data.
It exposes sensitive application specific information contained in exception message.
It affects application stability by not closing file handle properly.
It violates input validation guidelines by not validating data and file arguments.
It violates exception throwing guideline by throwing a broad exception.
16.
Question: Which of the following correctly identify the differences between a Callable and a Runnable?
Select 3 option(s)
A Callable cannot be passed as an argument while creating a Thread but a Runnable can be.
A Callable needs to implement call() method while a Runnable needs to implement run() method.
A Callable can return a value but a Runnable cannot.
A Callable can be used with ExecutorService but a Runnable cannot be.
17.
Question: A developer has written the following code snippet:
Console c = System.console(); //1
String line = c.readLine("Please enter your name:"); //2
System.out.println("Hello, "+line); //3
Which of the following checked exceptions may be thrown by this code?
Select 1 option(s)
java.io.IOException
java.lang.Exception
java.io.EOFException
None
None
18.
Question: Consider the following class...
class Test{
public static void main(String[ ] args){
var a = new int[]{ 1, 2, 3, 4 };
int[] b = { 2, 3, 1, 0 };
System.out.println( a [ (a = b)[3] ] );
}
}
What will it print when compiled and run ?
Select 1 option(s)
It will not compile.
It will throw ArrayIndexOutOfBoundsException when run.
It will print 1.
It will print 3.
It will print 4.
None
19.
Question: What will the following code print?
List ls = Arrays.asList("Tom Cruise", "Tom Hart", "Tom Hanks", "Tom Brady");
Predicate p = str->{
System.out.println("Looking...");
return str.indexOf("Tom") > -1;
};
boolean flag = ls.stream().filter(str->str.length()>8).allMatch(p);
Select 1 option(s)
It will not print anything.
It will not print anything but will throw an exception at run time.
Looking...
Looking...
Looking...
< exception stack trace >
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
Looking...
None
20.
Question: Given:
class Base{
public List getList(int id){
return null;
};
}
class Derived extends Base{
@Override
*INSERT CODE HERE*
//valid code
}
}
What can be inserted in the above code?
Select 2 option(s)
public List< ? extends CharSequence > getList(int id){
public List
String
getList(int id){
public ArrayList
StringBuilder
getList(int id){
public List
? super Object
getList(int id){
public List
CharSequence
getList(int id){
21.
Question: Identify correct usages of the following annotation:
public @interface AuthorInfo {
String name() default "";
}
Select 3 option(s)
@AuthorInfo("bob")
class A{
}
class A{
@AuthorInfo
String x = "";
}
class A{
@AuthorInfo("bob")
void m1(){ };
}
interface I{
@AuthorInfo(name="bob")
String x = "";
}
@AuthorInfo("bob")
interface I{
}
class A{
void m1(@AuthorInfo int x){ }
}
22.
Question: What will the following code print when compiled and run?
Collection col = new HashSet();
col.add(1);
var list1 = List.of(col); //1
col.add(2); //2
var list2 = List.copyOf(col); //3
System.out.println(list1+", "+list2);
Select 1 option(s)
It will not compile.
Exception at run time at line marked //1.
Exception at run time at line marked //2.
Exception at run time at line marked //3.
[1, 2], [1, 2]
[1], [1, 2]
[[1, 2]], [1, 2]
None
23.
Question: Consider that str is a local variable of class java.lang.String.
Which of the following lines of code may throw a NullPointerException in certain situations?
Or a tougher version of the question could be :
Which of the following lines of code are not an example of robust design ?
Select 3 option(s)
if ( (str != null) | ( i == str.length() ) )
if ( (str == null) | ( i == str.length() ) )
if ( (str != null) || (i == str.length() ) )
if ( (str == null) || (i == str.length() ) )
24.
Question: Consider the following code:
interface Classic {
int version = 1;
public void read() ;
}
class MediaReader implements Classic{
int version = 2;
public void read() {
//Insert code here
}
}
public class ReaderTest{
public static void main(String[] args) {
MediaReader mr = new MediaReader();
mr.read();
}
}
What can be inserted in the code above so that it will print 1 when run?
Select 1 option(s)
System.out.println(version);
System.out.println((Classic)version);
System.out.println(((Classic)this).version);
System.out.println(this.Classic.version);
System.out.println(MediaReader.version);
None
25.
Question: Which line(s) of code in the following program will cause compilation errors?
public class TestClass{
var value = 0; //1
public static void main(var args[]) //2
{
var secondArg = Integer.parseInt(args[2]); //3
if( true == 2 > 10 ) //4
{
value = -10;
}
else{
value = secondArg;
}
for( ; value>0; value--) System.out.println("A"); //5
}
}
Select 3 option(s)
1
2
3
4
5
26.
Question: Given the following code, which method declarations can be inserted at line 1 without any problems?
public class OverloadTest{
public int sum(int i1, int i2) { return i1 + i2; }
// 1
}
Select 3 option(s)
public int sum(int a, int b) { return a + b; }
public int sum(long i1, long i2) { return (int) i1; }
public int sum(int i1, long i2) { return (int) i2; }
public long sum(long i1, int i2) { return i1 + i2; }
public long sum(int i1, int i2) { return i1 + i2; }
27.
Question: Consider the following code:
class Account{
private String id; private double balance;
ReentrantLock lock = new ReentrantLock();
public void withdraw(double amt){
try{
lock.lock();
if(balance > amt) balance = balance - amt;
}finally{
lock.unlock();
}
}
}
What can be done to make the above code thread safe?
Select 1 option(s)
Change new ReentrantLock() to new ReentrantLock(true).
Move the call to lock.lock(); to before the try block.
Declare lock variable as private and final.
Make the lock variable private, final, and static.
Make the lock variable static.
No change is required.
None
28.
Question: Given the following definitions and reference declarations:
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
class C3 extends C1 implements I2 { }
C1 o1;
C2 o2;
C3 o3;
Which of these statements are legal?
Select 3 option(s)
class C4 extends C3 implements I1, I2 { }
o3 = o1;
o3 = o2;
I1 i1 = o3; I2 i2 = (I2) i1;
I1 b = o3;
29.
Question: Identify correct statements about the following code -
interface Drink{
default double getAlcoholPercent(){
return 0.0;
}
static double computeAlcoholPercent(){
return 0.0;
}
}
interface ColdDrink extends Drink{
String getName();
}
class CrazyDrink implements ColdDrink{
// INSERT CODE HERE
}
Select 1 option(s)
CrazyDrink must either implement getName or be marked abstract.
CrazyDrink must either implement getName as well as computeAlcoholPercent or be marked abstract.
CrazyDrink must either implement getName as well as getAlcoholPercent or be marked abstract.
CrazyDrink must either implement getName or be marked abstract. Further, computeAlcoholPercent must be removed from Drink.
None
30.
Question: Your application is packaged in myapp.jar and depends on a jar named datalayer.jar, which in turn depends on mysql-connector-java-8.0.11.jar. The following packages exist in these jars:
myapp.jar: com.abc.myapp
datalayer.jar: com.abc.datalayer
mysql-connector-java-8.0.11.jar: com.mysql.jdbc
You have decided to modularize your application even though datalayer and mysql libraries are still not modularlized. Which of the following would be a valid module-info for your app?
Select 1 option(s)
module abc.myapp{
requires com.abc.datalayer;
}
module abc.myapp{
exports com.abc.myapp;
}
module abc.myapp{
requires datalayer;
}
module abc.myapp{
requires datalayer;
requires mysql-connector-java;
}
module abc.myapp{
requires datalayer;
requires mysql-connector-java-0.0.11;
}
module abc.myapp{
requires com.abc.datalayer;
requires com.mysql.jdbc;
}
None
31.
Question: What letters will be printed by this program?
public class ForSwitch{
public static void main(String args[]){
char i;
LOOP: for (i=0;i<5;i++){
switch(i++){
case '0': System.out.println("A");
case 1: System.out.println("B"); break LOOP;
case 2: System.out.println("C"); break;
case 3: System.out.println("D"); break;
case 4: System.out.println("E");
case 'E' : System.out.println("F");
}
}
}
}
Select 2 option(s)
A
B
C
D
F
32.
Question: How can you fix the following code to make it compile:
import java.io.*;
class Great {
public void doStuff() throws FileNotFoundException{
}
}
class Amazing extends Great {
public void doStuff() throws IOException, IllegalArgumentException{
}
}
public class TestClass {
public static void main(String[] args) throws IOException{
Great g = new Amazing();
g.doStuff();
}
}
Assume that changes suggested in a option are to be applied independently of changes suggested in other options.
Select 2 option(s)
Change doStuff in Amazing to throw only IllegalArgumentException.
Change doStuff in Great to throw FileNotFoundException and IllegalArgumentException.
Change doStuff in Amazing to throw only IOException.
Change doStuff in Great to throw only IOException instead of FileNotFoundException.
Replace g.doStuff() to ((Amazing) g).doStuff().
33.
Question: What changes should be applied to the following class to update it to use generics without changing any functionality? Choose minimal changes that are necessary to take advantage of generics.
import java.util.*;
public class BookStore {
Map map = new HashMap(); //1
public BookStore(){
map.put(new Book("A111"), new Integer(10)); //2
}
public int getNumberOfCopies(Book b){ //3
Integer i = (Integer) map.get(b); //4
return i == null? 0:i.intValue(); //5
}
}
Select 2 option(s)
Replace line //1 with Map
Book, int
map = new HashMap
Book, int
();
Replace line //1 with Map
Book, Integer
map = new HashMap
Book, Integer
();
Replace line //2 with map.put(new Book("A111"), 10); //2
Replace line //3 with: public Integer getNumberOfCopies(Book b) {
Replace line //4 and //5 with: return map.get(b);
Replace line //4 and //5 with:
Integer i = map.get(b);
return i == null? 0:i;
There is no need to change //4 and //5.
34.
Question: Consider the following method exposed by a class of a third party library:
public static void storeObjectToFile(final String fn, final Serializable obj) throws Exception {
validateOutputFile(fn);
validatePermissions();
try(var oos = new ObjectOutputStream(new FileOutputStream(fn)) ){
oos.writeObject(obj);
}
}
This method is used by several classes in your application to store user information in files. Identify correct statements about this approach.
Select 2 option(s)
It is prone to denial of service attack.
This method violates secure coding guidelines for storing sensitive data.
Serialization Filtering should be used to validate classes before they are serialized.
Storing user information in serialized files violates secure coding guidelines for storing sensitive data.
35.
Question: Your application consists of two jar files produced by two different teams - accounting-3.2.jar and reporting-5.6.jar. Classes in reporting-5.6.jar uses a class com.abc.account.Account in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.
The accounting team has decided to modularize their jar. Which of the following would be a valid module-info.java for the new accounting-3.3.jar?
Select 1 option(s)
module accounting{
requires com.abc.account;
}
module accounting{
export com.abc.account.*;
}
module accounting{
exports com.abc.account;
}
module accounting{
export com.abc.account;
}
module accounting{
export com.abc.account.Account;
}
module accounting{
provides com.abc.account;
}
None
36.
Question: Given:
1. Java source file location: src/moduleA/a/A.java
2. Expected class file location: out/moduleA/a/A.class
Which of the following commands will generate A.class in the expected directory?
(Assume that all directory paths are relative to the current directory.)
Select 1 option(s)
javac --module-path src --output-path out src/moduleA/a/A.java
javac --module-source-path src --output-path out src/moduleA/a/A.java
javac --module-source-path src -d out src/moduleA/a/A.java
javac --module-source-path src --module-path out src/moduleA/a/A.java
None
37.
Question: Which line(s) in the following code will fail compilation?
interface Tool{ //1
void operate(); //2
}
abstract class PowerTool implements Tool{ } //3
class PowerSaw implements PowerTool{ //4
@Override //5
public void operate(){ }
}
class SteamPowerSaw extends PowerSaw{ //6
@Override //7
public void operate(int pressure){ }
}
Select 2 option(s)
//1
//2
//3
//4
//5
//6
//7
38.
Question: Which statements about the following code are correct?
interface House{
public default String getAddress(){
return "101 Main Str";
}
}
interface Office {
public static String getAddress(){
return "101 Smart Str";
}
}
interface WFH extends House, Office{
private boolean isOffice(){ return true; }
}
class HomeOffice implements House, Office{
public String getAddress(){
return "R No 1, Home";
}
}
public class TestClass {
public static void main(String[] args) {
Office off = new HomeOffice(); //1
System.out.println(off.getAddress()); //2
}
}
Select 1 option(s)
Code for class HomeOffice will cause compilation to fail.
Code for interface WFH will cause compilation to fail.
It will compile fine and print R No 1, Home when run.
Line at //1 will cause compilation to fail.
Line at //2 will cause compilation to fail.
None
39.
Question: Identify the correct statements regarding DateFormat and NumberFormat classes.
Select 1 option(s)
They allow you to format a date or a number into a string but not vice-versa.
You can set the Locale after constructing a DateFormat or a NumberFormat object and before using it to do country specific formatting.
The following line of code will work on a machine in any locale :
double x = 12345.123; String str = NumberFormat.getInstance().format(x);
NumberFormat should not be used for negative values.
None of these.
None
40.
Question: What will the following code print when compiled and run?
public class Paper {
public String title;
public int id;
public Paper(String title, int id){
this.title = title;
this.id = id;
}
public static void main(String[] args) {
var papers = new Paper[]{
new Paper("T1", 1),
new Paper("T2", 2),
new Paper("T3", 3)
};
System.out.println(papers);
System.out.println(papers[1]);
System.out.println(papers[1].id);
}
}
Select 1 option(s)
papers
Paper
2
papers
T2,2
2
[LPaper;@
hashcode
Paper
2
[LPaper;@
hashcode
Paper@
hashcode
2
It will not compile.
None
41.
Question: Which of the following statements are true?
Select 2 option(s)
System.out.println(1 + 2 + "3"); will print 33.
System.out.println("1" + 2 + 3); will print 15.
System.out.println(4 + 1.0f); will print 5.0.
System.out.println(5/4); will print 1.25.
42.
Question: Given:
@Target(ElementType.FIELD)
public @interface DBField {
public String type();
public String value() default "";
public int invalue() default 0;
}
Identify correct usages of the above annotation.
Select 1 option(s)
interface A{
@DBField(type="string")
String name = "";
}
public class Person{
@DBField
String name = "";
}
public class Person{
@DBField(type="string", "")
String name = "";
}
public class Person{
@DBField(type="string", "", intValue=10)
String name = "";
}
None
43.
Question: Consider the following code:
class A{
public XXX m1(int a){
return a*10/4-30;
}
}
class A2 extends A{
public YYY m1(int a){
return a*10/4.0;
}
}
What can be substituted for XXX and YYY so that it can compile without any problems?
Select 1 option(s)
int, int
int, double
double, double
double, int
Nothing, they are simply not compatible.
None
44.
Question: What will the following program print?
public class TestClass{
static String str = "Hello World";
public static void changeIt(String s){
s = "Good bye world";
}
public static void main(String[] args){
changeIt(str);
System.out.println(str);
}
}
Select 1 option(s)
"Hello World"
"Good bye world"
It will not compile.
It will throw an exception at runtime.
None of the above.
None
45.
Question: Given:
byte b = 1;
char c = 1;
short s = 1;
int i = 1;
Which of the following expressions are valid?
Select 3 option(s)
s = b * b ;
i = b + b ;
s *= b ;
c = c + b ;
s += i ;
46.
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 1 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;
}
None
47.
Question: Consider the following code snippet:
for(var i=INT1; i<INT2; i++){
System.out.println(i);
}
INT1 and INT2 can be any two integers.
Which of the following will produce the same result?
Select 1 option(s)
for(int i=INT1; i< INT2; System.out.println(++i));
for(int i=INT1; i++< INT2; System.out.println(i));
int i=INT1; while(i++< INT2) { System.out.println(i); }
int i=INT1; do { System.out.println(i); }while(i++< INT2);
None of these.
None
48.
Question: Identify correct statement(s) about the following code:
public class FunWithOptional{
public static String getValue(){
return null;
}
public static void main(String[] args) {
Optional stro = Optional.of(getValue());//1
System.out.println(stro.isPresent());//2
System.out.println(stro.get());//3
System.out.println(stro.orElse(null));//4
}
}
Select 1 option(s)
It will throw a NullPointerException at //1.
It will throw a NullPointerException at //3.
It will throw a NoSuchElementException at //3.
It will throw a NullPointerException at //4.
It will print:
false
null
null
None
49.
Question: What will be the output of compiling and running the following program:
class TestClass implements I1, I2{
public void m1() { System.out.println("Hello"); }
public static void main(String[] args){
TestClass tc = new TestClass();
( (I1) tc).m1();
}
}
interface I1{
int VALUE = 1;
void m1();
}
interface I2{
int VALUE = 2;
void m1();
}
Select 1 option(s)
It will print Hello.
There is no way to access any VALUE in TestClass.
The code will work fine only if VALUE is removed from one of the interfaces.
It will not compile.
None of the above.
None
50.
Question: Which of the following statements are true regarding the try-with-resources statement?
Select 1 option(s)
AutoCloseable's close method throws IOException while Closeable's close method throws Exception.
Resources are closed in the reverse order of their declaration in the try clause (or creation, if they are created in the try clause).
AutoCloseable extends Closeable.
AutoCloseable's close() does not declare any throws clause.
Closeable's close() does not declare any throws clause while AutoCloseable's close() throws Exception.
None
51.
Question: Given the following code fragment:
List cities = List.of("USA", "Netherlands", "UK", "India", "France");
Comparator c = (a, b)->a.compareTo(b); //1
Comparator cr = c.reversed();//2
String joined = cities.stream().sorted(cr).collect(Collectors.joining(", "));//3
System.out.println(joined);
What is the result?
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
Compilation error at //3.
USA, UK, Netherlands, India, France
USA, Netherlands, UK, India, France
France, India, Netherlands, UK, USA
None
52.
Question: Identify correct statements about the modular system of Java.
Select 3 option(s)
A module can allow other modules to access all its types and members of its type through reflection.
By default, a module exhibits strong encapsulation by preventing reflective access to it types.
A module can be used by non-modular code by putting that module on the classpath.
An application can either use module-path or classpath but not both.
53.
Question: Given:
Path p1 = Paths.get("c:\\temp\\test1.txt");
Path p2 = Paths.get("c:\\temp\\test2.txt");
Which of the following code fragments moves the file test1.txt to test2.txt, even if test2.txt exists?
Select 2 option(s)
Files.move(p1, p2);
Files.move(p1, p2, StandardCopyOption.REPLACE_EXISTING);
try(Files.move(p1, p2)){
}
try(Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING)){
Files.delete(p1);
}
Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
Files.delete(p1);
54.
Question: Consider the following code snippet:
public class Test{
void test(){
MyClass obj = new MyClass();
obj.name = "jack";
// 1 insert code here
}
}
//In MyClass.java
public class MyClass{
int value;
String name;
}
What can be inserted at // 1, which will make the object referred to by obj eligible for garbage collection?
Select 1 option(s)
obj.destroy();
Runtime.getRuntime().gc();
obj = null;
obj.finalize()
obj.name = null; as well as obj = null;
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