Eran Medan

What should I build next?

Read this first

Why Java Is Still Relevant

Or why it’s not a bad idea learning it even if you hate it

(migrated from


Java is probably one of the most “love to hate” languages out there. According to this HN poll it is the 2nd most hated language among the poll participants (statistically insignificant, but still noteworthy), only 2 points behind PHP. Certainly not a great place to be.

There are many reasons why not to like Java, but there are also quite a few good reasons to learn it, even if you don’t like it. Actually there is an increasing number of reasons to start trying to like it again, or at least to hate it less.

So here are a few reasons why I think Java is still relevant for learning:

 1. X uses it (where X = Google, Amazon, Square etc…)

Google is using Java widely, and contributed a lot to the ecosystem (Google Guava, GWT, Guice etc). So if you want to work for Google...

Continue reading →

Server Side Events (SSE) in Java

I saw an excellent question on StackOverflow about implementing server side events using Servlet 3.0

Here is a full working example (Servlet 3.0 / Java EE 6) based on my answer

Some notes:

  1. it handles “browser tab / window closed” via out.checkError() that also calls flush()
  2. I wrote it quickly, so I’m sure it can be improved, just a POC, don’t use in production before testing

Servlet: (omitted imports for brevity)

@WebServlet(urlPatterns = {"/mySSE"}, asyncSupported = true)
public class MyServletSSE extends HttpServlet {

  private final Queue<AsyncContext> longReqs = 
      new ConcurrentLinkedQueue<>();
  private ScheduledExecutorService service;

  public void init(ServletConfig config) throws ServletException {
    final Runnable notifier = new Runnable() {
      public void run() {
        final Iterator<AsyncContext> iterator =

Continue reading →

Cake Pattern in Scala / Self type annotations

(migrated from

I’ve been trying to understand the cake pattern in Scala for some time, and until I didn’t sit and write some code, it didn’t click. Here is my attempt to explain it (to myself mostly) hope it might help others get a better understanding of this interesting pattern.

 What is it for?

Dependency injection, “the scala way” (among other possible usages, but this post focuses on this one)

 What is Dependency Injection?

The reverse of look-ups / named dependencies, e.g. if class X needs a database connection and gets it using

   val con = DBConnectionRepository.getByName("appDBConnection")

then this is not dependency injection, it is coupled to the repository, and to the name (can’t ever change it…)

Dependency injection tries to invert it, one simple way of doing so is by non optional constructor argument, another way is an abstract def...

Continue reading →

Will Java 8 Kill Scala?

This is an expansion of my HN comment In response to a comment by HN user justinsb on HN about this article of the same title

 The original comment (by HN user justinsb):

It isn’t that Java 8 will kill Scala, it is that Scala has demonstrated the utility of lambdas to the point where they can safely be incorporated back into Java. So Scala has “won”, but in my opinion likely Scala will now fade away. Java is necessarily very conservative with adopting language features, because it is very careful to maintain backwards compatibility. Java is a bit like Debian stable - out of date compared to Debian testing or even other distros - but solid as a rock. For features to make it into Java, they really need to be proved first in other languages or in external libraries.
This isn’t the first time Odersky has advanced Java either - he worked on Pizza, which showed how to add Generics to Java...

Continue reading →