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 - 11
Name
Email
Phone
1.
Question: Given:
package strings;
public class StringFromChar {
public static void main(String[] args) {
String myStr = "good";
char[] myCharArr = {'g', 'o', 'o', 'd' };
String newStr = null;
for(char ch : myCharArr){
newStr = newStr + ch;
}
System.out.println((newStr == myStr)+ " " + (newStr.equals(myStr)));
}
}
What will it print when compiled and run?
Select 1 option(s)
true true
true false
false true
false false
None
2.
Question: Given:
class LowBalanceException extends ______{ //1
public LowBalanceException(String msg){ super(msg); }
}
class WithdrawalException extends ______{ //2
public WithdrawalException(String msg){ super(msg); }
}
class Account{
double balance;
public void withdraw(double amount) {
try{
throw new LowBalanceException("Not Implemented");
}catch(WithdrawalException e){
throw new RuntimeException(e.getMessage());
}
}
public static void main(String[] args) {
try{
Account a = new Account();
a.withdraw(100.0);
}catch(WithdrawalException e){
System.out.println(e.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What can be inserted in the above code at //1 and //2 so that it will print "Not Implemented" when run?
Select 1 option(s)
WithdrawalException
Exception
WithdrawalException
RuntimeException
Exception
RuntimeException
RuntimeException
Exception
None
3.
Question: Assuming that the file module-info.java exists in c:\\temp\\src\\foo.bar but not in c:\\temp\\out\\foo.bar and the folder foo.bar exists in c:\\temp\\out, what will happen when the following code is run?
Path p1 = Paths.get("c:\\temp\\src\\foo.bar\\module-info.java");
Path p2 = Paths.get("c:\\temp\\out\\foo.bar");
Files.move(p1, p2);
Select 1 option(s)
module-info.java will be copied over to out\foo.bar folder.
module-info.java will be moved to out\foo.bar folder.
An exception will be thrown.
module-info.java will be moved to out with the name foo.bar.
None
4.
Question: Assume that a method named 'method1' contains code which may raise a non-runtime (checked) Exception.
What is/are the possible way(s) to declare this method so that it indicates that it expects the caller to handle that exception?
Select 2 option(s)
public void method1() throws Throwable
public void method1() throw Exception
public void method1() throw new Exception
public void method1() throws Exception
public void method1()
5.
Question: Which of the given options if put at //1 will compile without any error?
public class TestClass
{
public class A
{
}
public static class B
{
}
public void useClasses()
{
//1
}
}
Select 1 option(s)
new TestClass().new A();
new TestClass.B();
new A();
new TestClass.A();
All of these are valid.
None
6.
Question: Consider the following code:
class A {
public void doA(int k) throws Exception { // 0
for(int i=0; i< 10; i++) {
if(i == k) throw new Exception("Index of k is "+i); // 1
}
}
public void doB(boolean f) { // 2
if(f) {
doA(15); // 3
}
else return;
}
public static void main(String[] args) { // 4
A a = new A();
a.doB(args.length>0); // 5
}
}
Which of the following statements are correct?
Select 1 option(s)
This will compile and run without any errors or exception.
This will compile if throws Exception is added at line //2.
This will compile if throws Exception is added at line //4.
This will compile if throws Exception is added at line //2 as well as //4.
This will compile if line marked // 1 is enclosed in a try - catch block.
None
7.
Question: Consider the following interface definition:
public interface ConstTest{
public int A = 1; //1
int B = 1; //2
static int C = 1; //3
final int D = 1; //4
public static int E = 1; //5
public final int F = 1; //6
static final int G = 1; //7
public static final int H = 1; //8
}
Which line(s) will cause a compilation error?
Select 1 option(s)
1
2
3
4
5
6
7
8
None of them will cause any error.
None
8.
Question: What will the following code print when compiled and run?
List messages = Arrays.asList(new StringBuilder(), new StringBuilder());
messages.stream().forEach(s->s.append("helloworld"));
messages.forEach(s->{
s.insert(5,",");
System.out.println(s);
});
Select 1 option(s)
It will not print anything.
It will not compile.
It will throw IllegalStateException at runtime.
hello,world
hello,world
helloworld
helloworld
None
9.
Question: Given the following interface:
interface InputStreamHandler {
public long read(InputStream in) throws IOException;
}
and the following code in some other class:
public long getTotal(String file) throws IOException{
long sum = readFileBuffered(file,
(InputStream in) -> {
long current = 0;
for (;;) {
int b = in.read();
if (b == -1) {
return current;
}
current += b;
}
});
return sum;
}
public long readFileBuffered(String file, InputStreamHandler handler) throws IOException {
try (final InputStream in = Files.newInputStream(Paths.get(file))) {
return handler.read(new BufferedInputStream(in));
}
}
Identify correct statements.
Select 1 option(s)
This code prevents one category of denial of service attacks.
This code implements secure coding guidelines for mutability.
This code implements secure coding guidelines for Accessibility and Extensibility.
This code implements secure coding guidelines Data Integrity.
None
10.
Question: Identify valid statements.
Select 3 option(s)
Locale myLocale = System.getDefaultLocale();
Locale myLocale = Locale.getDefaultLocale();
Locale myLocale = Locale.getDefault();
Locale myLocale = Locale.US;
Locale myLocale = Locale.getInstance();
Locale myLocale = new Locale("ru", "RU");
11.
Question: Which of the following interface definitions can use Lambda expressions?
Select 1 option(s)
interface A{
}
@FunctionalInterface
interface A{
default void m(){};
}
interface A{
void m(){};
}
interface A{
default void m1(){};
void m2();
}
@FunctionalInterface
interface A{
void m1();
void m2();
}
None
12.
Question: What will the following code print when compiled and run?
List values = Arrays.asList("Java EE", "C#", "Python");
boolean flag = values.stream().allMatch(str->{
System.out.println("Testing: "+str);
return str.equals("Java");
});
System.out.println(flag);
Select 1 option(s)
Testing: Java EE
false
Testing: Java EE
Testing: C#
Testing: Python
false
Testing: Java EE
true
It will not compile because lambda expression is built incorrectly.
None
13.
Question: What will the following code fragment print?
Path p1 = Paths.get("c:\\personal\\.\\photos\\..\\readme.txt");
Path p2 = p1.normalize();
System.out.println(p2);
Select 1 option(s)
readme.txt
c:\personal\photos\readme.txt
c:\personal\readme.txt
c:\photos\readme.txt
None
14.
Question: Given:
import java.time.LocalDate;
import static java.time.DayOfWeek.*;
public class TestClass {
public static void main(String[] args){
var day = LocalDate.now().with(FRIDAY).getDayOfWeek();
switch(day){
case MONDAY:
TUESDAY:
WEDNESDAY:
THURSDAY:
FRIDAY:
System.out.println("working");
case SATURDAY:
SUNDAY:
System.out.println("off");
}
}
}
What is the output?
Select 1 option(s)
working
off
working
No output will be produced.
Compilation failure.
Exception will be thrown at run time.
None
15.
Question: Which of the following method would you use to get a JDBC connection while using JDBC 4.0 but not while using a previous version of JDBC?
Select 2 option(s)
public Connection getConnection1(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("user", userid);
p.setProperty("password", pwd);
return DriverManager.getConnection(url, p);
}
public Connection getConnection2(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("user", userid);
p.setProperty("password", pwd);
DriverManager.registerDriver("com.xyz.Driver");
return DriverManager.getConnection(url, p);
}
public Connection getConnection3(String url, String userid, String pwd) throws Exception{
Properties p = new Properties();
p.setProperty("jdbc.driver", "com.xyz.Driver");
p.setProperty("jdbc.user", userid);
p.setProperty("jdbc.user.password", pwd);
return DriverManager.getConnection(url, p);
}
public Connection getConnection4(String url, String userid, String pwd) throws Exception{
Class.forName("com.xyz.Driver");
return DriverManager.getConnection(url, userid, pwd);
}
public Connection getConnection5(String url, String userid, String pwd) throws SQLException{
return DriverManager.getConnection(url, userid, pwd);
}
16.
Question: What, if anything, is wrong with the following code?
void test(int x){
switch(x){
case 1:
case 2:
case 0:
default :
case 4:
case 'a'|'b': System.out.println('c');
}
}
Select 1 option(s)
Data Type of 'x' is not valid to be used as an expression for the switch clause.
The case label 0 must precede case label 1.
Each case section must end with a break keyword.
The default label must be the last label in the switch statement.
There is nothing wrong with the code.
The last case statement is invalid.
None
17.
Question: You are the maintainer of a library packaged as bondanalytics.jar, which is used by several groups in your company. It has the following two packages that are used by other applications:
com.abc.bonds
com.abc.bonds.analytics
You want to modularize this jar but some groups have not yet modularized their applications. How will such groups use the modularized jar?
Select 1 option(s)
They cannot. Two versions of the jar will need to be maintained - one modularized and one old.
They can remove module-info.class from your modular jar and use the jar just as before.
They can use the new modular jar just like they use the old jar earlier without any changes.
They would have to use the --module-path option to use the new modular jar.
None
18.
Question: Given the following class, which of the given blocks can be inserted at line 1 without errors?
public class InitClass{
private static int loop = 15 ;
static final int INTERVAL = 10 ;
boolean flag ;
//line 1
}
Select 4 option(s)
static {System.out.println("Static"); }
static { loop = 1; }
static { loop += INTERVAL; }
static { INTERVAL = 10; }
{ flag = true; loop = 0; }
var flag2 = flag ;
19.
Question: Which of the following are valid declarations independent of each other inside the following interface?
public interface FooI{
}
Select 3 option(s)
public int FOO;
public void bar();
private static void mbaz(){
}
private int BOO = 10;
public default void base(){
};
@Override
public void bar();
20.
Question: Given the following code (assume appropriate imports):
public class IOTest {
public static void main(String[] args) {
var myfile = Paths.get("test.txt");
try(var bfr = Files.newBufferedReader(myfile, Charset.forName("US-ASCII") )){
String line = null;
while( (line = bfr.readLine()) != null){
System.out.println(line);
}
}catch(Exception e){
System.out.println(e);
}
}
}
What will be printed when this code is run if test.txt doesn't exist?
Select 1 option(s)
java.io.FileNotFoundException: test.txt
java.nio.file.FileNotFoundException: test.txt
java.nio.file.NoSuchFileException: test.txt
java.nio.file.InvalidPathException : test.txt
None
21.
Question: Given:
@Target({ElementType.LOCAL_VARIABLE, ElementType.FIELD, ElementType.METHOD}) //1
@Target({ElementType.TYPE})//2
@Retention(RetentionPolicy.RUNTIME)//3
public @interface DebugInfo { //4
String name() default=""; //5
String[][] params();//6
java.util.Date entryTime();//7
}
Which line(s) will cause compilation failure?
Select 4 option(s)
//1
//2
//3
//4
//5
//6
//7
22.
Question: Following is a program to capture words from command line and create two collections. One that keeps only unique words and one that keeps all the words in the order they were entered. What should replace AAA and BBB?
static Collection unique = new AAA();
static Collection ordered = new BBB();
public static void main(String args[]) throws Exception
{
BufferedReader bfr = new BufferedReader( new InputStreamReader( System.in ) );
String s = bfr.readLine();
while(s != null && s.length() >0)
{
unique.add(s);
ordered.add(s);
s = bfr.readLine();
}
System.out.println(unique);
System.out.println(ordered);
}
Select 2 option(s)
Set, List
LinkedList, HashSet
HashSet, LinkedList
HashSet, ArrayList
Vector, TreeSet
23.
Question: Given:
class Game{ }
class Cricket extends Game{ }
class Instrument{ }
class Guitar extends Instrument{ }
interface Player{ void play(E e); }
interface GamePlayer extends Player{ }
interface MusicPlayer extends Player{ }
Identify valid declarations.
Select 1 option(s)
class Batsman implements GamePlayer< Cricket >{
public void play(Game o){ }
}
class Bowler implements GamePlayer
Guitar
{
public void play(Guitar o){}
}
class Bowler implements Player
Guitar
{
public void play(Guitar o){ }
}
class MidiPlayer implements MusicPlayer {
public void play(Guitar g){ }
}
class MidiPlayer implements MusicPlayer< Instrument > {
public void play(Guitar g){ }
}
None
24.
Question: What will be the contents of d at the end of the following code?
Deque d = new ArrayDeque();
d.add(1);
d.addFirst(2);
d.pop();
d.offerFirst(3);
(Assume that in the output, front of deque is on the left side and the end is on the right side.)
Select 1 option(s)
1, 3
3, 1
An exception will be thrown at run time.
Order of elements in the Deque cannot be predicted.
It will not compile.
None
25.
Question: What will the following class print when compiled and run?
import java.util.*;
public class TestClass {
public static void main(String[] args) {
TreeSet s = new TreeSet();
TreeSet subs = new TreeSet();
for(int i = 324; i<=328; i++)
{
s.add(i);
}
subs = (TreeSet) s.subSet(326, true, 328, true );
subs.add(329);
System.out.println(s+" "+subs);
}
}
Select 1 option(s)
[324, 325, 326, 327, 328] [326, 327, 329]
[324, 325, 326, 327, 329] [326, 327, 329]
[324, 325, 326, 327, 328] [326, 327]
It will throw an exception at runtime.
It will not compile.
None
26.
Question: Which of the following texts can occur in a valid resource bundle file?
Select 2 option(s)
greetings=bonjour
< key name="greetings">bonjour</key >
< key name="greetings" value="bonjour" / >
< key >
< name>greetings < value>bonjour"< /value >
< /key >
< key >greetings< /key >
< value >bonjour< /value >
greetings1=bonjour
greetings2=no bonjour
greetings1=bonjour,greetings2=no bonjour
27.
Question: Given:
ArrayList source = new ArrayList();
source.addAll(Arrays.asList(1, 2, 3, 4, 5, 6));
List destination =
Collections.synchronizedList(new ArrayList());
source
.parallelStream() //1
.peek(item->{destination.add(item); }) //2
.forEachOrdered(System.out::print);
System.out.println("");
destination
.stream() //3
.forEach(System.out::print); //4
System.out.println("");
What changes must be made to the above code so that it will consistently print
123456
123456
?
Select 1 option(s)
Replace code at //1 with
.stream()
Replace code at //2 with
.map(item->{destination.add(item); return item; })
Replace code at //3 with
.parallelStream()
Replace code at //4 with
.forEachOrdered(System.out::print);
None
28.
Question: Consider the following code:
public class Logger{
private StringBuilder sb = new StringBuilder();
public void logMsg(String location, String message){
sb.append(location);
sb.append("-");
sb.append(message);
}
public void dumpLog(){
System.out.println(sb.toString());
//Empty the contents of sb here
}
}
Which of the following options will empty the contents of the StringBuilder referred to by variable sb in method dumpLog()?
Select 1 option(s)
sb.delete(0, sb.length());
sb.clear();
sb.empty();
sb.removeAll();
sb.deleteAll();
None
29.
Question: What will the following program print?
public class TestClass{
public static void main(String[] args){
Object obj1 = new Object();
Object obj2 = obj1;
if( obj1.equals(obj2) ) System.out.println("true");
else System.out.println("false");
}
}
Select 1 option(s)
True
False
It will not compile.
It will compile but throw an exception at run time.
None of the above.
None
30.
Question: What will the following code print?
Stream ss = Stream.of("a", "b", "c");
String str = ss.collect(Collectors.joining(",", "-", "+"));
System.out.println(str);
Select 1 option(s)
-a+,-b+,-c+
a,-+b,-+c
-a,b,c+
It will throw an exception at run time.
None
31.
Question: Identify correct statements about the modular JDK.
Select 3 option(s)
The foundational APIs of the Java SE platform are found in java.base module.
The modular JDK is composed of two modules - the java module and the jdk module.
JDK is divided into a set of modules that can be combined at compile time, build time, and run time into a variety of configurations.
The modular JDK is divided of two kinds of modules - the standard modules and the non-standard modules.
32.
Question: Identify the correct statements about the following code:
import java.util.*;
class Person {
private String name;
public Person(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String toString() { return name; }
}
class Helper {
public void helpPeople(Queue people, Queue helped) {
do {
Person p = (Person) people.poll();
System.out.println("Helped : " + p + " ");
helped.offer(p.getName());
} while (!people.isEmpty());
}
public static void main(String[] args) {
Queue q = new LinkedList();
q.offer(new Person("Pope"));
q.offer(new Person("John"));
Queue helpedQ = new LinkedList();
Helper h = new Helper();
h.helpPeople(q, helpedQ);
}
}
Select 2 option(s)
It will print :
Helped : Pope
Helped : John
It will compile with a warning.
It will throw an exception at runtime.
It will compile without warning but will throw an exception at runtime.
It will print :
Helped : John
Helped : Pope
It will print : Helped : John
It will print : Helped : Pope
33.
Question: What will the following code print when compiled and run?
public class TestClass{
public static int operate(IntUnaryOperator iuo){
return iuo.applyAsInt(5);
}
public static void main(String[] args) {
IntFunction fo = a->b->a-b; //1
var x = operate(fo.apply(20)); //2
System.out.println(x);
}
}
Select 1 option(s)
Compilation error at //1.
Compilation error at //2.
15
-15
20
Exception at run time.
None
34.
Question: What will the following lines of code print?
System.out.println(1 + 5 < 3 + 7);
System.out.println( (2 + 2) >= 2 + 3);
Select 1 option(s)
They will not compile.
1false10
false
true
false
false
false
None
35.
Question: What can be done to get the following code to compile and run? (Assume that the options are independent of each other).
public float parseFloat( String s ){
float f = 0.0f; // 1
try{
f = Float.valueOf( s ).floatValue(); // 2
return f ; // 3
}
catch(NumberFormatException nfe){
f = Float.NaN ; // 4
return f; // 5
}
finally {
return f; // 6
}
return f ; // 7
}
Select 4 option(s)
Remove line 3, 6
Remove line 5
Remove line 5, 6
Remove line 7
Remove line 3, 7
36.
Question: Given:
class A{
public List getList(){
//valid code
};
}
class B extends A{
@Override
*INSERT CODE HERE*
//valid code
};
}
What can be inserted in the above code?
Select 5 option(s)
public List
? extends Number
getList(){
public List
? super Integer
getList(){
public ArrayList
? extends Number
getList(){
public ArrayList
Number
getList(){
public ArrayList
Integer
getList(){
37.
Question: As a part of an application, you have serialized and stored some objects of a class in the database. At another place in the same application, you deserialize those objects.
After a few months you determine that you need to add one new String field in the class.
Which of the following statements are correct regarding the above described situation?
Select 1 option(s)
The objects serialized earlier cannot be deserialized to the updated class objects.
Objects serialized earlier can be deserialized to the updated class objects by adding a new serialVersionUID field with a value of 0 to the updated class.
No special change is necessary in the updated class. Objects serialized earlier will be deserialized to the updated class objects but the newly added field will be null.
Old serialized objects can be deserialized only if the original class had explicitly defined a serialVersionUID field and if the updated class maintains the same value for that field.
It is possible to deserialize the older objects into the update class objects even if the original class did not explicitly define the serialVersionUID field.
None
38.
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 classes from com.abc.accounts package in accounting-3.2.jar while classes in accounting-3.2.jar do not refer to classes from reporting-5.6.jar.
The application is currently launched using the following command:
java -classpath accounting-3.2.jar;reporting-5.6.jar com.abc.reporting.Main
The accounting team has decided to modularize the new version of their jar but the reporting team hasn't.
Which of the following commands can be used to launch the reporting application using the new version of accounting jar?
Select 2 option(s)
java -classpath accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java -classpath reporting-5.6.jar --module-path accounting-3.3.jar;
com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar com.abc.reporting.Main
java --module-path accounting-3.3.jar;reporting-5.6.jar
--add-modules accounting
--module reporting/com.abc.reporting.Main
(Assume that the module name in accounting-3.3.jar is accounting.)
39.
Question: Consider the following method code:
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 ( *INSERT CODE HERE* e ) { //LINE 100
}
}
What can be inserted at //LINE 100 to make the method compile?
Select 1 option(s)
Exception|IOException
FileNotFoundException|SecurityException|IllegalArgumentException
FileNotFoundException|IOException
IOException|RuntimeException
IOException|NoSuchFileException
None
40.
Question: What will be the result of attempting to compile and run the following code?
public class PromotionTest{
public static void main(String args[]){
int i = 5;
float f = 5.5f;
double d = 3.8;
char c = 'a';
if (i == f) c++;
if (((int) (f + d)) == ((int) f + (int) d)) c += 2;
System.out.println(c);
}
}
Select 1 option(s)
The code will fail to compile.
It will print d.
It will print c.
It will print b.
It will print a.
None
41.
Question: Given the following complete contents of TestClass.java:
import java.util.ArrayList;
import java.util.Collections;
class Address implements Comparable
{
String street;
String zip;
public Address(String street, String zip){
this.street = street; this.zip = zip;
}
public int compareTo(Address o) {
int x = this.zip.compareTo(o.zip);
return x == 0? this.street.compareTo(o.street) : x;
}
}
public class TestClass {
public static void main(String[] args) {
ArrayList
al = new ArrayList();
al.add(new Address("dupont dr", "28217"));
al.add(new Address("sharview cir", "28217"));
al.add(new Address("yorkmont ridge ln", "11223"));
Collections.sort(al);
for(Address a : al) System.out.println(a.street+" "+ a.zip);
}
}
What will be printed?
Select 1 option(s)
yorkmont ridge ln 11223
dupont dr 28217
sharview cir 28217
sharview cir 28217
yorkmont ridge ln 11223
dupont dr 28217
sharview cir 28217
dupont dr 28217
yorkmont ridge ln 11223
The order of output messages cannot be determined.
It will throw an exception at run time.
It will not compile.
None
42.
Question: Given:
interface I { }
class A implements I{
public String toString(){ return "in a"; }
}
class B extends A{
public String toString(){ return "in b"; }
}
public class TestClass {
public static void main(String[] args) {
B b = new B();
A a = b;
I i = a;
System.out.println(i);
System.out.println((B)a);
System.out.println(b);
}
}
What will be printed when the above code is compiled and run?
Select 1 option(s)
in i
in a
in b
I
A
in b
in a
in a
in b
in a
in b
in b
in b
in b
in b
None
43.
Question: Which of the following sets of interface definitions are valid?
Select 1 option(s)
interface Measurement{
public int getLength(){
return 0;
}
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public default int getLength(){
return 0;
}
public static int getBreadth(){ return 0; }
}
interface Size extends Measurement{
public static final int UNIT = 100;
public static int getLength(){ return 10;}
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private void helper(){ }
}
interface Measurement{
public default final int getUnit(){ return 100; }
private void helper(){ }
}
interface Size extends Measurement{
public int getLength();
}
interface Measurement{
public int getLength();
public static int getBreadth(){ return 0; }
private void helper(){ }
}
interface Size extends Measurement{
private final int STEP = 10;
}
None
44.
Question: Consider the following code.
LocalDate d = LocalDate.now();
Locale loc = new Locale("fr", "FR");
// 1 insert code here.
What should be inserted at //1 above so that it will print the date in French format?
Select 1 option(s)
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy", loc);
System.out.println(df.format(d));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d, loc));
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
df.setLocale(loc);
System.out.println(df.format(d));
D.setLocale(loc);
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy");
System.out.println(df.format(d));
None
45.
Question: Which of the following statements will correctly create and initialize an array of Strings to non null elements?
Select 4 option(s)
String[] sA = new String[1] { "aaa"};
String[] sA = new String[] { "aaa"};
Var[] sA = new String[1] ; sA[0] = "aaa";
String[] sA = {new String( "aaa")};
String[] sA = { "aaa"};
String[] sA = new String[1] ; sA[0] = "aaa";
46.
Question: Which of the following are valid JDBC URLs?
Select 1 option(s)
jdbc:derby://localhost:1527/sample
//jdbc://derby://localhost:1527/sample
http://jdbc:mysql:localhost/sample
https://mysql.com:3306/sample
None
47.
Question: Given:
public class Book {
private String title;
private String genre;
public Book(String title, String genre){
this.title = title; this.genre = genre;
}
//accessors not shown
}
and the following code:
List books = List.of(
new Book("Gone with the wind", "Fiction"),
new Book("Bourne Ultimatum", "Thriller"),
new Book("The Client", "Thriller")
);
Reader r = b->{
System.out.println("Reading book "+b.getTitle());
};
books.forEach(x->r.read(x));
What would be a valid definition of Reader for the above code to compile and run without any error or exception?
Select 2 option(s)
abstract class Reader{
abstract void read(Book b);
}
abstract class Reader{
void read(Book b);
}
interface Reader{
void read(Book b);
default void unread(Book b){ }
}
interface Reader{
default void read(Book b){ }
void unread(Book b);
}
interface Reader{
default void read(Book b){ System.out.println("Default read");};
}
48.
Question: Consider the following code:
Locale.setDefault(new Locale("es", "ES"));
ResourceBundle rb = ResourceBundle.getBundle("appmessages");
String msg = rb.getString("greetings");
System.out.println(msg);
You have created a valid resource bundle file named appmessages_es_ES.properties that contains 'greetings' property. However, when you run the above code, you get an exception saying, "java.util.MissingResourceException: Can't find bundle for base name appmessages, locale es_ES".
What could be the reason?
Select 1 option(s)
appmessages_es_ES.properties is not present in PATH.
appmessages_es_ES.properties is not present in CLASSPATH.
appmessages_es_ES.properties is not specified using -D option on command line.
appmessages_es_ES.properties is not present in JAVA_HOME.
None
49.
Question: What will the following code snippet print:
Float f = null;
try{
f = Float.valueOf("12.3");
String s = f.toString();
int i = Integer.parseInt(s);
System.out.println(""+i);
}
catch(Exception e){
System.out.println("trouble : "+f);
}
Select 1 option(s)
12
13
trouble : null
trouble : 12.3
trouble : 0.0
None
50.
Question: Given:
class Booby{
}
class Dooby extends Booby{
}
class Tooby extends Dooby{
}
public class TestClass {
Booby b = new Booby();
Tooby t = new Tooby();
public void do1(List dataList){
//1 INSERT CODE HERE
}
public void do2(List dataList){
//2 INSERT CODE HERE
}
}
and the following four statements:
1. b = dataList.get(0);
2. t = dataList.get(0);
3. dataList.add(b);
4. dataList.add(t);
What can be inserted in the above code?
Select 1 option(s)
Statements 1 and 3 can inserted at //1 and Statements 2 and 4 can be inserted at //2.
Statement 4 can inserted at //1 and Statement 1 can be inserted at //2.
Statements 3 and 4 can inserted at //1 and Statements 1 and 2 can be inserted at //2.
Statements 1 and 2 can inserted at //1 and Statements 3 and 4 can be inserted at //2.
Statement 1 can inserted at //1 and Statement 4 can be inserted at //2.
None
51.
Question: Consider the following classes in one file named A.java...
abstract class A{
protected int m1(){ return 0; }
}
class B extends A{
@Override
int m1(){ return 1; }
}
Which of the following statements are correct.
Select 1 option(s)
The code will not compile as you cannot have more than one class in one file.
The code will not compile because class B does not override the method m1() correctly.
The code will not compile as A is an abstract class but does not have any abstract method.
The code will not compile because @Override annotation is used incorrectly.
The code will compile fine.
None
52.
Question: Consider the following array definitions:
int[] array1, array2[];
int[][] array3;
int[] array4[], array5[];
Which of the following are valid statements?
Select 3 option(s)
array2 = array3;
array2 = array4;
array1 = array2;
array4 = array1;
array5 = array3;
53.
Question: Consider the following code:
String id = c.readLine("%s", "Enter UserId:"); //1
System.out.println("userid is " + id); //2
String pwd = c.readPassword("%s", "Enter Password :"); //3
System.out.println("password is " + pwd); //4
Assuming that c is a valid reference to java.io.Console and that a user types jack as userid and jj123 as password, what will be the output on the console?
Select 1 option(s)
Enter UserId:jack
userid is jack
Enter Password :
password is jj123
Enter UserId:jack
userid is jack
Enter Password :*****
password is jj123
Enter UserId:jack
userid is jack
Enter Password :
password is ****
Enter UserId:jack
userid is jack
Enter Password : password is jj123
It will not compile.
None
54.
Question: Consider the following program:
public class TestClass{
public static void main(String[] args) { calculate(2); }
public static void calculate(int x){
String val;
switch(x){
case 2:
default:
val = "def";
}
System.out.println(val);
}
}
What will happen if you try to compile and run the program?
Select 2 option(s)
It will not compile saying that variable val may not have been initialized.
It will compile and print def.
As such it will not compile but it will compile if calculate(2); is replaced by calculate(3);
It will compile for any int values in calculate(...);
55.
Question: What will the following code print when compiled and run?
public static void main(String[] args) {
Stream<List> s1 = Stream.of(
Arrays.asList("a", "b"),
Arrays.asList("a", "c")
);
Stream news = s1.filter(s->s.contains("c"))
.flatMap(olds -> olds.stream());
news.forEach(System.out::print);
}
Select 1 option(s)
ab
ac
[a, b]
[a, c]
[ab]
[ac]
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