Java 8 LocalTime class

The java.time.LocalTime class is an immutable class that represents a time, often viewed as hour-minute-second. Time is represented to nanosecond precision. For example, the value “13:45.30.123456789” can be stored in a LocalTime. This class does not store or represent a date or time-zone. Instead, it is a description of the local time as seen on … Read more

Java 8 LocalDate class

The java.time.LocalDate class is an immutable class without a time-zone in the ISO-8601 calendar system, such as 2018-04-03. Java LocalDate class methods Method Description LocalDateTime atTime(int hour, int minute) It is used to combine this date with a time to create a LocalDateTime. int compareTo(ChronoLocalDate other) It is used to compares this date to another … Read more

Java 8 Date Time API

Before starting Java date time API, let’s discuss some important drawbacks of old date time API. Some drawbacks of old java date time api All the Date classes in old java date time api are mutable that’s why they are not thread safe. Old java date time classes are not defined consistently. Date Class is … Read more

Java 8 Type Inference improvements

Type Interface feature was introduced in Java 7 which provides ability to compiler to infer the type of generic instance. We can replace the type arguments with an empty set of type parameters () diamond. Before Java 7 following approach was used: List list = new List(); We can use following approach with Java 7: … Read more

Java 7 Type Inference

Java 7 introduced a new feature Type Interface which provides ability to compiler to infer the type of generic instance. We can replace the type arguments with an empty set of type parameters () diamond. Before Java 7 following approach was used: List list = new List(); We can use following approach with Java 7: … Read more

Java 8 Base64 example

Java 8 provides a new feature Base64 to deal with decryption and encryption. Java 8 Base64 class provides three different encoders and decoders to encrypt information at each level. Simple Encoding and Decoding: It uses the Base64 alphabet specified by Java in RFC 4648 and RFC 2045 for encoding and decoding operations. The encoder does … Read more

Java Parallel Array Sorting

Java 8 provides a new additional method parallelSort() in the Arrays class of java.util package. It is introduced to support the parallel sorting of array elements. The parallelSort() method uses the concept of multithreading which makes it much faster compared to the normal sort when there are lot of elements. Java parallel array sorting example … Read more

Java 8 Optional Class

Java 8 introduced a new public final class Optional in java.util package. It is used to deal with NullPointerException in java application. It provides the methods to easily check whether a variable has null value or not. Commonly used methods of Java Optional class: Optional.ofNullable(): It returns a Non-empty Optional if the given object has … Read more

Java 8 StringJoiner class

Java 8 introduced a new class StringJoiner in the java.util package which provides the facility to join more than one strings with the specified delimiter. We can also use prefix and suffix to the final string while joining multiple strings. Joining strings by specifying delimiter package com.w3schools; import java.util.StringJoiner; public class TestExample { public static … Read more

Java 8 collectors class

Collectors is a final class that extends the Object class which provides reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, grouping etc. Java Stream Collectors groupingBy and counting example package com.w3schools; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; public class Test{ public static void main(String[] args) … Read more