Monday, February 2, 2009

Difference between rebuild and make in jdeveloper

The difference is ...

  • Rebuild is compiling all selected .java files, regardless if an up-to-date .class file is available or not
  • Make is compiling those selected .java files for which no up-to-date .class file is available PLUS all .java files which are on the source path AND dependent on the selected .java files

Please note that in both cases the selection makes a difference:
  1. if your selection includes only .java files or packages, only files in the same project will be compiled
  2. if you select one or more projects, compilation will also include any projects which depend on the selected project(s). To prevent building a long list of dependend projects the latest builds of JDev offer the feature Build | Make Only and Build | Rebuild Only, respectively.

Monday, January 26, 2009

Java Util package doesnt have a generic tree ?

Hi
Many a times developers say that java util package doesn't support a geveric java tree
the api does have
A generic tree can be written as here and here

Google created its own collections framework that is being used in many of its applications as explained in videos 1 and 2. the project can be downloaded from here.

Friday, January 23, 2009

Oracle doesnt support dirty read

more details at


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.jdbc.OracleStatement;

public class ConnectionClass {
public ConnectionClass() {
}
public Connection getConnection() throws ClassNotFoundException,
SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@hyc65003fwks.idc.oracle.com:1521:nn11g",
"scott","tiger");
con.setAutoCommit(false);
System.out.println("isolation lvl "+con.getTransactionIsolation());
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
return con;
}

public static void main(String[] args) throws ClassNotFoundException,
SQLException {
ConnectionClass obj = new ConnectionClass();
Connection con1 = obj.getConnection();
Connection con2 = obj.getConnection();
obj.doUpdate(con1);

obj.read(con2);
con1.rollback();
con1.close();
System.out.println("again reading.......");
obj.read(con2);
con2.close();
}
int i=0;
public void doUpdate(Connection con) throws SQLException {
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

i++;
String sql = "insert into delme values('aa"+i+"')";
System.out.println("sql >>>"+sql);
System.out.println(stmt.executeUpdate(sql));
stmt.close();
}
public void read(Connection con) throws SQLException {
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from delme";
System.out.println("sql >>>"+sql);
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();

}


}
/* Exception in thread "main" java.sql.SQLException: READ_COMMITTED and SERIALIZABLE are the only valid transaction levels
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:439)
at oracle.jdbc.driver.PhysicalConnection.setTransactionIsolation(PhysicalConnection.java:3988)
at jdbcproj.ConnectionClass.getConnection(ConnectionClass.java:22)
at jdbcproj.ConnectionClass.main(ConnectionClass.java:29)
Process exited with exit code 1. */


Thursday, January 22, 2009

HashMap and null keys

most of us know a hashMap allows null keys and also null values , but what if we add two values corresponding to same null key

      map.put(null,null);
map.put(null,"D");
map.put(null,"E");

What will be the output of
System.out.println(map)

will for the null key it will print the last key value pair , i.e. as per my understanding the null key is unique and on adding more value elements to the same null key will override the old values

Convert HashMap to HashTable

How will you convert a HashMap having null values and/or keys to a hash table ?


import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HashTableHashMap
{

public static void main(String[] args) {
Map map = new HashMap();
map.put("a",null);
map.put("b","B");
map.put(null,"D");
System.out.println(map);
Hashtable ht = new Hashtable();
Set set = map.entrySet();
Iterator itr = set.iterator();
while(itr.hasNext()){
Map.Entry entry = (Map.Entry)itr.next();
Object key = entry.getKey();
Object val = entry.getValue();
if(key==null){
key = ""+null; // Or whatever you want
}
if(val==null){
val = ""+null; // Or whatever you want
}
ht.put(key,val);
}
System.out.println(ht);
}
}

Monday, January 19, 2009

iPhone apps using java

hi
this video tutorial at google provides good insight
http://developerlife.com/theblog/?p=842