Archive for the ‘Java’ category

Calendar getDisplayName() JDK 6.0 vs JDK 1.5.0

November 5th, 2008

If you have somehow used jdk6.0 while developing your application that uses Calendar API of java.util.Calendar, and have used getDisplayName method to extract the display names for fields of the calendar, specific to your desired style and locale, and then had to compile your application with jdk1.5.0 only to realize that compiler spits swear words at you…Here is quick fix for you!

This is what you did in jdk6.0:

//get your application locale
Locale userLocale = getContext().getLocale();

//define a calendar
Calendar calendarInstance = Calendar.getInstance();

//Extract the month name in SHORT format (viz. "Jan","Feb" etc.) for the context locale.
calendarInstance.getDisplayName(calendarInstance.get(Calendar.MONTH),Calendar.SHORT,userLocale);

Here is what you can do to achieve the same getDisplayName functionality in jdk 5.0:

//import the following class
import java.text.DateFormatSymbols;

//declare variable.
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();

//Get the short names for months in a Calendar
String[] months = dateFormatSymbols.getShortMonths();

//Use the month field of Calendar to fetch the short name of month for cell label.
months[calendarInstance.get(Calendar.MONTH)];

Once you acquire the SHORT name for the field, you can use it for your labels, or column headers etc. based on where you require it.

Ideally, you shouldn’t have to fall back on the previous version of jdk, yet sometimes the project requirements can’t be altered even for better things in life.

Hope this tip helps!

Hello World – I am here!

May 18th, 2007

There can’t be a more apt way of entering the Java world than “Hello World!”. Those magical words can transform about the most ordinary lives. At least for me they did.

I am relatively an infant in the Java world, but I am a precocious infant so I will say whatever I think is right and you have only two options, you agree with me or you die.

Java technology stack has grown from strength to strength in last decade and today it has reached a level of maturity that inspires confidence that the world could indeed depend on software. That intangible, quirky stuff some nerds keep punching in on their keyboards and that can do some wonderful stuff only we don’t know how it does that.

My ride through the software world allowed me to witness the prehistoric programmig languages like Fortran-77 and Pascal but as I moved ahead it has only gotten better with time.

In the life of a programmer, the real transformation occurs when one moves from straightforward procedural languages to the world of Object Oriented Programming, which kinda adds a realistic paradigm to the world of software. The complexity of objects in the real world and their relationships are translated verbatim in the OOPS world and that is when things start getting better. It’s like a boy turning into a man. Both the programmer and his code enter a new level of maturity and capability.

So, who am I? My name Rishik, and I would like to think it is a unique name, however it is no more. I have worked as a programmer for last 6 years now and worked on different sets of technologies. Currently, I am having an affair with Java Technology Stack. And I can’t express how rewarding this relationship has been right from its inception. I work with Pramati Technologies, and I have recently added another role to my portfolio, which is “Relationship Manager”. Apart from being a developer I am now into business development for half of my time. And I started this blog to bring out the lighter side of Java.

Let’s see what comes first, the chicken or the egg!


Fatal error: Call to undefined function spa_default_options() in /home/rishikd1/public_html/accidentalpatterns/wp-content/plugins/snap-shots-for-wordpressorg/ald-snapshots.php on line 97