[Java 8] Collection.removeIf() example


[New Algorithm] Anagram

Jon Bentley’s book Programming Pearls contains a problem about finding anagrams of words. The statement: Given a dictionary of english words, find all sets of anagrams. For instance, “pots”, “stop” and “tops” are all anagrams of one another because each can be formed by permuting the letters of the others. I thought a bit and…

Simple Java socket server with Executor

And an example with the ExecutorService class:  


[HOWTO] Timing multiple threads using CountDownLatch

Here’s an example program which spawns a number of threads of a class and counts the time taken to execute them all. The CountDownLatch may also be used in simulation programs where a JOIN element is needed.

Some details from the Java API:

A synchronization aid that allows one or more threads to…

Best practices for better REST API

Copied from here: http://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/ Web APIs has become an very important topic in the last year. We at M-Way Solutions are working every day with different backend systems and therefore we know about the importance of a clean API design. Typically we use a RESTful design for our web APIs. The concept of REST is…

Java Comparator example

Here’s our class we want to compare. Note the implemented inner classes that implement the Comparator interface:

And here’s the client class:


Java Merge Sort

Here is a Java example of Merge Sort algorithm:

And here is the Bootom Up Merge Sort:


[JAX-RS] Use @Provider to leverage JAX-RS provider auto-discovery feature.

There are at least 2 ways to register a JAX-RS resource such as a set of web methods or the filters. 1. The first and the verbose way is to override the getClasses method in a subclass of Application. Like this:

The drawback with this approach is that you have to explicitly add all…