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
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
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
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
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
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”
English summary: This article is in Norwegian and describes debugging of Java code in the Eclipse Java IDE.
Continue reading Debugging i eclipse
English summary: This article is in Norwegian and describes first startup of the eclipse Java IDE, and writing and running an “Hello World” application inside eclipse.
Continue reading Hello world! i eclipse