Home » Search Results for: java 8

Search Results for: java 8

Java 8 Functional Interfaces Introduction Example

Hello readers! In this tutorial, we will learn the amazing feature of Java 8 Functional Interfaces. 1. Introduction To achieve the benefits of functional programming in Java, JDK developers introduced Functional Interfaces/Single Abstract Method (SAM) Interfaces in Java 8 programming. A functional interface is an interface that has only one abstract method A functional interface can have multiple default and ...

Read More »

Java 8 Lambda Expressions Introduction Example

Hello readers! In this tutorial, we feature a comprehensive article on Java 8 Lambda Expressions.  1. Introduction To achieve the benefits of functional programming in Java, JDK developers introduced Lambda Expressions in Java 8 programming. A lambda expression is a nameless function which does not have the name, return type, and access modifiers A lambda expression instance can be assigned ...

Read More »

Java 8 Optional In Depth Example

1. Introduction This is an in-depth article about Java 8 Optional. A new class Optional was introduced in Java 8. The optional class is part of java.util package. Optional is used to represent a value. It can be present or absent. No more null checks and NullPointerException are needed. Optional helps in avoiding any runtime NullPointerExceptions. It helps in developing clean ...

Read More »

Java 8 Functional Programming Tutorial

Java 8 supports functional programming via the lambda expression and Stream API. In this tutorial, I will demonstrate how Java 8 supports functional programming via common pre-defined functional interfaces, Collections, and Stream API.                 Table Of Contents 1. Introduction 2. Technologies Used 2.1 Maven Project 3. Java 8 Predefined Functional Interfaces 3.1 Function ...

Read More »

Java 8 Format LocalDateTime Example

1. Introduction Java 8 Date-time API provides a java.time.LocalDateTime class which is an immutable date-time object and often is viewed as a year-month-day-hour-minute-second format. It contains a java.time.format package to handle the formatting of dates and times. This package includes three classes: DateTimeFormatter – to print and parse date-time objects. It provides common formatting constants as well as a string ...

Read More »

Java 8 Compare Dates Example

1. Introduction Java 8 added a new set of packages to provide a comprehensive date-time model. Java 8 Date-Time API is a JSR-310 implementation.                   There are several interfaces: ChronoLocalDate, ChronoLocalDateTime, ChronoZonedDateTime in java.time.chrono packages. They all have isBefore, isAfter, isEquals, and compareTo methods to compare two dates. Java 8 date classes: ...

Read More »

Java 8 Stream Collectors groupingBy Example

1. Introduction SQL GROUP BY is a very useful aggregation function. It groups database records on certain criteria. Java 8 Stream API enables developers to process collections of data in a declarative way. Java 8 Collectors class provides a static groupingBy method: to group objects by some property and store the results in a Map instance. It has three signatures, which ...

Read More »

Java 8 TemporalAdjusters Example

1. Introduction Java 8 Date-Time API is a JSR-310 implementation. It has a new set of packages to provide a comprehensive date-time model. java.time – base package for managing dates and times java.time.chrono – handles alternative calendaring and chronology systems java.time.format – handles formatting of dates and times java.time.temporal – accesses to date and time using fields, units, and adjusters Java 8 ...

Read More »

Java 8 Check if Array Contains a Certain Value Example

1. Introduction An array is a data structure which holds a fixed number of values of a single type. In this example, I will demonstrate how to check if an array contains a certain value in three ways: Convert an array to a Collection and check with the contains method Use Arrays.binarySearch to check when the array is sorted Convert an array ...

Read More »

Java 8 Convert String to Char Array Example

1. Introduction The Java String class represents character strings. An array is a data structure which holds a fixed number of values of a single type. The char type is a primitive type which represents a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65535 inclusive). The Character class wraps thechar type as a value in an object. An object ...

Read More »