Posts

Showing posts from 2010

JDBC-4 hot features:

Stale connections ---isvalid():   Because a stale connection does not necessarily mean a closed connection (which might be garbage collected), connections that became unusable often took up those valuable connection resources. A new method in JDBC 4's Connection class, isValid(), allows a client to query the database driver if a connection is still valid. This allows a more intelligent management of connection pools by clients.   Preparedstaement pooling---poolable property:   While one database connection is indistinguishable from another, the same does not hold for statements: Some SQL statement are more frequently used than others in any application domain. Prior to JDBC 4, there was no way to tell such statements apart in a statement pooling environment. While every JDBC 4 PreparedStatement is poolable by default, the new poolable property allows an application to offer a hint to the statement pooler as to whether a statement should be pooled. This allows an application d

how to get total Heap Size in JVM

Runtime runtime = Runtime.getRuntime(); System.out.println("Total Heap Size of JVM"+runtime.totalMemory());

Increase JVM Heap Size for better performance.

Setting/Increase JVM heap size It is possible to increase heap size allocated by the Java Virtual Machine (JVM) by using command line options. Following are few options available to change Heap Size. 1 -Xms< size >        set initial Java heap size 2 -Xmx< size >        set maximum Java heap size 3 -Xss< size >        set java thread stack size For example, you can set minimum heap to 64 MB and maximum heap 256 MB for a Java program HelloWorld. 1 java -Xms64m -Xmx256m HelloWorld

How to examine the amount of free memory in java

Runtime runtime = Runtime.getRuntime(); System.out.println ("Free memory : " - + runtime.freeMemory() );

ArrayList or vector

ArrayList: Its not thread safe-- its unsynchronized. ArrayList can be traversed with Iterator Interface. So Its faster compared to Vector. Vector: It is thread safe and synchronized. Vector can be traversed with  Enumeration-- Interface

Non Static Variables

Can be accessed only by creating an instance. It will be not be updated when a new instance of the object is created. public class NonStaticVariables {  public NonStaticVariables() {         instancecount++;     }     private   int instancecount;     public static void main(String args[]){         NonStaticVariables nsv=new NonStaticVariables();     System.out.println(nsv.instancecount);   NonStaticVariables nsv1=new NonStaticVariables();     System.out.println(nsv1.instancecount);     } }

Static Variables

Can Be Accessed directly in the main method. Static instance variable will be updated on creating a new instance of the  object. public class StaticVaribles {     public StaticVaribles() {         instancecount++;     }     private static  int instancecount;     public static void main(String args[]){     System.out.println(instancecount);     StaticVaribles sv=new StaticVaribles();     System.out.println(instancecount);         StaticVaribles sv1=new StaticVaribles();     System.out.println(instancecount);     } } /*output run: instancecount->0 instancecount->1 instancecount->2 */

innerclasses

I nner Classes in java: Inner classes are the nested classes. example of a inner class: class MyOuter{ class MyInner{ public void display(){ System.out.println("Inner class"); } } } Type- 1: aCCESS outer class variable from inner class class MyOuter{ private int i=10; class MyInner{ public void display(){ System.out.println("Accessing private member of the outer"+i); } } } Type-2: Create an Instance of Inner class in outer class: class MyOuter{ private int i=0; public void makeInner(){ /*Creating an instance of the inner class in the outer class*/ MyInner in= new MyInner(); /*call the inner class method*/ in.display(); } class MyInner{ public void display(){ system.out.println("Accessing private memeber of the outer"+i); } } } Type-3: Create an Instance of Inner claSS from outside outerclass class MyOuter{ private int i=15; public void makeInner(){ /*Creating an instance of the inner class in the outer