var var

I just learnt today that var in Java is not actually a language keyword. It is actually a reserved magic type name. You can use it as a variable: Why anyone would ever do that, apart from freaking out the code reviewer, I don’t know 🙂

Suppressing PMD Warnings in Java and Kotlin

Recently I was working on a project which had both Java and Kotlin classes, and used the PMD Source Code Analyzer. Occasionally, it was necessary to suppress a PMD warning, for example when you have a long line because of a code template. Suppressing warnings is slightly different for each language, and can be easy […]

Dynamic Kafka Topics in Quarkus

This post describes sending Kafka events to dynamic topics in Quarkus. Previously I suggested using the KafkaProducer, but it is pretty much obsolete since Quarkus 2, and all metadata is ignored. I ended up with serialization issues. The solution is to use a standard Emitter and add metadata to the message. For example, this class […]

Simple Annotation Processor

I recently needed to develop an annotation processor in Kotlin, posting here for future reference. This is the class level annotation: And here is the declaration of the annotation processor: Followed by the usual overrides: These fields keep track of what has been processed: The process method: identifies types to process, and extracts configuration information. […]

Java Enhanced Switch

A switch statement allows the application to have multiple possible execution paths based on the value of a given expression in runtime. The evaluated expression is called the selector expression which must be of type char, byte, short, int, Character, Byte, Short, Integer, String, or an enum. In Java 14 a neat language feature was […]

Java Non-Denotable Types

You learn something new everyday as a programmer. Whilst reading a preview of The Well-Grounded Java Developer 2nd Edition (MEAP V02), I noticed something that looks like duck typing! This is referred to as a non-denotable type, it is inferred as the type of the expression that is assigned. In this case, the type is […]

Quick Sort in Java

This is a Java implementation of an earlier post named QuickSort in which I used Python. This version uses lists rather than arrays so it can be used to sort a list of any object that implements the Comparable interface. First the method which does the sorting: Followed by the main method: As per the […]

Selection Sort in Java

This is a Java implementation of a Selection Sort in Python from a previous post. I like the selection sort because it is simple, but it is not the most efficient. I’ll explore more in this post, and see how fast I can push this algorithm. Let’s begin by implementing what was done in Python […]

Pass by Reference or Value?

Pass by Value Java always passes arguments by value. It’s simple in the case of primitives, a copy of the value is assigned to the function argument: As expected, this outputs: The value of the x variable (5) is passed to the doSomething method and copied to an argument named a. This local argument is […]