Thursday 28 August 2014

Spring Data MongoDB Hello World Example

In this Post we will see how to Integrate Spring Data + MongoDB + Maven step by step.
To integrate Spring with MongoDB we require Spring Data and Mongo DB jars.

Java + MongoDB Hello World Examle

A simple Java + Maven  + MongoDB  hello world example.

In this Post we will see step by step how to connect MongoDB, create database, collection and document, save, update, remove, get and display document.



Wednesday 6 August 2014

How to generate MD5 Hash in Java


There are multiple ways to generate MD5 hash in Java Program. Not only Java API provides convenient method to generate MD5 hash, you can also use popular open source frameworks, like Spring and Apache commons Codec to generate MD5 digest in Java.

 MD5 is popular Message Digest Algorithm, which is most commonly used to check data integrity e.g. comparing MD5 check-sum to see, if any file is altered or not. Though, MD5 was not considered a good cryptographic algorithm for security purpose due to several vulnerability found on it, it's still good enough or cheking integrity of file. 

How do I encode URL parameters

When using the GET method, parameter names and their values get submitted on the URL string after a question mark. Different parameter name/value pairs are separated by ampersands.

However, what happens if the parameter value in the URL string has a space or some other special character? Submitting an HTML form will result in special characters being automatically converted to special codes for us. However, sometimes it is necessary to encode these characters without the aid of an HTML form. Java  has a class called URLEncoder that can encode these characters so that they are properly handled. The encode method takes two parameters, the string to be encoded and the encoding scheme. Unless you're smoking crack, you probably want the encoding scheme to be "UTF-8".

How to read a properties file with a Resource Bundle

A ResourceBundle offers a very easy way to access key/value pairs in a properties file in a Java.
ResourceBundle class is used to internationalize the messages. In other words, we can say that it provides a mechanism to globalize the messages.

The hardcoded message is not considered good in terms of programming, because it differs from one country to another. So we use the ResourceBundle class to globalize the massages. The ResourceBundle class loads these informations from the properties file that contains the messages.

Tuesday 5 August 2014

Find Out Your Java Heap Memory Size

In this article, we will show you how to use the -XX:+PrintFlagsFinal to find out your heap size detail. In Java, the default and maximum heap size are allocated based on this – ergonomics algorithm.


Heap sizes
Initial heap size of 1/64 of physical memory up to 1Gbyte
Maximum heap size of 1/4 of physical memory up to 1Gbyte

Spring MVC And Excel File

In this Post we will see step by step use of AbstractExcelView class in Spring MVC application to export data to Excel file for download.

In this sample we are going to export data to Excel file via Apache POI library.



Monday 4 August 2014

Java Virtual Machine Internals

This article explains the internal architecture of the Java Virtual Machine (JVM).