Posts

Showing posts from May, 2011

XML-SAX

================== =================================== When to Use SAX SAX key points  =====================================================  SAX event model is used when you want to convert existing data to XML. ITs an event-driven, serial-access mechanism for accessing XML documents. This protocol is frequently used by servlets and network-oriented programs that need to send and receive XML documents, because it's the fastest and least memory-intensive mechanism that is currently available for dealing with XML documents. SAX is fast and efficient, and its event model makes it most useful for such state-independent filtering. For example, a SAX parser calls one method in your application when an element tag is encountered and calls a different method when text is found. If the processing you're doing is state-independent (meaning that it does not depend on the elements have come before), then SAX works fine. SAX requires much less memory than DOM, because SAX does n...

Java Interview Questions

Memory Management When does GarbageCollector will run What will happen if garbage collector is not able to free memory

SQL Injection in java

SQL Interview Questions ====================================== What is sql inject attack What is sql injeciton ======================================  This is the way you can pass INVALID or VUNARABLE input parameters to query and retrive information more than expected. This is the way to break the Security of Database lavel. for eg.   Suppose you have sql query like statement     "SELECT * FROM `users` WHERE `name` = '" + userName + "';"        This SQL code is designed to pull up the records of the specified username from its table of users. You can see here that query is taking parameter dynamically. Here you may use prepared statement. At the run time value of userName variable will be added to query. If you pass the userName= ' or '1'='1  the actual statement will look like  SELECT * FROM `users` WHERE `name` = '' OR '1'='1'; If this code were to be used in an authentication procedure then this example could...

Memory Management in java

Memory management is the process of recognizing when allocated objects are no longer needed, deallocating (freeing) the memory used by such objects, and making it available for subsequent allocations.  Garbage collection solves many, but not all, memory allocation problems. You could, for example, create objects indefinitely and continue referencing them until there is no more memory available. Garbage collection is also a complex task taking time and resources of its own. =========================== When does GarbageCollector will run What will happen if garbage collector is not able to free memory =========================== Consider the possibility that the garbage collector may never even run during an application's lifetime. There is no guarantee as to when or if the JVM will invoke the garbage collector -- even if a program explicitly calls System.gc() . Typically, the garbage collector won't be automatically run until a program needs more memory than is currently ava...

Difference between Compareble and Comparator interface

What is difference between Comparable and Comparator interface 1) Comparable interface is in java.lang package Comparator interface is in java.util package ================================ 2) int compareTo(Object o1) method takes input as only object int compare(Object o1, Objecto2) method takes input as 2 object ================================ 3) java.lang.Comparable: int compareTo(Object inuptObject1) This method compares this object with inputObject1. Returned int value has the following meanings.    1. positive (this) object is greater than inuptObject1    2. zero     (this) object equals to inuptObject1    3. negative (this) object is less than inuptObject1 java.util.Comparator: int compare(Object object1, Object object2) This method compares object1 and object2 objects. Returned int value has the following meanings.    1. positive  object1 is greater than object2    2. zero ...

equals and hashCode method key points

equals and hashCode method key points The Java super class java.lang.Object has two very important methods defined in it. They are -     * public boolean equals(Object obj)     * public int hashCode() public boolean equals(Object obj) This method checks if some other object passed to it as an argument is equal to the object on which this method is invoked. The default implementation of this method in Object class simply checks if two object references x and y refer to the same object. i.e. It checks if x == y. This particular comparison is also known as "shallow comparison". public int hashCode() This method returns the hash code value for the object on which this method is invoked. This method returns the hash code value as an integer and is supported for the benefit of hashing based collection classes such as Hashtable, HashMap, HashSet if tow object are NOT equls as per equlas(object) method, then they still may have same hashCode, i.e. un...