{

Learn free java8 tutorials


Java8 - Array Stream Lambda Expression How to Examples

January 11, 2023 ·  5 min read

Stream API Array Lambda Examples In my previous post, We covered and learned lambda expressions in java8. This post is about the frequently used Array lambda expression examples using Streams API. Following are examples that we learn with java8 lambda expressions Java8 trim white spaces in an array of string Java8 count of words in a string Convert primitive type to Object type in an array of elements Convert Object List to Primitive Array Array Sort using lambda expression in java8 Convert Array to Stream of Arrays Convert Array to List using Java8 with examples You can convert Array to list before java8 using the below lines of code...


Java8 - BinaryOperator interface examples | Functional Interface tutorials

January 11, 2023 ·  2 min read

What is BinaryOperator in java8? BinaryOperator is an interface defined in the java.util.function package in java8. This interface extends the BiFunction interface. It is used to perform an operation that accepts two parameters of the same type and returns the same type value as a result. It assigns Lamda expressions or method references. Learn the BinaryOperator interface and its method usage and examples. Syntax: @FunctionalInterface public interface BinaryOperator<T> extends BiFunction<T,T,T> { public static <T> BinaryOperator<T> minBy(Comparator<?...


Best LocalDate examples with a tutorial in Java8

February 28, 2022 ·  6 min read

Learn the java.util.LocalDate class with the top 10 examples. Contents What is java.time.LocalDate class in java8 java8 LocalDate Example How to get Today, Yesterday, and Tomorrow’s date? How to create a LocalDate Object in java? How to get a Year, Month, and Day of Week, Month, Year from the current date? How to convert java.sql.timestamp to LocalDate in java8? How to Convert Localdate to Instant Object? How to compare LocalDate instances in java8?...


Best used forEach Examples in java8 with the explanation

February 28, 2022 ·  4 min read

java8 forEach examples Java8 introduced forEach for iteration of elements - collections, Arrays, and Map. It allows the developer to iterate collections using an internal iterator. It uses with Lambda Expressions and Method reference. Java 7 for each loop example To iterate the list of strings, We have used for each enhanced iteration in java7. import java.util.ArrayList; import java.util.List; public class StringArrayLoopExample { public static void main(String[] args) throws Exception{ List<String> list = new ArrayList<>(); list....


How to convert List into comma separated string

February 28, 2022 ·  3 min read

In this blog post, How to convert List into a comma-delimited string. It covers the following examples for Convert the list of custom objects into a comma-separated string Convert List of Strings/Long/Integers into a comma-separated string. How to convert a List of custom objects into a comma-separated string There are multiple ways to convert a list of objects into comma-separated strings. here object can be the custom object of the java class....


Java 8 - IntToDoubleFunction functional interface example

February 28, 2022 ·  1 min read

IntToDoubleFunction is a functional interface in java.util.function package. It is introduced in java8. It has one abstract method -applyAsDouble takes an int as input and does the conversion, returning the double value of the integer. It is used in lambda expression as well as method references. Here is an IntToDoubleFunction Syntax public IntToDoubleFunction{ double applyAsDouble(int a) } applyAsDouble method applies to given integer argument and returns the result of the method....


Java 8 Supplier Interface examples | Functional Interfaces tutorials in java

February 28, 2022 ·  3 min read

java.util.function.supplier Interface The supplier is a functional interface defined in java.util.function package in java8. This returns the supplier of the result. It has a single abstract method get(). This interface is used as an assignment target for lambda expressions and method references/constructor references. Following is a Supplier interface declaration @FunctionalInterface public interface Supplier<T>{ T get(); } T is the result produced by this method. Simple Supplier get Example It is an example of printing a message using the supplier....


Java8 Summary Statistics Primitive Numeric Data Examples

February 28, 2022 ·  3 min read

In this blog post, We are going to cover the basics of primitive Summary Statistics classes in java8. java8 Summary Statistics Introduction Summary Statistics is to calculate Statistical data such as count, sum, max, min, and average operations on numeric data. Before java8, here are steps to get Summary Statistics of the sum and average operations. First Numeric data might be iterated or loop Add each element to a temporary variable to sum it up average would be returned by dividing the sum by the number of elements It needs to be handled by the developer....


Java8 - Learn Constructor Reference tutorials with examples

February 28, 2022 ·  3 min read

In my previous post, we learned java8 method references with examples. In this blog post, We are going to learn the Constructor Reference tutorials with examples. What is Constructor Reference in java? Constructor references are to reference a class with an object created using class name and new keyword. for Like Method references, references to Constructor can be created to do object initialization. method references use method name, Constructor references use the new keyword and class name....


Java8 - Learn Method Reference Tutorials with examples

February 28, 2022 ·  2 min read

In this tutorial, the About to learn method reference is introduced in the java8 version. What is Method reference in java8 Method reference allows the developer to call a method or constructor by their names. It is one more short way of writing lambda expressions. It uses the symbol :: to separate class/object/constructor from the method name. Sometimes, we used to get the compile-time warning like “The target type of this expression must be a functional interface” so this error is because of the need to assign method reference or lambda expression to a functional interface....


java8 - Best 10 Optional Class Examples

February 28, 2022 ·  4 min read

In my previous post, We covered the following articles about Optional classes and examples in Java 8 Contents How to Convert List to Optional in java8? How to Convert List to List java8? How to Convert Optional String to String How to Convert String to Optional String How to Convert Optional to Stream of type Object in java8? How to Convert Optional to Optional in java8? Concatenate two or more Optional Strings into Optional Strings in java8 How to remove Empty null Optional values from ArrayList?...


java8 - ChronoUnit enum class examples

February 28, 2022 ·  4 min read

What is ChronoUnit in java? java.time.temporal.ChronoUnit is an Enumeration class introduced in java8. It is used to measure the time in Years, Months, Weeks, Days, Hours, Minutes, Seconds, Microseconds, Nanoseconds. Before java8, developers used integer values for Days, Weeks, hours, etc. With the java8 version, These integer values represent with ChronoUnit enumeration constants. It implements the TemporalUnit interface. It contains the following constants Nanos Micros Millis Seconds Minutes Hours HalfDays Days Weeks Months Years Decades Centuries Millennia Eras Forever Some of the methods...


Java8 - Consumer interface tutorials| Functional Interface examples in java

February 28, 2022 ·  2 min read

What are Consumer interfaces in Java8? Consumer interfaces are functional interfaces in java.util.function package in Java 8. It takes a single parameter and outputs any result. Functional interfaces contains one abstract method accept() and default method is andThen(). This is defined in java.util.function package since java 8 version. This can be assigned a target for lambda expressions as well as method references. Consumer interfaces are used to consume the data supplied by streams, process it, and print the result or chain to another interface in a Stream programming flow....


Java8 - Functional Interfaces tutorials with examples

February 28, 2022 ·  4 min read

What are Java 8 Functional Interfaces? Functional Interfaces are new concepts introduced in Java 8. The name itself says it is an interface that contains only abstract methods. Importantly, An instance of this interface is created by lambda expressions, method references and constructor references. This was introduced to have a concept of functional programming in Java 8. Java 8, allows creating a custom functional interface as well as using the inbuilt functional interface....


Java8 - How Lambda Expression Scope works with examples

February 28, 2022 ·  3 min read

In my previous posts, We already learned how to create a lambda expression with examples in java8. This post is about the scope of variables and this/super keyword scope in lambda expressions with examples. Lamda Expression Scope in java8 In Java, we have the following different scopes. Class Scope Variables declared in a class can be accessed anywhere in a class. Method scope variables declared in the method can be accessed anywhere in the declared method only....


java8 - java.time.Clock Class Beginner guide with examples

February 28, 2022 ·  2 min read

It cover the Clock class with examples. java.time.Clock Class in java8 Clock class was added in java8. It is used to represent Date, Time, and Timezone with the best available Clock. Clock class is an abstract class, instances cannot be created. It provides Factory static methods to create Instance of Clock instances. It provides static method - OffsetClock,SystemClock,TickClock,FixedClock It is immutable and threads safe. This class is an input parameter for most of the classes available in the java....


java8 - java.time.instant class tutorial with examples

February 28, 2022 ·  5 min read

In this tutorial, You are about java.time.Instant example and how to convert to a different time and date classes in java 8. Contents What is instant in java? Instant Class Examples How to convert java.time.instant to java.util.Date in java8? How to convert java.util.Date to java.time.instant in java8? How to check if two instant dates are equal in java8? How to convert LocalDateTime to Instant in java8? How to Convert Instant to LocalTime object in java8?...


Java8 - Java.time.Period Class example

February 28, 2022 ·  3 min read

In this tutorial, You are about java.time.Period example and how-to examples using this class in java 8. Contents What is Period in java? What is the Difference between Java.time.Period and Java.time.Duration? Java.time.Period class Example How to create a Period object? How to add/subtract many days to the current date? How to calculate age in years/months/days using Period class? Conclusion What is Period in java? When working with Date and Time API in java8, There is a requirement to find out the amount of time between two dates....


java8 - java.time.ZoneId class tutorials with examples

February 28, 2022 ·  3 min read

What is ZoneId in Java? ZoneId is an abstract class defined in java.time package. This is used to represent timezone such as Asia/Calcutta. This provides rules for creating LocalDateTime and Instant objects. Time in the earth or world is divided into regions. Whereas each part of the region is called a time zone. Timezone is an offset or number of hours difference from Standard time zone UTC - Coordinate Universal Time....


java8 - java.util.DoubleSummaryStatistics class example

February 28, 2022 ·  4 min read

In my previous post, discussed Introduction to Summary Statistics in java8. In this blog post, We are going to explore the DoubleSummaryStatistics class and methods with examples. What is DoubleSummaryStatistics in java? DoubleSummaryStatistics is one of the classes for creating state objects for calculating statistical operations like sum, max, min, average, and count of a double data. DoubleSummaryStatistics is for Double datatype defined in java.util package. There are other classes like IntSummaryStatistics for integer data type and LongSummaryStatistics for the long datatype....


Java8 - java.util.function.Function Interface tutorial with Examples

February 28, 2022 ·  2 min read

java util Function class This is a simple Functional interface, with which the method takes as input and returns the output. This interface is used to map the objects - which takes one type as input, processes it, and returns the output in another type. This interface has only a single abstract method.java.util.function.The function is a predefined interface introduced in java 8. This post is about the predefined functional interface - Function examples with tutorials....


Java8 - java.util.function.Predicate Interface tutorials Examples

February 28, 2022 ·  2 min read

The predicate is a functional interface introduced in java8. It has only one abstract method. The predicate interface is in java. util.function package and it takes a single argument. It evaluates the predicate on the given parameter. public interface Predicate<T> { boolean test(T t) } T is input value test(T t) - Only single abstract method. return true if the given input value matches the condition, else return false Predicate Test method example import java....


Java8 - java.util.IntSummaryStatistics class example

February 28, 2022 ·  4 min read

In my previous post, we discussed Introduction to Summary Statistics in java8. It covers the IntSummaryStatistics class and its method with examples. What is IntSummaryStatistics class in java? IntSummaryStatistics is a class for getting statistical data using sum, max, min, average, and count operations on integer data. IntSummaryStatistics is for Integer datatype defined in java.util package. There are other classes like DoubleSummaryStatistics for double data type and LongSummaryStatistics for the long datatype....


Java8 - java.util.LongSummaryStatistics class example

February 28, 2022 ·  3 min read

In my previous post, we covered the Summary Statistics introduction, IntSummaryStatistics, and DoubleSummaryStatistics It covers LongSummaryStatistics with examples. What is LongSummaryStatistics class in java8? LongSummaryStatistics is a class for collecting statistical data using sum, max, min, average, and count operations on long data. Java.util package provides three classes IntSummaryStatistics for Integer data, DoubleSummaryStatistics for double data and LongSummaryStatistics for long data. These classes work with streams and lambda expressions....


Java8 - Lambda Expressions Guide & examples

February 28, 2022 ·  5 min read

In this blog post, I will cover the basics of java8 Lambda expressions tutorials with examples. Lambda Expressions java8 Lambda expressions are an important feature introduced in java8 to achieve functional programming. This expression enables the creation of an anonyms class with the implementation of functional interfaces. Anonyms class has no name for it. The functional interface contains only single abstract methods, introduced in java8 to achieve functional programming in java language....


Java8 - Learn java.util.Optional class with examples

February 28, 2022 ·  5 min read

Learn the Optional class in java8 with examples. Contents What is Optional Class in java How to create an Empty Optional Instance? How to Create an optional non-empty instance? Optional ofNullable() method Optional isPresent() method usage Optional ifPresent() method example Optional get() method example Optional orElse() method examples Optional orElseGet() method example Optional orElseThrow method example Optional filter() method example Optional map() method example Optional flatMap() method with example What is Optional Class in java In Java Applications, Many Developers face NullPointerException during development....


Java8 - Learn Interface Default and Static Methods tutorials with examples

February 28, 2022 ·  4 min read

In this blog post, You are about to learn Default and static methods in interfaces tutorials with examples. Why Default Methods interface is required? Default Methods is one of the features introduced for the java 8 version. Before Java 8 version, The interface has only abstract methods. Implementations of abstract methods have to be provided by the class which implements the interface. If any interface code is released, We can’t change the interface structure....


Java8 - Learn Numeric Function interfaces with examples

February 28, 2022 ·  4 min read

Contents What are the Function interface in java8? ToLongBiFunction interface in java example ToLongFunction Interface example in java ToDoubleFunction Interface java example ToDoubleBiFunction interface example ToIntFunction example ToIntBiFunction<T,U> interface DoubleToLongFunction IntFunction example IntToLongFunction interface LongFunction Interface LongToDoubleFunction interface LongToIntFunction interface What are the Function interface in java8? Java8 introduced a functional interface to achieve functional programming with java language. java.util.function package has many predefined functional interfaces. These functional interfaces can be assigned as a target to lambda expressions or method /constructor references....


Java8 - Numeric BinaryOperator interface examples | Functional Interfaces tutorials

February 28, 2022 ·  2 min read

In this blog post, We are going to learn the Numeric BinaryOperators class in java8 with examples. In my previous post, discussed BinaryOperator tutorials with examples What is Binary Operator? Binary Operators are operators that take two parameters of primitive type and output the same primitive type values. Numeric BinaryOperators are declared in java.util.function package. Each numeric primitive types like long, int, and double have binary operators. Java8 has following numeric binary operators...


Java8 - OptionalDouble class Example

February 28, 2022 ·  3 min read

What is java.util.OptionalDouble in java? OptionalDouble class is introduced in java8. This is Optional container for double values that may contains empty or non empty values. if double value is present, isPresent() method returns true, and getAsDouble() method returns double value. OptionalDouble is a primitive double version of the Optional class whereas Optional is an Optional class for Double Object. OptionalDouble class Example This is an usage of isPresent(), getAsDouble(), orElse() and Lambda expressions example....


Java8 - OptionalInt class Example

February 28, 2022 ·  3 min read

java.util.OptionalInt OptionalInt is a container class that contains null or not null int values. OptionalInt is a primitive int version of Optional class whereas Optional is an Optional class for Integer Object. It is defined java.util package and aviable since java8 version. isPresent() method returns true. getAsInt() method returns integer value. Creation Empty OptionalInt Instance empty() method creates OptionalInt instance. No object presented in it. isPresent() method returns false, false meaning absense of values...


Java8 - OptionalLong Class Example

February 28, 2022 ·  3 min read

java.util.OptionalLong OptionalLong class is introduced in java8 along with OptionalInt and OptionalDouble. This is an optional container for long values that may or may not contain empty or nonempty values. if long value is present,isPresent() method returns true. getAsLong() method returns long value.OptionalLong is a primitive long version of Optional class whereas Optional is an Optional class for Long Object. It is defined java.util package since java8 version Creation Empty OptionalLong Instance empty() method creates OptionalLong instance....


Java8 - Stream map methods with examples

February 28, 2022 ·  4 min read

Contents What is a Stream map in java8? java Map Filter examples How to convert Map to List using streams? How to convert List of String to uppercase or lowercase? Conclusion What is a Stream map in java8? map()method map the object to other objects of the same type or different type. It is an intermediate operation in processing stream of objects they called lazily and accept input as a function and output stream of objects which contains results by applying a function to each element of a stream....


Java8 java.time.Duration class with examples

February 28, 2022 ·  2 min read

what is java.time.Duration class in java8 java.time.Duration is an object introduced in java8. This is a measurement to find micro time information between two dates. This measures time in micro and nano seconds. This is a useful finding period between various Date and Time API classes. This is an immutable class, Once created, we can not change its value and thread-safety class. Signature public final class Duration implements TemporalAmount, Comparable<Duration>, Serializable Duration class internally store the two below values...


java8 java.time.ZoneOffset tutorials with examples

February 28, 2022 ·  3 min read

What is ZoneOffset class in java8? ZoneOffset class is defined in the java.time package and introduced in java8 as part of Date time API enhancements. It is used to represent offset from UTC Time zone and Offset returns hours/ minutes difference from UTC timezone. timezone is part of the earth like a group or single countries on which all follow the standard time. Each time zone contains two properties....


java8 Numeric Object Consumer examples | Functional Interface tutorials

February 28, 2022 ·  2 min read

Learn the Numeric BinaryOperators class in java8 with examples. Primitive Consumer functional interfaces are defined in java.util.function package. It has only a single abstract method that takes object values and other numeric values and results in nothing. It accepts two values as input like the BiConsumer interface. All functional interfaces use as a variable assigned with lambda expression or method reference. You can check my related posts: Consumer Interface tutorials Primitive Consumer Interface ObjIntConsumer class in java8 java....


Java8 Primitive Consumer Interface examples| Functional Interface tutorials

February 28, 2022 ·  2 min read

Learn about primitive Consumers in java8 with examples. java.util.function.consumer Interface Java 8 introduced different consumer interfaces in java.util.function package. IntConsumer LongConsumer DoubleConsumer Consumer is an operation that accepts numeric values and outputs no result. In my previous post, documented consumer tutorials. java8 IntConsumer class IntConsumer is an interface defined in java.util.function package. It has only a single abstract method - accept() which takes an input value and returns nothing....


Java8 Primitive Supplier Examples | Functional Interface tutorials

February 28, 2022 ·  2 min read

Learn about the primitive supplier in java8 with examples. What is Primitive Supplier in Java8? java.lang.function package provides various primitive supplier interfaces. java8 has functional interfaces for different data types like integer, long, double, and Boolean. This post explains various primitive supplier and usage examples. Java 8 introduced different Primitive Supplier interfaces in the java.util.function package. IntSupplier LongSupplier DoubleSupplier BooleanSupplier All these interfaces can be assigned with lambda expressions and method/constructor references....


Java8 UnaryOperator interface Examples tutorials

February 28, 2022 ·  3 min read

What is UnaryOperator in java? UnaryOperator is a functional interface in java.util.function package. It operates on one operand and returns the result of the same operand type. These are assigned with lambda expressions or method or constructor references. UnaryOperator java8 examples Here is an UnaryOperator interface declaration @FunctionalInterface public interface UnaryOperator<T> extends Function<T, T> { static <T> UnaryOperator<T> identity() { return t -> t; } } UnaryOperator extends Function interface....


Java8- Learn LocalDateTime Basics with Example

February 28, 2022 ·  3 min read

What is java.time.LocalDateTime in java8? LocalDateTime is introduced in java8 language as part of Date and Time API enhancement. It represents Date and time without timezone information. Example LocalDateTime object displays as 2022-12-14T06:12:40. It is an immutable object, which means once the object is created, will not be modified. It is used to store dates like birthdays and holidays with time information. LocalDate contains only year, month, Day, hour, minute, and second with nano-precision....


Subscribe
You'll get a notification every time a post gets published here.