Implementing CRUD Operations with MyBatis XML Mappers
Implementing data persistence logic requires a clear mapping between Java objects and database tables. The following demonstration outlines the configuration and execution of Create, Read, Update, and Delete (CRUD) operations using MyBatis.
Entity Class Definition
First, define a Plain Old Java Object (POJO) to represent the data structure. T ...
Posted on Fri, 18 Sep 2026 16:28:18 +0000 by sungpeng
Implementing House Construction Using the Builder Pattern
The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to generate different representations. This is particular useful when an object requires multiple components built in a specific sequence, and each component may have varying complexity. The pattern enables clients ...
Posted on Fri, 18 Sep 2026 16:24:06 +0000 by Flying Sagittarius
Grouping Anagrams Using Sorted Strings as HashMap Keys
---------------🎈🎈 LeetCode Problem 49: Group Anagrams 🎈🎈-------------------
In Java, arrays cannot be used directly as keys in a HashMap because their hashCode() method does not reflect the actual content. It is therefore recommended to use immutable objects such as strings as keys.
Approach 1: Use a Sorted String as the Key
⭐️ Since two ...
Posted on Fri, 18 Sep 2026 16:20:45 +0000 by ckwall
Sorting and Comparing Java Collections: A Deep Dive into Comparator and Comparable
The Comparable Interface
Comparable is a core Java interface used to define the natural ordering of objects of a custom class. Any class that implements this interface must override the compareTo() method, which encodes the comparison logic between the current object and another instance of the same class.
Usage Example
Classes that implement C ...
Posted on Fri, 18 Sep 2026 16:19:10 +0000 by manamino
Java Lock Mechanisms: Usage Scenarios and Implementation Examples
Java Lock Mechanisms: Usage Scenarios and Implementation Examples
Understanding Locks in Java
In Java, locks are synchronization mechanisms primarily used to control resource access in multi-threaded environments, ensuring data consistency and thread safety. The main functions of locks include:
Exclusive Access - Locks prevent multiple threads ...
Posted on Fri, 18 Sep 2026 16:18:10 +0000 by loveccb
Exception Handling and Error Management in Java
When executing a method that may encounter issues during runtime, we need proper exception handling mechanisms. Exceptions halt program execution, so we must use try-catch blocks to handle these scenarios gracefully.
Here's an example demonstrating basic exception handling:
public static void main(String[] args) {
try {
new Divisio ...
Posted on Fri, 18 Sep 2026 16:18:29 +0000 by KyleVA
LeetCode - Partition Equal Subset Sum
Given a non-empty array nums containing only positive integers, determine whether the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Example 1:
<strong>Input:</strong> nums = [1,5,11,5]
<strong>Output:</strong> true
<strong>Explanation:</strong> The array can ...
Posted on Fri, 18 Sep 2026 16:15:47 +0000 by verycleanteeth
Installing Java Development Kit on Ubuntu 18.04
Start by downloading the Oracle JDK 8 archive (jdk-8u301-linux-x64.tar.gz) from the official website. Since Oracle requires authantication, the file is typically fetched on a local machine and transferred to the server via SCP or SFTP.
Log into the Ubuntu 18.04 server and place the archive in a temporary location, for example ~/downloads:
mkdir ...
Posted on Fri, 18 Sep 2026 16:06:45 +0000 by MastahUK
Core Data Structures and Algorithmic Patterns for Engineering Interviews
Design Patterns: Singleton Instantiation
Eager initialization constructs the instance during class loading. Lazy evaluation defers creation until explicit retrieval, requiring synchronization to prevent race conditions in concurrent environments.
class EagerSingleton {
private EagerSingleton() {}
private static final EagerSingleton INST ...
Posted on Thu, 17 Sep 2026 16:36:14 +0000 by LikPan
Solving the Generalized N-Sum Problem
Problem Statement
For an input array and target value, return all distinct n-element tuples where the sum equals the target. The solution must avoid duplicate combinations in the result.
Example:
Input: [1, 0, -1, 0, -2, 2], target = 0, n = 4
Output: [[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]]
Generalized Solution
The approach uses recurs ...
Posted on Thu, 17 Sep 2026 16:36:34 +0000 by Pinkmischief