Posts Tagged: "Java"

Is it true a Sorted array process faster than an unsorted array?

Processing a sorted array is often faster than an unsorted array because sorted arrays enable more efficient algorithms and optimizations. For example, operations like searching, range queries, and duplicate removal can take advantage of the order in the sorted data. Unsorted Array Approach (Brute Force) For an unsorted array, the brute force approach would be […]

var in Java 11 bypass the protected access restriction

The behavior of var in Java, introduced in Java 10, does not bypass the protected access restriction in any special way. Instead, the misunderstanding often arises from how var is interpreted and its interactions with visibility rules in Java. Let’s break it down: How var Works The Protected Access Modifier Misinterpretation of var and protected […]

Differences between Checked and Unchecked Exceptions at Runtime?

In Java, exceptions are categorized into Checked and Unchecked exceptions. While they differ primarily at compile-time, there are also runtime considerations. Here’s an explanation with examples: 1. Checked Exceptions Definition: Runtime Behavior: Example: import java.io.FileReader;import java.io.IOException;public class CheckedExample { public static void main(String[] args) { try { FileReader file = new FileReader("nonexistentfile.txt"); // Throws FileNotFoundException […]

How to do a RegEx match open tags except XHTML self-contained tags

To match open HTML tags but exclude self-closing XHTML tags using Regular Expressions (RegEx), you can use the following pattern: RegEx Pattern <([a-zA-Z][a-zA-Z0-9]*)(?![^>]*\/>)> Explanation of the Pattern Example HTML Snippet <div> <img src="image.jpg" /> <input type="text" /> <span>Text</span> <br /> <p>Paragraph</p></div> Matches Using the RegEx <([a-zA-Z][a-zA-Z0-9]*)(?![^>]*\/>)>: Code Example JavaScript Example const html = `<div> <img […]