Page cover

Java Utility Package (Open Source)

A high-performance and user-friendly toolkit tailored for developing small to medium-sized back-end applications

Includes classes for Logging, PBKDF2, JDBC, SMTP, HTTP, FIFO/LIFO Queues, Threads, Files and Utilities

Free Download

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).

  • FIFO / LIFO Queues Simple to use, thread-safe and named queues with first-in-first-out and last-in-first-out modes.

  • Command Argument Parser A simple command line argument parser to define, parse and retrieve command options and arguments.

  • 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.

Logging Example

Code / Debug Output
try {
   int result = 10 / 0;
   } catch (Exception e) {
      KLog.error("Unexpected error occured", e);
   }
}
2025-09-03T16:48:28.946 D main[1]:ch.k43.util.KLog:<clinit>:199                        ===== Application started 2025-09-03T16:48:28.904 =====
2025-09-03T16:48:28.947 D main[1]:ch.k43.util.KLog:<clinit>:200                        Java Utility Package (Open Source/Freeware) Version 2025.09.02
2025-09-03T16:48:28.947 D main[1]:ch.k43.util.KLog:<clinit>:201                        Homepage java-util.k43.ch - Please send any feedback to [email protected]
2025-09-03T16:48:28.947 D main[1]:ch.k43.util.KLog:<clinit>:204                        KLog properties read from file KLog.properties
2025-09-03T16:48:28.969 D main[1]:ch.k43.util.KLog:<clinit>:220                        Network host abmacbookpro (10.0.0.104)
2025-09-03T16:48:28.969 D main[1]:ch.k43.util.KLog:<clinit>:224                        OS platform Mac OS X Version 26.0/aarch64
2025-09-03T16:48:28.972 D main[1]:ch.k43.util.KLog:<clinit>:229                        OS disk space total 3.63 TiB, free 2.28 TiB, usable 2.28 TiB
2025-09-03T16:48:28.973 D main[1]:ch.k43.util.KLog:<clinit>:235                        Java version 23 (Java HotSpot(TM) 64-Bit Server VM - Oracle Corporation)
2025-09-03T16:48:28.973 D main[1]:ch.k43.util.KLog:<clinit>:240                        Java directory /Library/Java/JavaVirtualMachines/graalvm-jdk-23.0.1+11.1/Contents/Home
2025-09-03T16:48:28.973 D main[1]:ch.k43.util.KLog:<clinit>:245                        Java CPUs 10, de/CH, UTF-8, UTC +02:00 (Europe/Zurich)
2025-09-03T16:48:28.973 D main[1]:ch.k43.util.KLog:<clinit>:255                        Java heap maximum 16.00 GiB, current 1.01 GiB, used 9.94 MiB, free 1022.06 MiB
2025-09-03T16:48:28.973 D main[1]:ch.k43.util.KLog:<clinit>:262                        Java classpath ../bin/:../lib/angus-mail-2.0.3.jar:../lib/jakarta.mail-api-2.1.3.jar:../lib/org.json.20230618.jar:../lib/h2-2.2.224.jar:../lib/jakarta.activation-api-2.1.3.jar:../lib/angus-activation-2.0.2.jar
2025-09-03T16:48:28.974 D main[1]:ch.k43.util.KLog:<clinit>:266                        Current user andybrunner, language de, home directory /Users/andybrunner/
2025-09-03T16:48:28.974 D main[1]:ch.k43.util.KLog:<clinit>:272                        Current directory /Users/andybrunner/Documents/Eclipse-Workspace/Java-Utility-Package/src/
2025-09-03T16:48:28.974 D main[1]:ch.k43.util.KLog:<clinit>:276                        Temporary directory /var/folders/9s/tbyqn_vn7bs9rf3f1rc2jpxw0000gn/T/
2025-09-03T16:48:28.974 D main[1]:ch.k43.util.K:getLocalData:1598                      Local data for thread main created
2025-09-03T16:48:28.974 D main[1]:ch.k43.util.K:saveError:2535                         Error message saved: Unexpected error occured
2025-09-03T16:48:28.974 E main[1]:Test:main:13                                         ===> Unexpected error occured
2025-09-03T16:48:28.975 E main[1]:Test:main:13                                         ===> Java Exception: java.lang.ArithmeticException: / by zero
2025-09-03T16:48:28.975 E main[1]:Test:main:13                                         ===> Stack Trace[1]: Test.main(Test.java:11)

HTTP Example

Code / Output
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());
      }
   }
}
{"success":"true"}

JDBC Example

Code / Output
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());
      }
   }
}
{
  "ADDRESSES": [
    {
      "SEQUENCE": 1,
      "LASTNAME": "Smith",
      "FIRSTNAME": "Joe"
    },
    {
      "SEQUENCE": 2,
      "LASTNAME": "Miller",
      "FIRSTNAME": "Bob"
    },
    {
      "SEQUENCE": 3,
      "LASTNAME": "Johnson",
      "FIRSTNAME": "Evelyn"
    }
  ]
}

Prerequisites

The Java Utility Package does not require additional libraries with the exception of these classes:

Class
Library

KSMTPMailer, KLogSMTPHandler

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

See the section Tips / FAQ on how to create a native binary executable with GraalVM.

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