Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java 8 Interview Questions and Answers

Test your skills through the online practice test: Java 8 Quiz Online Practice Test

Related differences

Java 7 vs Java 8Java 8 vs Java 9

Ques 11. What is the difference between Predicate and Function?

Both are functional interfaces.
  • Predicate<T> is single argument function and either it returns true or false. This can be used as the assignment target for a lambda expression or method reference.
  • Function<T,R> is also single argument function but it returns an Object. Here T denotes type of input to the function and R denotes type of Result. This can also be used as the assignment target for a lambda expression or method reference.

Is it helpful? Add Comment View Comments
 

Ques 12. What the issues with Old Date and time API before Java 8? Date and Time API differences between Java 8 and earlier Java version.

Issues with old Date and Time API:
  • Thread Safety: You might be already aware that java.util.Date is mutable and not thread safe. Even java.text.SimpleDateFormat is also not Thread-Safe. New Java 8 date and time APIs are thread safe.
  • Performance: Java 8 new APIs are better in performance than old Java APIs.
  • More Readable: Old APIs such Calendar and Date are poorly designed and hard to understand. Java 8 Date and Time APIs are easy to understand and comply with ISO standards.

Is it helpful? Add Comment View Comments
 

Ques 13. Provide some APIs of Java 8 Date and Time.

LocalDate, LocalTime, and LocalDateTime are the Core API classes for Java 8. As the name suggests, these classes are local to context of observer. It denotes current date and time in context of Observer.

Is it helpful? Add Comment View Comments
 

Ques 14. How will you get current date and time using Java 8 Date and TIme API?

You can simply use now() method of LocalDate to get today’s date.
LocalDate currentDate = LocalDate.now();
System.out.println(currentDate);

Output:
2017-09-09

You can use now() method of LocalTime to get current time.
LocalTime currentTime = LocalTime.now();
System.out.println(currentTime);
 
Output:
23:17:51.817

Is it helpful? Add Comment View Comments
 

Ques 15. Do we have PermGen in Java 8? What is MetaSpace in Java 8?

Until Java 7, JVM used an area called PermGen to store classes. It got removed in Java 8 and replaced by MetaSpace.
Major advantage of MetaSpace over permgen:
PermGen was fixed in term of maximum size and can not grow dynamically but Metaspace can grow dynamically and do not have any size constraint.

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook