Java - Interview Questions and Answers for 'Java 8' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Java 8' - 24 question(s) found - Order By Newest

Not frequently asked as it was introduced with Java 8.
 Q1. Difference between final and effectively final ? Why is effectively final even required ?Core Java
Admin
info@buggybread.com
Ans. Final variable means a variable that has been declared final and hence cannot be de referenced after initialization. Effective final means a variable that has not been declared final but haven't been reassigned the value after initialization.

First is the regulation that restricts the reassignment and will raise a compilation error if we try to do so. Second is the outcome without the restriction.

Effective Final is the eventual treatment of the variable that is required for many features. For eq - Java 8 requires that local variables referenced from a lambda expression must be final or effectively final.It means all local referenced from lambda expressions must be such that their value shouldn't be changed after initialization whether declared final or not.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   final   effective final   final vs effective final   lambda expressions      expert

Try 2 Question(s) Test


Not frequently asked as it was introduced with Java 8.
 Q2. What is StringJoiner ?Core Java
Admin
info@buggybread.com
Ans. StringJoiner is a util method to construct a string with desired delimiter. This has been introduced with wef from Java 8.

Sample Code

StringJoiner strJoiner = new StringJoiner(".");
strJoiner.add("Buggy").add("Bread");
System.out.println(strJoiner); // prints Buggy.Bread


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   string   stringjoiner


Not frequently asked as it was introduced with Java 8.
 Q3. What is the use of Optional ?Core Java
Admin
info@buggybread.com
Ans. Optional is a good way to protect application from runtime nullPointerException in case the the absent value has been represented as null. So basically Optional class provides the type checking during compile time and hence will never result in NPE.

For ex -

List> intList = new ArrayList>();
intList.add(Optional.empty());
intList.add(Optional.of(new Employee("abc")));
intList.add(Optional.of(new Employee("xyz")));
intList.add(Optional.of(new Employee("123")));
System.out.println(intList.get(0).getName());

So Now , even when the first list element is empty, this code will never throw an NullPointerException.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   optional


 Q4. Why can't we have diamond problem with interfaces ?Core Java2017-07-30 08:15:33

Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     diamond problem  interfaces  java 8  default methods


Not frequently asked as it was introduced with Java 8.
 Q5. What is the @FunctionalInterface annotation ?Core Java
Admin
info@buggybread.com
Ans. This is an informative annotation that specify that the interface is a functional interface. A Function Interface has only one abstract method and many default methods. Compiler generates an error if the interface specified with the annotation doesn't abide by the specifications for functional interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   functional interface   default methods


Rarely asked as it was introduced with Java 8.
 Q6. Difference between DoubleSummaryStatistics , IntSummaryStatistics and LongSummaryStatistics ?Core Java
Admin
info@buggybread.com
Ans. They all does the same task i.e to compute statistical information on the stream of data. They differ by the way they store the statistical information as they expect a different data type of the values being used.

IntSummaryStatistics and LongSummaryStatistics expect non floating point values and hence stores the statistical information like min,max and sum as non floating values ( int or long ) whereas DoubleSummaryStatistics stores these information as floating value.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   lambda expressions   doublesummarystatistics   intsummarystatistics   longsummarystatistics   summarystatistics


Rarely asked as it was introduced with Java 8.
 Q7. Name few "Optional" classes introduced with Java 8 ?Core Java
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/java-optional-classes-and-interfaces.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   optional   java 8   java8


Rarely asked as it was introduced with Java 8.
 Q8. What are the changes in Java.io in Java 8 ?Core Java
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes_62.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java 8   java.io   java8


 Q9. Name few Java Util classes introduced with Java 8 ?Core Java
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes_25.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java.util   util   java 8   java8



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Rarely asked as it was introduced with Java 8.
 Q10. Name few java.lang classes introduced with Java 8 ?Core Java
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java.lang   java8   java 8


Rarely asked as it was introduced with Java 8.
 Q11. What is DocLint in Java 8 ?Core Java
Admin
info@buggybread.com
Ans. DocLint Provide a means to detect errors in Javadoc comments early in the development cycle and in a way that is easily linked back to the source code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java 8   doclint   java8 features


Rarely asked as it was introduced with Java 8.
 Q12. What are the errors identified by DocLint ?Core Java
Admin
info@buggybread.com
Ans. Bad syntax, such as unescaped characters or unmatched parentheses

Bad HTML, such as invalid or missing tags or attributes

Bad references, such as referencing a non-existent type with @see

Accessibility errors, such as a missing summary or caption from a table

Missing info, such as an undocumented parameter

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   doclint


Rarely asked as it was introduced with Java 8.
 Q13. Which keyword specify that a variable is effectively final ? a. final b. No Keyword c. Both of the above d. None of the aboveCore Java
Anonymous
Ans. No Keyword

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java 8   java8   final   effectively final        rare


Rarely asked as it was introduced with Java 8.
 Q14. Which of the following has been introduced with Java 8 ? a. StringBuffer b. StringBuilder c. StringFilter d. StringJoinerCore Java
Anonymous
Ans. StringJoiner

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   java 8   string   stringjoiner


 Q15. What was the driving force to introduce default methods in Interfaces wef from Java 8 ?Core Java2016-07-14 14:36:49

Ans. Earlier any class implementing an interface was supposed to implement all methods declared in an interface. There was no place for optionally implementing all or subset of methods.Though we have abstract classes wherein we could have provided such a mechanism by declaring some methods as abstract while providing definition for some. But as Abstract classes have a body and are comparatively heavier than interfaces and interfaces associate closely to the concept of providing interfacing than abstract classes, Java might have though of providing optional implementation for default methods. This way same interface can be reused in variety of ways rather than making copies of an interface to suit different needs.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java 8   java8  interface default methods  default methods     Infoview Technologies  Oracle  Oracle Polska  Infosys  Tata Consultancy (TCS)  CEBS Worldwide


 Q16. Does default methods introduce multiple inheritance and the Diamond problem in Java 8 ?Core Java2016-07-20 17:16:28

Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error.

For example -

interface MyInterface {
public void default myMethod(){
}
}

interface MyInterface2 {
public void default myMethod(){
}
}

class MyClass implements MyInterface,MyInterface2 {
}

This code will compilation error "Duplicate Default Method"

if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     default methods  java 8  multiple inheritance  diamond problem   interfaces


Rarely asked as it was introduced with Java 8.
 Q17. What is the use of :: operator wef from Java 8 ?Core Java2016-07-25 13:27:57

Ans. We can refer to a function using this operator like System.out.println(intList.stream().reduce(Math::max).get());

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     :: operator   lambda expression  java 8


 Q18. How Spliterator in Java 8 different than iterator ?Core Java2016-11-24 09:44:49

Ans. Though there are many differences the way internally they both iterates the collections and streams respectively, but the main difference in performance that is achieved by spliterator as it can iterate Streams in Parallel whereas iterator only iterates collections sequentially.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java8  java 8  spliterator  java 8 streams  streams


 Q19. What is a method reference in Java ?Core Java2017-01-29 13:55:22

Ans. Introduced with java 8 , Method References help us to point to methods by their name.

A method references is described using :: symbol

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     method reference  java 8  lambda expressions



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Is it ok to use optional everywhere just to get over nullpointerexception ?Core Java2017-05-23 08:16:28

Ans. Optional is to be used for arguments / atrributes which are indeed optional i.e the request should continue even if they aren't provided. It should not be used for mandatory attributes or arguments as we would like application to shout out ( with error message / exception trace ) to signify a problem.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     optional  nullpointerexception  java8  java 8     Itech


 Q21. Explain Java 8 concurrency mechanism.Core Java2017-07-22 07:52:01

 This question was recently asked at 'IBM'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     synchronization  concurrency  java 8  java8     IBM


 Q22. Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello". Core Java2017-08-06 11:51:10

Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     lambda expressions  java 8  java8  java 8 filter  findAny()


 Q23. Given a collection of Employee objects, how can we get the customers with name starting with 'A' using lambda expression.Core Java2017-08-17 11:01:46

 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java8  java 8  lambda


 Q24. Write a Program that gets a set of numbers , filters out the non prime numbers , calculate the factorial of each prime number and then finds the average of all factorials using Lambda expressions2017-05-14 14:02:57

Ans. public class BuggyBread1 {
   
   public static void main(String args[]) {
      
      // Declare and Initialize the Collection
      Set<Integer> intSet = new HashSet<Integer>();

      // Add Elements
      intSet.add(1);
      intSet.add(2);
      intSet.add(3);
      intSet.add(4);
      intSet.add(5);

      double averageOfNonPrimeFactorials = intSet.stream().filter(p->checkIfPrime(p)).collect(Collectors.averagingInt(p->calculateFactorial(p)));
      
      System.out.println(averageOfNonPrimeFactorials );
   }
   
   static private boolean checkIfPrime(int num){
      for(int count=2;count < num;count++){
         if(num % count == 0){
            return false;
         }
      }
      return true;
   }
   
   static private int calculateFactorial(int num){
      int factorial = 1;
      for(int count=num;count > 0;count--){
         factorial = factorial * count;
      }
      return factorial;
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java 8  lambda expressions  lambda  filter  Collectors  factorial  prime number




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: