In this post under Java language, I will show with example how to assign null value to var variable. Assigning a null value to a non-var variable is simple as shown below String message = "Hello World"; . . . . message = null; But assigning null value to var variable is different. We need…… Continue reading Assigning null value to var variable
Category: Core
var variable value can change but not datatype
In this post under Java language, I will introduce you to one of the restrictions that apply to var variable. In the previous post under Java language, I introduce you guys to var variable (local variable type inference variable) and also covered some restrictions to remember when declaring var variable. But didn’t covered this restriction…… Continue reading var variable value can change but not datatype
Local Variable Type Inference (var) example
In this post under Java language, I will introduce you to Local Variable Type Inference (also called var variable) added in Java 10. Before java 10, any variable declared should be accompained with the data type as shown below int sum; float salary; String name; As shown in the above code, the “int” is the…… Continue reading Local Variable Type Inference (var) example
Accessing main class members using instance main method
In this post under Java Language, I will show with example how to access member variables and methods when using instance main method. But before showing the new approach lets recap the old approach. This will help in comparing old and new approach. Below is the example showing the old approach Old Approach package core.language;…… Continue reading Accessing main class members using instance main method
New changes to age old main method
In this post under Java, Language, I will introduce you to changes done to our age old main method as part of Java 25. Pre Java 25, if we have to write our main method, we used to mark it public make the return value of the method “void” mark it static provide String array…… Continue reading New changes to age old main method
Instance Main and Non-Instance Main method in one class example
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
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