Java - New in Java 8 - Interview Questions

What are the key Java programming language features introduced in Java 8?

 

Following are some of the key features introduced in Java 8

1. Lambda Expressions: Functional programming constructs introduced in Java programming language to simplify java code.

2. Method references: Feature that enables reference to methods and method constructors without executing them.

3. Default and Static methods in Interfaces: Enables to add new functionality to interfaces, without impacting implementing classes.

4. Repeating annotations: Enables to repeat the same annotation multiple times to a declaration or type.

5. Type annotations: Annotations that can be used anywhere where a type is used.

6. Collections - Streams API: Functional-style operations that act on streams of data elements.

7. Security: New features and enhancements to Java Security API.

8. Concurrency: New interfaces and classes added to Concurrency API.

What are Lambda expressions in Java programming language??

 

Lambda expressions is a Java programming language feature introduced in Java 8 that provides functional programming constructs to the Java programming language, which simplifies the Java code in certain cases such as with Java anonymous inner classes. Lambda expressions blends functional programming features with object oriented programming features of Java resulting in simplified and more powerful concurrency features.

Lambda expressions are blocks of Java code that can be defined and passed as data which can be executed at a later time.

What new features in Interfaces are introduced in Java 8?

 

Prior to Java 8, Interfaces could contain only method declarations in the form of abstract methods.

In Java 8, interfaces can contain method implementations in the form of static methods and default methods.

Static methods, similar to the class static methods, can now be implemented in interfaces. Interface static methods cannot be overridden by implementing classes. Similar to a class static method, an interface static method can be invoked outside of the interface by using interface name.

Default methods are declared using the 'default' keyword, and can be added either to new interfaces or to existing interfaces. New classes implementing the interface can override the default methods. Existing classes already implementing the interface are not impacted.

//interface with abstract, default and static methods
public class MyInterface() {
  //abstract method
  abstract void logAbstract();

//default method
  default void logDefault() {
    System.out.println('default method invoked');
  }

  //static method
  static void logStatic() {
    System.out.println('static method invoked');
  }
}

What are repeating annotations?

 

Java 8.0 introduced a new Java language feature regarding annotations. You can now repeat an annotation multiple times on a type declaration.

What are type annotations? Name some common type annotations.

 

Java 8.0 introduced a new Java language feature regarding annotations. In addition to using annotations on type declarations, you can now apply annotations whenever you use types.

Following are some examples of Type annotations

@NonNull
@ReadOnly
@Regex,
@Tainted
@Untainted

Java Interview Guide has over 250 REAL questions from REAL interviews. Get the guide for $15.00 only.
 
BUY EBOOK
 
 
Java Interview Guide

$15.00

BUY EBOOK
  SSL Secure Payment
Java Interview Quesiuons - Secure Payment
Java Interview Guide

$15.00

BUY EBOOK
  SSL Secure Payment
Java Interview Quesiuons - Secure Payment
 

Java - Interview Questions

Java - Object Oriented ProgrammingJava - Objects & ClassesJava - Data TypesJava - VariablesJava - StringsJava - ArraysJava - CollectionsJava - ReflectionJava - Lambda ExpressionsJava - StreamsJava - GenericsJava - ExceptionsJava - IOJava - ThreadsJava - ConcurrencyJava - JDBCJava - NetworkingJava - SecurityJava - JVM InternalsJava - PerformanceJava - New in Java 8Java - New in Java 9Java - New in Java 10Java - New in Java 11
 
MASTER Java  

Top ranked courses to help you master Java skills.
Java Programming Masterclass

iconicon

Offered By - Tim Buchalka
Platform - Udemy
Rating - * * * * *
Students Enrolled - 575,000 +

RECOMMENDED RESOURCES
Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example