Tales from the jar side: Generating robot images with Java, Useful Spring videos, Craig Ferguson is funny, Google is evil, Elon is awful, and the usual toots and skeets are what they are
Been injured by water droplets in clouds? You may be entitled to condensation. (rimshot)
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of September 3 - 10, 2023. This week I taught week 1 of my Spring in 3 Weeks course and my two-day Getting Started with Spring and Spring Boot course, both on the O’Reilly Learning Platform.
[Note to jarhead Bill Fly: See? I got the dates right again! That’s two in a row!]
Regular readers of (and listeners to, and now video viewers of) this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader (or listener, or viewer). If you wish to become a jarhead, please subscribe using this button:
As a reminder, when this message is truncated in email, click on the title to open it in a browser tab formatted properly for both the web and mobile.
Generating Images with Java
In last week’s newsletter, I talked about how I wrote the code to connect Java to the Dall-E image generator inside the OpenAI API. I promised I would make the corresponding video this week, and, lo and behold, I actually finished it:
That robot on the thumbnail was one of the ones I generated. If you check out the GitHub repository containing the code, you’ll find that the prompt I used was:
The code uses Java’s HttpClient
API to transmit JSON data to the service, serialized using Google’s Gson parser, and then processes the returned image. What made it interesting this time is that instead of returning a URL for the generated images, I asked for the other response type in the body, which was 64-bit binary encoded JSON strings. With a bit of help from the AI Assistant tool inside IntelliJ IDEA, I was able to decode the images into byte arrays and save them into local png files in the src/main/resources
folder.
That turned out much easier than I expected, and it’s code that would have taken me a lot of searching to figure out before these AI tools came along. I haven’t used the java.nio
packages very much, and I certainly haven’t used the java.util.Base64
class. This is just one more example of how tools like Github Copilot and the AI Assistant have changed my programming abilities enormously. They are especially good at reminding me about API’s I don’t know well or don’t remember.
In fact, since I’d already used JavaFX in a different part of this project, I asked the AI Assistant to help me write a JavaFX Image Carousel that displayed all the downloaded images, rotating to the next one after three-second intervals. That’s shown in the video, but that also seemed perfect for a YouTube short, so I extracted it to Descript and spent a couple hours fixing it up. Here’s the result:
Feel free to take a look — the short is less than 30 seconds long, so it’s not asking for too much of your time. I added some music in the background, along with the captions, to make it a bit more entertaining.
It doesn’t have a ton of views yet, but something highly notable happened with the first 20 or so. Check out the data in this image, from my YouTube Studio app:
See the boxed value? The average percentage viewed is how much of the video an average viewer watched. For my regular videos, a typical value for that number ranges between 20% to 40%, meaning most people don’t even watch half (I’m trying to improve that, of course). Shorts are only 60 second long or less, so the percentages are generally a lot higher. I’ve exceeded 100% a couple of times, meaning that some people watch it roll around and start playing again.
A value like 267% means that the average viewer is watching this video nearly three times in a row, probably to look at the robot pictures. Lol. That number will drop, of course, and of all my Shorts this is by far the shortest, but still, that was fun.
Also, YouTube changed Shorts so that now you can add a link at the bottom of the short to a related long-form video, which I did. I’ll have to see if that helps the number of views on the longer, code-related video. We’ll see.
(Stats as of publication time: 34 views, 185% APV)
Useful Spring Videos
Introducing Spring AI
As long as we’re discussing videos, I need to mention a couple I watched this week that have been very helpful to me.
The video I published this week, which I talked about in the previous section, is about integrating the OpenAI APIs into Java. As it happens, the Spring people have been thinking the same thing. That’s both gratifying, since it means I was on the right track and taking a reasonable approach, and frustrating, because the bulk of the public attention will go to them. Of course, that’s probably as it should be.
I’m not going to stop my series of videos, however, for a few reasons:
I kind of like the approach I’m taking.
I don’t require anybody to use Spring, though some of my videos will do so.
Even though I’m only one developer and they have a whole team, I’ll probably be able to publish more quickly than they will. I expect they have an entire approval process to go through, and they’re trying to create a complete solution, while I’m only interested in a few small use cases.
At any rate, at the recent SpringOne conference as part of VMware Explore, they announced a very early project called Spring AI. Here’s a link to the reference guide. If you look, you’ll see the current version is 0.2.0-SNAPSHOT, which is really, really early. I mean, that’s an alpha version — not even beta, much less some milestone or early release.
That early a version did not keep my friend and fellow NFJS speaker Craig Walls from making a new YouTube video about it. Here is his video, called Introducing Spring AI:
What jumps out at me from the video is that Spring AI does a few things I haven’t been working on, like:
It provides prompt templates as formatted ways to make requests.
It does a lot more work with output processing than I do (which they call output parsing, but you always parse the output so I’m not sure what they mean there).
They’re planning to do call chaining. I am as well, and have done some of that, but I’ll be interested in seeing how they do it. That part isn’t available yet.
They have several data loaders planned, including what’s called embeddings, which presumably will let you customize the AI to use your own data.
Craig does his usual good job going through the basics. If you’re interested in the area, I recommend checking out his video. I’m planning a similar one myself, hopefully this week, but I’ll be using Spring directly rather than incorporating the Spring AI project.
The new RestClient class
Meanwhile, my friend Dan Vega released a video this week on a new API that’s coming with Spring Boot 3.2, due to be released in November. Since Spring Boot 3 came out, we’ve had three ways to access RESTful web services:
The legacy
RestTemplate
, which I used for years and is currently in maintenance mode, meaning no new changes are planned for it,The new
WebClient
, which is reactive and provides a modern, fluent way of accessing web services (with even more buzzwords involved), andThe newer Http Exchange Interfaces, which allow you to define a simple WebClient bean and an interface, and Spring generates all the required code to make it work.
I have a video on that last one, called CSI (Code Scene Investigations): Dan Vega Uncovers Spring Boot 3.0’s Http Interfaces. Yeah, that’s a terrible name, which didn’t really work even when I released it. I’m probably going to have to update both the title and the thumbnail on that one.
At any rate, Dan is back with a new video, called A First Look at the New RestClient In Spring Boot 3.2:
The new RestClient
class has the look and feel of the WebClient
, but is synchronous like the RestTemplate
. It’s probably going to replace the RestTemplate
eventually. Dan puts it through its paces, which is quite helpful. He also uses the Http Interfaces, which have been expanded to work with the RestClient
as well. I’m now pretty eager for Spring Boot 3.2 to be released so I can use both on a regular basis.
I should mention that while watching Dan’s video, I decided to catch up on another one of his videos, which was about reading YAML data using the Jackson parser in Spring Boot, which I didn’t know you could do. I doubt I’ll use that much, but I still learned a lot about configuring apps that I didn’t know before.
CraigyFerg
On Friday evening, as an early anniversary present, my wife presented me with tickets for us to go see Craig Ferguson that night at the Mohegan Sun. If you don’t know him, Craig is a Scottish-American comedian was the host of the Late Late Show (which came on after Letterman) from 2005 - 2014. Younger people might recognize him as the voice of Gobber in How to Train Your Dragon.
He’s still touring, as his post on Xitter shows (he’s @CraigyFerg there):
The fact he’s there is one of the few remaining reasons to check out Xitter on occasion.
(And yeah, I’m going to call X/Twitter that. Seems appropriate somehow, especially if you go with the English pronunciation of the Chinese name “Xi”.)
My wife and I have always thought Craig was awesome. I think this was the third time we’ve seen him. The first was at Carnegie hall in New York, and the last two were here at the Mohegan Sun, which is about a 45 minute drive for us. He was excellent, but keep in mind he and I are almost exactly the same age, so I get his references.
Toots and Skeets
Elon, yet again?
[Editor: No. Don’t not going there. Don’t do it.]
First, he picked an anti-semitic fight with the Anti-Defamation League, magnifying Nazi propaganda:
[Editor: NO. Stop! Just because he’s a vile, malignant narcissist and a troll doesn’t mean you have to waste space in this newsletter about him.]
Then it came out that he cut off the Starlink satellite system in Ukraine, preventing an attack on the Russian Navy. That’s both military interference in direct opposition to one of our allies and enabling them to continue to bomb civilians, including children—
[Editor: Come ON. STOP IT.]
Fine. I’ll just settle for this image:
[Editor: Ugh. BUT THAT’S ENOUGH, OKAY?]
Fine. Except for this comment:
[Editor: (Weeps uncontrollably)]
To think three years ago we all thought he was Tony freakin’ Stark. We were so, so wrong. Let’s move on.
Google Is Evil
Remember how Google’s original company motto was “Don’t be evil?”
Yeah, me neither. Here’s a direct link to that article. Feel free to read it, but before you do:
Go into your Chrome Settings
Select Privacy and Security
Click on Ad privacy
Click on each of the three topics on that page and toggle them off.
In addition to the basic evil of tracking every site you visit, the real evil here is that the latest Chrome update opts you into to all them by default. Even worse, the text tries to make it sound like this is a privacy improvement, which is just flat out lying.
Of course, you could also switch to Firefox. Unfortunately, some of my job-related sites require Chrome, so I’m kind of stuck most of the time.
Some Perspective
And now for something completely different:
Maybe it really was Adam and Steve all along.
Good analogy
Fun with names
Robert Fettuccine. That explains so much.
In case of …
No Hanson brother is an island
You could make the argument
I think Kolinahr is overrated. I’d settle for more jamaharon.
Monkees / Smash Mouth reference
To the tune of I’m a Believer:
I asked GPT-4 to finish the song. Here’s what it came up with:
I thought plums were only meant as breakfast food
Meant for someone else but not for me
Plums were out to get me
That's the way it seemed
Delicious stonefruit haunted all my dreams
Then I saw her fridge, now I'm a plum thiever
Not a trace of guilt in my mind
I'm in love, oh I'm a plum thiever
Couldn't leave 'em if I tried
I thought plums were more or less a healthy snack
Seems the more I ate the less I had
What's the use in buying?
All you get is gone
When I needed plums I got none
Then I saw her fridge, now I'm a plum thiever
Not a trace of guilt in my mind
I'm in love, oh I'm a plum thiever
Couldn't leave 'em if I tried
Plums were out to get me
That's the way it seemed
Delicious stonefruit haunted all my dreams
Oh then I saw her fridge, now I'm a plum thiever
Not a trace of guilt in my mind
I'm in love, oh I'm a plum thiever
Couldn't leave 'em if I tried
I told GPT-4 not to give up its day job.
Have a great week, everybody!
The video version of this newsletter will be on the Tales from the jar side YouTube channel tomorrow.
Last week:
Week 1 of my Spring in 3 Weeks course, on the O’Reilly Learning Platform
Getting Started with Spring and Spring Boot, ditto.
First day of my Software Design course at Trinity College, Hartford, which went fine, but hey, it’s only one day.
This week:
Week 2 of Spring in 3 Weeks, on the O’Reilly Learning Platform
Software Design, my course for undergrads at Trinity College