Pages

Monday 9 December 2013

Difference between using Context Object and Request Object with the RequestDispatcher




Context Object with RequestDispatcher

Request Object With RequestDispatcher 

1. Using Context object with the getRequestDispatcher() its mandatory to write url starting with " / " .

1. Using Request object with the getRequestDispatcher(), its not mandatory to use " / " before url. 
2. It uses the context path of the URI

2. It uses the context path if we write
" / " before url and if we are not writing " / " then the request will be forwarded using relative path.

3. If we are not writing " / " before
 url then container will throw IllegalArgumentException exception " This given path is invalid, since it doesn't start with  / " . 

3. If we are not writing " / " before url then it forward the request using relative path.

4. For ex-

RequestDispatcher   rd = getServletContext().
getRequestDispatcher("/url");

4. For ex-

RequestDispatcher   rd = getServletContext().
getRequestDispatcher("/url");

                     or

RequestDispatcher   rd = getServletContext().
getRequestDispatcher("url") ;

Tuesday 3 December 2013

Difference between Shallow and Deep Cloning



Shallow Cloning 

Deep Cloning 

1. It is a default cloning and can be done by using clone() method.

1.It is done by the user itself by writing the code for the deep cloning.
2. Shallow cloning fails to clone object members. 

2. Using deep cloning we can able to clone object member also .

Monday 2 December 2013

Difference between include and forward of RequestDispatcher in Servlet




include()  

forward()

1. It is used to include the response to the source servlet.

1. It is used to forward the request to the other servlet or JSP page.  
2. Response get committed after including all other resources(servlet/JSP) responses.  
2. Response get committed by the RequestDispatcher object and also close the response stream. 
3. A servlet class can have multiple include statement to execute. 
3. A servlet class can have multiple forward statement conditionally but will execute only one.  
4. After executing include() control will back to the source servlet and will add information to response object. 
4. After executing forward() control will
back to the source servlet but other informations cannot be added to that response object.

Wednesday 27 November 2013

Difference between Static and dynamic polymorphism



Static Polymorphism 

Dynamic Polymorphism 

1. It is otherwise called as compiler-time polymorphism.

1.It is otherwise called as run-time polymorphism.
2. Overloading is used to achieve this.

2.Both overriding and dynamic dispatch is used to achieve this.

3. It is also called as static binding as compiler is binding the method with the object based on the argument.

3. It is called as dynamic binding as JVM will decide from which class the method will be executed based on the object assign.


4.Static method can be overloaded.

4. Static method never follow dynamic dispatch concept. 

5. All works are done at the compilation time by the compiler that's why called as static binding.

5. All works are done at the run-time by the JVM that's why called as dynamic binding.

6. It is achieved by the compiler at the compile time.

5. It is achieved by the JVM at the run-time.

Tuesday 26 November 2013

Difference between Abstract class and interface in Java





Abstract class  

Interface

1.  A class become abstract when we use ' abstract ' keyword before the class name.

1. No need of using any abstract keyword but we need to use ' interface ' keyword. 

2. We can use instance variable.

2. We cannot use any instance variable.
3. Can define static/ non-static variable.

3. Variables are by-default static.

4. Can use static/ non-static method

4. Static and non-static both cannot be used.

5. Can use private and protected with the variable 

5.  Cannot use private and protected with the variable.

6. Static and instance both initialization block are allowed. 

6. Both static and instance initialization block are not allowed.

7. Constructor are used to initialize instance variable defined in abstract class. 

7. Cannot define constructor in an interface.

8.Cannot be used for achieving multiple inheritance. 

8. It is used to achieve multiple inheritance in java.

9. Can define final and non-final method but final method should not be abstract. 

9. Cannot define final and non-final method.

10. Can define abstract and non-abstract method in an abstract class. 

10.Cannot define non-abstract method and by-default method are abstract.

11.' extends ' keywords are used to extend abstract class. 

11.' implements ' keyword are used to implement any interface.

12. It extends java.lang.Object class.

12.It cannot extend java.lang.Object class.

13. Can define main method in an abstract class. 

13.Cannot define main method in an interface.

14. Instance ' inner class ' is allowed inside as abstract class. 

14. Instance inner class in not allowed and will be converted into static inner class by compiler.

Friday 22 November 2013

Difference between Primitive type and Reference type in Java



Primitive type  

Reference type

1. It is predefined in any programming language.

1.It is predefined as well as user-defined in Object oriented language.
2. It is used to store value may be integer, decimal , floating or boolean.

2.It is used to store the reference value of the object and is of integer type.

3.Size of the primitive type are varies according to the type. 

3. Reference type has fixed size of 8 Byte.


4.It doesn't point to any object as it simply stores the required value.

4. It always points to the
corresponding object whose address is stored as a reference value. 

5. int, float,char,short,byte etc are the example of primitive type
5. String, Array,Class, interface are the examples of reference type.

Saturday 16 November 2013

What are the differences between public and private access modifier in java




Public access modifier  
Private access modifier

It is uses the public keyword in java .

It uses the private keyword in java.

Member defined using public is visible ANYWHERE.

Member defined using private is only visible to that class only

Public can be used with class.

Private cannot be used with the class

We can make an interface as public.

We cannot make an interface as private.

Thursday 14 November 2013

Difference Between Top-level class and Inner class in Java




Top-level class  

Inner class

It cannot be declared as static.

It can be declared as static.
We cannot use private and protected access modifiers with top-level class
We can use private and protected
access modifiers with inner class as it is the member of the outer class. 
It can be executed independently by the JVM with its class name.
It cannot be executed independently
but can be executed with the the help
of its outer class 
Syntax for .class file -> 
< class_name > . class
Syntax for .class file -> 
< outer_class > $ < inner_class > . class

It cannot have any local top- level class.

We can have local inner class

Saturday 2 November 2013

Difference between java and php




JAVA 

PHP

1. Java is an object oriented language

1. PHP is a scripting language. 
2. It provides better security than PHP
2. PHP has weaker security as compared to Java.
3.Frameworks are available for its every web architectural layer. 
3. No such facility available in PHP
4. Maintenance is easier . 
4. Maintenance is little difficult.
5. Project developed in java are costlier.
5. Project developed in PHP is little cheaper then Java.

Wednesday 30 October 2013

Difference between BeanFactory and ApplicationContext container

BeanFactory : 
  • BeanFactory is an interface which has one concrete cubclass called XmlBeanFactory.
    Following is the way to create BeanFactory container instance
    BeanFactory bf=new XmlBeanFactory(res);
    Resources may be of type ClasspathResource or FileSystemResources.
  • BeanFactory will be loaded lazily by default.
  • BeanFactory container does not support annotation.
  • BeanFactory does not support BeanPostProcessor.
  • BeanFactory does not support Event publishing.
  • BeanFactory does not provide a way to resolve message bundle.
ApplicationContext : 
  • ApplicationContext is an interface which has 3 concrete subclass called
    ClasspathXmlApplicationContext
    FileSystemXmlApplicationContext
    XmlWebApplicationContext
  • BeanFactory configured with ApplicationContext container will be loaded aggressively by default.
  • ApplicationContext container do support annotation.
  • ApplicationContext container do support BeanPostProcessor.
  • Application context do provide a way to resolve message bundle.

Tuesday 29 October 2013

Difference between DTD and SCHEMA

DTD :
  • DTD support only two data type called PCDATA and CDATA.
  • DTD does not alow to describe custom datatype.
  • DTD does not support XML namingspace.
  • DTD document may not be an XML document.
  • DTD's may be internal or external.
  • You can include one DTD in xml document.
SCHEMA :
  • SCHEMA support built in data type as int, long, float, doubble, String, Date etc.
  • SCHEMA allow you to describe custom datatype.
  • SCHEMA must support XML namingspace.
  • SCHEMA document must be an XML document.
  • SCHEMA must be external always.
  • You can include multiple XSD's in xml document.

Components of Log4j

There are mainly 3 components to work with Log4j :

  • Logger :
    Logger component is used to access the log statement in java class instead of printing on console.
  • Appender :
    Appender is used to write the log statement in some specific external file, network, database etc.
  • Layout : 
    Layout component is used to specify the format in which you have to write the log message.

Difference between SAX parser and DOM parser ?

SAX Parser :
  • Sax is read only parser.
  • Sax follows event driven model.
  • Using Sax you can read the data sequentially.
  • Sax occupies very less memory because only one element information will be stored in the memory at a time.
DOM Parser :
  • Dom is read write parser.
  • Dom follows tree model.
  • Using Dom you can read the data randomly.
  • Dom occupies more memory because entire object graph and memory will be loaded in main memory at a time.

Saturday 26 October 2013

Difference between compiler and interpreter



Compiler  

Interpreter

1. To compile the programme for which compiler is used.

1. To interpret the programme
for which interpreter is used.
2. Compiler is used to compile whole programme at a time and produce all
the errors after inspecting all the instructions.  

2. Interpreter is used to interpret the
programme line by line and show
immediately if found while interpreting.

3. It check the whole programme once. 

3. It checks the programme line by
line and unless we correct the error occurred in respective line it won't interpret next line.


4. It is much faster.

4. It is slower as compared to compiler.

5. C is compiled language in which compiler is used to compiler the c code.

5. Java is compiled + Interpreted
language in which compiler and interpreter both are used.