
Java Utility Package (Open Source)
A high-performance and user-friendly toolkit tailored for developing small to medium-sized back-end applications
Follow the development at Mastodon #JavaUtil.
If you have any questions or feedback, feel free to contact me at [email protected]
Features
Advanced Logging Capabilities Simplify logging with an easy-to-use framework based on the standard Java Logger. Includes enhanced logging handlers (JDBC and SMTP) and versatile logging formatters (Tabular Text, CSV, XML, JSON, and YAML).
Password Vault Securely hash, store, and verify passwords using PBKDF2 with the PBKDF2WithHmacSHA512 algorithm.
Database Integration Seamlessly access any JDBC-compliant database and retrieve data in multiple formats, including JSON, YAML, CSV, XML, tabular, or raw Java objects.
Email Functionality Create and send MIME multipart SMTP messages with support for text, HTML content, and file attachments.
HTTP / Socket Support Create raw TCP/IP socket applications or HTTP server applications (for web or REST services).
Thread Management Leverage a convenient class for starting and terminating Java threads with ease.
File Operations Read and write files in various formats, including byte streams, character streams, Java Properties, and JSON data.
Utility Methods Access a large collection of static utility functions for common programming tasks.
GraalVM Support The generation of native executable code with GraalVM is supported by including the necessary reflection definitions in the distributed JAR file.
HTTP Example
import ch.k43.util.KHTTPClient;
import ch.k43.util.KLog;
public class HTTPGet {
public static void main(String[] args) {
KHTTPClient http = new KHTTPClient();
if (!http.get("https://reqbin.com/echo/get/json")) {
KLog.error("Error: {}", http.getLastError());
} else {
System.out.println(http.getResponseDataAsString());
}
}
}
JDBC Example
import ch.k43.util.KDB;
import ch.k43.util.KLog;
public class Database {
public static void main(String[] args) {
try (KDB db = new KDB(KDB.JDBC_H2, "jdbc:h2:mem:mydb", "", "")) {
KLog.abort(!db.isConnected(), "Error: {}", db.getErrorMessage());
db.exec("CREATE TABLE addresses (sequence INT AUTO_INCREMENT, lastname VARCHAR(20), firstname VARCHAR(20))");
db.prepare("INSERT INTO addresses (lastname, firstname) VALUES (?, ?)");
db.execPrepare("Smith", "Joe");
db.execPrepare("Miller", "Bob");
db.execPrepare("Johnson", "Evelyn");
db.exec("SELECT * FROM addresses");
System.out.println(db.getDataAsJSON());
}
}
}
Prerequisites
Java SE 1.8 (Java 8) or higher
The Java Utility Package does not require additional libraries with the exception of these classes:
Installation / Usage
Download the latest Java JAR file
Add import ch.k43.util.* statement in your Java code
Make sure that the file ch.k43.util.jar can be found at compile time and in the classpath at runtime
Test Installation
You may test the package by running the HelloWorld program, which is part of the distribution jar.
% java -jar ch.k43.util.jar
Java Utility Package (Freeware) Version 2025.02.19
Note: To enable logging, place a valid KLog.properties file in the current directory
JVM version 23 running on Mac OS X Version 15.3.1/aarch64
Motivation for this toolkit
In my professional life as an administrator and developer, I have benefited many times from countless freeware and open source products. It is therefore natural for me to also contribute to this community (see my other freeware projects).
This collection of Java classes was created in the course of various projects and will be further developed (see Design Goals). I hope that this tool will also serve you well.
Freeware / Open Source / Unlicensed
This software is freeware, open source and unlicensed. It was created with love and passion in the beautiful country of 🇨🇭 Switzerland. This software shall be used for Good not Evil. As far as I know, no animal was harmed in the making of this software 😊
Last updated