Defining DSN on the fly in java
Talking about the traditional way of connecting to database involves.. Defining a driver making a dsn in the administrator console etc. Here is a short way in which you don’t need to worry about setting a dsn everytime project location gets shifted.
You can use the JDBC-ODBC but define your DSN “on the fly” by passing all ODBC configuration params inside the connect string:
// example for db test1.mdb, user dba, pw sql con = DriverManager.getConnection(
"jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};
DBQ=C:/data/Access/test1.mdb","dba","sql");
Look out: 1 blank before (*.mdb) !!!
Don’t forget the Class.forName() before!
New Features of JDK 1.5
One most common question which I faced in 4/7 interviews for my campus recruitment drive was the topic of this post.
The most prolific feature that comes as an advancement over previous version is “generics and collections”. This feature allows us to come in new era of data structures. It includes enhanced packages for arraylists, vectors, linkedlists etc. and even provides a lots of support for variance in enterprise environment.
New Features in JDK 1.5 Virtual Machine
JDK 1.5 garbage collector comes with a unique capability called ergonomics over previous version. This gives a set of tuners or command line options for the programmer to tune the garbage collector without peeping into the code itself. This includes a lots of new profilers and type setters.
Garbage Collection
Garbage Collection is a mechanism through which a compiler takes care of unreferenced allocations off the heap. A garbage collection routine mainly fires up when the heap gets filled or small chunks are left. Here are some of the types of collectors.
Reference Counting – Some data is maintained for each allocation. This includes a counter which takes the total number of references to it. A collector runs periodically and collects all allocations with count zero.
Concurrent – This collector runs one thread of application for collection. In this way we don’t need to wait for the collection. Stopping of applications is done only when the collector thread is initialized.
Mark And Sweep – One of the most popular collector in which the referenced pointers are marked and rest of the allocations are sweeped out or collected. This needs stopping of all processes.
Mark Compact -This technique adds the compaction after sweeping to cover probs of external fragmentation.
Copying Collector – This is and advancement for mark and sweep. This type of collector copies the marked allocations to the different space and collects all of previous once all copying is done.
Parallel Copying Collector – The parallel copying collection is a version of copying collection that runs as many threads as there are CPUs, preventing the workload from being restricted to only one CPU. The standard copying collection is unable to spread the workload to different processors, which creates an unnecessary bottleneck in performance.
Generational Collector – This is a scheme of collection for controlling frequency. Generations of collections are made which are usually heap space division. Each generation may have different collector. Allocations are transferred to the older generation if they survive through a defined number of collections. The collector for older generation runs less frequently than younger one. Java uses 2 generations for its work and .Net compiler has 3 generations.
JVM 1.5 Open Source
In the last year, I got the opportunity to work on virtual machine for java. As mentioned, it is really hard to compile the code for proceeding on to the work. The source code needs a lots of specified preinstallations for making every part of it compiled. This includes gcc, gnumake, alsa, etc. Another problem arises in getting the matching specifications available. So, the next way is to parse through the make files. (Make files hold the key to the compilation flow and specifications). The make files of deploy, comtrol and j2se modules hold the specifications callings. So, we can change the specifications as per our requirements. There is a risk of upcoming errors because of this but they are less hazardous then these..
It takes 6-8 hrs for compilation of code on a linux machine with good configuration.