Tag Archives: java

Java record withers what and when

This blog post is the result of searching the internet to find out what Java records with “withers” will look like and in what version of Java records with withers will arrive.

In addition, while trying to figure out Java withers, I discovered that reforming my current beans with builders into records with builders, I could throw away half the boiler plate code. Continue reading Java record withers what and when

Build beans better with builders

Builders provide a nice, if verbose, way to create immutable java beans.

The upsides are a nice syntax for creating immutable beans, and a way to provide copy-on-write behaviour for immutable objects.

The downsides are the need for verbose boilerplate code, approximately doubling the code size of the bean source files, and the overhead of one extra object created and then left for garbage collection, for each created bean.

Continue reading Build beans better with builders

Chaining Optionals using flatMap and map

The blog post How I learnt to like Optional shows an example of how to chain Optional values safely, using Optional.orElse() to provide empty objects for the next level in the chain.

This blog post uses Optional.flatMap() and Optional.map(), to achieve the same thing, without having to create the empty objects, and without doing any evaluation for empty objects.

Continue reading Chaining Optionals using flatMap and map

How I learnt to like Optional

I used to see Optional<Something> as a completely useless addition to Java, adding to the bloat of Java without being any clearer than checking if a reference is null.

I have changed my mind, and now think Optional<> can be useful in making code simpler, easier to understand, and more robust.

The reason I changed my mind, was the usefulness of Optional.orElseThrow() when having to traverse deeply nested data structures in Java code.

Continue reading How I learnt to like Optional

Installing apache karaf on debian

Until the RFP (Request For Packaging) bug for karaf in the debian bug tracker is resolved, here is an APT archive with a karaf package for debian (architecture “all”).  The package is created using native debian packaging tools, and built from a source tarball and the APT archive itself is created, using aptly.
Continue reading Installing apache karaf on debian

Packaging karaf with native debian packaging tools

Note! This is an improvement over the packaging in  Installing apache karaf on debian stretch, this package is packaged using native debian packaging tools instead of fpm, and is built from the karaf source tarball instead of the karaf binary tarball.

Apache karaf is an OSGi container and application server that is provisioned from maven, and has an ssh server. Basically it is possible to start an empty karaf, ssh in and give some commands to install an application using maven.

There still isn’t a native .deb package on maven (see  the RFP (Request For Packaging) bug for karaf in the debian bug tracker), but this package can be installed from my own maven repository.

The packacing projecct can be found on github: https://github.com/steinarb/karaf-debian
Continue reading Packaging karaf with native debian packaging tools

Installing apache karaf on debian stretch

Edit: It is now possible to install karaf on debian without building it yourself, the package installed is not the one described here, but the new and improved package built from source with native debian packaging tools, that can be found here  https://github.com/steinarb/karaf-debian
Continue reading Installing apache karaf on debian stretch

Making a Java windows service in 10 minutes

This blog post describes how to create a windows service from a Java application, it is a slightly more fleshed out version of the JavaZone 2016 lightning talk “A Java windows service in 10 minutes”.

A problem sometimes encountered by a Java programmer, is to make your Java program into a Windows Service. This is may be a bump in your project, particularly if you don’t know anything about windows services, or much about windows for that matter.

The demo created a running, working, Windows service server using 14 lines of Java code, and some maven configuration.
Continue reading Making a Java windows service in 10 minutes

Objektorientering i Java: “Monstersim”

English summary: This article is in Norwegian and presents a step-by-step receipe for creating a Java program that simulates a dragon and a troll in a cave. The purpose is to give an introduction to the Java programming language, object orientation, computer simulation, and the eclipse Java IDE’s support for aiding coding (in particular “Quick Fix”).

Denne artikkelen tar deg gjennom en steg-for-steg bruksanvisning for å lage et program som simulerer en drage og et troll i ei grotte. Artikkelen er ganske lang, men bør være rett fram å følge.

Continue reading Objektorientering i Java: “Monstersim”