Writing key values from Java to Consul

How to write key values to Consul In the first example we are going to use the HTTP API directly, in the second one we are going to use the Java Consul API ecwid. On Github you’ll find all the examples. So, let’s start. HTTP APIIn this example we store the value „buon giorno“ with …

Discover updates or vulnerabilities

Keep your dependencies up-to-date with gradle This is an import task, e.g. nearly every 6 months major releases of frameworks are available or new vulnerabilities are found on a daily basis. I’ll show you two gradle plugins which helps you that your software project won’t be left behind. The first one is gradle-version-plugin. This plugin …

Never write in Java a getter or equals method again

The lombok project helps you to be more productive Lombok is a great tool. Your code often gets verbose for common tasks. So what does lombok? The framework is plugged into the build process. It autogenerates bytecode into your class fields through a couple of annotations. Here comes the build.gradle: So let’s have a look …

Workaround – No tests found with Testrunner JUnit 5

Java 8, Eclipse, JUnit 5 & Gradle It seems to be a bug in Eclipse and it’is fixed in the Oxgen Release 3 (4.7.3). But I still have the problem in my Java 8 project. So I did a little trick. I changed the version for the engine and the launcher back to 5.1.0. [code] …

Calculate memory usage of Java objects

With Twitter’s ObjectSizeCalculator If you are looking for an easy way to estimate the object size than this could interest you. [code] // gradle dependency // https://mvnrepository.com/artifact/com.twitter.common/objectsize  compile group: ‚com.twitter.common‘, name: ‚objectsize‘, version: ‚0.0.12‘ System.out.println( ObjectSizeCalculator.getObjectSize(myObject) ); [/code] The memory size of your object depends on the architecture, the actual vm implementation and whether the …

Embedded Jetty with Servlet and Annotations

How do I programmatically configure Jetty that I can use Servlet Annotations? If you doing just servlets with jetty, this article could be interesting for you. I show you how I did it. Here comes the configuration: [code] … server = new Server(port); server.addBean(LOG); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); String webxmlLocation = JettyServer.class.getResource("/webapp/WEB-INF/web.xml").toString(); webAppContext.setDescriptor(webxmlLocation); …

Unit Testing Servlets with Mockito

A quick example how to write unit tests for servlets Okay, I’m writing a Servlet. So I want to write a unit test too. With Mockito this is a quite simple task. Here I show you a simple unit test for a Hello World Servlet. The Servlet returns only „Hello World“. [code] public class HelloWorldServletTest …

Reading YAML configurations in Java

How can I use YAML for my Java application? YAML is human-readable and a cool datat interchange format. It’s lean appearance make it special e.g. for configuration files or when humans view or edit data structures. It’s well suited for hierachical data presentation and you can easily map common data structures. Jackson and SnakeYaml Here I …

Initializing HashMaps in Java

How can I initialize a HashMap with some pre-defined entries? In this article I’ll show you how you create a HashMap with values. Java doesn’t provide a method like Array.asList(). For initializing a map you have to implement something like that: [code] //Old fashion way Map<Integer, String> oldFashion = new HashMap<Integer, String>() {{ put(1, "one"); put(2, "two"); }}; …

Lambda Expressions

Lambda Expressions sind cool. Das Feature bietet eine Vielzahl von Vorteilen. Meiner Meinung sind Lambda Expression eine tolle Sache, da das Feature – die Verwendung von Single Abstract Method-Interfaces vereinfacht – mittels Functional Interfaces Logik implementieren kann ohne das zusätzlich eine Klasse geschrieben werden muss – und mit neuen der Stream API eine bessere Verteilung und …

Consent Management Platform von Real Cookie Banner