Wednesday, August 27, 2008

12 Sly Web Tricks That Put You in Control

Great article on PC World about 12 Sly Web Tricks That Put You in Control. You find out how you can Turn Wi-Fi Thieves' Worlds Upside Down (literally), Make a Laptop Thief Regret It, Finding out if the email you sent was read or not, Send a Self-Destructing Email, and other similar (and sometimes very useful) information.

Tuesday, August 26, 2008

Basic Set operations in Java

How do we work with Sets in Java when it comes to performing the basic operations: Union, Intersection, Subset, Complement, Cartesian Product (for which there is no standard Java method in the Set Interface)? Do we have some kind of a collection that maps this mathematical concept into Java? Yes we do.

The Set Interface models the mathematical concept of a set and it is a Collection that contains no duplicate objects. Before talking about the specific methods that we will use, you must be aware of the three most used Set implementations: HashSet (uses a hash table to store its elements), LinkedHashSet (HashSet that also maintains a doubly-linked list running through all of its entries), and TreeSet (a sorted set).

Assume we have two sets s1 and s2. Going back to the basic set operations, we have:
- Union: the union of sets s1 and s2 is a set whose elements are contained in either set s1 or s2.

Java: s1.addAll(s2) - adds all elements from s2
in s1 if they are not already present.

- Intersection: the intersection of two sets s1 and s2 is a set whose elements are in both s1 and s2.
Java: s1.retainAll(s2) - s1 becomes the intersection of
s1 and s2.

- Subset: s2 is a subset of s1 if all elements of s2 are also elements of s1.

Java: s1.containsAll(s2) - returns true if s1 contains
all of the elements of s2.

- Complement: the complement of s2 in s1, denoted s1 - s2, is a set of all elements that are members of s1 but not of s2.

Java: s1.removeAll(s2) - removes from s1 all the
elements that are also contained in s2.

- Cartesian Products: the Cartesian product of two sets s1 and s2 is the set of all ordered pairs (x, y), where x is an element in s1, and y is an element in s2.

Java: public static Set computeCartesianProduct(Set s1,
Set s2) {
result = null;
if (s1 == null || s2 == null) {
throw new IllegalArgumentException();
if (s1.isEmpty()) {
return s2;
if (s2.isEmpty()) {
return s1;

result = new HashSet
for (Object obj1 : s1) {
for (Object obj2 : s2) {
result.add("(" + obj1 + "," + obj2 + ")");

return result;

UPDATE (04/30/09): For the Cartesian Product operation above, I have used a raw type for unknown set element type. As of Java 1.5, you should consider using generics. For example, you should use an unbounded wildcard type for the input parameters of the computeCartesianProduct method, making the above code type safe and more flexible. This implies that instead of using the declaration Set s1, you should actually have Set<?> s1.

Friday, August 22, 2008

Sun Certified Java Programmer (SCJP) Exam

Today, I passed the Sun Certified Java Programmer (SCJP 1.5) exam. Throughout this post, I will share my experience preparing for it.

Before I get started, a little bit of background. I started developing in Java in 2001 (second year of college). Most of the software I have written was using the standard and mobile editions of the Java Platform. I have some knowledge of the enterprise world of Java, but mostly through Servlets and JSPs than anything else. In addition, I took a 6-months Java tutorial back in 2005 that covered OO Topics and Java Core (everything up to concurrency), Java Advanced (concurrency, networking, RMI, JDBC, XML) and Java Enterprise (Servlets, JSP, Custom Tags, JMS, EJB). Hence, I was not knew to this technology when I first started preparing for the SCJP exam in mid June (I also became a SCJA in January this year).

First step was to find a study book. This was not hard since I already knew about the SCJP for Java 5 Study Guide from Sierra and Bates (I already had the 1.4 version of the book). This is an excellent material, no doubt about it. It has a complete coverage of the exam objectives, examples, exercises, exam watches, basically anything you would possibly want from a certification book. Highly recommend it. I only went through this book once, done most of the exercises, and took the free practice exam that comes with the CD (you also get a bonus MasterExam practice test). Once I indentified my weaknesses, I went over again through the specific chapters in the book. At the end, I took the MasterExam practice test and did a little better. How many times you read the book really depends on you, on how familiar you are with Java, on how fast you graps the topics detailed there. I read about people who read the books as many as five times. If you think it helps, and you have time, it is up to you!
Now I have to mention that the two practice tests were the hardest from all the test that I have done afterwards, harder than the exam, hence if you nail these tests, the real exam will feel much easier. It might be harder also because, like other practice tests I took, when you get a multiple-choice question, they don't specify how many correct answers you have, while the real exam, and some of the other test, does. I understood the reason why it is not specified, but I would have wanted an option from where to choose if I should be given, or not, the number of correct answers.

Next step, a combination of taking many mock exams, and reading online SCJP notes. The best place to go for this is to the Java Ranch SCJP Forum webpage. How much it helped me? Enormous! Beside the benefit of having a forum specifically dedicated for SCJP, you get links to basically anything that you might want (and need) for this exam, such as faq, notes, mock exams, etc. Such a pool of resources gathered under one roof is almost impossible to find. Two thumbs up for everybody involved there!

If you want commercial practice tests, I would suggest Whizlabs, uCertify, Sun's own ePractice Certification Exam. From what I read, and from my own experience, I would say that Whizlabs is harder than any practice exams I know (except the one from the book). It contains tips, study notes, and 4 practice exams - best overall preparation kit. uCertify is a bit easier than the real exam, and it contained minor software errors, but was a good resource in the end. Bundled in it come 7 tests, tips, notes, etc . Sun's web-based practice exam came the closest to how the real exam was (which kind of makes sense, I know). This is the main reason I bough it. The score that I got form the third (and last) practice test was the one I got in the real exam.

Going through many mock exams and practice tests, I started writing my own SCJP Notes document. It contains everything that I thought was essential for the exam (inspired from the book and many existing online notes), together with things I have missed at tests (my own weaknesses if you like). You can read the document here.

As for the exam itself, you get 210 minutes (I was done in around 130 minutes). Honestly, I thought I would do worse than I did. I was unsure on some of the answers I had given, but when you take so many mock and practice exams, when you read from the many resources available out there, you have to start trusting your guts. And this is mostly true on API related questions, i.e. does the reverse method exist in both String and StringBuffer classes? What about replace? Java 1.5 specific questions (topics not present on older versions of Java) were on the exam quite often (such as generics, autoboxing, varags, etc). The Thread-related questions were harder than I expected, and I did the worse on that section than I did on any other (only 75%). In the practice exams, threads were one of my strongest suites. If you aks me, Concurrency, Generics and Collections are the hardest topics around.

What can I say more? Good luck to any of you who want to take this exam, and if you have any questions, drop me a comment.

Tuesday, August 19, 2008

Cell Phones - Top 3 best sellers

I remember reading about it a while ago. Digging a little through the Internet, I found the source in engadget. Here are the facts:

  1. Nokia 1100 - around 200 million units sold.
  2. Motorola RAZR V3 - around 50 million units sold (although I believe that the Motorola StarTac sold more units).
  3. LG Chocolate - around 10 million units sold.
Now, Apple's iPhone has a big chance of overrunning the third spot by the end of 2008 (with the new improved and cheaper 3G model). We'll just have to wait and see. Of course, searching the internet will reveal a different top for the most selling cell phones.

On a similar note, CNET has published a review on the best 5 cell phones. Why haven't I owned any of them yet?

Saturday, August 9, 2008

DimDim 4.0 Released

DimDim, a free web conferencing service, has launched version 4.0. Some of the key features added were:
  • Recording: You can now record your meetings and share playback URLs or embed the recording directly onto your own website just like YouTube videos.
  • Multiple Presenters: With a single click you can allow any attendee to share their presentation, whiteboard, webcam - even their desktop.
  • Mac Desktop Sharing: Mac users can share their desktop with anyone using just a browser.
  • Free Teleconferencing: With the improved free VoIP microphone sharing everyone now gets their own unlimited free conference call account.
  • Private Meetings: Simply assign a meeting key and only those who know both your meeting room name and your meeting key will be able to join.
  • No Install: Now you don't need to install anything to join or even host a meeting. You'll only need to install our screen casting plug-in if you choose to share your desktop.
Sign up and give it a spin.

Thursday, August 7, 2008

Web Design - Scalability and Speed

Greg Linden reported that every 500ms of latency costs Google 20% of its traffic. Similarly, every 100ms of latency costs Amazon 1% of their sales. The presentation concludes that speed matters (big time), but it is hard to achieve high speeds when you are manipulating large data. Here is where a scalable design matters. My experience with web design is minimal. Maybe you have some good feedback/tutorials/articles on how to achieve scalability when large amounts of data is involved.