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 […]

Binary Search in Java

This is a Java implementation of the Binary Search in Python I did earlier. Refreshing my Java 🙂 And the example client code: This outputs: There are several other options available in the JDK Arrays and Collections classes: For a more detailed explanation of binary search, please see my earlier post.

Java Long versus long in Spring Boot

Recently I’ve had to jump onboard a Java Spring Boot project. Not having used Java for a long time, I was surprised that my code was throwing null pointer exceptions (NPEs). In C#, I rarely encountered an NPE. Indeed, I thought the new compiler work on null-reference types was a waste of focus. The only […]