Skip to main content

Posts

Java 25 Feature: Structured Task Scope

Recent posts

Java 25: Flexible Constructors

Java 25 Features Java 25 Example: FlexibleConstructors In Java 8 /*In java 8 the super constructor is needed to be the first call in child class constructor (if needed)*/ Super constructor gets first call in child constructor, this is not flexible-code, that means if super class is getting initialized even before initializing the child class, if child class initialization failed then super class constructor is created and will be useless. Copy public class FlexibleConstructors { public static void main(String[] args) { try { Cat cat = new Cat(true, "Russian Bob Cat"); System.out.println("Animal Details: " + cat.breed + "--" + cat.domestic); Cat lion = new Cat(false, "African Lion"); System.out.println("Animal Details: " + li...

Java 25 Feature: Flexible Code Compilation by Pran Sukh

Java 25 Features Java 25 Example: Primitive Pattern Matching Copy /* In java 25 you need explicit definition of class and main method, just for start it's easy to understand the execution. * But in real Object-Oriented applications you cannot go without classes and inheritance */ void main(){ int i = 3; char any = 'P'; oldWayOfUnBoxing(i); oldWayOfUnBoxing(any); checkObject(i); checkObject(any); } static void oldWayOfUnBoxing(Object obj) { if (obj instanceof Integer) { int i = ((Integer) obj).intValue(); // First obj is boxed to Integer then unboxed to int with .intValue of Integer class log("Primitive obj of type int is converted/unboxed to int with Integer class"); } if (obj instanceof Character) { char c = ((Character) obj).charValue(); // First ob...

Java 25 Sealed Classes and Interfaces

Sealed Classes and Interfaces in Java 25 | Complete Guide Mastering Sealed Classes and Interfaces in Java 25 With the release of Java 25 , developers now have more control over inheritance hierarchies through the use of sealed interfaces and sealed classes . This feature is a big step in strengthening object-oriented programming in Java. 🔍 What are Sealed Interfaces and Classes? Sealed types in Java allow developers to specify which classes or interfaces are allowed to extend or implement a given type. This enables controlled extension, useful in domain modeling , security, and compiler optimizations . 📌 Java 25 Code Example: Modeling a Cat Hierarchy 1. Sealed Interface: SIAnimal This sealed interface can only be implemented by the SCat class. 2. Sealed Abstract Class: SCat The abstract class SCat can only be extended by the listed subclasses: Lion , Tiger , BobCat , and Leapord . 3. Final Class: Lion ...

regex in python python hunter

Regular Expressions is a powerful concept if understood clearly you can save your valuable time to extract out the particular text from huge string or paragraph. It is wildly pronounced as regex, it can help you to automate the boring stuff, like searching particular text form log files, python used this same concept in web scrapping. Below are some common examples to understand the regex. Method names will help you to have an idea that what exactly the regex is intended to do. if you don't understand any regex or want to create your own regex with your requirements then you can comment below, i'll reach you ASAP. Thanks. import re def phoneNumberPattern (): print ( "*" * 10 ) print ( "phoneNumberPattern()" ) regexObj = re . compile( r'\d\d\d-\d\d\d-\d\d\d\d' ) mo = regexObj . search( 'Find my phone number from this string 998-805-4332' ) print (mo . group()) def grouping (): print ( "*...

Fallback tag in xslt by pran sukh on python hunter blog.

Fallback: As the name is self explanatory to use something as an alternative if the primary thing does not work well. In xslt the fallback tag works as an alternative tag if any given tag does not work or is not supported by xslt processor.  Note: This fallback will always work in not supported tags, so run time exception will not occur. Data.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="XSL.xsl"?> <records> <record> <name> Adam Barr </name> <address> 222 Cherry </address> <phone> 555-797-2355 </phone> </record> <record> <name> Jeff Adell </name> <address> 730 Elm </address> <phone> 555-797-5555 </phone> </record> </records> XSL.xsl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1...

Calling xslt template with param tag by pran sukh on Python Hunter

In XSLT we may need to use same template for different xml data tags, and also there might be a situation where we need to send some special instructions to template tag to act upon give condition or value and produce/process the xml data. Data.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?xml version='1.0'?> <?xml-stylesheet type="text/xsl" href="XSLT.xsl"?> <lists> <ol> <li> the </li> <li> cat </li> <ol> <li> sat </li> <li> on </li> <li> the </li> </ol> <li> mat </li> </ol> </lists> XSLT.xsl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <?xml version='1.0'?> <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" ...