java

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.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

How to install Java, Scala, and SBT on Linux Mint alvin May 19, 2017 - 7:27pm

Lately I’ve been in the process of “making the switch” from macOS to Linux Mint, and to that end, I just installed the Java 8 JDK/SDK, Scala 2.12, and SBT 0.13 on a new Linux Mint system, and I want to note here how I did that while it’s still fresh in my mind. Here are my notes in a compact form.

Functional programming: Everything is immutable alvin May 6, 2017 - 12:38pm

“Remember how weird it seemed when you first learned that a String in Java was immutable? Well, in functional programming it’s all like that. Everything is immutable.”

(From a discussion with a Java developer recently.)

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 get cleaned HTML as a String from HTMLCleaner alvin March 11, 2017 - 2:35pm

If you ever need to get the “cleaned” HTML as a String from the Java HTMLCleaner project, I hope this example will help:

IntelliJ IDEA: Keystrokes I commonly use on MacOS (OS X) alvin March 6, 2017 - 6:26pm

As a quick note, this is a list of the IntelliJ IDEA keystrokes I use on my MacOS systems:

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

Here’s a Unix shell script that I use that 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:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Scalasti, a Scala interface to the StringTemplate Java template library alvin February 15, 2017 - 10:57am

I use the Java StringTemplate library in my Android applications, and Brian Clapper has created a Scala wrapper around it that he calls Scalasti. His intro: “Scalasti is a Scala interface to the StringTemplate Java template library. It provides a subset of the features of StringTemplate, using a more Scala-friendly syntax.”

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 alvin February 7, 2017 - 1:11pm

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.