Java 15 – Text blocks

Text blocks are all about writing multi-line strings in a clean and readable way. This was added as part of JEP 378 in Java 15. One can read the detailed information of the feature from the JEP details. In this post, I will show you how to use text blocks and some things to keep … Read more

Difference between Function.andThen and Function.compose

There are two different ways to mix functions in Java: using andThen using compose It is important to understand the difference between the two. andThen: function1.andThen(function2) will first apply function1 to the input and the result of this will be passed to the function2. compose: function1.compose(function2) will first apply the input to the function2 and … Read more

Different ways of declaration and initialization of arrays in Java

The below code shows the different ways one can declare and initialize an Array in Java: Line 5: Declaration of array along with initialization of its values. Here it is not required to pass the size of the array. Line 8-9: Declaration of array by providing its size. The array will be initialized with 0 … Read more

How to use regular expression in Java?

Regular expressions are very important tool for seraching in text. Below is the code snippet for executing regex search and capturing different parts of the string based on the regular expression The groups are captured by using (). In the regular expression above ([0-9]+)([_])(.*)([\.])([A-Za-z]+) the first group is defined as a number with at least … Read more

JDK 14 – JEP 361 Switch Expressions out from preview

In my previous post, I wrote about switch expressions and related enhancements released as a preview feature for JDK 12. Subsequently, in JDK 13 there were some changes proposed, like using yield keyword to return value from the switch block and released in preview. In the upcoming JDK 14 release, which will go GA in … Read more

JEP 355 Text Blocks in JDK 13

JDK 13 went GA on September 17th, 2019 and the prominent new features are listed here. One of the new features is “text blocks”. This allows writing multiline strings easily without the need for concatenation while splitting into different lines. Lets quickly look at the different ways of creating multiline strings: String aBlock = “”” … Read more

How to Create QRCode Using QRGen in Java

In one of my previous articles, we saw how to create QRCode and its SVG equivalent using Zxing Java library. The Zxing library is no longer actively maintained and for this, there is a wrapper around Zxing library called QRGen, which provides much higher level APIs and a builder syntax for generating QR Codes. In … Read more

JDK 12 – JEP 325 Switch Expressions

JDK 12 went GA on March 19, 2019, keeping its word on shorter release cycles and frequent releases. The features part of the release can be found here. One of the interesting features for the developers is the “JEP 325 Switch Expressions” which is available as a preview feature. A preview feature as defined here … Read more

How to create a QR Code SVG using Zxing and JFreeSVG in Java?

In this article, we will look at how to use the Zxing QR code generation library and JFreeSVG library to create a QR Code SVG image in Java. QR Code Generation The below code creates a java.awt.image.BufferedImage object representing QR Code using Zxing library: public static BufferedImage getQRCode(String targetUrl, int width, int height) { try … Read more

%d bloggers like this: