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

A Java FIFO queue class

In my spare time lately I’ve been writing this Android football game, and for the game I needed a simple FIFO queue. I haven’t used Java much lately, and after a quick Google search showed things that were more complicated than what I had in mind, I wrote my own FIFO queue.

A Java tuple class

After working with Scala for a long time, I had to come back to Java for a while to work on an Android app. Right away I missed a lot of things from the Scala world, including all of the built-in Scala collection methods, and other things as simple as the Scala Tuple classes.

If you haven’t used them before, a Scala Tuple class lets you write code like this:

A Java method to determine if an integer is between a range

Last night I was writing some code for my Android football game, and decided it would be best if I had a between method, so I could write some code like this to show that I wanted to test to see if a number was between an integer range:

if (between(distance, 8, 10)) { ...

That could would be interpreted as, “If the distance is between the values 8 and 10, do whatever is in the code block.” (I can make that code more readable in Scala, but in Java I think that’s the best I can do.)

How do I round a float or double to an integer in Java?

Java math FAQ: How do I round a float or double to an integer in Java?

Solution: Use Math.round() to round a float (or double) to the nearest integer (int) in Java.

You can see how this works in the examples that follow, where the result is shown in the comment after each line:

A custom JavaFX web browser (to show stock quotes)

I’m currently doing something completely different, and writing a little custom web browser using JavaFX and its WebView component. I’m using it so I can easily look at stock quotes and charts. I just started on it, and the current UI looks like this:

A custom JavaFX WebView web browser