Writing by shivdev on Tuesday, 24 of June , 2008 at 1:34 pm
Sometimes developers create new files and forget to add them into their VCS. Later they want to see what files are WRITABLE (not read only) that have been added (newly created) so they can be added to the version control system.
dir /a:-R /s /b *.java
The *.java above can be replaced with *.* to search for all writable files.
The Linux equivalent to find the list of writable files would be something like. You can tweak the grep and the maxdepth to suit your needs.
find . -maxdepth 100 -type f -writable | grep .java
Category: Java
Writing by shivdev on Sunday, 22 of June , 2008 at 5:03 pm
EMMA is an open-source toolkit for measuring and reporting Java code coverage. Tutorial Coming Soon…
Category: Java
Writing by shivdev on Friday, 30 of May , 2008 at 10:59 am
We recently migrated from Java 4 to Java 6 and found out that Copy To Clipboard from JTable, JTextBox etc. just didn’t work.
String selection = “Clip This”;
StringSelection data = new StringSelection(selection);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data, data);
Then I happened to notice that there was an exception on startup and it couldn’t find flavormap.properties.
FileNotFoundException:C:\Program%20Files\Java\jre1.6.0_06\lib\flavormap.properties
It occurred to me at that point that the there was a SPACE in the location “Program Files” and God Knows why thats not handled correctly. So I simply uninstalled Java 6 from its Default Location and reinstalled it in C:\jdk1.6.0_6 and that did it for me.

I did a lot of searching for solutions, but looks like nobody else ran into this problem. Hey, fixing these type of issues is what we developers get paid for, right? But Microsoft, Sun – PLEASE – Don’t point fingers at each other. Just handle these issues.
Category: Java
Writing by shivdev on Friday, 22 of February , 2008 at 5:03 pm
Find Bugs is an open source tool that looks at your source code (actually class files) and compares it with a bunch of “buggy patterns” and report potential problems. This is called a “static analysis” tool which means it analyzes your program without actually running it.
IBM has a nice tutorial Find Bugs Part 1 – Improve the quality of your code
Category: Java
Writing by shivdev on Sunday, 23 of December , 2007 at 2:53 pm
Sometimes developers require that you need to use a SPECIFIC version of a JDK or a JRE etc. To download any version of Java go to Archive: Java[tm] Technology Products Download.
Category: Java
Writing by shivdev on Saturday, 22 of December , 2007 at 2:09 pm
Here is an example of a Simple Singleton. There are 3 things to remember.
- Create a private static instance of the singleton class.
- The constructor must be private.
- There must be a static method to get the “single” instance of the singleton class.
/* This is NOT Thread Safe - This is a Simple Example of a Singleton*/
public class SimpleSingleton {
private static SimpleSingleton instance = null;
private SimpleSingleton () {
}
public static SimpleSingleton getInstance() {
// lazily create an instance
if (instance == null) {
instance = new SimpleSingleton ();
}
return instance;
}
}
Now here is an example of a Thread Safe Singleton achieved using the synchronized(instance). The reason for checking (instance == null) twice is so that we don’t want all threads to wait when getInstance() is called. Threads must wait only when instance is being created.
public class ThreadSafeSingleton {
private static ThreadSafeSingleton instance = null;
private ThreadSafeSingleton() {
}
public static ThreadSafeSingleton getInstance() {
// Threads will acquire a lock and wait ONLY if instance is NOT NULL
if (instance == null) {
// Only One Thread allowed at a time from this point
synchronized (instance) {
if (instance == null) {
instance = new ThreadSafeSingleton();
}
} // End of Synchronized Block
}
return instance;
}
}
Another Thread Safe Singleton Example
Another way of achieving a Thread Safe Singleton without worrying about synchronization, is by instantiating the Singleton object when the CLASS gets loaded (in the static block). However, the we lose the “lazy initialization” nature of the ThreadSafeSingleton shown above.
public class Singleton {
static {
// This happens when the class is loaded.
instance = new Singleton();
}
private static Singleton instance = null;
private Singleton () {
}
public static Singleton getInstance() {
return instance;
}
}
Category: Interview,Java