Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Java 8 Features

A structured repository demonstrating the key features introduced in Java 8, implemented through hands-on examples. Each package focuses on one specific concept for clarity and easy navigation.


Concepts Covered

# Feature Package
1 Functional Interfaces functional_interfaces/
2 Lambda Expressions lambdas/
3 Built-in Functional Interfaces (Consumer, Predicate) functional_interfaces/
4 Interface Inheritance & Non-Functional Interfaces functional_interfaces/
5 Default & Static Methods in Interfaces default_methods/
6 Multithreading with Lambda (Runnable) lambdas/

Concepts in Detail

Functional Interfaces & Lambdas

A Functional Interface is any interface with exactly one abstract method, annotated with @FunctionalInterface. Java 8 allows these to be implemented using lambda expressions instead of verbose anonymous inner classes.

// Traditional way
Interface obj = new Interface() {
    public void incomplete() {
        System.out.println("implemented");
    }
};

// Java 8 Lambda way
Interface obj = () -> System.out.println("implemented");

Interface Inheritance

An interface can extend another interface and still remain a functional interface, as long as it does not add any new abstract methods. Adding even one new abstract method breaks the @FunctionalInterface contract.

Built-in Functional Interfaces

Java 8 ships with ready-to-use functional interfaces in java.util.function:

  • Consumer<T> — takes input, returns nothing
  • Predicate<T> — takes input, returns boolean
  • Function<T, R> — takes input, returns a result
  • Supplier<T> — no input, returns a result

Multithreading with Lambda

Java 8 lambdas simplify thread creation by allowing Runnable to be expressed as a single-line lambda, eliminating the need to create a separate class.


About

Hands-on implementation of Java 8 features, including Functional Interfaces, Lambda Expressions, built-in interfaces (Consumer, Predicate), interface inheritance, multithreading with Runnable, and Stream API operations such as filtering, matching, and Optional usage.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages