Wednesday, January 8, 2020

Java Program To Convert A Primitive Array To A List

1. Overview

In this programming tutorial, You will learn how to convert any primitive type array to a List. Primitive types are int, float, double, byte, long.
By end of this article, you will be able to convert int[] array to List<Integer> and float[] array to List<Float> or any primitive array to any List implementation.

Example programs are shown in classic java and using java 8 streams.

Java Program To Convert A Primitive Array To A List


Tuesday, January 7, 2020

Java 14 @Serial Annotation

1. Introduction


In this tutorial, we will learn a new annotation @Serial introduced in Java 14. This annotation is similar to the @Override annotation, @Serial annotation is used in combination with the serial lint flag to perform compile-time checks for the serialization-related members of a class.


Already this feature is available in build 25.

Java 14 @Serial Annotation

Monday, January 6, 2020

Creating A Simple ToDo Spring Web Application (Spring MVC)

1. Overview


In this tutorial, We'll learn how to create a simple ToDo web application using the Spring web framework. Spring web framework is called as officially Spring MVC. Let us create a simple REST api with CRUD operations such as Create, Read, Update, and Delete. You will learn and understand by a step by step tutorial. In the previous article, we have shown how to build a first Hello World application in Spring Boot and all possible real-time exceptions.

Spring 5.0.3.RELEASE
Bootstrap 3.3.7
Hibernate 4.3.11.Final
h2.version 1.4.197
JDK 1.8
Spring data 1.11.4.RELEASE


Sunday, January 5, 2020

Java Program: Read File Line By Line

1. Overview


In this programming tutorial, We'll learn today how to read a text file line by line. Java programs are shown for all possible ways to read file contents.
One of the file tutorials, we have already discussed in-depth on How to read large text files efficiently in java.

We will learn different approaches to read file line by line as String and pass this string to a separate method to process it.

Following are the java API class that provides a way to process the files.

Java Read File Line By Line


BufferedReader
Scanner
Files
RandomAccessFile

Saturday, January 4, 2020

How to Kill a Java Thread

1. Overview


In this tutorial, We will cover stopping a Thread in Java which is not that simple since the Thread.stop() method is deprecated. Because Thread.stop() method can lead to the monitored objects being corrupted. But, Still, many developers and applications are still using Thread.stop() method. Because they are not aware of its problems (monitored objects being corrupted.).

How to Kill a Java Thread Or How to stop a thread without using stop() method

let us see what are the other possible ways to stop the thread from its execution. This is a tricky topic for intermediate developers. Please read twice and practice the programs.

Wednesday, January 1, 2020

Java 8: Counting Matches on a Stream Filter - Stream.count(), Collectors.counting()

1. Overview


In this java 8 tutorial, We'll learn how to find the count of a Stream using Stream.count() and Collectors.counting() methods and also how to find the count that matches a specified condition or a Predicate. To use Predicate, we must use the filter() method from Stream API.
Let us start writing a few examples of finding count.

Java 8: Counting Matches on a Stream Filter


Java 8 Stream API filter() examples

1. Overview


In this Stream tutorial, We will learn today what is Stream filter introduced in Java 8. Java 8 has a Stream API and it has a filter() method which takes the Predicate Functional Interface as an argument. filter() method is a part of Intermediate Operations which is used in the middle of streams and returns a Stream as output.

Java 8 Stream filter() example