Java Custom Exception Example

In this example we will look briefly at the basics of Exception, in Java Programming Language. We will also see, how to create a custom Exception Class. 1. Basics of Exception As per oracle docs, An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. In laymen terms, when a condition occurs, in which the routine is not … Continue reading Java Custom Exception Example

Java performance tutorial – How fast are the Java 8 streams?

In this JAX Magazine sneak preview, JAX London speaker Angelika Langer answers the most important question for anyone using Java streams: are they really faster? Java 8 came with a major addition to the JDK collection framework, namely the stream API. Similar to collections, streams represent sequences of elements. Collections support operations such as add(), remove(), and contains() that work on a single element. Streams, in contrast, have bulk … Continue reading Java performance tutorial – How fast are the Java 8 streams?

Java Memory Management

You might think that if you are programming in Java, what do you need to know about how memory works? Java has automatic memory management, a nice and quiet garbage collector that quietly works in the background to clean up the unused objects and free up some memory. Therefore, you as a Java programmer do not need to bother yourself with problems like destroying objects, … Continue reading Java Memory Management

Strategy Pattern in Java 8

These are two examples on how to implement a Strategy pattern designusing Java 8 functional style together with Cyclops pattern matching and Hamcrest libraries. PrintDependingOnInput method is a strategy that will System.println some message based on the log passed. AddPrefix is another strategy that will add a prefix to a message based on the message content. package com.marco.patternmatching; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.core.AllOf.allOf; … Continue reading Strategy Pattern in Java 8