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 …
Kategorie-Archiv: Java
How to specify Java Source and Target Compatibility in a Gradle multi project
I have a multiple project setup and I want to build top level projects using different JDKs. I did some experiments by myself and the following configuration worked for me (using gradle 3.1 and the wrapper function). At the root level my gradle.properties file looks like this: [code] org.gradle.daemon=true JDK7_HOME=/usr/lib/jvm/jdk-7-oracle-x64 JDK8_HOME=/usr/lib/jvm/oracle-java8-jdk-amd64 [/code] Default JDK should be JDK 7. …
„How to specify Java Source and Target Compatibility in a Gradle multi project“ weiterlesen
Analyze application performance with CDI Interceptors
Using interceptors for analyzing performance issues Do you know statements in your code like this? [code] … long start = System.currentTimeMillis(); //some computing… long end = System.currentTimeMillis(); long duration = end – start; … [/code] Analyzing how long the execution of a method takes is a cross-cutting concern. Cross-cutting concerns like transactions, caching or measuring latencies are aspects of a …
„Analyze application performance with CDI Interceptors“ weiterlesen
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"); }}; …
Reading and Writing JSON with JSON Processing API
As a big fan of Java EE 7, recently I had a look at the JSON Processing API. As you know JSON is a data exchange format widely used in web services and other connected applications. The new JSON Processing API (JSR 353), is a lightweight API to parse, transform, and query JSON data using a object model or …
„Reading and Writing JSON with JSON Processing API“ weiterlesen
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 …
Default Methoden in Java 8
Mit Default-Methoden läßt sich Logik nun direkt in Interfaces abbilden. In anderen Sprachen ist die Verwendung solcher vorgefertigter Funktionalität auch als Mixin bekannt. Default-Methoden erlauben, das Interfaces direkt als funktionale Bausteine verwendet werden können. Klassisch wurde mit einem Interface eine Schnittstelle nur definiert, die dann eine Implementationklasse erfüllt. Default-Methoden revolutionieren die Art und Weise wie mit Interfaces und …
Eclipse und Java 8
Nun, nachdem ich bequem das JDK8 auf meinem Rechner habe, will ich näturlich die neuen Features in meiner Lieblings-IDE ausprobieren. Mmmh, ich mußte feststellen, dass Eclipse Kepler noch gar nicht für Java 8 vorgesehen ist. Aber alles gar kein Problem, denn unter http://downloads.efxclipse.org/eclipse-java8/ kann sich jeder eine Eclipse Version herunterladen, die Java 8 unterstützt. Ich habe die …
Einfach und schnell Java 8 auf Linux installieren
Ich habe einen Weg entdeckt, wie ich bequem Java 7 und Java 8 auf meinem Rechner mit Kubuntu installieren kann. Am JDK 8 reizen mich die neuen funktionalen Features. Die Leute von webupd8.org haben in ihrem Artikel sehr schön beschrieben, wie man per apt JDK7 und JDK8 installieren kann. Das tolle daran ist, dass du auch …
„Einfach und schnell Java 8 auf Linux installieren“ weiterlesen