recent posts related to java, jdbc, spring, etc.

Example: How to use javapackager to build a MacOS application bundle

Table of Contents1 - Building a MacOS application bundle with javapackager2 - The longer story3 - The Mac/Java class4 - The three scripts5 - javapackager notes

I recently learned how to use the Java javapackager command to build a macOS application bundle — i.e., a regular macOS application — from a Java application. In this tutorial I’ll show how to create a Mac application bundle from a simple Java class, in this case a Java Swing class.

A ‘printf’ format reference page (cheat sheet)

Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my own purposes, and then thought I would share it here.

A cool thing about the printf formatting syntax is that the specifiers you can use are very similar, if not identical, between several different languages, including C, C++, Java, Perl, Ruby, and others, so your knowledge is reusable, which is a good thing.

How to build a macOS application from a Java Jar file

Table of Contents1 - Background2 - Requirements3 - Building your application4 - Note 1: Font smoothing5 - Note 2: Setting the “application category”6 - The Mac/Java AppBundler7 - More information8 - Summary

In this article I’ll show how to build a macOS application from a Java Jar file. I tested this with Java 1.8 on macOS 10.12.5 (Sierra) on June 29, 2017.

Three assumptions in this process are:

The rationale for Optional (in Java) alvin March 23, 2017 - 12:57pm

Wesley Reisz shared this nice image titled, “The Rationale for Optional” (in Java). Optional in Java is similar to Option in Scala.

How to search multiple jar files for a string or pattern (shell script)

Here’s a Unix shell script that I use to search Java JAR files for any type of pattern. You can use it to search for the name of a class, the name of a package, or any other string/pattern that will show up if you manually ran jar tvf on each jar file. The advantage of this script — if you’re a Unix, Linux, or Cygwin user — is that it will search through all jar files in the current directory:

How to write a Java method that returns a generic type (syntax) alvin February 7, 2017 - 2:45pm

As a quick note, if you need some examples of the syntax of how to write a Java method that returns a generic type, I hope these are helpful:

A Java method to round a float value to the nearest one-half value

As a quick note, here’s a Java method that will round a float to the nearest half value, such as 1.0, 1.5, 2.0, 2.5, etc.:

 * converts as follows:
 * 1.1  -> 1.0
 * 1.3  -> 1.5
 * 2.1  -> 2.0
 * 2.25 -> 2.5
public static float roundToHalf(float f) {
    return Math.round(f * 2) / 2.0f;

The comments show how this function converts the example float values to their nearest half value, so I won’t add any more comments here.