[Java 8] Map.computeIfAbsent()

The computeIfAbsent method is similar to compute(), however it only has side effects on the map if the key wasn’t there before applying the method. One important thing is that the signature takes a Function as an argument and not a BiFunction as in the case of compute().

Here’s an example:


[Java 8] Map.compute example

Here’s a Java 8 Map.compute() example. Basically this construct replaces an idiom such as:

It does an in-place transformation by using a BiFunction, therefore you need to return if you have more than one statement. Another important thing about compute: If the BiFunction returns null and the key was in the map, it is…

[JAX-RS] Access-Control-Allow-Origin as a Filter

So if you’re getting the Access-Control-Allow-Origin error in chrome. Then you need to be sending those headers with the response from the server. One solution would be to put it in the Response in each method. A better (and more scalable) solution is to use a filter. Then don’t forget to disable it in production.

Netbeans ugly fonts

If the fonts “cut your eyes” in Netbeans then: Open netbeans.conf under ${netbeans-home}/etc/ In the netbeans_default_options= section append at the end:

and restart netbeans.

[Java Concurrency] An example of AtomicInteger

Here’s a simple example that shows how AtomicInteger can be used instead of the not thread-safe int Counter implementation.  


[JAVA 8] Custom DTO mapping

Very nice idea: http://www.idanfridman.com/mapping-your-entities-to-dtos-using-java-8-lambda-expressions/ Mapping your Entities to DTO’s Using Java 8 Lambda expressions We all facing the cluttered overhead code when we need to convert our DTO’S to Entities(Hibernate Entities, etc..) and backwards. In my example ill demonstrate how the code getting much shorter with Java 8. Let’s create the Target DTO:


Java CyclicBarrier example

An example from the very good Java 8 book “Beginning Java 8 Language Features”. :


[Java] util.concurrent.Semaphore example

An example from the very good Java 8 book “Beginning Java 8 Language Features”. :


[SOLVED] arduino libncurses.so.5: cannot open shared object file: No such file or directory

If you’re trying to work with arduino under Fedora 24 (may be under others as well) and you’re getting this kind of errors:

All you need to do is make a symbolic link to the required file. If you look under

You will find files like:

So you need to make a…