The most successful people in any walks of lives may not be the most talented ones but are definately the most passionate & dedicated ones.

Wednesday, February 23, 2011

Re-defining mistake !!!





Ok,yes,it's a mistake.I know it's a mistake.
But their r certain things in life where u knw it's a mistake but u don't really knw it's a mistake bcos the only way to really knw its a mistake is to make the mistake, and look back, and say, "Yep. That was a mistake."

going by this premise

Really,the bigger mistake would be to not make the mistake, bcos then u go ur whole life not really knwng if something is a mistake or not.


And Damm the whole thing... I never made a mistake -:)


Cheers !!!

Thursday, February 17, 2011

Difference between Padma Vibhushan, Padma Bhushan and Padma Shri


Padma Vibhushan
The Padma Vibhushan is India's second highest civilian honour. It consists of a medal and a citation and is awarded by the President of India.

It is awarded to recognize exceptional and distinguished service to the nation in any field, including government service. The award was suspended between 1977 and 1980. No award was made between 1992 and 1998 as well.

The award was established by Presidential decree on 2 January 1954. It comes after the Bharat Ratna and before the Padma Bhushan. Padma Vibhushan was originally established as the Pahela Varg (First Class) of a three-class "Padma Vibhushan" awards. However the structure was changed in 1955 and there is no record of the award being presented to any of the recipients in the original structure.


Padma Bhushan
The Padma Bhushan award is an Indian civilian decoration established on January 2, 1954 by the President of India. It stands third in the hierarchy of civilian awards, after the Bharat Ratna and the Padma Vibhushan, but comes before the Padma Sri. It is awarded to recognize distinguished service of a high order to the nation, in any field.


Padma Shri
Padma Shri (also spelt Padma Shree, Padmashree, Padma Sree and Padma Sri) is an award given by the Government of India generally to Indian citizens to recognize their distinguished contribution in various spheres of activity including the Arts, Education, Industry, Literature, Science, Sports, Social Service and public life. (The word "Padma" (Sanskrit) means "Lotus".)

It stands fourth in the hierarchy of civilian awards after the Bharat Ratna, the Padma Vibhushan and the Padma Bhushan. On its obverse, the words "Padma" and "Shri", in Devanagari, appear above and below the lotus flower. The geometrical pattern on either side is in burnished bronze. All embossing is in white gold.



I felt enlighted to learn more about my country's hightest civilian honors. Hope you enjoyed it too !!!



Cheers !!!

Thursday, February 10, 2011

Why it is not advisable to declare a constructor in servlet?

Technically you can define constructors in servlet. But, the declared constructor cannot access the ServletConfig object or throw a ServletException so placing a constructor wouldn't add much value and hence we usually don't do it.

Then why is it not customary to declare a constructor in a servlet? Because the init() method is used to perform servlet initialization. In JDK 1.0 (servlet were written in this version), constructors for dynamically loaded Java classes such as servlets cannot accept arguments. Also, Java constructors cannot be declared in interfaces and javax.servlet.Servlet is an interface. Now the classes which implement this interface are GenericServlet and HttpServlet which don't do anything in these constructors [as per the API documentation].

So, javax.servlet.Servlet interface cannot have a constructor that accepts a ServletConfig parameter. To overcome this, init() method is used for initialization instead of declaring a constructor.

This is what I think, please go ahead and pen down on what you think about this and if you differ from my opinion, I assure you that you won't be the first one.



Cheers !!!
Vinay

What happens if you call destroy() from init() in a servlet ?

Well the answer [believe me I was surprised to know this] is :-
destroy() gets executed and the initialization process continues.

Explanation:-In java servlet, destroy() is not supposed to be called by the programmer. But, if it is invoked, it gets executed. The implicit question is, will the servlet get destroyed? No, it will not. destroy() method is not supposed to and will not destroy a java servlet. Don’t get confused by the name. It should have been better, if it was named onDestroy().

The meaning of destroy() in java servlet is, the content gets executed just before when the container decides to destroy the servlet. But if you invoke the destroy() method yourself, the content just gets executed and then the respective process continues. With respective to this question, the destroy() gets executed and then the servlet initialization gets completed.

If you still aren't clear, then please re-visit servlet life cycle once.


Cheers !!!
Vinay

ALL-IN-ONE (Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency)

These terms signify the relationships between classes. These are the building blocks of object oriented programming and very basic stuff. But still for some, these terms look like Latin and Greek. Just wanted to refresh these terms and explain in simpler terms.

Association
1) Association is a relationship between two objects. In other words, association defines the multiplicity between objects.
2) Different types of association between objects are:- one-to-one, one-to-many, many-to-one, many-to-many.
3) Example: A Student and a Faculty are having an association.


Aggregation
1) It is a specific case of association.
2) Aggregation is also called a “Has-a” relationship i.e. When an object ‘has-a’ another object, then you have got an aggregation between them.

Composition
1) Composition is a special case of aggregation.
2) When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.

Difference between aggregation and composition
1) When there is a composition between two objects, the composed object cannot exist without the other object. Composition is more restrictive. This restriction is not there in aggregation.
2) In aggregation, though one object can contain the other object, there is no condition that the composed object must exist. The existence of the composed object is entirely optional.
3) In both aggregation and composition, direction is must. The direction specifies, which object contains the other object.
4) Example: - Let analyze Library, Student and Books.

Relationship between library and student is aggregation because a student can exist without a library and therefore it is aggregation.

Relationship between library and book is composition because A book cannot exist without a library and therefore its a composition.

In terms of coding snippet example of difference between aggregation and composition

Aggregation Example: the object exists outside the other, is created outside, so it is passed as an argument (for example) to the constructor. Ex: People – car. The car is created in a different context and then becomes a person’s property.

****************************************************************************

// WebServer is aggregated of a HttpListener and a RequestProcessor

public class WebServer

{

private HttpListener listener;

private RequestProcessor processor;
public WebServer(HttpListener listener, RequestProcessor processor)

{

this.listener = listener;

this.processor = processor;

}

}

****************************************************************************

Composition Example: the object only exists, or only makes sense inside the other, as a part of the other. Ex: People – heart. You don’t create a heart and then passes it to a person.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

// WebServer is an composition of HttpListener and RequestProcessor & controls their lifecycle

public class WebServer

{

private HttpListener listener;

private RequestProcessor processor;
public WebServer()

{

this.listener = new HttpListener(80);

this.processor = new RequestProcessor(“/www/root”);

}

}

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

Here the key difference [wrt code snippet above] to note is that :-

In Aggregation we are passing the already instantiated objects [ HttpListener and RequestProcessor ] from outside the Webserver class so they exist independently of the Webserver class though Webserver class shares “has-a” relationship with them.

In Composition we are instantiating the classes [ HttpListener and RequestProcessor with in the Webserver class so they are dependent on Webserver class. Here also Webserver class shares “has-a” relationship with them.


Abstraction
1) Abstraction is specifying the framework and hiding the implementation level information. Concreteness will be built on top of the abstraction.
2) It gives you a blueprint to follow to while implementing the details. Abstraction reduces the complexity by hiding low level details.
3) Example: A wire frame model of a car.



Generalization
1) Generalization uses a “is-a” relationship from a specialization to the generalization class.
2) Example: (a) Consider there exists a class named Person. A student is a person. A faculty is a person. Therefore here the relationship between student and person, similarly faculty and person is generalization. (b) Lets have specialization class [Triangle and Circle] and generalization class [shape] so the relationship b/w specialization to generalization class is that every Square “is-a” Shape.



Realization
1) Realization is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to realize the blueprint class.
2) In other words, you can understand this as the relationship between the interface and the implementing class.

Dependency
Change in structure or behavior of a class affects the other related class, then there is a dependency between those two classes.

Please feel free to disagree (if you find anything wroing) on the above explanations and believe me you won't be the first one. Do spare me for any typo's above (if any). Happy-to-learn !!!


Cheers,

Vinay