In this post under Java language, I will show with example how Java runs a program which has two main methods. Here two main methods means one traditional public static void main method as shown below public static void main(String[] args) { } and another being the new main method as shown below void main()…… Continue reading Instance Main and Non-Instance Main method in one class example
Category: Core
Instance Main method example
In this post under Java language, I will introduce you to new feature added to Java called “Instance Main Method”. This feature was added in Java version 25. Pre Java 25, if we have to write class with “main” method, we used to mark it as public and static as shown below. You also need…… Continue reading Instance Main method example
Custom Compact constructor in Record
In this post under Java Record, I will explain with example what is custom compact constructor, what is the use and how to add them in Record. In the previous post under Java Record, I showed what is canonical constructor, what is custom canonical constructor and what is the purpose of it. Below are the…… Continue reading Custom Compact constructor in Record
Text Block With Indentation
In this post under Java Core, I will show you with example how indentation is calculated in Text Block. Below is the main class with three variety of text block. Example3 package core.string; public class Example3 { public static void main(String[] args) { String textBlock1 = """ <html> <head> <title>TextBlock1<title> </head> <body>Body of TextBlock1</body> </html>…… Continue reading Text Block With Indentation
Text Block simple example
In this post under Java Core, I will introduce you to newly added “Text Block” feature. This feature was added as part of Java 15. Pre Java 15, if we have to declare a multiline string we used to declare it as shown below String result = "Since Java 15, text blocks are \n" +…… Continue reading Text Block simple example
Using Comparable with multiple fields
In this post under Java Collections, I will show an example of how to use Comparable interface when we need to sort collections on multiple fields For our example, we will sort a collections of employee objects. I need to sort the collections of employee objects in ascending order first using there name and then…… Continue reading Using Comparable with multiple fields
Pattern matching with instanceof
Hi all, in this post under Java pattern matching section, I will introduce you to pattern matching and how to use it with instanceof operator. Please don’t confuse java pattern matching with regex pattern matching Regex pattern matching checks whether a given text matches a text pattern and may optionally extract parts of the text.…… Continue reading Pattern matching with instanceof
List Fill demo
In this post under Java Collections, I will explain with example the purpose of “fill” static method in “Collections” utility class. This method takes any list as input and replace all the elements of the list with user given object. So if we have a list named “entries” containing below elements [1, 2, 3, 4,…… Continue reading List Fill demo
List nCopies demo
In this post under Java Collections, I will explain with example the purpose of “nCopies” static method in “Collections” utility class This method creates a list containing n copies of input object. Where n and input object are user specified. So basically this method takes two arguments.1) The object to be replicated in the list2)…… Continue reading List nCopies demo
List rotation demo
In this post under Java Collections, I will explain with example how to rotate elements in a list. Java “Collections” utility class has static method named “rotate” which will rotate elements in a list. This method takes two arguments.1) the list2) integer representing the distance Below is the complete main class for your reference Main…… Continue reading List rotation demo