Home » Java » Core Java

Core Java

Call That An Exception?

While this is a Java example to do with testing and wiremock, it relates to a more universal problem. We were trying to retry Wiremock’s verify method, which may be called by our test before the endpoint we’re checking is hit. In that situation, we’d want to try again a few seconds later in a loop until timing out. Interesting, ...

Read More »

Mythematical Codey Code

Consider the following snippet: int max = 10; int a = 0; while (true) { // do a thing that may result in an early return if (++a >= max) { break; } } throw new RuntimeException("It ran out of attempts"); There are a few WTFs in the above. The loop’s a bit weird, the flow of control seems to ...

Read More »

ZeptoN is Putting Program into Java

1. Introduction The Java programming language or “Java” was introduced in 1995. Yet in the almost quarter-century it has added features not originally in the core language. Such features include enumerations, generics, many enhancements to the basic C-style functional switch statement, assertions, etcetera. Java is a programming language that has evolved over time to meet the needs of Java software ...

Read More »

Explode a WAR File Recursively

Abstract Ever need to explode a WAR file as well as exploding all JAR files in the WAR file? Ya, me too! I wrote ferris-war-exploder to explode either: A JAR fileA WAR file which every JAR file it finds also exploded.An EAR file with every JAR file (see #1) and WAR file (see #2) also exploded. Basically, ferris-war-exploder explodes anything ...

Read More »

Proving There’s No Exception

How do you prove the existence of nothingness? Should you? In some tests I’ve written, especially around either validation, or around creating an empty object, what I really want to write is something like: 1 2 assertThat( ... call some code ... )    .doesntThrow(); You could reasonably write something like this. It would be the obverse of the assertThatThisThrowsException type ...

Read More »

Discovering the Magic Version Number of .class Files

Abstract What version of Java was used to create your .class files? For your own projects, this is easy to figure out because you choose your Java version when you compile. For the hundreds or thousands of dependencies in your project, this question is not so easy to answer. Inside every .class file is a magic number with a byte ...

Read More »

The Remainder Operator Works on Doubles in Java

I’ve been teaching at OSU for nearly two years, and it always astounds me how much I learn from my students. For instance, in the past, I’ve had students write strange pieces of code that I didn’t understand. At this point, even after 300+ blog posts, several YouTube videos, and even collecting code snippets from over 100 languages, you’d think ...

Read More »