Java 8

As you are already aware Java 8 was released a week or so back. Its one of the most awaited released of Java since long. The stand out feature in it is do with movement towards functional programming. I strongly suggest you do a bit of reading on functional programming if you have not done so yet. For your easier consumption i have provided a quick summary of changes in Java 8 here.

Interface Improvements

  • You can add ‘static’ methods to interfaces.
  • You can provide default implementation of methods in interfaces with ‘default’ keyword.
  • You can not provide default implementation for Object class methods in interfaces.
  • An interface that defines exactly one abstract method is called Functional Interface.


  • Provides a simpler syntax to instantiate functional interfaces. e.g () -> {}
  • It can also be understood as a simplified way to instantiate anonymous classes.
  • Input params and return types can be inferred. Both the braces are optional but the arrow is mandatory.
  • A lambda that access a variable or object defined outside its body is called a Capturing lambda. Such variables must be effectively final.
  • Abstract classes can not be instantiated using Lambda. It may lead to execution of hidden code, ie of the constructor (if any).


  • New package introduces concept of Stream and allows functional style operations on their values.
  • A stream is like an iterator that can be traversed once, then its used up.
  • Streams can be sequential or parallel and can be toggled between them.
  • Operations on streams are either Intermediate or Terminal. Intermediate operations allow further operations on the stream but terminal operations close the stream.
  • Intermediate operations are lazy and only a terminal operation starts processing of the stream.
  • Some stream operations are stateful as they modify the state of underlying stream.
  • Some stream operations are short circuiting as they stop any further processing on the stream.
  • Streams can be infinite but they should have a short circuiting operation.


  • New java.util.Function package introduces built in functions like Function, Consumer, Supplier etc and their variations.
  • New java.time package introduces completely new Date and Time API on lines of Joda datetime library.
  • Lot of default methods added to collection API interfaces and methods accepting functions.
  • The underlying javascript engine is rewritten completely and named Nashorn.
  • Lots of enhancements to existing classes and interfaces.

Here is the link i found best so far on java 8 –

Unable to build EntityManagerFactory (Spring Data JPA + ehcache)

Here is a quick post about a ticky issue that i recently spent some time on and felt good to resolve it. Its about proper packaging and usage of ehache in a spring data based layered application.

The data-layer of the application is used by two client applications (both running on same linux box) by following means.
1. By a web app running on weblogic using weblogic user.
2. By a batch process running on another jvm as standalone application.
Things worked fine when ‘weblogic’ user is used to run both wls server and the batch process. But when the batch process is executed with another user (say ‘batchuser’ while wls running with ‘weblogic’ user we got the following exception.

2014-03-26 14:38:01,695 ERROR [main] [] – Job Terminated in error: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [applicationContext-dl.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [applicationContext-dl.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory at

We are using ehcache and it is configured to use ‘’ (which defaults to /tmp in linux) for the diskstore storage option. Also all the individual cache definitions in ehcache are configured to overflow-to-disk. Since both the applications use the same ehcache.xml file (packaged in the datalayer.jar file) both the applications try to reserve space in /tmp for overflow using same chache names for the entities. When both use same login id they are able to share the files representing the caches but when using different login ids the unix file system does not allow one user to use a file that is created and exclusively locked by different user.

Solutions for us was easy. We do not need the diskstore facility for now as we only have 4 objects to cache and they are small enough to not bother our memory footprint much. So we removed the diskstore definition from cache and it has worked fine. But the correct solution is to not use the same space for storing caches from two different user processes. One could use ‘user.home’ or something similar for diskstore path. Another way could be to not package the ehcache.xml configuration file in datalayer.jar and let the client supply its own configured file in classpath.

Cost of Living : London

This post is mostly for professionals across the world who seek to travel long term (> 6m?) to UK, more specifically London for employment reasons and always end up asking themselves, how much does it really cost to live there and what kind of life my pay package will offer me there? Answers to both the questions can be summed up in two words ‘It depends’.🙂

So one can not provide an answer that fits all individual lifestyles. So you can find thousands of pages on the net talking about the range of prices one have to pay for each expense head. Also i am yet to see one post which gives a detailed break down of all expense heads (at least the compulsory ones) for a regular life there. I attempt that here. Have a look at the table below.

Monthly Expenses GBP Remarks
House Rent 750 London subrubs. 2BHK, Zone 4 East
Water + Gas + Electricity 70
Council Tax 100
Tube+Bus Pass 150 Office travel to Central London
Tv License 15
TV+Broadband+Landline 75
Food Expenses 300 Cooking at home 6 days a week
Cellphone+Intl Phone 25
Kids Education 50 Govt School only. Private school expenses 700 GBP/m
Misc 100 Just goes before you realize
Total 1635  

This is a sample summary of monthly expenses for a family of 3 (Couple and young child) living in Zone 4 in London subrub area and commuting to central London on work as of early 2013. Apart from these there are few annual expenses one incurs specifically if you are an expatriate. Sample expenses shown below.

Annual Expenses GBP Remarks
Annual Vacation 1500 Trip to home country once a year
Shopping & Misc 1000 Personal shopping + Gifts
Health Insurance 400 Saved if provided by Employer.
Total 2900  

As i said earlier these are just sample numbers with statistics gathered from very few families staying in same vicinity. Expense heads and actual expenses depend on lot of factors and probably that is the reason why there is no post out there which sums it all in one place. One can take this as an example and do some rough maths to get a picture.

Continuous Integration (CI) Stack

In past during the Waterfall ways of development, before introduction of CI practices, the development teams use to spend time on a phase called Integration phase. The teams use to collect code from various groups/teams and integrate them into one workable code. This was a difficult and error prone task as it involved integration of weeks or months worth of potentially conflicting changes. It was difficult to get it right and almost always lead to delays in project completion via introduction of bugs and uncovering of unforeseen issues too late in the cycle. Continuous Integration process came to being to address these issues.

In simplest form, CI is the process of continuously building software with every change committed into the version control system and providing feedback to appropriate stake holders.

Example CI process flow

Example CI process flow

The diagram above (not my creation, taken from Dzone, not able to find the link anymore) explains a simple CI process. It starts with developers committing changes into Version Control System (VCS), Subversion in this example. The project needs to create a build script that can be used to build the software. A CI server either keeps checking the VCS for changes or the VCS notify the CI server whenever a change is committed. Upon notification the CI server starts a build using the build script. A feedback mechanism should be put in place (email or message etc) so that a notification is sent to appropriate stakeholders on completion of build process.

CI Stack

The above described simplistic CI process can be extended to automate lot more, for activities that are usually done in software development work and achieve bigger benefits. We discuss here one such extension that we have setup and used in multiple projects and reaped benefits. Include couple of more tools in the above discussed CI setup and call this collectively a CI stack.

Sample CI stack deployment

Sample CI stack deployment

The diagram above showcases a simple CI Stack that we have setup and used. At the core of it is a CI Server (Jenkins in this case) on which there is a job defined that fetches the latest code from version control system (SVN here) and does a Maven based build. Maven is used as the tool to script the build and manage project dependencies.

The dependency management functionality of Maven needs an artifact repository to resolve various dependency versions. Nexus is used here to maintain and manage a centralized Maven repository and the above build process utilizes nexus to resolve the project dependency libraries. Nexus acts as a proxy to Maven Central repository. If an artifact/version needed by a project is not available locally with Nexus, it connects to Maven Central over internet and downloads the artifact/version and stores it in local file system. For all further requests for the same artifact/version is locally resolved by Nexus.

The end of the build process invokes an automated static code analysis using Sonar. Sonar is a static code analysis tool that integrates popular code analysis tools like Checkstyle, PMD and FindBug into one tool. It also provides exhaustive metric reports based on the results of analysis using the above tools. It also captures code coverage statistics gathered using tools like Cobertura or Emma. These reports are stored in a DB so it can be referred anytime via a pretty web based UI.

The above integrated stack augments the continuous build and test capabilities of a regular CI server with Continuous Inspection capabilities via Sonar and centralized dependency management and release management capabilities using Nexus. The whole stack is hidden behind a HTTP server which acts as a reverse proxy to hide/shield the individual servers from direct access. It also helps simplify the access URLs of various constituent tools of the stack using a unified IP: port address.

This stack can be extended to add further capabilities. One such thing is web based code review using Trac tool. This can be integrated into individual developer IDEs as well while the web based reports can help QA personnel to extract necessary metrics.


  • Detect integration problems early and reduce risk of failure.
  •  Comprehensive tests help detect bugs early, makes easier to find root cause.
  •  Early warning of broken code, incompatible changes.
  •  Availability of ‘current’ build for demo, testing, release.
  •  Generated metrics and frequent check-ins push for better code.
  • Speed up builds and save developer time.
  •  Save company bandwidth and protect against internet outage.
  •  Control and audit dependencies.
  •  Centrally deploy third-party publicly unavailable artifacts.
  •  Maintain internal repositories and help inter-team (project) collaboration.
  • Continuous automated builds including tests and continuous inspection of code.
  •  Historical trends help analyze project progression direction.
  •  Trigger builds on code check-in or on specific schedule.
  • Automated code quality checks that includes check for Coding standard violations, Best practices, Test coverage, Technical debt, Code complexity etc.
  •  The reported matrices can be used as exit criteria for release of code beyond development environment.
  •  Web based reporting making it accessible anywhere and on any device.

Best Practices

The list below provides a few popularly known and often used best practices around CI based development.

  • Manage all source code in one centralized VCS repository.
  • Make frequent and small commits. Organize the code into smaller group of tasks and make group commits are task level.
  • Automate builds using build scripts that avoid the need of manual configurations. The scripts should be capable of running on multiple platforms and environments.
  • Centralize dependency management and reduce pre-installed tool dependency minimal.
  • Develop code in private workspaces and do private builds before committing code to VCS.
  • Send automated feedback from CI server to development teams and other stakeholders.
  • Fix build errors on priority, as soon as they occur.
  • Use dedicated machines to do build and deployment.
  • Create exhaustive test cases to cover all paths in code, group them by type and automate the test execution to add self testing capabilities.
  • Execute automated code analysis for standards, best practices and potential bugs. Define a build threshold and notify stakeholders on threshold breach.
  • Externalize application configuration into property files and separate configuration from installation.


The table below summarizes the software used to setup this CI Stack along with their purpose.

Nexus Manage and maintain Maven repositories
Jenkins Continuous Integration server
Sonar Static code analysis tool
Maven Build automation tool
JRE The Java runtime environment
Tomcat Web container
Apache HTTP Http server to provide reverse proxy capabilities
SVN Version control system
Trac Web based code review over SVN server

Cisco VPN connection automation

The Cisco VPN client software provides a GUI based tool to setup and connect to a vpn network using various connection methodologies. Connection configurations to a particular network can be stored as a profile.

My team needed to do vpn connect and disconnect quite a few times during the day. The operation involved multiple monotonous clicks to connect or disconnect. So it called for one click automated process.

Similarly we had Continuous Integration server that needed to connect over vpn to get code from source control management system. The server could not be put on a permanent vpn connection as doing so made the server inaccessible to local network. The server should be available on local network most of the time but can connect to vpn for a brief period of time during a job execution to checkout code. This needed a silent and automated way of connection and disconnection from vpn.

Thankfully the vpn client software does provide a command line interface though the accompanying documentation leaves lot to be desired. So a bit of playing around was needed to get it working.

Here are the windows scripts that can be used to automate the connect/disconnect task. I am using Cisco VPN client version 5.0.x.

@echo off
rem Try connecting to vpn using command line silently, ie without any prompt whatsoever.
set user_id=yourUserId
set pwd=yourPassword
set install_dir="C:\Program Files (x86)\Cisco Systems\VPN Client"
set profile_name=yourProfileNameWithoutFileExtension
%install_dir%\vpnclient.exe connect %profile_name% user %user_id% pwd %pwd% nocertpwd stdin < vpn-input.txt
rem Cisco vpn client returns 200 on successful connection.
if %errorlevel% neq 200 goto failed
echo Connected to vpn. :)
goto end
echo Failed to connect to vpn with error code = %errorlevel%.
goto end
exit /B %EXITCODE%
@echo on


@echo off
rem Kill the VPNGUI program if it is running; so you dont get any pop up dialog.
taskkill /F /IM vpngui.exe
rem Try disconnecting vpn using command line silently, ie without any prompt whatsoever.
set install_dir="C:\Program Files (x86)\Cisco Systems\VPN Client"
%install_dir%\vpnclient.exe disconnect
rem Cisco vpn client returns 201 on successful disconnection.
if %errorlevel% neq 201 goto failed
echo Disconnected from vpn. :)
goto end
echo Failed to disconnect to vpn with error code = %errorlevel%.
goto end
exit /B %EXITCODE%
@echo on

The functions of the files are self explanatory. But still to be foolproof,
vpn-connect.bat – connects to the vpn
vpn-disconnect.bat – disconnects from vpn
vpn-input.txt – used by vpn-connect.bat to silent the warning pop up (if any) thrown during connection operation

To make the scripts work, one would need to create a connection profile using the vpnclient user interface, copy the files into a folder and then change the following,

In vpn-connect.bat,

  • Put the vpn connection user id in ‘user_id’ variable.
  • Put the vpn connection password in ‘pwd’ variable.
  • Put the path to vpn client installation directory in ‘install_dir’ variable.
  • Put the connection profile you created using the vpn client in ‘profile_name’ variable.

In vpn-disconnect.bat,

  • Put the path to vpn client installation directory in ‘install_dir’ variable.

In vpn-input.txt,

  • No change needed.

You can change the error codes to values that suits your automation environment. I have explicitely set the values to either 0 or 1 as the scripts are used by Jenkins (on the Continuous Integration server) and it fails the build if the batch execution returns a non-zero error level. The vpn client returns 200 on successful connection.

Once these setup are done you can just double click on vpn-connect.bat to get connected to vpn and do the same on vpn-disconnect.bat for disconnection; as simple as that. Enjoy.🙂