Skip to content
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Java standard test 5 Code 1Z 829
Welcome to your Java Test - 5
Name
Email
Phone
1.
Question: Given that a class named mywids.Widget is part of a module named mod.wids packaged in mywidgets.jar, which of the following commands can be used to execute this class?
(Assume that the jar file is located in the current directory and the jar file does not have any entry in its manifest.)
Select 1 option(s)
java --module-path mywidgets.jar --module mywids.Widget
java --module-path mywidgets.jar --module mod.wids/mywids.Widget
java --module-path mywidgets.jar --module mod.wids --main-class mywids.Widget
java --module-path mywidgets.jar --module mod.wids mywids.Widget
None
2.
Question: Given the following code:
sealed interface Cacheable permits Value, Result{
default void clear(){ System.out.println("clearing cache..."); }
}
Which of the following definitions will compile without error?
Select 2 option(s)
interface Value extends Cacheable{ }
non-sealed abstract class Result implements Cacheable{ }
non-sealed interface Value extends Cacheable{ }
non-sealed abstract class Result implements Cacheable{ }
abstract non-sealed interface Value extends Cacheable{ }
sealed abstract class Result implements Cacheable permits IntResult{ }
final class IntResult extends Result{ }
non-sealed interface Value extends Cacheable{ }
non-sealed abstract class Result { }
non-sealed interface Value extends Cacheable{ }
abstract class Result { }
final class IntResult extends Result implements Cacheable{ }
3.
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; }
4.
Question: Given that a file named test1.txt contains the following data:
01234567
and the following code snippet:
char[] buf = new char[5];
try( FileReader fr = new FileReader("c:\\temp\\test1.txt");
FileWriter fw = new FileWriter("c:\\temp\\test2.txt")){
while( fr.read(buf) != -1){
fw.write(buf);
}
}
What will be the contents of test2.txt after the above code is run?
Select 1 option(s)
0123456700
0123401234
01234567
0123456734
0000000000
None
5.
Question: Given:
Assuming that a SUBJECT table with no rows also exists, identify correct statements.
Select 2 option(s)
Two PreparedStatement objects are created.
Three PreparedStatement objects are created.
Two SQL statements are executed.
Three SQL statements are executed.
An SQLException will be thrown because the ResultSet is not closed.
It will cause memory leaks because Connection, PreparedStatement, and ResultSet objects are not closed.
6.
Question: What will the following code fragment print?
Path p1 = Paths.get("c:\\..\\temp\\test.txt");
System.out.println(p1.normalize().toUri());
Select 1 option(s)
file:///c:/temp/test.txt
file:///c:/../temp/test.txt
file:///c:/test.txt
An exception will be thrown.
None
7.
Question: Given:
static boolean validateInput(String str){
return INSERT CODE HERE;
}
Which of the following expressions can be inserted in the above code so that the validateInput method will return true if and only if the input string contains non-whitespace data?
Select 1 option(s)
!str.isBlank()
!str.isEmpty()
str.strip() != ""
!str.equalsIgnoreBlanks("")
str.compareTo("") != 0
None
8.
Question: Add descriptionGiven:
public class ThreadSafety{
List sList = new ArrayList();
public Student getStudent(){
var s = sList.remove(0);
return s;
}
...other irrelevant code
}
If two threads, T1 and T2, concurrently execute getStudent() method on the same ThreadSafety instance, which of the following are possible outcomes? (Assume that there are no nulls in the list.)
Select 3 option(s)
T1 gets a Student object and T2 gets IndexOutOfBoundsException.
T1 and T2 get two different instances of Student objects.
T1 gets a Student object and T2 gets null.
T1 gets a Student object and T2 gets a ConcurrentModificationException.
Both the threads get a reference to the same Student object.
9.
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
10.
Question: Which of the following are valid ways to create a LocalDateTime?
Select 1 option(s)
java.time.LocalDate.parse("2015-01-02");
java.time.LocalDateTime.parse("2015-01-02");
java.time.LocalDateTime.of(2015, 10, 1, 10, 10);
java.time.LocalDateTime.of(2015, "January", 1, 10, 10);
None
11.
Question: Given:
var books = new ArrayList(List.of(new Book("The Outsider", "Stephen King"),
new Book("Becoming", "Michelle Obama" ), new Book("Uri", "India")));
Stream bkStrm = books.stream(); //1
int count = bkStrm.peek(x->x.getTitle()).count();//2
Assuming that the Book class has appropriate constructor and method, what changes can be made to the above code independent of each other to make it will compile ?
Select 1 option(s)
None
12.
Question: Given the following line of code:
LocalDateTime dt = LocalDateTime.parse("2022-01-02T17:13:50");
Which of the following lines will return the date string in ISO 8601 format?
Select 2 option(s)
dt.format(java.time.format.DateTimeFormatter.DATE_TIME);
dt.format(java.time.format.DateTimeFormatter.ISO_DATE_TIME);
dt.format(java.time.format.DateTimeFormatter.LOCAL_DATE_TIME);
dt.toString();
13.
Question: What will the following code print when run?
Period p = Period.between(LocalDate.now(), LocalDate.of(2022, Month.SEPTEMBER, 1));
System.out.println(p);
Duration d = Duration.between(LocalDateTime.now(),
LocalDateTime.of(2022, Month.SEPTEMBER, 2, 10, 10));
System.out.println(d);
Assume that the local time on the system at the time this code is run is 2nd Sep 2022 1:00 AM.
Select 1 option(s)
P-1D
PT9H10M
P1D
PT9H10M
P-1D
P9H10M
P1D
P9H10M
None
14.
Question: Given:
public class TestClass{
static int someMethod(){ return 100; }
static class MyWorker{
Runnable r;
public MyWorker(Runnable r){
this.r = r;
}
}
public static void main(String[] args) {
//INSERT CODE HERE
MyWorker w = new MyWorker(r);
}
}
What can be inserted in the above code?
Select 3 option(s)
Runnable r = ()->System.out.println("Hello");
Runnable r = { System.out.println("Hello");}
Runnable r = () -> System.out::println();
Runnable r = (a)->System.out.println(a);
Runnable r = -> System.out.println();
Runnable r = ()-> { someMethod(); };
Runnable r = ()-> someMethod();
15.
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
16.
Question: What will be the output if you run the following program?
public class TestClass{
public static void main(String args[]){
int i;
int j;
for (i = 0, j = 0 ; j < 1 ; ++j , i++){
System.out.println( i + " " + j );
}
System.out.println( i + " " + j );
}
}
Select 1 option(s)
0 0 will be printed twice.
1 1 will be printed once.
0 1 will be printed followed by 1 2.
0 0 will be printed followed by 1 1.
It will print 0 0 and then 0 1.
None
17.
Question: Given the following code snippet:
int rate = 10;
int t = 5;
XXX amount = 1000.0;
for(int i=0; i<t; i++){
amount = amount*(1 - rate/100);
}
What can XXX be?
Select 1 option(s)
int
long
only double
double or float
float
None
18.
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
19.
Question: What will the following code fragment print?
Path p1 = Paths.get("photos\\..\\beaches\\.\\calangute\\a.txt");
Path p2 = p1.normalize();
Path p3 = p1.relativize(p2);
Path p4 = p2.relativize(p1);
System.out.println(
p1.getNameCount()+" "+p2.getNameCount()+" "+
p3.getNameCount()+" "+p4.getNameCount());
Select 1 option(s)
6 4 10 10
7 4 11 10
7 3 8 9
6 3 1 1
None
20.
Question: Which of the following are valid declarations inside the FooI interface?
interface AI{
void moo();
}
interface FooI extends AI{
//INSERT CODE HERE
}
Select 2 option(s)
private void foo(){ };
private abstract void foo();
static void foo();
protected void foo();
public final void compute();
final void foo(){ }
@Override
void moo();
21.
Question: Which of the following statements will compile without any error?
Select 4 option(s)
System.out.println("a"+'b'+63);
System.out.println("a"+63);
System.out.println('b'+new Integer(63));
String s = 'b'+63+"a";
String s = 63 + new Integer(10);
22.
Question: Consider the following classes...
class Car{
public int gearRatio = 8;
public String accelerate() { return "Accelerate : Car"; }
}
class SportsCar extends Car{
public int gearRatio = 9;
public String accelerate() { return "Accelerate : SportsCar"; }
public static void main(String[] args){
Car c = new SportsCar();
System.out.println( c.gearRatio+" "+c.accelerate() );
}
}
What will be printed when SportsCar is run?
Select 1 option(s)
8 Accelerate : Car
9 Accelerate : Car
8 Accelerate : SportsCar
9 Accelerate : SportsCar
None of the above.
None
23.
Question: Which of the following methods can be called on a String object?
Select 4 option(s)
substring(int i)
substring(int i, int j)
substring(int i, int j, int k)
equals(Object o)
formatted(Object... o)
24.
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
25.
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
26.
Question: Your application includes a method that generates a report using Employee data. While generating the report, if this method detects inconsistent payment records, it cannot generate the report. You want to create a new exception class that should be thrown in this situation. Which of the following is a valid implementation for this exception?
Select 1 option(s)
public class ReconciliationException extends Throwable{
}
public class ReconciliationError extends Error{
}
public class ReconciliationException extends Exception{
}
public class ReconciliationException {
}
None
27.
Question: Which of the following code snippets appearing in a method are valid.
Select 1 option(s)
for(var x : System.getProperties().entrySet()){
var m = x.getKey();
}
for(var x : System.getProperties().keySet()){
System.out.println(x.length());
}
var obj = null;
var k = System.out::println;
var _ = new ArrayList<>();
var _ = 10;
None
28.
Question: Given:
class MyException extends Exception {
private final int code;
public MyException(int code, Throwable actualEx){
super(actualEx);
this.code = code;
}
public MyException(int code, String message, Throwable actualEx){
super(message, actualEx);//1
this.code = code;
}
public String getMessage(){
return String.format("Exception - Code=%d, Msg=%s, OrigMsg=%s",
code, super.getMessage(), this.getCause().getMessage()); //2
}
}
public class TestClass {
public static void main(String[] args) {
try{
throw new MyException(404, "NOT FOUND",
new IOException("FILE UNREADABLE")); //3
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
What is the result?
Select 1 option(s)
Compilation failure at //1
Compilation failure at //2
It will print:
Exception - Code=404, Msg=NOT FOUND, OrigMsg=FILE UNREADABLE
It will print:
Exception - Code=404, Msg=, OrigMsg=FILE UNREADABLE
It will print:
Exception - Code=404, Msg=, OrigMsg=
It will print:
Exception - Code=404, Msg=FILE UNREADABLE, OrigMsg=NOT FOUND
It will print:
Exception - Code=404, Msg=null, OrigMsg=null
None
29.
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
30.
Question: What will be printed when the following program is compiled and run?
class Super{
public int getNumber( int a){
return 2;
}
}
public class SubClass extends Super{
public int getNumber( int a, char ch){
return 4;
}
public static void main(String[] args){
System.out.println( new SubClass().getNumber(4) );
}
}
What will be printed?
Select 1 option(s)
4
2
It will not compile.
It will throw an exception at runtime.
None of the above.
None
31.
Question: Which is the first line that will cause compilation to fail in the following program?
// Filename: A.java
class A{
public static void main(String args[]){
A a = new A();
B b = new B();
a = b; // 1
b = a; // 2
a = (B) b; // 3
b = (B) a; // 4
}
}
class B extends A { }
Select 1 option(s)
At Line 1.
At Line 2.
At Line 3.
At Line 4.
None of the above.
None
32.
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
33.
Question: Given:
public class Student {
private String name;
private int marks;
//constructor and getters and setters not shown
public void addMarks(int m){
this.marks += m;
}
public void debug(){
System.out.println(name+":"+marks);
}
}
What will the following code print when compiled and run?
List slist = List.of(new Student("S1", 40),
new Student("S2", 35),
new Student("S3", 30));
Consumer increaseMarks = s->s.addMarks(10);
slist.forEach(increaseMarks);
slist.forEach(Student::debug);
Select 1 option(s)
S1:50
S2:45
S3:40
S1:40
S2:35
S3:30
It will not print anything.
It will not compile.
None
34.
Question: Given:
public static void main(String[] args) {
INSERT CODE HERE
List.of(args).forEach(x);
}
Which of the following options can be inserted in the above code without causing a compilation error?
Select 2 option(s)
Consumer x = ()->{ System.out::println; }
Consumer x = System.out::println;
var x = System.out::println;
Consumer x = (m)->{ };
Consumer x = (String msg)->{ System.out.println(msg); };
35.
Question: Given:
//creating Book objects using Book(String title, String author) constructor
var books = List.of( new Book("Where the Crawdads Sing", "Dalia Owens" ),
new Book("The Outsider", "Stephen King"),
new Book("Elevation", "Stephen King"),
new Book("Coffin from Hong Kong", "James Hadley Chase") );
Stream bkStrm = books.stream();
*INSERT CODE HERE*
Assuming Book class has appropriate constructor and accessor methods, which of the following lines of code will get you the first book written by Stephen King from the list of of books?
Select 1 option(s)
None
36.
Question: What can be the return type of method getSwitch so that this program compiles and runs without any problems?
public class TestClass{
public static XXX getSwitch(int x){
return x - 20/x + x*x;
}
public static void main(String args[]){
switch( getSwitch(10) ){
case 1 :
case 2 :
case 3 :
default : break;
}
}
}
Select 1 option(s)
int
float
long
double
char
byte
short
None
37.
Question: Assume that a table named department exists and has the following data:
Select 1 option(s)
1 1 FINANCE 222
1 1 HR 111
0 null null null
Exception at run time.
true 1 FINANCE 222
true 1 HR 111
None
38.
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
39.
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.
40.
Question: Given that test1.txt exists but test2.txt doesn't exist, consider the following code?
public class FileCopier {
public static void copy1(Path p1, Path p2) throws Exception {
Files.copy(p1, p2, StandardCopyOption.COPY_ATTRIBUTES);
}
public static void main(String[] args) throws Exception {
Path p1 = Paths.get("c:\\temp\\test1.txt");
Path p2 = Paths.get("c:\\temp\\test2.txt");
copy1(p1, p2);
}
}
Which file attributes will be copied over to test2.txt?
Select 1 option(s)
hidden
readonly
archive
Copying of the attributes is platform and system dependent.
It will print unable to copy file and test2.txt will not be created.
None
41.
Question: Consider the following code:
public class Student {
private Map marksObtained
= new HashMap();
private ReadWriteLock lock = new ReentrantReadWriteLock();
public void setMarksInSubject(String subject, Integer marks){
// valid code to set marks for a given subject
}
public double getAverageMarks(){
//1 - INSERT CODE HERE
var sum = 0.0;
try{
for(Integer mark : marksObtained.values()){
sum = sum + mark;
}
return sum/marksObtained.size();
}finally{
//2 - INSERT CODE HERE
}
}
}
What should be inserted at //1 and //2?
Select 1 option(s)
lock.lock();
and
lock.unlock();
lock.readLock();
and
lock.readUnlock();
lock.read();
and
lock.unlock();
lock.readLock().lock();
and
lock.readLock().unlock();
None
42.
Question: Consider the following code snippet ...
boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );
What will it print ?
Select 1 option(s)
It will not compile.
It will throw ArrayIndexOutOfBoundsError at Runtime.
false, true
true, false
It will print false, false.
None
43.
Question: Consider the contents of following two files:
//In file A.java
package a;
public class A{
A(){ }
public void print(){ System.out.println("A"); }
}
//In file B.java
package b;
import a.*;
public class B extends A{
B(){ }
public void print(){ System.out.println("B"); }
public static void main(String[] args){
new B();
}
}
What will be printed when you try to compile and run class B?
Select 1 option(s)
It will print A.
It will print B.
It will not compile.
It will compile but will not run.
None of the above.
None
44.
Question: Consider the following code fragment:
public static void myMethod(int x) //Specify throws clause here
{
try{
if(x == 0){
throw new ClassNotFoundException();
}
else throw new NoSuchFieldException();
}catch(RuntimeException e){
throw e;
}
}
Which of the following is a valid throws clause for the above method?
Select 2 option(s)
No throws clause is necessary.
throws ClassNotFoundException, NoSuchFieldException
throws ClassNotFoundException
throws NoSuchFieldException
throws Exception
45.
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 can be inserted at //1 and //2 so that it will print the price of all the books having a title that starts with "A"?
List books = Arrays.asList(
new Book("Atlas Shrugged", 10.0),
new Book("Freedom at Midnight", 5.0),
new Book("Gone with the wind", 5.0)
);
Map bookMap = //1 INSERT CODE HERE
//2 INSERT CODE HERE
bookMap.forEach(func);
Select 1 option(s)
None
46.
Question: Given:
Character[] ca = { 'b', 'c', 'a', 'e', 'd' };
List l = Arrays.asList(ca);
l.parallelStream().peek(System.out::print).forEachOrdered(System.out::print);
Identify the correct statement about the above code.
Select 1 option(s)
The characters printed by peek may be in any order but the characters printed by forEachOrdered will always be in the same order as the original list i.e. bcaed.
The characters printed by forEachOrdered will always be in the same order as the one printed by the peek method.
If forEachOrdered is replaced with forEach, the order of the characters printed by forEach will be the same as the one printed by peek.
Both - peek and forEachOrder - may print the characters in any order.
None
47.
Question: Which of the following statements are correct regarding the module system of Java.
Select 3 option(s)
Although not recommended, it is possible to customize what packages a module exports from the command line.
An advantage of java modules functionality is that users of a module cannot alter the list of exported packages of that module.
If a module does not export a package, there is no way to export that package to all other modules from the command line.
If a module wants to read another module but only temporarily, it can request such access using command line options.
A module can request access to another module temporarily using command line options but only if the target package already exports that package in its module-info.
Modules allows a sealed class and its direct subtypes to be members of different packages.
48.
Question: Which of the following are valid implementations of java.lang.Comparable?
Select 1 option(s)
None
49.
Question: Given:
import java.util.*;
public class EventProcessor{
public void processEvents(Collection c){
c.forEach(o -> System.out.println(o));
}
}
class MapEventProcessor extends EventProcessor{
public void processEvents(Map events){
*INSERT CODE HERE*
}
}
Which of the following options can be inserted in the above code without compilation error?
Select 2 option(s)
super.processEvents(events.values());
super.processEvents(events);
events.forEach( (k, v)->processEvents(v));
processEvents(events.values());
processEvents(new List(events.values));
50.
Question: Given the following set of member declarations, which of the following is true?
int a; // (1)
static int a; // (2)
int f( ) { return a; } // (3)
static int f( ) { return a; } // (4)
Select 2 option(s)
Declarations (1) and (3) cannot occur in the same class definition.
Declarations (2) and (4) cannot occur in the same class definition.
Declarations (1) and (4) cannot occur in the same class definition.
Declarations (2) and (3) cannot occur in the same class definition.
Declarations (1) and (2) cannot occur in the same class definition.
51.
Question: Consider the following class...
public class ParamTest {
public static void printSum(int a, int b){
System.out.println("In int "+(a+b));
}
public static void printSum(double... a){
System.out.println("In double "+(a[0]+a[1]) );
}
public static void printSum(float a, float b){
System.out.println("In float "+(a+b));
}
public static void printSum(int a, float b){
System.out.println("In intfloat "+(a+b));
}
public static void main(String[] args) {
printSum(1, 2.0);
}
}
What will be printed?
Select 1 option(s)
In float 3
In float 3.0
In double 3.0
In double 3
In intfloat 3.0
It will not compile.
None
52.
Question: What will the following code print when compiled and run?
class Test{
public static void main(String args[]){
int c = 0;
A: for(var i = 0; i < 2; i++){
B: for(var j = 0; j < 2; j++){
C: for(var k = 0; k < 3; k++){
c++;
if(k>j) break;
}
}
}
System.out.println(c);
}
}
Select 1 option(s)
7
8
9
10
11
None
53.
Question: Consider the following method which is called with an argument of 7, d, where d is some double value:
public void method1(int i, double d){
int j = (i*30 - 2)/100;
POINT1 : for(;j<10; j++){
var flag = false;
while(!flag){
if(d > 0.5) break POINT1;
}
}
while(j>0){
System.out.println(j--);
if(j == 4) break POINT1;
}
}
What will it print?
Select 1 option(s)
It will print 1 and 2
It will print 1 to N where N depends on the value passed as an argument to the parameter d.
It will not compile.
It will throw an exception at runtime.
None
54.
Question: java.util.Locale allows you to do which of the following?
Select 2 option(s)
Provide country specific formatting for fonts.
Provide country and language specific formatting for HTML pages.
Provide country and language specific formatting for Dates.
Provide country specific formatting for Currencies.
Provide country and language specific formatting for properties files.
55.
Question: Which of the following commands can be used to identify class and module dependencies?
Select 1 option(s)
jar -describe
java --describe
jmod describe
jmod --describe
jmod --show-module-resolution
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
Articles
Home
About
About Us
Our Services
Software Development
Technology Up-Skill Programs
Java Job Placement Program
Data Science / Data Analyst / Ai Job / Placement Program
IT Staffing
Gallery
Employers
Job Seekers
3000 Technical Interview Questions
120+ Advanced Java Interview Questions and Answers
Artificial Intelligence (AI) Interview Questions and Answers
Top 100 AWS Interview Questions and Answers
Business Intelligence Interview Questions and Answers
Top C# Interview Questions and Answers
120+ Core Java Interview Questions and Answers
Top 100 Programming / Coding Interview Questions and Answers
Top 100 Cyber Security Interview Questions and Answers
Top 100 Data Analyst Interview Questions and Answers
Top 100+ Data Science Interview Questions and Answers
Top Deep Learning Interview Questions And Answers
Top 100+ DOCKER Interview Questions And Answers
Top 100+ Excel Interview Questions and Answers
Express.js Interview Questions & Answers
100 Full Stack Interview Questions and Answers
Top 80 GitHub Interview Questions And Answers
Top 100 Hibernate Interview Questions And Answers
Top Informatica Interview Questions and Answers
Top 50+ JavaScript Interview Questions and Answers
Top 80+ Jenkins Interview Questions and Answers
Top JUnit Interview Questions And Answers
Top 100 Machine Learning Interview Questions and Answers
MEAN Stack Interview Questions and Answers
MERN Stack Interview Questions and Answers
Microservices Interview Questions & Answers
Top 80+ MongoDB Interview Questions and Answers
Top NLP Interview Questions And Answers
Advanced PHP Interview Questions and Answers
PL/SQL Interview Questions & Answers
Top Power BI Interview Questions and Answers
Top 100 Python Interview Questions and Answers
Top 100 PyTorch Interview Questions And Answers
REST Interview Questions & Answers
Top 100 R Programming Interview Questions & Answers
SaaS Interview Questions and Answers
Top 50+ SAS Interview Questions and Answers
Top Software Testing Interview Questions and Answers
Top 50+ Spring Boot Interview Question and Answers
Top 60 Scala Interview Questions And Answers
Top 40 SOAP Interview Questions and Answers
SQL Interview Questions and Answers
Top 50+ TensorFlow Interview Questions and Answers
Tableau Interview Questions and Answers
Job Seeker Resources
Java Test
Free Java SE 21 Certification Practice Tests
Java SE 17 Certification Preparation Test
Free Java Test SE 11 Certification
Free 30 Minute Java Test
5 Minute JAVA Test
AWS Test
AWS Data Engineer Associate Certification Exam
AWS Certified Data Analytics Certification Test
Java and AWS free tests and Quiz
30 Minute AWS Test
5 Minute AWS Test
Microsoft Test
Microsoft Power BI Data Analyst
Microsoft Azure Data Scientist Associate Certification Test
Tableau Test
Tableau Desktop Specialist
Tableau Certified Data Analyst
Free snowflake snowpro core certification tests
Free Databricks certified Data Analyst Test
Azure Data Engineer Associate Certification
Inspirational Videos
Latest Jobs
FAQ
Articles
Contact Us
(510) 550 - 7200
39141 Civic Center Dr, Suite 201, Fremont, CA 94539, US