Posts

Showing posts from April, 2015

How SQL Indexes Work internally ?

Image
When an index is created, it records the location of values in a table that are associated with the column that is indexed. Entries are added to the index when new data is added to the table. When a query is executed against the database and a condition is specified on a column in the WHERE clause that is indexed, the index is first searched for the values specified in the WHERE clause. If the value is found in the index, the index returns the exact location of the searched data in the table. Figure 16.1 illustrates how an index functions. Suppose the following query was issued: SELECT *  FROM TABLE_NAME WHERE NAME = 'SMITH'; As shown in Figure 16.1, the NAME index is referenced to resolve the location of all names equal to 'SMITH'. After the location is determined, the data can be quickly retrieved from the table. The data, in this case names, is alphabetized in the index. A full table scan would occur if there were no index on the table and the same que

Java Documentation Tips and Tricks Referral link

A great source to know about Java Documentation. http://zeroturnaround.com/rebellabs/reasons-tips-and-tricks-for-better-java-documentation/?utm_source=mkto&utm_medium=email&utm_campaign=RebelLabsNewsletterApril

How does java Hashmap works internally,,!

What is Hashing? Hashing in its simplest form, is a way to assigning a unique code for any variable/object after applying any formula/algorithm on its properties. A true Hashing function must follow this rule: Hash function should return the same hash code each and every time, when function is applied on same or equal objects. In other words, two equal objects must produce same hash code consistently. Note : All objects in java inherit a default implementation of hashCode() function defined in Object class. This function produce hash code by typically converting the internal address of the object into an integer, thus producing different hash codes for all different objects. HashMap is an array of Entry objects: Consider HashMap as just an array of objects. Have a look what this Object is: static class Entry<K,V> implements Map.Entry<K,V> {           final K key;           V value;           Entry<K,V> next;           final int hash;   ...    }  

Mutable and Immutable Objects

Mutable Objects:  When you have a reference to an instance of an object, the contents of that instance  can  be altered Immutable Objects:  When you have a reference to an instance of an object, the contents of that instance  cannot  be altered Immutability and Instances To demonstrate this behaviour, we'll use  java.lang.String  as the immutable class and  java.awt.Point  as the mutable class. Point myPoint = new Point( 0, 0 ); System.out.println( myPoint ); myPoint.setLocation( 1.0, 0.0 ); System.out.println( myPoint ); String myString = new String( "old String" ); System.out.println( myString ); myString.replaceAll( "old", "new" ); System.out.println( myString ); In case you can't see what the output is, here it is: java.awt.Point[0.0, 0.0] java.awt.Point[1.0, 0.0] old String old String We are only looking at a single instance of each object, but we can see that the contents of  myPoint  has changed, but the contents o

When to go for Interfaces and Abstract Classes?

From Java How to Program about abstract classes: Because they’re used only as superclasses in inheritance hierarchies, we refer to them as abstract superclasses. These classes cannot be used to instantiate objects, because abstract classes are incomplete. Subclasses must declare the “missing pieces” to become “concrete” classes, from which you can instantiate objects. Otherwise, these subclasses, too, will be abstract. To answer your question "What is the reason to use interfacs?": An abstract class’s purpose is to provide an appropriate superclass from which other classes can inherit and thus share a common design. As opposed to an interface: An interface describes a set of methods that can be called on an object, but does not provide concrete implementations for all the methods... Once a class implements an interface, all objects of that class have an is-a relationship with the interface type, and all objects of the class are guaranteed to provide the functionality