Comparison of Maps in Java Collections Framework

March 26, 2015

Maps, Hash tables(in general sense), Dictionaries whatever you call them, in every well known programming language there are similar data structures. In java we have Maps as a part of the collections framework.
Although Maps do not implement Collection interface they are still one of the most important part of the framework. Java SE library provides several implementations of Map data structures. Of them, some of the commonly used are HashMap, LinkedHashMap, TreeMap, etc.

Note that the following diagram corresponds to the java 7 & 8 collections framework and it is an abstract view of the relevant classes and interfaces. AbstractMap class which is implemented by several concrete classes has been omitted.

Method Overriding with Exceptions in Java

March 17, 2015

Understanding method overriding with Exceptions has made some confusions in my mind. So I tried to list all the possible cases in terms of declarations of exceptions in super class method. The list of 3 main cases are as follows.

Case 1: Super class method declares NO exceptions

Here there are only 2 possible sub cases.
  1. Sub class method does not declare any Exceptions. This is the most obvious one since there are no Exceptions involved. So I'll omit the code sample.

Dropbox as a Git Remote Repository

March 5, 2015

I have been experimenting with various methods to synchronize my personal projects with my home PC and my laptop. Exporting, importing, making changes, and again exporting........this has been a real headache especially the huge mess it creates with all the dependency issues that I have to resolve every time.  Of course the use of version controlling would be best solution as many of the developers out there would agree. But still the private repositories are not for free (eg GitHub), so it is out of my scope since I still cannot afford one :'(

Here's my most 'recent' solution and the probably the best so far, ie. maintaining a git remote repository in a file hosting service such as Dropbox or Google Drive. I'm a beginner to learning Git. At the beginning I did some silly mistakes like using Git clients which made learning git far more complicated; I still hate EGit - the eclipse default git client :-@  but once I switched to good old fashioned command line it all made sense.

JSP Basics

December 30, 2014

Java Server Pages or JSPs are very similar to typical html pages except they are embedded with java code. This simplifies the development of dynamic web applications.

How JSPs are related to Servlets

JSPs are basically an abstraction to Servlets. Before compilation, JSPs are translated into Servlets and then compiled by the servlet container.

JSP Lifecycle

  1. JSP is translated into a Servlet (creating equivalent Java source code for a servlet) and Compiled by the servlet container.
  2. An instance of the corresponding Servlet class is created and initialized by the by calling jspInit() method.
  3. This servlet object stays in the memory and for each request _jspService() method is invoked, passing the request and response objects.
  4. When the container needs to remove the servlet instance from service jspDestroy() method is called.

JSP Syntax

Introduction to Linear Regression: Normal Equation

November 1, 2014

Normal Equation (Method II)

The use of Normal Equation to solve for the optimal \(\ \theta\) and find the hypothesis function is an alternate method to what we talked about in the last post and probably the easiest, but of course they have their own benefits and drawbacks.

Here we don't need to define a cost function, therefore we don't need to select \(\ \alpha \); the learning rate or specify number of iterations. Same as before, X is our feature matrix and for the intercept term \(\ \theta_0\), a column of ones should be added to X before calculation.

Introduction to Linear Regression: Cost Function

October 29, 2014

Cost Function (Method I)

For calculating the cost in linear regression, typically we use Sum of Squared Error method(SSE)

\(\ J(\theta) = \frac{1}{2m}\sum_{i=1}^m{(h(x^{(i)})-{y^{(i)}})^2}\)

The goal is to minimize \(\ J(\theta)\) and figure out \(\ \theta\) values corresponding to the minimum cost. There are several optimization algorithms used to achieve this.