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

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Java8' - 41 question(s) found - Order By Newest

next 30
Frequently asked at Manhattan Associates ( Based on 2 feedback )
  Q1. What is a Lambda Expression ? What's its use ?Core Java
Ans. Its an anonymous method without any declaration.

Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code.

It promotes Developer productivity, Better Readable and Reliable code.

  Sample Code for lambda

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

   Like         Discuss         Correct / Improve     java   java8   lambda expression   architecture     Asked in 58 Companies      expert        frequent

Try 1 Question(s) Test


Not frequently asked as it was introduced with Java 8.
 Q2. Difference between final and effectively final ? Why is effectively final even required ?Core Java
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.
 Q3. What is StringJoiner ?Core Java
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


 Q4. Difference between Predicate, Supplier and Consumer ? Core Java
Ans. Predicate represents an anonymous function that accepts one argument and produces a result.

Supplier represents an anonymous function that accepts no argument and produces a result.

Consumer represents an anonymous function that accepts an argument and produces no result.

  Sample Code for Predicate

  Sample Code for Supplier

  Sample Code for Consumer

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

   Like         Discuss         Correct / Improve     java   java8   predicate   consumer   supplier   lambda expression   predicate vs consumer vs supplier      expert


 Q5. What are few of the Annotations pre defined by Java?
Ans. @Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation.

@Override annotation informs the compiler that the element is meant to override an element declared in a superclass.

@SuppressWarnings annotation tells the compiler to suppress specific warnings that it would otherwise generate.

@SafeVarargs annotation, when applied to a method or constructor, asserts that the code does not perform potentially unsafe operations on its varargsparameter. When this annotation type is used, unchecked warnings relating to varargs usage are suppressed.

@FunctionalInterface annotation, introduced in Java SE 8, indicates that the type declaration is intended to be a functional interface, as defined by the Java Language Specification.

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

   Like         Discuss         Correct / Improve     java   java8   annotations   pre defined annotations


 Q6. Name few meta-annotations ?
Ans. @Retention annotation specifies how the marked annotation is stored:

@Documented annotation indicates that whenever the specified annotation is used those elements should be documented using the Javadoc tool. (By default, annotations are not included in Javadoc.)

@Target annotation marks another annotation to restrict what kind of Java elements the annotation can be applied to.

@Inherited annotation indicates that the annotation type can be inherited from the super class. (This is not true by default.) When the user queries the annotation type and the class has no annotation for this type, the class' superclass is queried for the annotation type. This annotation applies only to class declarations.

@Repeatable annotation, introduced in Java SE 8, indicates that the marked annotation can be applied more than once to the same declaration or type use. For more information, see Repeating Annotations.

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

   Like         Discuss         Correct / Improve     java   java8   annotations   meta annotations


 Q7. Does java allow implementation of multiple interfaces having Default methods with Same name and Signature ?Core Java
Ans. No. Compilation error.

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

   Like         Discuss         Correct / Improve     java   java8   default method   yes-no     Asked in 1 Companies      intermediate


  Q8. What are Default Methods ?Core Java
Ans. With Java 8, We can provide method definitions in the Interfaces that gets carried down the classes implementing that interface in case they are not overridden by the Class. Keyword "default" is used to mark the default method.

  Sample Code for interface default

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

   Like         Discuss         Correct / Improve     java   java8   default methods     Asked in 7 Companies      expert        frequent


 Q9. Can we use static method definitions in Interfaces ?Core Java
Ans. Yes, Effective Java 8.

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

   Like         Discuss         Correct / Improve     java   java8   static interface methods   yes-no     Asked in 1 Companies


Not frequently asked as it was introduced with Java 8.
 Q10. What is the use of Optional ?Core Java
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


Rarely asked as it was introduced with Java 8.
 Q11. Name few "Optional" classes introduced with Java 8 ?Core Java
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


 Q12. What was the driving force to introduce default methods in Interfaces wef from Java 8 ?Core Java
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     Asked in 6 Companies


 Q13. Is it ok to use optional everywhere just to get over nullpointerexception ?Core Java
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     Asked in 1 Companies


 Q14. If there is a conflict between Base Class Method definition and Interface Default method definition, Which definition is Picked ?
Ans. Base Class Definition.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


Frequently asked these days as there are major changes in Java 8.
  Q15. What are new features introduced with Java 8 ?Core Java
Ans. Lambda Expressions , Interface Default and Static Methods , Method Reference , Parameters Name , Optional , Streams, Concurrency.

  Sample Code for Lambda

  Sample Code for interface default

  Sample Code for Optional

  Sample Code for Streams

  Sample Code for java.time

  Sample Code for Predicate

  Sample Code for Consumer

  Sample Code for MapMerge

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

   Like         Discuss         Correct / Improve     java   java8   technical lead   technical architect     Asked in 14 Companies      expert        frequent


Rarely asked as default methods have been introduced with Java 8.
 Q16. Can we have a default method without a Body ?Core Java
Ans. No. Compiler will give error.

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

   Like         Discuss         Correct / Improve     java   java8   default method   yes-no        rare


Rarely asked as default methods have been introduced with Java 8.
 Q17. Can we have a default method definition in the interface without specifying the keyword "default" ? Core Java
Ans. No. Compiler complains that its an abstract method and hence shouldn't have the body.

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

   Like         Discuss         Correct / Improve     java   java8   default methods   default keyword   yes-no


 Q18. Can a class implement two Interfaces having default method with same name and signature ?

public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}

public interface DefaultMethodInterface2 {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}

public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Ans. No. Compiler gives error saying "Duplicate Default Methods"

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q19. What If we make the method as abstract in another Interface ?

public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}

public interface DefaultMethodInterface2 {
public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}

public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Ans. Even then the Compiler will give error saying that there is a conflict.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q20. What if we override the conflicting method in the Class ?

public interface DefaultMethodInterface {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}

public interface DefaultMethodInterface2 {
default public void defaultMethod(){
System.out.println("DefaultMethodInterface2");
}
}

public class HelloJava8 implements DefaultMethodInterface,DefaultMethodInterface2 {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}

public void defaultMethod(){
System.out.println("HelloJava8");
}
}
Ans. There won't be any error and upon execution the overriding class method will be executed.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q21. What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?
Ans. There won't be any problem as the Base class method will have precedence over the Interface Default methods.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q22. If a method definition has been specified in Class , its Base Class , and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ?
Ans. Class method definition is overriding both the definitions and hence will be picked.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q23. If a method definition has been specified in the Base Class and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ?
Ans. Base Class Definition will have precedence over the Interface Default method definition.

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

   Like         Discuss         Correct / Improve     java   java8   default methods


 Q24. Can we access Interface static method using Interface references ?
Ans. No, only using Interface Name.

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

   Like         Discuss         Correct / Improve     java   java8   static interface methods


 Q25. Can we have default method with same name and signature in the derived Interface as the static method in base Interface and vice versa ?
Ans. Yes , we can do that as static methods are not accessible using references and hence cannot lead to conflict. We cannot do inverse as Default methods cannot be overridden with the static methods in derived interface.

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

   Like         Discuss         Correct / Improve     java   java8   default methods   static interface methods


 Q26. What does the following lambda expression means ?

helloJava8 ( x-> x%2 )
Ans. helloJava8 receives an Integer as argument and then returns the modulus of that Integer.

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

   Like         Discuss         Correct / Improve     java   java8   lambda expression


Not frequently asked as it was introduced with Java 8.
 Q27. What is the @FunctionalInterface annotation ?Core Java
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.
 Q28. Difference between DoubleSummaryStatistics , IntSummaryStatistics and LongSummaryStatistics ?Core Java
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.
 Q29. What are the changes in Java.io in Java 8 ?Core Java
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


 Q30. Name few Java Util classes introduced with Java 8 ?Core Java
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


next 30

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: