Heap dump of a running JVM with jmap

Category: Uncategorized

You don’t have to wait for your JVM to die with an OutOfMemoryError to get the heap dump you get when you use the -XX:+HeapDumpOnOutOfMemoryError flag. Setting that flag is a good thing though – you get a dump after the heap is big and bloated just before the JVM dies making it easier to […]

Continue reading » 5 Comments

Java – The 4 inner/nested class types

Category: Uncategorized

If you are trying to clear your thoughts around just how many different types of inner/nested classes there are in Java, this should be a quick refresher. All but the first kind are known as inner classes. Static member classes – These will not hold on to a reference to the enclosing class. You do […]

Continue reading » 1 Comment

Double braces initialization in Java

Category: Uncategorized

This little trick is not very well known and can look like completely new syntax to the uninitiated. But it is actually a form of something you use quite frequently – anonymous inner classes. // Normal list initialization List<String> days1 = new ArrayList<String>(); days1.add("Sun"); days1.add("Mon"); days1.add("Tue"); // Double braces initialization. Compact! List<String> days2 = new […]

Continue reading » 1 Comment

Find duplicate files

Category: Uncategorized

So you know you have a bunch of files all with similar content but different file names strewn all over a directory tree. How would you identify the repetitions so that you can work towards eliminating them? Here is some CLI magic that helps you do so (sourced from CommandLineFu). find -not -empty -type f […]

Continue reading » 1 Comment

Eclipse jsp jstl error – Cannot find the tag library descriptor for http://java.sun.com/jsp/jstl/core

Category: Uncategorized

You get that error for the missing tld when standard.jar and jstl.jar are not found. If you are using maven, adding the following should fix it. <!– standard.jar –> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <!– JSTL –> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> </dependency> Try restarting Eclipse if the error doesn’t go away after adding this. Do […]

Continue reading » 4 Comments

Vi – Disable wrapping

Category: Uncategorized

So your neatly formatted csv file looks all ugly in vi because your screen isn’t wide enough? [Esc]:set nowrap[Enter] There, that will disable wrapping and your file will make sense once again.

Continue reading » 1 Comment

MySql on a RAM disk for super fast performance with the innodb storage engine

Category: Uncategorized

In a development environment, having a super fast database can be immensely helpful. If you are not lucky enough to already have an SSD in your system, you need to make yourself a RAMDisk. I had a system with 6 gig of RAM. I allocated 500 meg for a RAM Disk. You can create one […]

Continue reading » 2 Comments

Maven dependency – Local jar file from an external third party to be installed into project repository

Category: Uncategorized

Some time back, I was working on an application that involved payments processing. I worked with a payments company called DataCash. They made available a jar file with their API. Now the app I was working on used Maven for dependency management. Usually, if one needs an API to be included for use in the […]

Continue reading » 1 Comment

Time portion from your Date / DateTime / Timestamp field getting truncated when using the JDBC ResultSet?

Category: Uncategorized

Problem – You see that from Date-Time value you are saving into your database, the time part is getting truncated at some point. What on earth is happening? You may notice that if you look at the field in your database, you do see the time being persisted. So infact, it is something you are […]

Continue reading » 1 Comment

Sending a SIGBREAK signal to a Java process to do a thread dump in Windows

Category: Uncategorized

In Linux / Unix if you want a Java process to do a thread dump, you can do a kill -3 <pid>. In Windows, doing the equivalent requires sending a Ctrl+Break to the input console which results in a SIGBREAK being sent to the process. But what if you do not have an input console? […]

Continue reading » 2 Comments

Java NullPointerException Ninja – 10 facts you need to know to avoid problems with null

Category: Uncategorized

1.The instanceof operator is NPE safe. So, instanceof null always returns false. It does not cause a NullPointerException. You can eliminate messy conditional code if you remember this fact. // Unncessary code if (data != null && data instanceof InterestingData) { } // Less code. Better! if (data instanceof InterestingData) { } 2. A null […]

Continue reading » 9 Comments

Crash your JVM by killing the garbage collector!

Category: Uncategorized

My HotSpot 1.6.0_21 JVM crashes if the following code is run on it. And by “crashes”, I mean that the JVM crashes and leaves an hs_err_pid####.log file with the thread dump from the JVM itself – there is no exception from the application code. class Crash { public static void main(String[] args) { Object[] link […]

Continue reading » Comments Off on Crash your JVM by killing the garbage collector!

How to suspend VM on startup when remote debugging your Java app

Category: Uncategorized

You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched. A problem that you can run into when attempting to do this is that since the code runs right in the beginning, the JVM may rush past it before you have had a […]

Continue reading » 2 Comments

Assigning a reference to itself in Java has no effect, right? – WRONG!

Category: Uncategorized

You see this piece of code in your beloved code base…. referenceToSomethingImportant = referenceToSomethingImportant; You immediately delete it since assigning a variable to itself will never do any thing. Of course the compiler or the JIT machinery is always going to optimize it away anyway. Right? Wrong. Oh yes, there might be another thread you […]

Continue reading » 2 Comments

Atomic array classes and volatile arrays in the JVM

Category: Uncategorized

Declaring an array volatile does not do what many think it does! The common, simplistic understanding of the volatile keyword in Java is that if a variable is being modified by multiple threads, it should be marked volatile so that changes can be seen by other threads. (There is more to it that I’ll leave […]

Continue reading » Comments Off on Atomic array classes and volatile arrays in the JVM