Using curl to test port connectivity

It's often necessary to troubleshoot port connectivity as common env, but not found telnet.

curl -v telnet://target ip address:desired port number

curl -v telnet://dragon1:22
* Rebuilt URL to: telnet://dragon1:22/
* Trying
* Connected to dragon1 ( port 22 (#0)


Generate Cron Expression in SOP

Sometimes, the cron expression is difficult to generate while you want to resolve urgent things. Let us SOP to generate cron expression.

Here are two links to easily generate cron expression.

  1. http://www.cronmaker.com/
  2. Cron Expression Generator & Explainer - Quartz


Building Software

Based on Kent Beck describes three activities in building software:

  1. First make it work. (make business or money first)
  2. Then make it right. (refactor code ...you and others can understand it as needs change)
  3. Then make it fast. (refactor code for "needed" performance, don't do this first)


My Development Principals in Java World

Here are my development principals in java world. 

  • Simple and Small objects
  • Immutable object
  • Interface, it’s a contract that our object must obey in order to communicate with other objects.
  • Don’t use static object and method
  • Don’t use null anywhere
  • Multiple contractor to reuse your code-fee
  • Always chain exception
  • Aspect-oriented programming for special handling
  • A unit test is a part of class.
  • ...continue...


Switch JDK verson on Mac

When you installed many of jdk versions, there are two ways to switch the jdk.

  • Using Java Preferences application, but Apple decided to remove it.
  • Using java_home in console

After a lot of googing a found simple way solution, I’d like to share.

Edit your profile /.bash_profile or /.zshrc

alias java_ls='/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d[,_]" | cut -d , -f 1 | colrm 1 4 | grep -v Home'

function java_use() {
export JAVA_HOME=$(/usr/libexec/java_home -v $1)
export PATH=$JAVA_HOME/bin:$PATH
java -version

Execute java_ls


Execute java_use 1.8

java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)


Different Between Reader/Writer and InputStream/OutputStream

A Reader/Writer are designed for character-oriented streams. If the information we are reading is all text, then the Reader will take care of character decoding for you. For example, you can read all in text file to represent the characters in Java.

An InputStream/OutStream are designed for byte-oriented streams. It grabs/writes the data byte by byte without performing any kind of translation. For example, you can read/write image data, mp3…or any binary files.


Observer Pattern

The observer pattern is a behavioral design pattern which defines a one-to-many relationship between objects. When the observable object changes its state, all dependent objects are notified and updated automatically. In stock market case, a stock trading system keeps track of all trades of specific stocks (subjects) and must inform all trader (observers) when a new trade has been made for new prices.

Word Definitions


someone who sees or notices something


something that is observable can be seen or measured

Code Example


To be honest, I don’t want the Observable class to be tightly coupled with the classes that are interested in observing it. It doesn’t care who it is as long as it fulfils certain criteria. I think we might consider the event-bus if there are a lot of usage in your system. There are two reasons :

  • It replaces the tight coupling introduced by explicit listeners with a flexible loosely coupled design.
  • An event bus can be thought of like the observer pattern with an extra layer of decoupling.

Reference Link