Difference between StringBuffer & StringBuilder


StringBuffer:

  1. Every method present in StringBuffer is Synchronized

  2. At a time only one thread can operate on StringBuffer object. Hence StringBuffer is thread safe

  3. Relatively performance is low

  4. Introduced in 1.0v

StringBuilder:

  1. No method present in StringBuilder is Synchronized

  2. Multiple threads can operate on StringBuilder object. Hence StringBuilder is not thread safe

  3. Relatively performance is high

  4. Introduced in 1.5v

differce between jdk,jre and jvm


JDK: jdk is an acronym for Java Development Kit(JDK).It provides environment to develop & run java applications.It contains JRE + development tools.
                                     JDK = JRE + tools
JRE: jre is an acronym for Java Runtime Environment(JRE).It is used to provide runtime environment.It contains libraries and JVM.
                                     JRE = JVM + Libraries
JVM: jvm is an acronym for Java Virtual Machine(JVM).It is a specification that provides runtime environment.JVM is platform dependent.

servlet cookies in java


javax.servlet.http
Class Cookie

public class Cookie

                         extends java.lang.Object

                         implements java.lang.Cloneable

cookies are a small amount of information sent by a servlet to a Web browser,saved by the browser, and later sent back to the server. A cookie’s value can uniquely identify a client, so cookies are commonly used for session management.

A cookie contain  a name, and a value.

The browser is expected to support 20 cookies.

The cookie size is 4 KB.

The cookie contains only one constructor 

public Cookie(java.lang.String name, java.lang.String value)
some of the methods of cookies are

public void setComment(java.lang.String purpose)

public java.lang.String getComment()

public void setDomain(java.lang.String pattern)

public java.lang.String getDomain()

public void setMaxAge(int expiry)

public int getMaxAge()

public void setPath(java.lang.String uri)

public java.lang.String getPath()

public void setSecure(boolean flag)

public boolean getSecure()

public java.lang.String getName()

public void setValue(java.lang.String newValue)

public java.lang.String getValue()

public int getVersion()

public void setVersion(int v)

public java.lang.Object clone()

ServletConfig


javax.servlet
Interface ServletConfig

public interface ServletConfig

ServletConfig is a servlet container object 

ServletConfig object is created at the time of application initialization

ServletConfig methos are show below 

1. public java.lang.String getServletName()

2.  public ServletContext getServletContext()

3.  public java.lang.String getInitParameter(java.lang.String name)

4.  public java.util.Enumeration getInitParameterNames()

   

explain about filters in servlets


javax.servlet
Interface Filter

Filter concept is introduced in Servlet 2.3

javax.servlet.Filter contains the following methods

1.   void init(FilterConfig filterConfig)

                        throws ServletException

2.  void doFilter(ServletRequest request,

                                  ServletResponse response,

                                 FilterChain chain)

              throws java.io.IOException,ServletException

3.  void destroy()