#1 Class Access Types

Class can be declared with public and default access-modifiers and abstract, final non-access-modifiers.

Where as inner classes can include all access modifiers public, private, default and protected.

Singleton – Creational Design Pattern

Singleton Design Pattern is one of the creational design pattern which creates only one instance of the class. Only one instance of the class is created per Java Virtual Machine. Singleton pattern is used for logging, drivers object and thread pool. There are different ways to create singleton design pattern, but all of them follow three concepts

  1. private constructor to restrict access to other classes.
  2. private static variable of the same class that is only instance of the class.
  3. public static method to return the instance of the class.
class SingletonPattern {
   private static SingletonPattern defaultInstance;
   private SingletonPattern() { }
   public static SingletonPattern getInstance() {
      if(defaultInstance == null) {
         System.out.println("Singleton Pattern Default Instance Created");
         defaultInstance = new SingletonPattern();
      return defaultInstance;

The above singleton class is not thread-safe and may not be useful in multi-thread environment. Need to take necessary steps to make it thread safe. The below method of creating singleton pattern is the most widely used and doesn’t require any synchronization techniques.

class SingletonPattern {
    private SingletonPattern() { }	
    private static class SingletonHelper {
        private static final SingletonPattern INSTANCE = new SingletonPattern();
    public static SingletonPattern getInstance() {
        return SingletonHelper.INSTANCE;

Share files to download from tomcat

Sharing files with friends or colleagues who are in same network is every easy now. All you need is tomcat and name of your computer. So let’s see how we can do it.

I’m assuming tomcat installation be tomcat=”C:\tomcat”

  1. Download Apache Tomcat & Java. Configure environmental variable “JAVA_HOME” with path for Java installation directory and “CATALINA_HOME” with path for Tomcat installation directory.
  2. Go to tomcat/bin and run “startup” batch file. check from browser whether you able to access tomcat home page(http://localhost:8080). if you reach here it means your tomcat installation is good, now lets do some setup.
  3. Go to folder that you want to share and create a simple web.xml file in it.
  4. Go to tomcat/conf open server.xml file and add context for the directory that you want to share like “<Context docBase=”D:\Personal\Tutorials” path=”/Tutorials” reloadable=”true” source=”D:\Personal\Tutorials”/>”
  5. Go to tomcat/conf open web.xml, search for “listings” in “init-param” tag you will find param-name as “listings” change its corresponding param-value to “true

That’s all now save all the changes and run tomcat, folder you shared will be available in the path you mentioned in step 4.

For example in my case directory is available at http://localhost:8080/Tutorials


Design Patterns – Introduction

Design Patterns are proven solutions provided to commonly occurred problems while designing software solution. They evolved over years to resolve most common problems, so we can follow them blindly without any hesitation.

Are Design Patterns dependent on any programming language? No, Design Pattern is an approach, it is not tied to any programming language. Once understood can be applied in any programming language.

Little History from wiki-

Patterns originated as an architectural concept by Christopher Alexander (1977/79). In 1987, Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns to programming – specifically pattern languages – and presented their results at the OOPSLA conference that year. In the following years, Beck, Cunningham and others followed up on this work.

Design patterns gained popularity in computer science after the book Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994 by the so-called “Gang of Four” (Gamma et al.), which is frequently abbreviated as “GoF”.

GoF Design Patterns are foundation for all the design patterns out there. They are 23 in number divided into three categories.

  1. Creational Patterns – Different ways of creating objects.
    • Singleton
    • Factory
    • Abstract Factory
    • Prototype
    • Builder
  2. Structural Patterns – Different ways of orgainising classes and objects, using associations and aggregations to form complex structures.
    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Facade
    • Flyweight
    • Proxy
  3. Behavioural Patterns – Interaction/Communication b/w objects, they help to keep communication loosely coupled.
    • Chain of responsibility
    • Command
    • Interceptor
    • Iterator
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Template method
    • Visitor

We will discuss each one of these patterns in details in the subsequent posts.

Shared Git repository on LAN

Few days back me along with my colleagues came up with an idea to do POC on healthcare mobile app using ionic. I thought of creating a common code repository in one of our systems and share that code repository using office LAN. A part from pull and push commands in git I didn’t know anything. So obviously like any other developer I googled, after lot of research I successfully created a Git repository in our LAN. Here are the steps

Create a bare repository (Bare repository is the one that has no working tree. It means its whole contents is what you have in .git directory. You can only commit to bare repository by pushing to it from your local clone. It has no working tree, so it has no files modified, no changes)

 git init –bare project1.git

Share it to the users on LAN

Clone this project in some other location on our system using command.

git clone //192.168.xxx.xxx/xx/xx/project1.git

Create you project setup files here or dump project into cloned project1 folder and Add the files to cloned repository using

git add .

Then commit the files using

git commit -m “First commit”

At this point your bare repository doesn’t have any branches, when you commit the files in our local cloned project repository it creates a master branch local to our codebase.

Push the changes to the newly created master branch in local code using

git push

The default branch of bare repository is “origin” and default branch of your local cloned repository is “master”. You can check it by commands from cloned repository

git remote (returns origin)

git branch (returns master)

Now it’s very simple, we know the branch of our remote repository & our local branch. Now we need to push the local changes on master to origin.

git push [remote-repository-name] [local-branch-name]

git push origin master

It’s done !! Now any one who has access to project1.git can simply clone the project using command

git clone //192.168.xxx.xx/*/*/project1.git

Finally we can use the most used command pull & push to do our daily activities on code base. Hope this helps.

Gradle Error: Ionic build for android

I’m learning Ionic framework to develop hybrid apps. However when I’m trying to build the application encountered “gradle” errors. If you encountered any of these errors follow below instructions

  1. Download gradle distribution from here.
  2. Go to “<<project>>/platforms/android/gradle/wrapper” paste the downloaded zip file at this location
  3. Edit <<project>>/platforms/android/gradle/wrapper/gradle-wrapper.properties replace distributionUrl to “gradle-x.x.x.zip” which you copied in above step.

This should solve gradle errors.

Start with Ionic

Ionic is a open source framework which is used to build Android and IOS apps  with “HTML 5, CSS & JavaScript”. Ionic helps you to write applications which can be used either in Android/IOS. Ionic along with “Apache cordova” provides support to build hybrid apps. Ionic is completely built based on “AngularJs”. So If you know angular, you know Ionic

How to start ?

1. Install Nodejs (node pakage manager) & GitHub (source control)
2. Install Java, Android sdk & apache-ant & configure your environmental variables


3. Install Cordova, unorm, cordova-common, cordova-registry-mapper

npm install -g cordova
npm install -g unorm
npm install -g cordova-common
npm install -g cordova-registry-mapper

4. Install ionic

npm install -g ionic

5. Create new project on desktop

ionic start <<project-name>> blank

6. Add platform you app wants to run on like Android or OS. I’m showing Android here

ionic platform add android

7. Build and emulate your project. I’m considering only Android. In order “emulate” command to you need to install android sdk in our system.

ionic build android
ionic emulate android

8. Android emulate is very slow and will consume lot of time. So install “Genymotion” . It provides an actual android device, as if you connected one through usb. In order to use the device created in Genymotion, start the device and run the below command from application page

ionic run android

9. Ionic creates a whole project for you with the structure of real-time application. “www” is the folder where you need to write everything regarding your application like css, js, html etc…

10. In order to deploy application into virtual machine, start the device from Genymotion and run “ionic run android”. If you want to test the changes in browser run “ionic serve”. This will open your application on browser.
12. Once your application is ready run following commands from project folder to create and sign apk.

cordova build –release android

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore platforms/android/build/outputs/apk/android-release-unsigned.apk alias_name

zipalign -v 4 android-release-unsigned.apk <<app-name>>.apk

Oh!!! you are ready to go ?? Go and install the application in your android device and test it

I have came up with this steps after referring to Ionic website. Refer to Ionic website for detailed information.

AngularJs Tip: Don’t use $watch on $scope

Try to use “ng-change” instead of “$watch” when you want to watch a particular value. There are couple of benefits like performance improvement because of no overhead on digest cycle & writing test cases for ng-change is very easy compared to writing them on $watch.

AngularJs: Understanding loading Modules – II

This is my last post in the series to understand workflow for loading modules into Angular, Dependency Injection. Here is the workflow diagram created by me. This is as per my understanding of the concepts. Feel free to correct me if I’m wrong.angular_module_overview1