Introduction This example shows you how to convert milliseconds into years, months, weeks, days, hours, minutes, seconds in Java. Sometimes we need to convert the milliseconds into years or months or weeks or days or hours or minutes or seconds. For example, when you want to check the exact time taken by a program to […]
Introduction This example shows you hot to convert milliseconds into days, hours, minutes, seconds in Java. Sometimes we need to convert the milliseconds into days or hours or minutes or seconds. Typically when you want to check the exact time taken to execute a program then you may need to calculate the time. So in […]
In this tutorial I am going to show how default and static methods can be included into Java 8 interface. Prior to Java 8 we did not have such mechanism to include default method or static method into interface but Java 8 provides such option to include those methods. Static methods are regarded as utility […]
In this tutorial I am going to show how to create custom thread pool in Java. Multi-threaded and multi-process programming is a great way to optimize CPU usage and get things done quickly. Creation of Threads in Java is a costly IO operation. Therefore it is not advisable to create & destroy thread(s) every often. […]
I came across a situation where I required to fetch data from a HashMap and add it to an ArrayList. So I will show you here how to iterate a Map and form an object and finally add it to the List using Java 8 lambda expression.
Introduction In this tutorial, I will show you how you are going to collect and convert objects using lambda expression in Java 8 stream API. We will collect objects and map to another custom objects using Java 8 stream API with the help of Lambda Expression. Suppose you have entity classes generated from your database […]
This tutorial will show you how to use Java 8 stream API’s filter and map methods. filter() method is used to produce a stream containing only a certain type of objects into the result output and map() method is used to transform a stream from one type to another type into the result output.
A Future represents the pending result of an asynchronous computation. It offers a method — get — that returns the result of the computation when it’s done. The problem is that a call to get is blocking until the computation is done. This is quite restrictive and can quickly make the asynchronous computation pointless. CompletableFuture<T> […]
The Date-Time package, java.time, introduced in the Java SE 8 release, provides a comprehensive model for date and time. Why do we need for a new Date and Time library ? Non thread-safe The existing classes (such as java.util.Date and SimpleDateFormatter) aren’t thread-safe, leading to potential concurrency issues for users — not something the average […]
This tutorial will explain about Java’s new API called stream, which is introduced in Java 8 and included in package java.util.stream. The stream API supports functional-style operations on collection of elements or stream of elements in a collection. For example, you only want to print even numbers from a list of numbers, then you can […]