Performance measures in Pl/Sql

Cases should be avoided –1. DO NOT use FUNCTIONS (,TO_NUMBER ,Decode,NVL, TO_CHAR) unnecessarily when a simple join would work
2. DO NOT use ‘SELECT *’ explicitly. Make sure that you select only required columns from the tables.
3. DO NOT use HAVING clause where a WHERE clause would do.
4. DO NOT use ORDER BY clause in a query unless necessarily by logic.
5. DO NOT use UNION and DISTINCT together in a single query
6. DO NOT use CURSOR LOOPS unnecessarily when a simple/single DML/SELECT can serve the purpose
7. DO NOT use DUAL table unnecessarily in programs and queries.

Cases should be followed –
1. Use UNION ALL as far as possible instead of UNION.
2. Use single/direct DML’s/SELECT’s instead of LOOP’s.
3. Use BULK COLLECT & FORALL for looping when the loop is going to get executed multiple time (take > 100 iterations as a base).
4. Use MATERIALIZED VIEWS or GLOBAL TEMPORARY TABLE for queries fetching data across dblinks
5. Use EXISTS in place of IN in the queries.
6. Care should be taken to use the LIMIT clause while using BULK operations in order to limit memory utilization. LIMIT should be set between 500-1000 and reduced or decreased as per performance behavior of the program

References – http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#i48876
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/design.htm#i29012

pimp it

Marker interface in java

Marker interface is a interface which don’t have any mehtod.It is used to tag the implementing class based on their purpose.Marker interface is a Java interface which doesn’t actually define any fields. It is just used to “mark” Java classes which support a certain capability –the class marks itself as implementing the interface. For example, the java.lang.Cloneable interface.
In java language programming, interfaces with no methods are known as marker interfaces or tagged interface.Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.Marker interfaces are understood by the JVM. The JVM takes care of how to deal with a class that implements that marker interface

Why we use marker interface.
The marker interfaces are used to provide certain functionality to classes you code. Take for instance the Cloneable interface. This interface is implemented by the JVM itself and allows copies of objects to be created without the developer having to write code for this purpose. User written marker interfaces can also be used for inheritance purposes.Marker Interfaces are used to mark the capability of a class as implementing a specific interface at run-time.

Example of marker Interface.

java,lang.Cloneable
java,io.Serializable
java.util.EventListener

pimp it

Anonymous Classes in Java

A type of inner class that has no name that you define right in the middle of a method (where static init blocks and instance init blocks count as methods). You define it, and create an object of that type as a parameter all in one line. An anonymous class is defined and instantiated in a single succinct expression using the new operator.Used for creating simple delegate callback objects.These anonymous inner classes can access the static and instance variables of the enclosing outer class.
Instead of passing arguments to a constructor, your inner class methods can reach out and grab what they need directly from local variables in the enclosing method. The other technique is to use an instance initialiser block. You are only allowed one per anonymous inner class.
Syntax for Anonymous Classes
new class-name ( [ argument-list ] ) { class-body }

package Vinay; 
public class VinayMain
{ 
public static void main(String[] args) 
{ 
// Here is where the anonymous class is defined and instantiated // 
Runnable vinayrun = new Runnable() 
{
int Total = 0; 
public void run() 
{ 
for (int i=0; i<10000000; i++) 
{
Total++;
} 
System.out.println(Integer.toString(Total)); 
 } 
 }; 
vinayrun.run(); 
} 
 }

create an instance, named vinayrun , of a nameless (anonymous) class which implements the java.lang.Runnable interface.And we are calling the run mehtod of anonymous class through vinayrun object.

Drawback– The big drawback with anonymous classes is they can’t have explicit constructors. You can’t pass them any parameters when they are instantiated.

Benefits of Anonymous Classes
The key benefit of an anonymous class is encapsulation (or clutter reduction). An anonymous class is, in a sense, the ultimate in private object oriented encapsulation. It is defined exactly where it is needed, it can never be used anywhere else, and it has totally local scope.One final key benefit of anonymous classes is that they have access to all data and methods of their containing classes, including private members; meaning that for small highly localized tasks, they may require less initialization.

References –
http://ssmela.googlepages.com/AnonymousClassesinJava.pdf
http://mindprod.com/jgloss/anonymousclasses.html