Posts Tagged Programming

Time Unit Conversion in Java

Ever needed a utility which converts from one unit of time to another?

Well with Java 5 and higher, you won’t have to create your own conversion routine any longer.

Say for example you wanted to specify a value in seconds but the method you need to call expects a value in milliseconds (which is a common thing in Java).

Then this would be how you can convert the value with the java.util.concurrent.TimeUnit utility.

long oneMinute = TimeUnit.SECONDS.toMillis(60);

Java 5’s TimeUnit supports conversion to and from nano, micro, milli and seconds while Java 6’s TimeUnit also supports minutes, hours and days.


Leave a Comment

Sun Certification Retake Promotion

This post has moved to a new location and is only kept here for archiving purposes.

To commemorate Sun’s awarding 500,000 certifications, purchase a voucher by June 20 for most Sun certifications – and should you need it, you can take the exam one additional time for free.

Taken from:

For SUN Philippines, however, here are the more detailed guidelines.

Please be informed that Sun is _relaunching the popular Sun Certification Retake Promotion starting April 2008_. Note the voucher code for this program is “DS”. The retake exam is not applicable for any assignment or essay exam. Validity date : 01 April to 30 June 2008

Below are some of the exams which qualify for the Free Retake Promotion. I also added some links to highly recommended books in case you need help with them.

Terms and Conditions

Exam vouchers are only valid in the country in which they are purchased. Each voucher associated with this program is valid for one exam and, if failed, one free retake. You must allow 72 hours after taking your initial exam before scheduling the free retake exam. Please also be aware that per Sun certification guidelines you must wait at least 14 days before you may retake any exam. Certification vouchers may only be used at an Authorized Prometric Testing Center in the country where it was purchased. Please be aware that exam vouchers are non refundable for any reason.

Happy studying!

Related Post:

Comments (1)

Java vs C# – switch statements

This is my first installment of a new blog series I’m planning to call Java vs C#.

Today, I’ll be discussing the behavior of “switch” statements in both Java and C#.

Consider this snippet for Java which prints out the values “1”, “2” and “Default” when value = 1.

Since I did not add “break” statements after each case, it should execute the code in the next cases up to the point where it reaches a break statement (or exits the switch).

switch (value) {
   case 1:
   case 2:

You would think that the snippet for C# below (which is patterned after the code above) would behave in exactly the same way.

switch (value)
   case 1: System.Console.WriteLine("1");
   case 2: System.Console.WriteLine("2");
   default: System.Console.WriteLine("Default");

But this is where it gets interesting, the code above will actually NOT compile.

Error 1 Control cannot fall through from one case label (‘case 1:’) to another
Error 2 Control cannot fall through from one case label (‘case 2:’) to another

They said that this is actually a safety mechanism for C# which help prevent debugging nightmares for developers in the event that these switch statements get bigger and more complex.

Seems like a valid point.

But it might be important to note that C# still allow fall through for switch statements, provided you do not add any logic to the case statements.

switch (value)
   case 1:
   case 2:
   default: System.Console.WriteLine("Default");

You can however work around the said fall through problem by using goto which I do not really recommend (so I’m not going to add any more details about that).

As a side note, in addition to int and enum types, C# switch statements also allow string types as argument.

So there you have it folks, switch statements in Java and C#.

Hope you enjoyed and learned something from my first installment.


Comments (1)

Content Assist / Code Completion problem with Eclipse and Netbeans

I’ve had the weirdest problem the other day. It was the first time I went back to using our DELL E1405 after being very comfortable with my company issued D620 (which I now had to surrender to my former employer). Everything was working well until I noticed a simple but very annoying problem:

CTRL+SPACE for Eclipse was not working!

I tried playing with the configuration, resetting everything to defaults, removing the plugins one by one. Nothing seemed to work. I tried a fresh copy and even got to the point of installing Netbeans. And guess what, CTRL+SPACE did not work for Netbeans either!

Which lead me to the conclusion that there must be something else causing the problem. I tried killing all the unnecessary processes one by one and got to the bottom of the problem.

It was the Logitech Quickcam v10 application. Unfortunately, I didn’t have internet connection at home which explains why I had to figure out the problem all by myself.

I tried searching the net when I got to the office and saw some posts that v11 of the application already fixes the problem.

What a relief!

Comments (9)