RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Sunday, December 4, 2011

Classic Singleton example

A classic and fool-proof example of Singleton sample is as follows,

Considering that we need to create a singleton for an Employee object(some POJO, for easier understanding), a Singleton can be expressed as,

class SampleSingleton{
private static Employee empObject= new Employee();
public static Employee getEmployee(){
return empObject;

On start up, I create a singleton object and assign it to the empObject, and each time I only send that single object to the caller.

Thursday, August 4, 2011

Deadlock via Threads sample

A sample demonstration of deadlock.
Here it goes.

public class DeadlockSample {

public static void main(String[] args) {
final DeadlockSample d = new DeadlockSample();
final DeadlockSample d1 = new DeadlockSample();
Thread t1 = new Thread() {
public void run() {
System.out.println("Thread t1 before entering synchronized block d");
synchronized (d) {
System.out.println("Thread 1: locked d");

try {
} catch (InterruptedException e) {
System.out.println("Thread t1 before entering synchronized block d1");
synchronized (d1) {
System.out.println("Thread 1: locked d1");

Thread t2 = new Thread() {
public void run() {
System.out.println("Thread t2 before entering synchronized block d1");
synchronized (d1) {
System.out.println("Thread 2: locked d1");

try {
} catch (InterruptedException e) {
System.out.println("Thread t2 before entering synchronized block d");
synchronized (d) {
System.out.println("Thread 2: locked d");

On execution,

Thread t1 before entering synchronized block d
Thread 1: locked d
Thread t2 before entering synchronized block d1
Thread 2: locked d1
Thread t1 before entering synchronized block d1
Thread t2 before entering synchronized block d

and the program goes into a deadlock. Each Thread waits for the other to complete.

Wednesday, February 16, 2011

JDK, Ant and Tomcat6 installation in ubuntu


Before a new installation is to be done, I prefer to un install the previous versions.

Open your Terminal(alt + shift + T) and do the following

first remove any previous versions of java using the

"sudo apt-get remove sun-java6-" command.

Than to install a new version of java,

type in

"sudo apt-get install sun-java6-jdk"

Type Y if prompted for Do u want to continue..

This is the preferred jdk to work on.

java Plugins can be added using the "sudo apt-get install sun-java6-plugin " command

If we need to install ant, just enter "sudo apt-get install ant"

Type Y if prompted for Do u want to continue..

To Install tomcat6,

the command to be used is "sudo apt-get install tomcat6"

Cheers :D

Thursday, February 10, 2011

Load Testing Tool For GWT

Long time no see......
Wondering what I was doing so long??

Well, lot of changes, actually..
I have moved over to using Ubuntu from Windows, and currently I am working on web app development using GWT, Spring and Hibernate.
Post application development, it's now the season of Testing!
Currently, I am on the lookout of a Load Testing tool for GWT.
Though there are tools out there in the web, search for a Load testing tool that uses GWT that supports Linux is getting more difficult each day..
This is my current status!

Friends, In case you come across any Load testing tool, let me know.


Monday, July 5, 2010

MVC Design Pattern

Originated from Smalltalk, MVC stands for Model-View-Controller.


Denotes the data objects, model comprises of everything that's being modified and presented to the user.


View is the screen representation of the model. The current state of the data objects is presented using this object.


Controller defines the way the User Interface reacts o the input given by the user. the data objects (Model) is manipulated using the Controller component.

Benefits of using the MVC:

Reliability(Clear seperation between the presentation and transaction layers)

High reuse and Adaptability(Multiple types of views can be used with the same server-side code)

Very low development and life Cycle costs:(Even low level programmers can develop and maintain the UI)

Rapid Deployment:(Development time can be reduced as UI designers focus)

Tuesday, May 11, 2010

CGI and Advantages Of Java Servlets Over Perl


There are two things a Web Server Application alone can't do:
1) Generate Dynamic Content (generating dynamic / on-the-fly web pages)
2) Perform Operations with form Data.
To perform these operations, the web server application uses helper applications.
These helper Applications perform the operations and sends information back to the web server application. (The web server application thinks that the page received is just another static page.)

The non-Java term for the helper application is CGI(Common Gateway Interface).

Most CGI programs were written using Perl and now I would like to bring out the advantages of Java over Perl.
* Java is Performance effective. With Perl, the server has to launch a heavy weight process for each and every request for that resource.
* Now we might get a thought that similarly in Java, each instance of the JVM would be a heavy weight process.
* In our case, Servlets stay loaded only once. Client requests for a servlet resource are handled as seperate Threads of the single running Servlet. We don't have the overhead of starting the JVM and loading the class.
* It can be pointed out that Web servers are able to keep a single Perl program running between clients, but, the point is not all web servers can do that. It's a special case which doesn't apply to all Perl CGI programs.
* Furthermore, Servlets can be a J2EE Client, whereas a Perl CGI Program cannot!

More to be discussed with respect to J2EE Clients.

What's a MIME type

The Content-Type response header's value in the HTTP Response is known as MIME type.
The MIME type tells the browser what kind of data the browser is about to receive so that the browser will know how to render that. The MIME type is any of the types sent in the HTTP Request's "Accept:" Header.


In the HTTP POST Request, if we have

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/

Content-Type: text/html
is the possible MIME type sent using the HTTP Response.