Category: Java tutorial
-
Stream.reduce() in Java
1. Introduction While working with Java streams, there are many terminal operations (such as sum, min, max, count and average) that return one value by combining the contents of a stream. These operations are called reduction operations. Reduction operations are not limited to returning a single value. Reduction operations can return a collection as well.…
-
Parallel streams in Java
1. Introduction Parallel computing entails fragmenting a task into smaller segments, tackling these segments concurrently (in parallel, with each one operating within its own thread), and subsequently combining the outcomes of the individual segment solutions. There is problem in implementing parallelism in Java applications that use collections as collections are not thread-safe. This means that…
-
Epsilon: A No-Op Garbage Collector
1. Introduction In Java 11, a No-Op Garbage Collector called Epsilon was introduced which handles memory allocation but does not implement any actual memory reclamation mechanism. When the Java heap limit is exhausted, the JVM terminates. Epsilon garbage collector promises lowest possible GC overhead. 2. Enabling Epsilon GC Epsilon GC can be enabled using -XX:+UnlockExperimentalVMOptions…
-
String lines() method in Java
1. Introduction The signature of the lines() method introduced in Java 11 is: This method returns a stream of lines extracted from the string, separated by line terminators. This method returns a stream which contains the lines from this string in the same order in which they occur in the string. A line terminator is…
-
String strip() method in Java
1. Introduction The syntax of this method is: This method returns the string after removing returning all its leading and trailing white spaces. This method was added in Java 11. A character is a Java whitespace character if and only if it satisfies one of the following criteria: If the String object represents an empty…
-
Java isBlank() method
1. Introduction The syntax of the isBlank() method of String class is: This method returns true if the string is empty or contains only white space codepoints, otherwise false. One important point to note here is the term white space codepoint. A character is a Java whitespace character if and only if it satisfies one…
-
String repeat method
1. Introduction Sometimes you might need to repeat a string certain number of times. In such case, you can use String class repeat() method. The signature of repeat method is: public String repeat(int count) – This method returns a string whose value is the concatenation of this string repeated count number of times. If this…
-
Local-Variable Syntax for Lambda Parameters
1. Introduction Local-Variable syntax for Lambda parameters was introduced as JEP 323. This change allows var to be used when declaring the formal parameters of implicitly typed lambda expressions. The goal of this change is to align the syntax of a formal parameter declaration in an implicitly typed lambda expression with the syntax of a…
-
HttpClient in Java 11
1. Introduction The HTTP Client was added in Java 11. This class was introduced to replace the legacy HttpUrlConnection class. Due to the issues with HttpUrlConnection, programmers used third-party libraries such as Apache HttpClient and Jetty. HttpClient is an abstract class available in java.net.http module and java.net.http package. This class represents an HTTP Client. An…
-
Concurrency vs Parallelism
1. Introduction At first, concurrency and parallelism may seem to be the same thing but actually these are different. In Java programming, understanding the concepts of concurrency and parallelism is important for developing efficient and robust applications. Java with its libraries and features provide rich support to both concurrency and parallelism. A simple example of…