To be Happy or not to be....????
Couple of days before i read in a newspaper that said,"India's youth population will definetly surpass China's development by 2020"
But the next day i read in the same newspaper that said, " Blood pressure and Diabetes are the 2 commonly found disease in the school going children especially who are less than 10Yrs ,because of the hectic study schedule and lack of play area".
Nagz
Friday, October 08, 2010
Monday, March 09, 2009
Various Methods of Implementing Singleton:
public class Singleton {
/*
*
* Type 1
*
* Advantages : Best of all the implementations available
* Thread safe
* Works on all version of jvm
*
*
protected Singleton(){
System.out.println("Singleton Contructor Called...");
}
private static class SingletonHolder{
private final static Singleton singleton = new Singleton();
}//End of class SingletonHolder
public static Singleton getInstance(){
return SingletonHolder.singleton;
}
*/
/*
*
* Type 2
*
* Advantage : Very basic singleton pattern .
* Works on all JDK Version
*
* Disadvantages : Not a thread safe
*
private Singleton(){}
private static Singleton singleton = null;
public Singleton getInstance(){
if(singleton==null){
singleton = new Singleton();
}
return singleton;
}
*/
/*
*
* Type 3
* Advantages : Thread Safe algorithm
* Disadvantages : Blocks to acquire a lock
*
*
private static Singleton singleton = null;
private Singleton(){};
public Singleton getInstance(){
if(singleton==null){
synchronized(Singleton.class){
singleton = new Singleton();
}//End of synchronized block
}//End of if
return singleton;
}
*/
/*
*
* Type 4
*
*Advantages : No Synchronized blocks and hence no locking
* Readily available . *Disadvantages : Not a lazy loaded singleton.
*
*
private static Singleton singleton = null;
static {
singleton = new Singleton();
}
private Singleton(){};
public Singleton getInstance(){
return singleton;
}
*/
}//End of class Singleton
public class Singleton {
/*
*
* Type 1
*
* Advantages : Best of all the implementations available
* Thread safe
* Works on all version of jvm
*
*
protected Singleton(){
System.out.println("Singleton Contructor Called...");
}
private static class SingletonHolder{
private final static Singleton singleton = new Singleton();
}//End of class SingletonHolder
public static Singleton getInstance(){
return SingletonHolder.singleton;
}
*/
/*
*
* Type 2
*
* Advantage : Very basic singleton pattern .
* Works on all JDK Version
*
* Disadvantages : Not a thread safe
*
private Singleton(){}
private static Singleton singleton = null;
public Singleton getInstance(){
if(singleton==null){
singleton = new Singleton();
}
return singleton;
}
*/
/*
*
* Type 3
* Advantages : Thread Safe algorithm
* Disadvantages : Blocks to acquire a lock
*
*
private static Singleton singleton = null;
private Singleton(){};
public Singleton getInstance(){
if(singleton==null){
synchronized(Singleton.class){
singleton = new Singleton();
}//End of synchronized block
}//End of if
return singleton;
}
*/
/*
*
* Type 4
*
*Advantages : No Synchronized blocks and hence no locking
* Readily available . *Disadvantages : Not a lazy loaded singleton.
*
*
private static Singleton singleton = null;
static {
singleton = new Singleton();
}
private Singleton(){};
public Singleton getInstance(){
return singleton;
}
*/
}//End of class Singleton
JDBC Url Pattern for Oracle 10i:
Recently while i was trying to configure Sun One Application Server with Oracle 10i
i found out that the traditional method of jdbc url pattern [jdbc:oracle:thin@myhost:port:service]
not working .
Then after spending some time in searching the net, i found that in 10i the jdbc url pattern has changed to "jdbc:oracle:thin:username/password@//myhost:1521/orcl".
NOTE:
Difference Between Service & SID:
Oracle SID is the unique name that uniquely identifies an instance/database.
Service name is the TNS alias for a database and this Service name is recorded in Tnsnames.ora file on your clients and it can be the same as SID (the default) or may be different.
Recently while i was trying to configure Sun One Application Server with Oracle 10i
i found out that the traditional method of jdbc url pattern [jdbc:oracle:thin@myhost:port:service]
not working .
Then after spending some time in searching the net, i found that in 10i the jdbc url pattern has changed to "jdbc:oracle:thin:username/password@//myhost:1521/orcl".
NOTE:
Difference Between Service & SID:
Oracle SID is the unique name that uniquely identifies an instance/database.
Service name is the TNS alias for a database and this Service name is recorded in Tnsnames.ora file on your clients and it can be the same as SID (the default) or may be different.
Sunday, July 20, 2008
Initialize on Demand Holder Class & Singleton
public class S {
private S() {}
private static class SHolder {
private static S s = new S();
}//End of Class SHolder
public static S getInstance() {
return SHolder.s;
}//End of getInstance
}//End of class S
Description:
The reason you need the inner class to hold the instance is if you have other static methods you want to be able to call without creating the singleton instance.
Static members are created when the class is first used, so calling another static method causes all static data (including the instance variable) to be initialized. By putting it in an inner class, only when the inner class is first referenced (which should only be during calls to the outer class's getInstance()) does the instance get created.
Basically the static inner class is slightly more lazy, but you'll only notice the difference if there are other static methods on your singleton class that are called before getInstance(). In general, I'd say it's bad practice to do that (static methods other than getInstance() on a singleton), but I guess some people must do that.
public class S {
private S() {}
private static class SHolder {
private static S s = new S();
}//End of Class SHolder
public static S getInstance() {
return SHolder.s;
}//End of getInstance
}//End of class S
Description:
The reason you need the inner class to hold the instance is if you have other static methods you want to be able to call without creating the singleton instance.
Static members are created when the class is first used, so calling another static method causes all static data (including the instance variable) to be initialized. By putting it in an inner class, only when the inner class is first referenced (which should only be during calls to the outer class's getInstance()) does the instance get created.
Basically the static inner class is slightly more lazy, but you'll only notice the difference if there are other static methods on your singleton class that are called before getInstance(). In general, I'd say it's bad practice to do that (static methods other than getInstance() on a singleton), but I guess some people must do that.
Wednesday, July 02, 2008
Thursday, September 20, 2007

Tongue Twisters
Peter bought a butter,
The butter Peter bought was bitter,
So Peter Bought A better butter,
To make the bitter butter better.
How much wood would a woodchuck chuck
if a woodchuck could chuck wood?
He would chuck, he would, as much as he could,
and chuck as much wood as a wood chuck would
if a woodchuck could chuck wood.
Which witch wished which wicked wish?
Peter Piper picked a peck of pickled peppers.
Did Peter Piper pick a peck of pickled peppers?
If Peter Piper picked a peck of pickled peppers,
where's the peck of pickled peppers Peter Piper picked?
She sells sea shells by the sea shore.
The shells she sells are surely seashells.
So if she sells shells on the seashore,
I'm sure she sells seashore shells.
A flea and a fly flew up in a flue.
Said the flea, "Let us fly!"
Said the fly, "Let us flee!"
So they flew through a flaw in the flue.
Betty Botter had some butter,
But, she said, "this butter's bitter.
If I bake this bitter butter, it would make my batter bitter.
But a bit of better butter that would make my batter better.
So she bought a bit of butter,
better than her bitter butter,
And she baked it in her batter,
and the batter was not bitter.
So 'twas better Betty Botter bought a bit of better butter.
A big black bug bit a big black bear,
made the big black bear bleed blood.
Lesser leather never weathered wetter weather better.
A bitter biting bittern Bit a better brother bittern,
And the bitter better bittern Bit the bitter biter back.
And the bitter bittern, bitten, By the better bitten bittern,
Said: "I'm a bitter biter bit, alack!"
Mr. See owned a saw.
And Mr. Soar owned a seesaw.
Now See's saw sawed Soar's seesaw
Before Soar saw See,
Which made Soar sore.
Had Soar seen See's saw before See sawed Soar's seesaw,
See's saw would not have sawed Soar's seesaw.
So See's saw sawed Soar's seesaw.
But it was sad to see Soar so sore
Just because See's saw sawed Soar's seesaw!
Silly Sally swiftly shooed seven silly sheep.
The seven silly sheep Silly Sally shooed shilly-shallied south.
These sheep shouldn't sleep in a shack;
sheep should sleep in a sack...
Thursday, September 13, 2007
Just For Laugh....
* Wife: Darling today is our anniversary, what should we do?
Husband: Let us stand in silence for 2 minutes.
* It's funny when people discuss Love Marriage vs Arranged.
It's like asking someone, if suicide is better or being murdered.
* A man who surrenders when he's wrong, is Honest.
A man who surrenders when not Sure, is Wise.
A man who surrenders even if he's Right, is a Husband.
* Why do Bride & Groom exchange varmaala during wedding?
To tell each other affectionately... Sweetheart U R Dead!
* Different Phases of a man:
After engagement: Superman
After Marriage: Gentleman
After 10 years: Watchman
After 20 years: Doberman
* There is only one perfect child in the world and every mother has it.
There is only one perfect wife in the world and every neighbour has it.
* Prospective husband: Do you have a book called 'Man, The Master of Women'?
Salesgirl: The fiction department is on the other side, sir.
----------------------------------------------------------------
Marriage and funny quotes:
I recently read that love is entirely a matter of chemistry.That must be why my wife treats me like toxic waste.David Bissonette
When a man steals your wife, there is no better revenge than to let him keep her.Sacha Guitry
After marriage, husband and wife become two sides of a coin; they just can't face each other, but still they stay together.Hemant Joshi
By all means marry. If you get a good wife, you'll be happy. If you get a bad one, you'll become a philosopher. Socrates
Woman inspires us to great things, and prevents us from achieving them.Dumas
The great question... which I have not been able to answer... is, "What does a woman want? Sigmund Freud
I had some words with my wife, and she had some paragraphs with me.Anonymous
"Some people ask the secret of our long marriage. We take time to go to a restaurant two times a week. A little candlelight, dinner, soft music and dancing. She goes Tuesdays, I go Fridays." Henny Youngman
"I don't worry about terrorism. I was married for two years." Sam Kinison
"There's a way of transferring funds that is even faster than electronic banking. It's called marriage." James Holt McGavran
"I've had bad luck with both my wives. The first one left me, and the second one didn't." Patrick Murray
Two secrets to keep your marriage brimming
1. Whenever you're wrong, admit it,
2. Whenever you're right, shut up.
Nash
The most effective way to remember your wife's birthday is to forget it once...
Anonymous
You know what I did before I married? Anything I wanted to. Henny Youngman
My wife and I were happy for twenty years. Then we met. Rodney Dangerfield
A good wife always forgives her husband when she's wrong. Milton Berle
Marriage is the only war where one sleeps with the enemy.
Anonymous
A son asked his Dad how much it costs to get married. His Dad replied: I don't know son, I'm still paying.
A man inserted an 'ad' in the classifieds: "Wife wanted". Next day he received a hundred letters. They all said the same thing: "You can have mine."
Anonymous
First Guy (proudly): "My wife's an angel!"
Second Guy: "You're lucky, mine's still alive."
* Wife: Darling today is our anniversary, what should we do?
Husband: Let us stand in silence for 2 minutes.
* It's funny when people discuss Love Marriage vs Arranged.
It's like asking someone, if suicide is better or being murdered.
* A man who surrenders when he's wrong, is Honest.
A man who surrenders when not Sure, is Wise.
A man who surrenders even if he's Right, is a Husband.
* Why do Bride & Groom exchange varmaala during wedding?
To tell each other affectionately... Sweetheart U R Dead!
* Different Phases of a man:
After engagement: Superman
After Marriage: Gentleman
After 10 years: Watchman
After 20 years: Doberman
* There is only one perfect child in the world and every mother has it.
There is only one perfect wife in the world and every neighbour has it.
* Prospective husband: Do you have a book called 'Man, The Master of Women'?
Salesgirl: The fiction department is on the other side, sir.
----------------------------------------------------------------
Marriage and funny quotes:
I recently read that love is entirely a matter of chemistry.That must be why my wife treats me like toxic waste.David Bissonette
When a man steals your wife, there is no better revenge than to let him keep her.Sacha Guitry
After marriage, husband and wife become two sides of a coin; they just can't face each other, but still they stay together.Hemant Joshi
By all means marry. If you get a good wife, you'll be happy. If you get a bad one, you'll become a philosopher. Socrates
Woman inspires us to great things, and prevents us from achieving them.Dumas
The great question... which I have not been able to answer... is, "What does a woman want? Sigmund Freud
I had some words with my wife, and she had some paragraphs with me.Anonymous
"Some people ask the secret of our long marriage. We take time to go to a restaurant two times a week. A little candlelight, dinner, soft music and dancing. She goes Tuesdays, I go Fridays." Henny Youngman
"I don't worry about terrorism. I was married for two years." Sam Kinison
"There's a way of transferring funds that is even faster than electronic banking. It's called marriage." James Holt McGavran
"I've had bad luck with both my wives. The first one left me, and the second one didn't." Patrick Murray
Two secrets to keep your marriage brimming
1. Whenever you're wrong, admit it,
2. Whenever you're right, shut up.
Nash
The most effective way to remember your wife's birthday is to forget it once...
Anonymous
You know what I did before I married? Anything I wanted to. Henny Youngman
My wife and I were happy for twenty years. Then we met. Rodney Dangerfield
A good wife always forgives her husband when she's wrong. Milton Berle
Marriage is the only war where one sleeps with the enemy.
Anonymous
A son asked his Dad how much it costs to get married. His Dad replied: I don't know son, I'm still paying.
A man inserted an 'ad' in the classifieds: "Wife wanted". Next day he received a hundred letters. They all said the same thing: "You can have mine."
Anonymous
First Guy (proudly): "My wife's an angel!"
Second Guy: "You're lucky, mine's still alive."
Saturday, January 06, 2007
Basic Doubts in Java & in Databases ? Ask Mr.Nagz.
DB:Differences between Stored Procedures and Functions:
Stored Procedures (SPROC)
1.Doesn't need to return values, but can return value.
2.Stored as a pseudo-code in database.i.e compiled form.
3.Can affect the state of database using commit.
4.Cannot be invoked from SQL Statements.[SELECT]
5.Procedures are mainly used to process the tasks.
User Defined Function[UDF]
1.Should return atleast one update parameter.Can return more than one parameter using OUT argument.
2.Parsed and compiled at runtime.
3.Cannot affect the state of database.
4.Can be invoked from SQL Statements [SELECT]
5.Functions are mainly used to compute values
--------------------------------------------------------------------------------
JAVA:What are Runtime Polymorphism & Compile time Polymorphism ?
Polymorphism is defined as one interface to control access to a general class of actions.There are two types of Polymorphism .
1.Compile Time Polymorphism
Compile time polymorphism is functions and operators overloading(C++)
2.Runtime polymorphism
Runtime polymorphism is done using inheritance and virtual functions(C++)
--------------------------------------------------------------------------------
JAVA:When should I use static class and when a singleton class?
I guess when I am creating some kind of library or utility class, I will prefer static class. e.g. if I create a string utility class, where I am not saving or handling any data, I will use static methods
--------------------------------------------------------------------------------
JAVA:Why Hibernate is gaining popularity or what are the drawbacks of ejb 2.1?
CMP beans are defined in one-to-one correspondence to the tables of the
relational model. Thus, they’re too coarse grained; they may not take full
advantage of Java’s rich typing. In a sense, CMP forces your domain model
into first normal form.
On the other hand, CMP beans are also too fine grained to realize the stated
goal of EJB: the definition of reusable software components. A reusable
component should be a very coarse-grained object, with an external interface
that is stable in the face of small changes to the database schema. (Yes,
we really did just claim that CMP entity beans are both too fine grained and
too coarse grained!)
Although EJBs may take advantage of implementation inheritance, entity
beans don’t support polymorphic associations and queries, one of the defining
features of “true” ORM.
Entity beans, despite the stated goal of the EJB specification, aren’t portable
in practice. Capabilities of CMP engines vary widely between vendors, and
the mapping metadata is highly vendor-specific. Some projects have chosen
Hibernate for the simple reason that Hibernate applications are much
more portable between application servers.
Entity beans aren’t serializable. We find that we must define additional data
transfer objects (DTOs, also called value objects) when we need to transport
data to a remote client tier. The use of fine-grained method calls from the
client to a remote entity bean instance is not scalable; DTOs provide a way of
batching remote data access. The DTO pattern results in the growth of parallel
class hierarchies, where each entity of the domain model is represented
as both an entity bean and a DTO.
EJB is an intrusive model; it mandates an unnatural Java style and makes
reuse of code outside a specific container extremely difficult. This is a huge
barrier to unit test driven development (TDD). It even causes problems in
applications that require batch processing or other offline functions.
-----------------------------------------------------------------------------------
DB:Differences between Stored Procedures and Functions:
Stored Procedures (SPROC)
1.Doesn't need to return values, but can return value.
2.Stored as a pseudo-code in database.i.e compiled form.
3.Can affect the state of database using commit.
4.Cannot be invoked from SQL Statements.[SELECT]
5.Procedures are mainly used to process the tasks.
User Defined Function[UDF]
1.Should return atleast one update parameter.Can return more than one parameter using OUT argument.
2.Parsed and compiled at runtime.
3.Cannot affect the state of database.
4.Can be invoked from SQL Statements [SELECT]
5.Functions are mainly used to compute values
--------------------------------------------------------------------------------
JAVA:What are Runtime Polymorphism & Compile time Polymorphism ?
Polymorphism is defined as one interface to control access to a general class of actions.There are two types of Polymorphism .
1.Compile Time Polymorphism
Compile time polymorphism is functions and operators overloading(C++)
2.Runtime polymorphism
Runtime polymorphism is done using inheritance and virtual functions(C++)
--------------------------------------------------------------------------------
JAVA:When should I use static class and when a singleton class?
I guess when I am creating some kind of library or utility class, I will prefer static class. e.g. if I create a string utility class, where I am not saving or handling any data, I will use static methods
--------------------------------------------------------------------------------
JAVA:Why Hibernate is gaining popularity or what are the drawbacks of ejb 2.1?
CMP beans are defined in one-to-one correspondence to the tables of the
relational model. Thus, they’re too coarse grained; they may not take full
advantage of Java’s rich typing. In a sense, CMP forces your domain model
into first normal form.
On the other hand, CMP beans are also too fine grained to realize the stated
goal of EJB: the definition of reusable software components. A reusable
component should be a very coarse-grained object, with an external interface
that is stable in the face of small changes to the database schema. (Yes,
we really did just claim that CMP entity beans are both too fine grained and
too coarse grained!)
Although EJBs may take advantage of implementation inheritance, entity
beans don’t support polymorphic associations and queries, one of the defining
features of “true” ORM.
Entity beans, despite the stated goal of the EJB specification, aren’t portable
in practice. Capabilities of CMP engines vary widely between vendors, and
the mapping metadata is highly vendor-specific. Some projects have chosen
Hibernate for the simple reason that Hibernate applications are much
more portable between application servers.
Entity beans aren’t serializable. We find that we must define additional data
transfer objects (DTOs, also called value objects) when we need to transport
data to a remote client tier. The use of fine-grained method calls from the
client to a remote entity bean instance is not scalable; DTOs provide a way of
batching remote data access. The DTO pattern results in the growth of parallel
class hierarchies, where each entity of the domain model is represented
as both an entity bean and a DTO.
EJB is an intrusive model; it mandates an unnatural Java style and makes
reuse of code outside a specific container extremely difficult. This is a huge
barrier to unit test driven development (TDD). It even causes problems in
applications that require batch processing or other offline functions.
-----------------------------------------------------------------------------------




















