Era of JVM language

May 22, 2016. | By: digvijayb

Java is computer programming language with multi-paradigm of programming Object-oriented, structured, imperative, concurrent and others desgined and created by James Glosling and his team at Sun microsystems. Released in 1995 with its promised “Write Once, Run Anywhere” now after 21 years of initial reslease in 2016 Java is one of the most popular programming languages in use particularly for client-server web applications, with a reported 9 million developers.

[Read More]

Creating Immutable Class

May 16, 2016. | By: digvijayb

How to create immutable class

Immutable Classes are those who’s object once created it can’t be change (or value can’t change). So to create Immutable Class in java there are some simple that are listed below.

Rules for immutable class:

  • No setter should provide for the field.
  • All field should be final and private.
  • Make the class final as an immutable class should not be inherited or an another for this could be to make the constructor private and construct instances in factory methods.
  • If there is any field which is a references to mutable objects make sure that it should not be modified :
    • Don’t provide methods that modify the mutable objects.
    • Don’t share references to the mutable objects. Always create a copy of the object and provide that for any operation.

[Read More]

Hello World With

May 7, 2016. | By: digvijayb

Simple of Templating by

Mustache.js is very popular templating js for web. Today we going to look at java version of mustache.

So for getting started we need a file which will act like a template for our program. For this we a file template.mustache which is simple text for a mail with some place holder in mustache syntax.

[Read More]

Builder pattern for creating object

Mar 8, 2016. | By: digvijayb

There are number of creational patterns which are use to create instances of class, but were builder pattern fit in and stand out from other creational pattern like static factory, telescoping constructor, javabean pattern and other’s. Is its ability to scale with a large number of parameters. So let’s get started with an example.

Let’s consider a case where we have to create object of a Product class with several field like name, description, sellPrice, costPrice, maxRetailPrice, discount and brand. For selling a product name, sellPrice and description are mandatory field, a product object is incomplete without these three information.So we are going to implement builder pattern in this case to incur the problem.

Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.

[Read More]

Zen of Python (PEP 20)

Dec 23, 2015. | By: digvijayb

PEP(Python Enhancement Proposal)-20 is the Zen of Python. Written by long time Python developer Tim Peters, the Zen is acknowledged as the core philosophy of Python. In fact, it is always accessible in any Python environment by using import this:

[Read More]

RESTful Web Service With Jersey And Spring

Sep 21, 2015. | By: digvijayb

Two of the coolest framework in java Jersey and Spring. we are going to integrate together to get best of the both for our restful web service. Jersey provides the JAX-RS API’s implementation to get web service structure ready. And spring logical support to our web service by it unique feature inversion of control (IoC)

Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

The Spring Framework is an open source application framework and inversion of control container for the Java platform.

Technology Stack

  • Spring 3.2.2.RELEASE
  • Jersey 1.8
  • Tomcat 7
  • JDK 1.6

[Read More]

Why Iterator interface provides remove() method but no add() method?

Sep 8, 2015. | By: digvijayb

The Interface Iterator provider as three method that are hasNext(), next() and remove(). This means that we can remove any element from a collection while iterating over it. so why we cannot add element to the collection. Why they don’t provide add() method.

Answer is, that they can’t allow you to concurrently read and add element to a collection. The Iterator work on any collection whether it Set, List or Map. So it does know very much the on which underlying it’s going to work and we know all the collection implementation maintain ordering of elements based on some algorithm. For example TreeSet maintains the order of elements in by implementation Red-Black Tree data structure. Therefore if we tried to add an element to TreeSet using the iterator at given index or position of iterator. it might corrupt the state of the underlying data structure. So, the add() method could change structural state of a data structure.

[Read More]

Struts Login With Internationalization and Localization Demo

Aug 5, 2015. | By: digvijayb

This is a very simple login demo web-app in struts 1.3 which support Internationalization and Localization (or a multilingual application which in English, Hindi, German, French and Spanish ). So before going any forward I have something share few day before writing this post I attended an interview for Struts 1x I have around 2+ year of experience in struts 1 and then ask me how to handle Internationalization and Localization in struts. And I have never worked with multilingual application before but have some idea about multiple resource file ending with a locale so as I came back got some time wrote and demo for the multilingual app.

[Read More]

StAX Parser Example

Aug 1, 2015. | By: digvijayb

Using StAX Parser

Parsing an XML Document with StAX parser which is one of the fastest way to parser document in current days. Having very less memory footprint, easy to implement then previous generation of parser like

DOM (Document Object Model) parse and others. This make StAX must use API for modern day application it is fast and lightweight. So, below we have a easy program to parse down an XML document using StAX.

Overview StAX Pull Model

StAX (Streaming API for XML) is an application programming interface (API) to read and write XML documents, originating from the Java programming language community. It is one most fastest API to parse an XML document and very lightweight too. StAX work’s on pull style of parsing unlike to SAX parser which is push style parsing.

[Read More]

Subscribe & Social

Subscribe to this blog via RSS.

Recent Posts


Java 14

Python 2

Wordpress 1

Ops 3

Shared 3

Angular 1

Web 1

Popular Tags

Java (14) Python (2) Wordpress (1) Ops (3) Angular (1) Web (1)


DGStack is web blog by digvijay bhakuni. This blog is about computer programming tips and trick. And some short tutorial and gettings started post about the framework, libriay, api and much more. The blog target mostly open source stuff like java, j2ee, nodeJs, angularJs, spring, struts, mongodb, mean, etc


This website claims no credit for any images posted on this site unless otherwise noted. Images on this blog are copyright to its respectful owners. If there is an image appearing on this blog that belongs to you and do not wish for it appear on this site, please E-mail with a link to said image and it will be promptly removed. And the information is best of my knowledge one can always write comment or mail regarding information is this blog.