Archive

Archive for August, 2009

Code too large for try statement ?

August 20th, 2009 CertPal 3 comments

If you didn’t already know it, the java language specification has limits on the size of a method. That limit is 65535 (number of bytes that the code occupies).

This so called limitation has never really bothered me. After practicing object oriented programming, modularization and good design principles you can only ask yourself ‘Who is crazy enough to write a method whose size is greater than 65535 !?’. But you know what ? It can happen. There are so many code gen tools out there and common libraries that will write code for you. Rules engines, JSP compilers, scripting/template engines will write dynamic code for you. If they do not write it withing the 65535 bytes limit, your code will not compile or will give a cryptic error and die.

Code suffering from this phenomenon will see this message – “Code too large to compile” or “Code too large for try statement“. So umm.. where did the try statement come from ?

Categories: java Tags: , ,

Can google detect swine flu ?

August 19th, 2009 CertPal 1 comment

Apparently it might be able to. Google has launched a flu trend service that can be used to determine the trends behind a flu pandemic / seasonal flu.

The flu trends faq hints at being able to detect pandemic flu. The quote from the faq reads

How is Google Flu Trends useful for pandemic flu?
Google Flu Trends models are built based on historic flu surveillance data. When a new flu virus causes the same symptoms as seasonal flu, Google Flu Trends can detect if overall flu rates are significantly increasing. Some search queries tend to be popular exactly when flu is happening, and are therefore good indicators of flu activity.

Google tries to understand search data and its related patterns and then determines if the search was related to a flu in any way. It then maps this search to geo data to find out how the flu spreads.

Java – Console

August 17th, 2009 CertPal 14 comments

To get sensitive user input without echoing it to the console/terminal, the Java SDK has introduced the java.io.Console class. The Console class is quite unique in the way it handles its data. It uses the native encoding of the system instead of the using the JVM’s default encoding.

The Console class provides methods to access the console/terminal, if any is associated with the JVM.

Using the Console class:
So how do you use the Console class ? Its pretty simple really. First get a reference to the Console class from the System class

1
Console con = System.console();

It is not always possible to get a reference to the console. Some scenarios prevent the developer from gaining access to the console. This method may return null in these cases. For example a batch process running on a server will not expect user input and usually does have a console. Your code must be capable of handling such situations.

Categories: Java certifications Tags: , ,

Sun java certification pitfalls

August 17th, 2009 CertPal 1 comment

Before you can go ahead and take the real Sun Java exams, you need to know some of the pitfalls that have plagued several test takers. Here are a few pointer

Do not buy a voucher before you are prepared to take the exam:

Often some candidates like to follow this approach hoping that the purchase of the voucher would force them to learn within a given time period. On the contrary this adds additional pressure to your preparation, since you need to study the objectives before the expiry date. Some candidates have lost money misinterpreting the expiry date on the voucher. Be wary of the MM/DD/YYYY Vs DD/MM/YYYY formats. Which one does your voucher display ?

When the candidates finally find that they have no more time to learn, they post a message on a forum that reads something like ‘I have voucher for exam X for a discount of Y%. Please call me to buy’. Remember, you are a candidate, not a voucher reseller :)

Java – Navigable Set

August 15th, 2009 CertPal 19 comments

Sets:

A Set is a collection that contains no duplicate elements. Sets are collections where no two elements are the same, which means that element1.equals(element2) should never return true. Also at most one element in a set can be null and no more.

A Set. Duplicates are not allowed and at most one null element is allowed

Sorted Sets:

A SortedSet is a set which sorts and maintains the ordering of its elements. Elements will be ordered by their natural ordering or by the use of a Comparator (if the developer provides one). A Comparable interface can help define the ordering for elements. For example a String’s natural ordering will dictate that elements be ordered this way “a”, “b”, “c” etc. The way in which elements are ordered in a Sorted data structure can be redefined by using the Comparator interface.