Java features explained with examples

Functional programming

This post presents some features of functional programming with Scala. In essence, functional programming is about programming by making use of mathematical functions. All well-known features of functional programming are just a result of using mathematical functions, e.g.: referential transparency immutable state higher-order functions pattern matching I especially like ‘pattern matching’ as it allows for a […]

Dealing with memory leaks

Background This post describes my experience playing around with Scala and some of its concepts like tail recursion and futures. It also offers an opportunity to see how a memory leak can happen and how to analyse it. I created a simple web crawler that takes a seed link (e.g. http://www.bbc.co.uk) and then, recursively (using tail recursion), collects all […]

AWS Key Management Service

One of the main concerns when developing an application is where/how to store the application secrets such as database passwords, tokens, etc. This post explores the use of AWS Key Management Service to manage the secrets in a Spring Boot application. The steps followed to configure AWS KMS are described in the next sections.   […]

Running Docker on AWS

Recently, while developing a new microservice, I decided to create a “mockserver” to mock a third party system. In order to do that, I created a Docker container encapsulating the server and the stubs to be served in response to the application requests. After running the microservice locally making use of the mockserver, the time […]

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 […]