Thursday, September 5, 2013

When to use Comparable and Comparator?

By  | September 8, 2013

Programcreek demonstrates examples of using Comparable and Comparator. The next question will be when to use Comparable and Comparator. Here I list two basic rules (actually only the first one is really important):
  1. If there is a natural ordering of the object, then the class should implement Comparable, e.g., integers, strings (generally in the alphabet order), and points. On the other hand, if an object has multiple ways of ordering, then Comparator interface should be used to specify which way of sorting should take place. For example, HDTV in the Programcreek example can either be sorted by size or band name. In such case, Comparator is should be used. Another advantage is that Comparator can specify which parameter to be used for ordering. It then can be self descriptive. Hence, we can have SizeComparator and BandComparator for comparison, respectively.
  2. If you are not able to change the code of the object, which means you cannot implement Comparable, then Comparator is the only way left.
In summary, order of comparison is very important while implementing objects. Requirements may even change during implementing. For example, strings are generally compared alphabetically, but you may need to compare strings on their lengths as well. Therefore, designing of comparison needs to be very careful. In general, implement Comparable for natural order and write a Comparator for other needs.

Scale, Standardize, and Normalize data

http://blog.pengyifan.com/scale-standardize-and-normalize-data/

Wednesday, September 4, 2013

MathJax with Blogger

MathJax in blogger.com is useful when I need to input equation in my blog. This is a instruction and test of using MathJax in blogger.com.
  1. set blogger.com template to "Simple". "Dynamic Views" seems not working.
  2. edit HTML by adding the following code between <head> and </head>.
    <script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>
    
  3. type math equation in the blog.
Note that, enclosing math in single $'s does not work. Instead, I use "\(" and "\)" for inline math and "\[" and "\]" for displayed math. For example:
\(\frac{2}{3}\)
will show an inline math "\(\frac{2}{3}\)", and
\\[z=\sqrt{x^2+y^2}\\]
will show a displayed math \[z=\sqrt{x^2+y^2}\]

Monday, September 2, 2013

How to Read a Paper

S. Keshav, How to Read a Paper, ACM Computer Communication Review, July 2007.
In this 2-page paper, (Keshav, 2007) introduced a very practical and efficient three-pass method for reading research papers. He also described how to use this method to do a literature survey. S. Keshav is a professor in CS at the Univ of Waterloo. The above link points to the updated version of Aug 2, 2013.
Some sentences that I like:
If a reviewer cannot understand the gist after one pass, the paper will likely be rejected; if a reader cannot understand the highlights of the paper after five minutes, the paper will likely never be read. For these reasons, a ‘graphical abstract’ that summarizes a paper with a single well-chosen figure is an excellent idea and can be increasingly found in scientific journals.

SSH and Thunar


sshfs name@server:/path/to/folder /path/to/mount/point

Saturday, August 31, 2013

Top books for advanced level java developers


There are plenty of Java 101 books. But to those who have been using Java for several months or years, most of them may look too simple. However, advanced Java books are not always right at hand, not partially because they require more skills, experienced, and deep thinkers to write.

In this post, I would like to share my experience with only advanced level of Java, which means books like "Thinking in Java" or "Head First Java" won't be listed although they are very good for starters. Also I try to avoid listing Java books for specific software, frameworks or certifications, which I assume is not "pure" Java.

(This list will grow up gradually)

Java in a Nutshell

It is a more reference than a must read.

The elements of Java style

It is directed at anyone who writes Java code, by furnishing a set of rules for Java practitioners, by offering a collection of standards, conventions, and guidelines for writing solid Java code, and by illustrating how to write solid Java code that will be easy to understand, maintain, and enhance.

Effective Java

This book is really only for deeper understanding Java developer. It brings together seventy-eight indispensable programmer’s rules of thumb: working, best-practice solutions for the programming challenges you encounter every day.

The Java language specification

Written by the inventors of Java, this book not only provide complet and accurate converage of the language, but also includes formal rules of the language from the practical behavior of compilers. You may not get skills by reading it, but what if you want to cross the line and crack Java VM...

Design patterns: elements of reusableobject-oriented software

Actually, examples in this book were written in C++ or smalltalk, but so what? If you want to grow as a developer, you have know Design Patterns, to take advantages of the best practices and experience of others, and learn from those who have face the same problems. There are many other similar books, but they are just doing patching work.

The Pragmatic Programmer: From Journeyman to Master

Again, it is not a book for Java developer only. "The cool thing about this book is that it's great for keeping the programming process fresh. The book helps you to continue to grow and clearly comes from people who have been there."