Skip to content

Java 8 stream short-circuit

Reading up a bit on Java 8, I got to this blog post explaining a bit about streams and reduction of them, and when it would be possible to short-circuit the reduction. At the bottom it states: Note in the case of findFirst or findAny we only need the first value which matches the predicate (although findAny i…

Speed of custom Java classes vs. Maps

Which is faster: a Set whose elements are each an instance of CustomObject as defined below: a Set whose elements are each an instance of Map<String, String> where each Map is of the format {“A” : Avalue, “B” : Bvalue, “C” : Cvalue}? or any other data structure that y…

How do I trigger the default signal handling behavior?

In my Java application I want to capture SIGINTs, do some pre-processing, and then let the default behavior (process termination) run. I would think I could do something like this: However when I send at SIGINT to this application, I get a SEGV: It seems SignalHandler.SIG_DFL is not meant to be called directl…

Why JAR Files Do Not Contain Documentation?

I’m in the process of writing a small Java library that contains a related code that I usually include in most of my android app. I decided to export the library as a jar file then drop the file in the libs folder of my future projects. Using Android Studio: I created a Java Library module and put my co…

How to send email with inline image using ThymeLeaf

I’m trying to send an email with an inline image using ThymeLeaf and Spring, but so far no success. The email sends, but the inline image won’t show in the email. The project is not web-based (not a website), but is a desktop stand-alone, not mobile This is how I get the image file: My service cla…

Integer parameters formula returns integer

Code below makes foo value as -1149239296 i. e. integer value which is out of bounds: Seems like Java takes type of first parameter and tryes to return formula’s result with that type. Where in Java specification one can read that story? I made such suggestion cause actually returns sets long value to f…

GridBagLayout gridwidth doesn’t work as expected

I’m working with the java swing LayoutManager GridBagLayout, and ran into this problem. I want a layout like this ACC BB But get a layout like this ACC B A and B take up the same number of columns despite B having a gridwidth of 2 where A’s gridwidth is 1. I don’t think there can be a vanish…

How you create confirmation link for email?

In my project I need to send letter to user email with confirmation link. My solution: Add string column “code” and boolean column “is_active” (with default value false) to user table. When user register, generate unique string key and save to database. Send to email link, for example …