DOS command to show listing of Writable Files

Writing by 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

Leave a comment

Category: Java

Emma – A Free Java Code Coverage Tool

Writing by 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…

Leave a comment

Category: Java

Copy To Clipboard Doesn’t work in Java

Writing by 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.


Change Default Install Location
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.

Leave a comment

Category: Java

Find Bugs

Writing by 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

Leave a comment

Category: Java

Java Downloads Archive

Writing by 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.

Leave a comment

Category: Java

Thread Safe Singleton

Writing by 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;
    }
}

Leave a comment

Category: Interview,Java

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.