Sunday, July 17, 2011

How to fix browser compatibility issues?

A normal developer never cares about the executing the application in different browsers while developing the application and he might doesn’t know that he will get lot of issues once the development is completed. This causes a big headache to him after completion of the application as he gets more number of cross browser compatibility issues and he can’t fix those instantly. 
Fixing the cross browser compatibility issues after completion of the project is night mare for the developer. He has to start fixing the issues from the starting stage of the application development.

Below is the small discussion to fix the browser compatibility issues for different browsers like Chrome, Internet Explorer and Mozilla Firefox.

Mozilla Firefox: 
The excellent feature that Firefox has is the add-ons. There are lot of add-ons you can add to Firefox in which Fire-Bug is the best add-on to fix the issues in applications while running in  the Firefox browser. When you install the fire bug add-on, one bug icon displayed on the right-bottom corner of the browser.
Once you open your application in firefox and click on the bug icon, you will see a window which contains html source code as shown in the below screenshot. The developer has to analyze the code which display on the firebug window and has to fix the issues.


The error console (Ctrl+sift+J gives the error console) of the firefox browser contains the java script errors in the site. Developer has to fix those errors by analyzing and debugging the JavaScript code.
Developer can fix the css related issues by modifying the css classes in the fire bug window.
You can view the fire bug window by just pressing the button F12.

You can read more about the Fire bug on http://getfirebug.com/whatisfirebug
 

Internet Explorer:
Microsoft is providing the developer tool along with the Internet explorer to analyze the issues in the IE. Once the proper analysis is done by the developer and he can fix the issues by updating the changes in javascript code or css classes.
Below screen shot shows the Internet Explorer developer tool. You can open this by going to Tools --> Developer Tools or by simple pressing the key F12.

You can read more on Internet Explorer developer tools on http://petelepage.com/blog/2010/06/internet-explorer-developer-tools/


Google Chrome:
By clicking on F12 button, you can open the Developer tool in the Chrome browser. Below screen shot shows the code analyzer of the Chrome browser.

You can read more on Chrome Developer tools on http://code.google.com/chrome/devtools/docs/overview.html 


I thought most of the cross browser issues comes with the javascript errors or javascript un supported methods in the browsers. If the developer cares about the javascript predefined functions while development, he can remove more number of cross browser issues.

Sunday, June 26, 2011

Make the life more colorful....

Colors are more important part of life. There are lot of colors with the combination of three major colors. Every one the world likes colors in their own way and for me, White and skyblue are favorite. Sometimes I like black too, most of my dresses are black, my shoes are black and my mobile is also black.

Here I am going to tell about the White color...

White is a symbol for peace and if you look into white for some time, your mindset will become more tension free. I think most of we choose White color for walls on that psychological reason.




So, bring more white color into your life from the black.


Below is the small collection on colorful life from the web...

Saturday, May 21, 2011

The Servlet init Vs Constructor

Generally Servlets don’t have the Constructor, because a servlet is just like an applet in the respect that it has an init() method that acts as a constructor, an initialization code you need to run should be place in the init(), since it get called when the servlet is first loaded.

You cann’t use a Constructor instead of init() method to initialize a servlet.The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext. 

Even while you trying to override the init() method you should pass the argument a ServletContext object because the container passes the ServletConfig object to the servlet only when it calls the init method. So ServletConfig will not be accessible in the constructor.

Servlet Life Cycle

A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.

The methods which are used to initialize a servlet, to service requests, and to remove a servlet from the server are called servlet life cycle methods. These are three methods namely init(), service(), destroy().

Init(): The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests
It Contains all information code for servlet and is invoked when the servlet is first loaded.
You can override this method to write initialization code that needs to run only once, such as loading a driver, initializing values and soon, another case you can leave normally blank.

public void init(ServletConfig config)throws ServletException

Service() : is called by the Servlet container after the init method to allow the servlet to respond to a request. Service method receives the request from the client and identifies the type of request and delegates them to doGet() or doPost() for processing.

public void service(ServletRequest request,ServletResponce response) throws ServletException,  IOException

Destroy() : The Servlet Container calls the destroy( ) before removing a Servlet Instance from Sevice. Executes only once when the Servlet is removed from Server.

public void destroy() 


Click here to know about Servlets

Java Servlets

Servlet is a Java class used to extend the capabilities of servers that host applications accessed via a request-response programming model. Although servlets can respond to any type of request(like HTTP, FTP), they are commonly used to extend the applications hosted by Web servers.


Servlets runs at Server side typically Web Server or Application server, and respond to request by giving the response to user after processing the request. 


A servlet that implements SingleThreadModel means that for every request, a single servlet instance is created. This implementation helps in implementing the business applications like bank transactions. 


A multi-threaded servlet means that one servlet is capable of handling many requests which is the way most servlets should be implemented. This allows servlets to support systems such as on-line conferencing.


A servlet can handle multiple requests concurrently, and can synchronize requests. Servlets can forward requests to other servers and servlets.


As Servlet are written in java, they can make use of extensive power of the JAVA API,such as networking and URL access, multithreading, databaseconnectivity, RMI object serialization.

A Servlet implementation can be done in three ways:

  1. By implementing the Sevlet interface into your class. The class which implementing the Servlet interface, should implement all the servlet life cycle methods defined in the Servlet interface.
  2. By writing a subclass to GenricServlet present in the javax.servlet package. The subclass must override the abstract service method present in the Generic servlet class.
  3. By writing a subclass to HttpServlet present in javax.servlet.http package. The subclass of HttpServlet must override any of the methods in doGet(), doPost(), doDelete(), doPut(), init(), destroy(), getServletInfo().


In general most of the cases Servlet implementation can done by sub classing to GenericServlet or HttpServlet.
Below are the differences between HttpServlet and GenericServlet:
  1. HttpServlet is the subclass of GenericServlet.
  2. Generic Servlet defines a generic, protocol-independent servlet. HttpServlet provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site.
  3. A sub class which extends GenericServlet must implement the abstract service() method. A subclass of HttpServlet must override at least one method, usually one of these: doGet(), doPost(), doDelete(), doPut(), init(), destroy(), getServletInfo().

Click here to know Servlet Life cycles

Abstract class in Java

Abstract class is class which has more than one abstract method which doesn’t have method body but at least one of its methods need to be implemented  in derived Class.  
Abstract classes can be used to implement the inheritance relationship between the classes that belongs same hierarchy.
  1. Classes and methods can be declared as abstract.
  2. Abstract class can extend only one Class.
  3. If a Class is declared as abstract , no instance of that class can be created.
  4. If a method is declared as abstract, the sub class gives the implementation of that class.
  5. Even if a single method is declared as abstract in a Class ,  the class itself  can be declared as abstract.
  6. Abstract class have at least one abstract  method and others may be concrete.
  7. In abstract Class the keyword abstract must be used for method.
  8. Abstract classes have sub classes.
  9. Combination of modifiers Final and Abstract is illegal in java.
The general form of abstract class is :     
    abstract type name (parameter list);

The Number class in the java.lang package represents the abstract concept of numbers. It makes sense to model numbers in a program, but it doesn't make sense to create a generic number object.

Sample Abstract Classes: HttpServlet, GenericServlet 

You can more avout Interface here 
Click here for Difference between Abstract class and Iterface

Interface in Java

Interfaces can be used to implement the Inheritance relationship between the non-related classes that do not belongs to the same hierarchy, i.e. any Class and any where in hierarchy.  Using Interface, you can specify what a class must do but not how it does.
  1. A class can implement more than one Interface.
  2. An Interface can extend one or more interfaces, by using the keyword extends.
  3. All the data members in the interface are public, static and Final by default.
  4. An Interface method can have only Public, default and Abstract modifiers.
  5. An Interface is loaded in memory only when it is needed for the first time.
  6. A Class, which implements an Interface, needs to provide the implementation of all the methods in that Interface.
  7. If the Implementation for all the methods declared in the Interface are not provided , the class itself has to declare abstract, other wise the Class will not compile.
  8. If a class Implements two interface and both the Intfs have identical method declaration, it is totally valid. 
  9. If a class implements two interfaces both have identical method name and argument list, but different return types, the code will not compile.
  10. An Interface can’t be instantiated. Intf Are designed to support dynamic method resolution at run time.
  11. An interface can not be native, static, synchronize, final, protected or private.
  12. The Interface fields can’t be Private or Protected.
  13. A Transient variables and Volatile variables can not be members of  Interface.
  14. The extends keyword should not used after the Implements keyword, the Extends must always come before the Implements keyword.
  15. A top level Interface can not be declared as static or final.
  16. If an Interface species an exception list for a method, then the  class implementing the interface need not declare the method with  the exception list.
  17.  If an Interface can’t specify an exception list for a method, the class can’t throw an exception.
  18.  If an Interface does not specify the exception list for a method, the class can not throw any exception list.
The general form of Interface is
Access interface name {
         return-type method-name1(parameter-list);
            type final-varname1=value;
          }
-----------------------
Marker Interfaces :  Serializable, Clonable, Remote, EventListener

Marker Interface is an Interface which does not have any method declarations. They are used to mark/tag the nature of the class. 

Click here to More about Abstract class
Click here for more about Difference between Abstract class and Interface

Need of Real beauty to my second part of my life

I am in need of a Real Beauty to be with me in my second part of the life as I have going to cross my bachelor life. At this point i am very happy to share my views about My Real beauty. The real beauty is not just a human being; it might be the place, object, animal etc… Here I am going to write about a beautiful lady, who should have real beauty characteristics to become part of my life.


Dove Real Beauty on Yahoo! India
I have used the word beauty on ladies by looking at their face so many times in the past. But once I decided to choose a real beauty as part of my life, then I used to think about how can I define a real beauty and  what a real beauty is?. Sometimes I found that it is a hard to define or describe about the beauty of women. But, after understanding of real beauty I would expecting few of the characters as part of my partner. 


The concept of beauty, in fact, is different from person to person. Anyone can tell you their personal definition of beauty: who they think is beautiful and who isn’t. 


Small Definition of Beauty…..


So what is Beauty? Beauty is a characteristic of a person, place, object or idea that provides a perceptual experience of pleasure, meaning or satisfaction. Beauty may occur in different form, physical beauty of female, inner beauty of kind man, graceful beauty of grandeur dame and even ordinary beauty of common people.


As we seeing every day, beauty contests like Miss Universe and shows like Extreme Makeover, as well as People Magazine featuring the most beautiful people in the world. If we observe clearly the competitions, we can have a true definition of a real beauty?.The concept of these shows is, the competitors should have internal beauty including the external beauty. As per this assumption only winner will be decided.


So, beauty is just not a person face or person body structure; it is also a characteristic of a person. 


True beauty doesn't need any kind of ornaments. It is a gift from God to Human beings. The person who gets blessed by nature gets blessed with precious beauty.


Expectations of My Real Beauty characters: 
  • She should have well outside beauty like The Moon.
  • She should have cool mind like an Ice.
  • She should have a kindly heart like The Ocean.
  • She should too kind like Mother.
  • She should help to others like Tree.
  • Her thoughts should be cleaner like Milk. 
This is my view about the real beauty. Different persons will have different views. So, others might have not consider all these points.

Thank you.

Wednesday, May 18, 2011

Java Singleton Design pattern

A class which must create only one object (ie. One instance) irrespective of any number of object creations based on that class.

Steps to develop single ton class:- 
1.Create a Private construcor, so that outside class can not access this constructor. And declare a private static reference of same class
2.Write a public Factory method which creates an object. Assign this object to private static Reference and return the object

Sample Code:-


public class SingleTonExample

{
private static SingleTonExample st=null;
private SingleTonExample()
{
System.out.println(“\nIn constructor”);
}
public static SingleTonExample getInstance()
{
if(st==null)
st=new SingleTonExample();
return st;
}
}

How to use the Singleton class created above is described in below class:

public class UsingSingletonClass{
             public void testMethod(){
               SingleTonExample st = SingleTonExample.hetInstance();
               //you can use the SingleTonExample object st for your requirements
}

}