Skip to main content


Showing posts from January, 2015

Java Lambda Expressions

About a 5 minute read.   
    Java SE 8 came with the ability to use some functional programming techniques with Java's object-oriented programming structure. Most notably is the introduction of Lambda expressions.

    When I first heard of Lambda's I searched the Internet for a quick explanation as to what they are. Most of the explanations I found seemed verbose and overly complicated. Which led me to put them aside until a later point when I "needed" or had extra time to learn about them. Now, that I understand them (sometimes I spend more time searching the Internet for a "quick" answer than what it would take to read a decent chapter of a book on the subject; finally I did the latter) I can't believe that I couldn't grasp it in the first place. 

    Without debating linguistics, simply put, a Lambda expression can be defined as an anonymous method. I believe that's the best description that can be provided to help a Java programmer under…

Server-Sent Events with Java back-end using Servlets

Yesterday, I provided an example of how to connect a client-side JavaScript EventSource object to a server-side Java Servlet for the use of server-sent events and, in particular, notifications. However, the example that I provided, like almost all similar examples on the Internet, was rudimentary. It lacked the ability to be efficient for real world applications. This was fine for the time being, because it was only created to emphasize and explain how to design such a system. But it led me to think how I could take that example and make it a little more applicable. So, after some thinking, and a little difficulty, I came up with a more efficient implementation.

    While developing this solution, I came to find out that there seems to be some problems with the EventSource Interface and how browsers implement it. This isn't too hard to believe since the API is still relatively new. However, it is slightly a nuisance to work with since some behavior is out of your hands. Also, …

Web Application Notifications

About a 5 minute read

    A popular part of an application is its ability to receive notifications. For instance, a social application such as Facebook, needs to notify its users when they have new friend requests, feed updates, and updates to their posts. There are many frameworks that provide the capability to do this but I'm going to experiment on making my own simple implementation. I'm going to use JavaScript for the client-side code and Java for the server-side code. The approach I will take is to use Server-Sent Events (SSE).

What are server-sent events?     Server-sent events are a publish-subscribe model. 
    Traditionally, a browser requests information from the server which then the server responds with such information. However, this is inefficient for a notification system because the browser doesn't know when such information is available. So, we need a way for the server to alert the browser with information when it is ready. There is a way called polling,…

JavaScript Immutability

5 minute read

In programming, when talking about immutability, there are some closely related words and their meanings that we should take in to account. There's immutable (of course), writable, and constant. So, let's have a look at these before diving into JavaScript specifics (Object.freeze() and Object.seal() methods).

Immutable The definition of immutable is: not mutable; unchangeable; changeless. In object-oriented programming, an immutable object is defined as an object whose state cannot be modified after it is created. Immutability works on the value not the variable. Therefore, a variable can point to an immutable object then to another or even a mutable object throughout its life. However, the immutable object the variable originally pointed to still will remain unchanged. In most programming languages, including Java and JavaScript, a String object is immutable. For example:

    var name = "Chris"; //defining a string object     name.toLowerCase(); //does…

Designing Modular JavaScript

Closures, self-executing functions, immediately-invoked function expressions, and module patterns. Some of JavaScript's most advanced topics. At first glance, these can seem a little overwhelming but once understood they become as straightforward and repetitive as fundamental DOM manipulations.

    Coming from a Java background, learning JavaScript was a bit awkward. One might mistakenly suspect that JavaScript is just a bare form of Java. However, despite the names, there are more differences than similarities between the two languages. Java is a statically-typed, class based, object-oriented programming language. JavaScript is a dynamically-typed, prototype based, object-oriented programming language. Certain aspects of the syntax are the same (an if-statement is an if-statement), but the former differences are enough to create some headaches. Before I elaborate on some of JavaScript's more advanced topics, I'm going to break down the differences between Java and Ja…