java

Oracle doesn’t want Java EE any more alvin October 5, 2017 - 8:38am

In case you missed the news, after that drawn-out legal battle about Java and Android, Oracle doesn’t want Java EE any more, and it was adopted by the Eclipse Foundation.

Passing an anonymous function to SwingUtilities.invokeLater (in Scala) alvin October 3, 2017 - 5:47pm

As a quick note, if you ever need to call the invokeLater of the Java SwingUtilities class in Scala, you can pass it an anonymous function (lambda) like this:

SwingUtilities.invokeLater(() => {
    // your gui-updating code here, such as:
    for (c <- newsControllers) c.updateContent()
})

(I haven’t worked with Java 8 lambdas too much, but I assume that the Java syntax is similar to that.)

Caliper, a tool for running benchmark tests in Java alvin September 5, 2017 - 10:24am

Caliper is a tool for running benchmarks (micro benchmark tests) in Java.

Android: How to send a message from a Thread to a Handler

As a quick example of how to use a Thread with a basic Handler in an Android application, the following code creates a view where the text in the TextView is updated to show the current date and time when the Button is tapped.

Java source code

First, here’s the Java source code for a file class named ThreadHandlerActivity:

The Java 8 lambda Thread and Runnable syntax and examples alvin August 19, 2017 - 12:55pm

As a quick note, here are some examples of the Java 8 lambda Thread and Runnable syntax.

Java 8 Thread/Runnable lambda syntax

First, here’s the Java 8 lambda syntax for a Runnable, where I create a Runnable and pass it to a Thread:

A Mac/Java javapackager example (getting the application bundle root directory) alvin August 18, 2017 - 7:39pm

I wrote earlier about how to use the javapackager command to create a macOS application bundle from a Java application, so I won’t repeat all of that information here. Instead, in this article I just want to show how to display an image that’s stored in the Contents/Resources/Java directory of a Mac/Java application bundle.

Good javapackager video (macOS + Java) alvin August 16, 2017 - 9:47am

If you’re interested in packaging Java applications on macOS, this is a good `javapackager` video on YouTube.

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.

The Mac/Java/Ant AppBundler error, java.nio.file.NoSuchFileException: Info.plist alvin August 15, 2017 - 5:30pm

As I learned recently, the Mac/Java AppBundler tool is a little out of date these days, but you can still use it with Java 8 and MacOS 10.12 to build Mac/Java applications. One problem you can run into is getting this ugly Info.plist error: