Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code, what is the behavior expected?

package com.hadoopexam;

import java.nio.file.FileAlreadyExistsException;

class Welcome {
@SuppressWarnings("finally")
public static void call() throws Exception {
try {
throw new FileAlreadyExistsException(null);
} finally {
throw new Exception();
}
}

public static void main(String[] args) {
try {
call();
} catch (Throwable throwable) {
System.out.println(throwable);
}
}
}

 : You have been given below code, what is the behavior expected?
1. It will not compile

2. It will compile and run with Throwable

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run with no output

5. It will compile and run with FileAlreadyExistsException


Correct Answer : Get Lastest Questions and Answer :
Explanation: : As you know, finally will be executed which will create an object of Exception class which will be catched in main method. Using dynamic binding it will
use actual type of Object. Hence, it will print Exception




Question : You have been given following code, what is the behavior expected

package com.hadoopexam;

import java.time.LocalDate;
import java.time.Month;
import java.time.Period;

class Welcome {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2014, Month.MARCH, 01);
LocalDate date2 = LocalDate.of(2016, Month.NOVEMBER, 01);
System.out.println(Period.between(date2, date1).getYears());
}
}
 : You have been given following code, what is the behavior expected
1. It will give compile time error

2. It will compile and run perfectly and print 1

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run perfectly and print -1

5. It will compile and run perfectly and print -2


Correct Answer : Get Lastest Questions and Answer :
Explanation: As you know, when we are using between method of Period class, it should have been used like between(start date, end date) . Here we are using in reverse
order hence, it will give -2 instead of 2.




Question : Which one of the following classes is best suited for storing timestamp values of application events in a file?
 : Which one of the following classes is best suited for storing timestamp values of application events in a file?
1. java.time.ZoneId class

2. java.time.ZoneOffset class

3. Access Mostly Uused Products by 50000+ Subscribers

4. java.time.Duration class

5. java.time.Period class


Correct Answer : Get Lastest Questions and Answer :
Explanation: The Instant class stores the number of seconds elapsed since the start of the Unix epoch (1970-01-01T00:00:00Z). The Instant class is suitable for storing a
log of application events in a file as timestamp values.
The ZoneId and ZoneOffset classes are related to time zones and hence are unrelated to storing timestamp values. The Duration class is for time-based values in terms of quantity of
time (such as seconds, minutes, and hours). The Period class is for date-based values such as years, months, and days.



Related Questions


Question : Which one of the following abstract methods does not take any argument but returns a value?


 : Which one of the following abstract methods does not take any argument but returns a value?
1. The accept() method in java.util.function.Consumer interface

2. The get() method in java.util.function.Supplier interface

3. Access Mostly Uused Products by 50000+ Subscribers

4. The apply() method in java.util.function.Function interface



Question : You have been given following code. What is the behavior you expect?

package com.hadoopexam;

import java.util.function.Predicate;

public class Welcome {
public static void main(String args[]) {
Predicate checkValue = "HadoopExam Learning Resource"::contains; //n1
checkString(checkValue, "Quick");
}

static void checkString(Predicate predicate, String str) {
System.out.println(predicate.test(str) ? "It has given String" : "It does not have given String"); //n2
}
}
 : You have been given following code. What is the behavior you expect?
1. There will be a compile time error at n1, because you cannot have a method reference with an Object.

2. There will be a compile time error at n2.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program will compile and run as well and print "It does not have given String"



Question : What would happen, if you use below code.

package com.hadoopexam;

import java.util.function.Predicate;

import java.util.function.ObjIntConsumer;

class Welcome {
public static void main(String[] args) {
ObjIntConsumer charAt = (str, i) -> str.charAt(i); // n1
System.out.println(charAt.accept("java", 2)); // n2
}
}
 : What would happen, if you use below code.
1. There will be a compile time error at line n1

2. There will be a compile time error at line n2

3. Access Mostly Uused Products by 50000+ Subscribers

4. There will be no error, it runs perfectly and print v



Question : You have been given below code. What is the expected behavior ?

package com.hadoopexam;
class Welcome {
public static void main(String[] args) {
"HadoopExam.com".chars().distinct().peek(ch -> System.out.printf("%c ", ch)).sorted();
}
}

 : You have been given below code. What is the expected behavior ?
1. Code will through a compile time error.

2. Code will run perfectly and print "H a d o p E x m . c"

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print ". a c d m o p x E H "



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.stream.Stream;


public class Welcome {

public static void main(String[] args) throws IOException {
Stream userHomes = Files.walk(Paths.get(System.getProperty("user.home")));
userHomes.forEach (fName ->
{//line n1
try
{
Path aPath = fName.toAbsolutePath();//line n2
System.out.println(fName + ":" + Files.readAttributes(aPath, BasicFileAttributes.class).creationTime());
} catch (IOException ex)
{
ex.printStackTrace();
}
});
}

}

 : You have been given below code, what is the expected behavior?
1. All files and directories under thehomedirectory are listed along with their attributes.

2. A compilation error occurs atline n1.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs atline n2.



Question : You have been given below code, what is the behavior expected?

package com.hadoopexam;

import java.util.Set;
import java.util.TreeSet;

public class Welcome {

int userId;
String userName;

public Welcome(int userId, String userName) {
this.userId = userId;
this.userName = userName;
}

public String toString() {
return userId + ":" + userName;
}

public static void main(String[] args) {
Set users = new TreeSet <> ();
users.add(new Welcome (101, "Amit"));
users.add(new Welcome (102, "Anurag"));
System.out.println(users);
}
}

 : You have been given below code, what is the behavior expected?
1. 101 : Amit , 102:Anurag

2. 102 : Anurag , 102: Amit

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will give compile time error.

5. It will give runtime error "java.lang.ClassCastException: com.hadoopexam.Welcome cannot be cast to java.lang.Comparable"