Archive for October, 2010

How coding to Interface and Inheritance helped me reuse code

Before going into the details I will state the requirement:

  • I need to fetch certain records from 3 different tables into 3 ArrayLists.
  • I have 3 Classes which store the information: Lets name it- Class1, Class2, Class3.
  • All the above 3 classes implement the Interface, lets name it Interface1. The interface has a method called init(). The main task of init() is to initiate the values of the instance variables with the values obtained from the ResultSet (database). This instance is then added to one of the 3 lists define above depending on the type of the reference.

Read more…

Categories: Java Basics Tags: ,

Execute external process from within JVM using Apache Commons Exec library

Executing external command from within JVM often causes problems- be it in terms of the code to write and manage or in the ease of implementation. I had similar requirement in my Major project for my Under Graduate Degree, where in I had to launch a C program from the Java code. I ran into different issues like- the Main thread getting blocked, the GUI freezing, or reading the output streams and so on. Finally I had to give up the idea and stick with launching the external command externally 😛 Had I found the Exec library from Apache Commons then, my work would have been lot easier. Anyways better late then never. I will quickly go through how one can use Exec library to launch external programs from JVM- Its a wrapper over Java’s ProcessBuilder, Runtime.getRuntime().exe(). Read more…