Java features explained with examples

Asynchronous REST endpoints

When developing a REST API, a major concern is how to scale the application to cope with large amounts of requests in an efficient way. This excellent article http://www.javaworld.com/article/2077995/java-concurrency/java-concurrency-asynchronous-processing-support-in-servlet-3-0.html explains the different models to deal with the requests: thread per connection, thread per request and the support for async Servlets introduced in Servlet 3.0. The basic ideas are: threads […]

Inside a class file

In this post, we will explore the inner parts of a class file going byte by byte!!   The class file format is defined at https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html. It says: Each class file contains the definition of a single class or interface. I will add that the class may be public or package-private. For instance, it is possible to […]

Overloading by return type

It is known that one of the limitations of Java is the inability to overload a method by return type as the return type is not part of the signature of the method. According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2, “Two methods or constructors, M and N, have the same signature if they have the same name, the same […]

Generics erasure

The use of Generics allows a type or method to operate on objects of different types while providing compile-time type safety. However, the JVM knows nothing about type parameters or generics as the compiler erases type parameters when creating bytecode. According to https://docs.oracle.com/javase/tutorial/java/generics/erasure.html, type erasure aim is “Type erasure ensures that no new classes are created […]