Prior to Sealed Classes feature there were two ways a developer could prevent a class to be extended: by declaring the class as final where no one can extend this class. 2. by making the class package private where no… Read More ›
Java
Java 16 – Pattern matching for instanceof
We all have used instanceof check with a subsequent cast to the desired type and in this process, we are doing two operations: validating whether the object we have is of the desired type using instanceof when the validation is… Read More ›
Java 16 – Records and Constructor
In my previous post, I introduced you to the new construct called Records which was introduced in Java 16. In this post, I will go a bit deeper into how you can override the default constructor of a record which… Read More ›
Java 16 – Records
We all, Java programmers, have complained whenever we were forced to create a class or use maps just to hold some data whilst other newer languages provided some out-of-the-box data structure for the same. Our problem has been addressed by… Read More ›
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… 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… 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… 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… Read More ›
How to parse number string with commas to Integer or Long?
Below is the code used for parsing number string with commas to Integer or Long
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… Read More ›