Learn free java8 tutorials


Java8- Learn LocalDateTime Basics with Example

September 6, 2018 ·  2 min read

java.time.LocalDateTime LocalDateTime is introduced in java8 language as part of Date and Time API enhancement. It represents Date and time without timezone information in 2018-09-06T06:12:40 It is immutable object once created, will not be modified It is used to store dates like birthday and holidays with time information. Local Date contains only year, month, Day, hour, minute, second with nano-precision. Syntax and Signature  This class implements ChronoLocalDateTime of LocalDate...


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

September 3, 2018 ·  1 min read

java.time.Clock Class  In this blog, We are going to cover Clock class with examples. Clock class was added in java8. It is used to represent Date, Time and Timezone with 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 OffsetClock,SystemClock,TickClock,FixedClock It is immutable and threads safe This class is a parameter for most of the classes available in java....


java8 - java.time.ZoneId class tutorials with examples

September 2, 2018 ·  3 min read

java.time.ZoneId class ZoneId is an abstract class defined in java.time package. This is used to represent timezone id Asia/Calcutta. This provides rules for creating LocalDateTime and Instant objects. Time in the earth or world is divided into time zones. each part of the region is called timezone. Timezone is an offset or number of hours difference from Standard time zone UTC - Coordinate Universal Time. Syntax public abstract class ZoneId implements Serializable Zone Id Object Creation It Provides of() method for creating the specific zone....


Learn java.time.ZoneOffset tutorials with examples

September 2, 2018 ·  3 min read

java8 ZoneOffset class ZoneOffset class is declared in java.time package and introduced in java8 as part of Date time API enhancements. It is used to represents offset from UTC Timezone, Offset returns hours/ minutes from which UTC timezone is a difference with timezone is part of the earth like a group or single countries on which all follow the standard time. Each timezone contains two properties. id - Asia/Calcutta  offset - time difference or offset from UTC/Greenwich - Example is +05:30 Features It is Immutable, Once Instance is created, can not able to modify its state of the instance It is Threadsafe implemented during multi-thread environment It is based on value-based class, When this classed checked against duplicate or identity instance using === operator, gives inconsistent result and behavior is specific to JVM....


Java8 - Learn Stream map methods with examples

August 28, 2018 ·  3 min read

Stream map method introduction map() method map the object to others object of the same type or different type. It is 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 Syntax <R> Stream<R> map(Function<? super T, ? extends R> mapper) map method takes Function as input....


Java8 - Java.time.Period Class example

August 28, 2018 ·  2 min read

In this blog post, We will cover the Java.time.Period Class with examples Period class Introduction When working with Date and Time API in java8, There is a requirement to find out the amount of time between two dates is a common requirement The period is measured in years, months, days and time duration is measured in. It is value based class. So two objects of Period equality check might produce unpredictable results....


Java8 - Learn Constructor Reference tutorials with examples

August 28, 2018 ·  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. Constructor Reference Introduction Like Method references, references to Constructor can be created to do object initialization. method references use method name, Constructor references uses new keyword and class name. Syntax ClassName :: new Constructor Reference Example  Here is an example for reference of String class name....


Java8 java.time.Duration class with examples

August 27, 2018 ·  2 min read

java.time.Duration tutorials 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 nanoseconds. This is a useful finding period of time 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.temporal.ChronoUnit enum tutorials with examples

August 27, 2018 ·  3 min read

ChronoUnit Examples java.time.temporal.ChronoUnit is an Enumeration class introduced in java8. This is replaced with integer values representing Days, weeks.. etc. It implements TemporalUnit interface. It is used to measure the time in Years, Months, Weeks, Days, Hours, Minutes, Seconds, Microseconds, Nanoseconds It contains the following constants Nanos Micros Millis Seconds Minutes Hours HalfDays Days Weeks Months Years Decades Centuries Millennia Eras Forever Usecases and Usage This can be used in Date and Time API for calculating below things...


java8 - java.time.instant class tutorial with examples

August 27, 2018 ·  4 min read

java.time.instant tutorials instant is a class defined in java.time package. It represents date and time in a timeline with correct nanoseconds precision. Java.util.Date represents date and time in milliseconds precision. Instant stores nanoseconds, so it requires more storage as it stores a number larger than long. Internally it stores in two fields. As part of Initialization of Instant, Constructor also two fields. Instant(long epochSecond, int Nanos) 1. Long epochSecond value - Number of seconds since standard epoch time...


Java8 Top 5 forEach Examples with tutorials

August 27, 2018 ·  3 min read

java8 forEach tutorials Java8 introduced forEach for iteration of elements - collections, Arrays, and Map. It allows the developer to iterate collections using an internal iterator. This can be used 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. List<String> list = new ArrayList<String>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); for (String str : list) { System....


Java8 - Top 10 LocalDate examples with tutorials

August 27, 2018 ·  4 min read

java.time.LocalDate LocalDate is introduced in java8 language as part of Date and Time API enhancement. It represents Date without timezone information in ISO format ie YYYY-MM-DD. It is used to store dates like birthday and holidays. Local Date contains only year month and Day. LocalDate Examples We are going to see the many usecases of LocalDate class. Get Today Yesterday and Tomorrows date ? LocalDate.now() method is used to get current date of a default time zone LocalDate....


Java8 - java.util.LongSummaryStatistics class example

August 25, 2018 ·  3 min read

In my previous post, we covered the Summary Statistics introduction, IntSummaryStatistics, and DoubleSummaryStatistics In this blog post, we are going to cover LongSummaryStatistics with examples. LongSummaryStatistics class LongSummaryStatistics is class for collecting statistical data using like 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 - java.util.IntSummaryStatistics class example

August 25, 2018 ·  3 min read

In my previous post, we discussed Introduction to Summary Statistics in java8. In this blog post, we are going to cover the IntSummaryStatistics class and its method with examples. IntSummaryStatistics class  IntSummaryStatistics is class for getting statistical data using like 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.DoubleSummaryStatistics class example

August 25, 2018 ·  4 min read

In my previous post, we discussed Introduction to Summary Statistics in java8. In this blog post, We are going to explore the DoubleSummaryStatistics class and methods with examples. Java8 DoubleSummaryStatistics class  DoubleSummaryStatistics is one of the clas for creating state object 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 Summary Statistics Introduction with Examples

August 24, 2018 ·  2 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 a 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 sum with a number of elements This need to be handled by the developer....


Java8 - Array Stream Lambda Expression How to Examples

August 23, 2018 ·  4 min read

Stream API Array Lamda 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. How to remove white spaces from string array in java8? A declared array of string objects, Some of the string elements contains whitespaces. Remove/trim of each string object and return string array without whitespaces Using lambda Stream map function in java8...


Java8 - How Lambda Expression Scope works with examples

August 22, 2018 ·  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 Basics In Java, we have 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...


java8 - Top 10 Optional Class Examples

August 22, 2018 ·  3 min read

In my previous post, We covered following articles about Optional classes in Java 8 Optional Class Tutorials OptionalInt class Examples OptionalLong class Examples OptionalDouble class Examples Now you got understanding of the basics and usage of Optional classes. java.util.Optional Examples The optional class is a container object for holding null or not null values. Following are the Optional Class How to examples Convert List to Optionalin java8? First Converted Array to List using Arrays....


Java8 - OptionalLong Class Example

August 21, 2018 ·  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 - OptionalInt class Example

August 21, 2018 ·  3 min read

java.util.OptionalInt OptionalInt is a container class which contains null or not null int values. OptionalInt is a primitive int version of Optional class whereas Optionalis 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 - OptionalDouble class Example

August 21, 2018 ·  3 min read

java.util.OptionalDouble 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. getAsDouble() method returns double value. OptionalDouble is a primitive double version of Optional class whereas Optionalis an Optional class for Double Object. OptionalDouble Example This is an usage of isPresent(), getAsDouble(), orElse() and Lamda expressions example. import java.util.OptionalDouble; public class OptionalDoubleDemo { public static void main(String[] args) { OptionalDouble optionalDouble = OptionalDouble....


Java8 - Learn java.util.Optional class with examples

August 21, 2018 ·  4 min read

In this Blog post, We are going to learn the Optional class with examples. Optional Class Basics In Java Applications, Many Developers faces NullPointerException during development. NullPointerException is a runtime exception which breaks the code. Java8 introduced Optionalclass to avoid null value checking and NullPointerException. Optional is a class defined in java.util package since Java8 version This is used to check the values or object is present or not....


Java8 - Learn Interface Default and Static Methods tutorials with examples

August 21, 2018 ·  4 min read

In this blog post, We will cover the basics of Default methods interfaces tutorials with examples. Why Default Methods interface is required? Default Methods is one of the features introduced for java 8 version. Prior to Java 8 version, 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, if any changes required for the interface, It causes code breaking in classes which implements interfaces....


Java8 - Learn Lambda Expressions in 10 minutes with tutorials and examples

August 21, 2018 ·  4 min read

In this blog post, I will cover the basics of java8 Lambda expressions tutorials with examples. Lamda Expressions Introduction Lamda Expresesions are important feature introduced in java8. This expression enables to create an anonyms class with implementation of FInterfacesinterfaces. 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. Please see my previous articles on Functional Interfaces....


Java8 - Learn Method Reference Tutorials with examples

August 20, 2018 ·  2 min read

Method reference basics java introduced method reference in java8 version. Method reference allows the developer to call a method or constructor by their names. Method references are one more short way of writing lambda expression. Method references use the symbol “::” to separate class/object/constructor from 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 the need to assign method reference or lambda expression to functional interface...


java8 Numeric Object Consumer examples | Functional Interface tutorials

August 19, 2018 ·  2 min read

In my previous posts, We learned with examples of various consumer interfaces as follows Consumer Interface tutorilas Primitive Consumer Interface Primitive Consumer functional interfaces are defined in java.util.function package. It has an only single abstract method which takes object value and other numeric value and results in nothing. This accepts two values as input like BiConsumer interface. All functional interfaces can be used as a variable assigned with lambda expression or method reference...


Java8 - Numeric BinaryOperator interface examples | Functional Interfaces tutorials

August 18, 2018 ·  2 min read

In my previous post, discussed BinaryOperator tutorials with examples Numeric BinaryOperators are declared in java.util.function package. Each numeric primitive types like long, int and double have binary operators. Binary Operators are operators that take two parameters of primitive type and outputs the same primitive type values DoubleBinaryOperator  It is a functional interface that takes two double values as input and output double value. It is a double version of BinaryOperator....


Java8 - BinaryOperator interface examples | Functional Interface tutorials

August 17, 2018 ·  2 min read

BinaryOperator is an interface defined in java.util.function package of java8. This interface extends BiFunction interface. This can be assigned with Lamda expressions/method references This performs an operation that accepts two parameters of the same type and returns the same type value as a result. In this post, We are going to learn BinaryOperator interface and it’s method usage and examples. Syntax @FunctionalInterface public interface BinaryOperator<T> extends BiFunction<T,T,T> { public static <T> BinaryOperator<T> minBy(Comparator<?...


Java8 - UnaryOperator interface Examples | Functional Interfaces tutorials

August 17, 2018 ·  2 min read

java.util.function.UnaryOperator UnaryOperator is a functional interface in java.util.function package It operates on one operand and return the result of same operand type. This are assigned with lambdaexpressions/metod/constructor references UnaryOperator code signature @FunctionalInterface public interface UnaryOperator<T> extends Function<T, T> { static <T> UnaryOperator<T> identity() { return t -> t; } } UnaryOperator extends Function interface, It extends abstract apply from the functional interface. Function Interface has default andThen() and compose methods...


Java8 Primitive Consumer Interface examples| Functional Interface tutorials

August 16, 2018 ·  2 min read

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. IntConsumer It has an only single abstract method - accept() which takes an input value and returns nothing And also default method - andThen(IntConsumer after) - Returns aggregation consumer of called consumer with after consumer result...


Java8 Primitive Supplier Examples | Functional Interface tutorials

August 16, 2018 ·  2 min read

Primitive Supplier Examples 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. All these interfaces can be assigned with lambda expressions and method/constructor reference. The Element class is used in all interface examples. package org.cloudhadoop.functions; public class Element { private Boolean enabled; private Integer number; public Element(Integer number, Boolean enabled) { this....


Java 8 Supplier Interface examples | Functional Interfaces tutorials in java

August 16, 2018 ·  3 min read

java.util.function.supplier Interface The supplier is a functional interface defined in java.util.function package in java8. This returns 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 reference Supplier interface declaration @FunctionalInterface public interface Supplier<T>{ T get(); } T is the result produced by this method. Basic Supplier get Example This is an example for usage of Supplier interface and calling get() method...


Java8 - Consumer interface tutorials| Functional Interface examples in java

August 16, 2018 ·  2 min read

Java8 Consumer interface Consumer interfaces are functional interfaces in java.util.function page and introduced in Java 8. It takes a single parameter and outputs any result. Functional interfaces has a single abstract method.This one abstract method accept() and default method is andThen() This is defiend in java.util.function package since java 8 version. This can be assigned 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 flow of programming...


Java8 - Learn Numeric Function interfaces with examples

August 16, 2018 ·  3 min read

Java8 features- Function interface examples Java8 introduced a functional interface to achieve functional programming with java language. java.util.function package has many predefined functional interfaces. This functional interfaces can be assigned as a target to lambda expressions or method /constructor references. These will be very useful during an iteration of objects, stream API processing and manipulate like filter data to process numeric data. This post is about various numeric(Integer, Long, Double related) functional interfaces examples....


Java 8 - IntToDoubleFunction functional interface example

August 16, 2018 ·  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 do the conversion, return double value of the integer. It can be used in lambda expression as well as method references. Syntax public IntToDoubleFunction{ double applyAsDouble(int a) } applyAsDouble method applies to given integer argument and returns the result of the method. Lambda IntToDoubleFunction usage example  The below code explains about the usage of applyAsDouble() using lambda expression with an example...


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

August 16, 2018 ·  2 min read

The predicate is a functional interface introduced in java8. It has only one abstract method. Predicate interface is in java.util.function package and it takes single argument. It evaluates the predicate on 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 condition, else return false Predicate Test method example import java.util.function.Predicate; public class PredicateDemo { public static void main(String[] args) { Predicate<Integer> predicateFunction = num -> (num > 0); System....


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

August 16, 2018 ·  2 min read

This is a simple Functional interface, with which method takes as input and return the output. This interface is used to mapping the objects - which takes one type as input, process it and returns the output in another type. This interface has an only 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 - Learn Functional Interfaces tutorials with examples

August 16, 2018 ·  4 min read

Java 8 features - Functional Interfaces Introduction Functional Interfaces are new concepts introduced in Java 8. The name itself says it is an interface which contains only abstract method. 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. With Java 8, It allows creating a custom functional interface as well as inbuilt functional interface provided by Java 8....