Mount samba file server to Linux Mint 17

1. Install cifs-utils package

2. Create a file for authentication information with root account

3. In authentication file, please specify username, password and domain.

4. Modify /etc/fstab file and to mount the samba at start-up.

Add following line to the end.

then use “mount -a” to mount immediately.


New virtual environment after laptop re-image

公司电脑终于被Re-image了,再也没有了Admin的权限,除了portable的软件,其它都要在系统里Order,然后推送。系统里的软件很少,五笔输入也没有一个。VMWare也是再也不能装了,虽然有正版的License,好在开源VirtualBox是可以的。在安装了新的Linux Mint 17环境之后,然后我惊喜的发现,VirtualBox和VMWare在使用上的感觉差别不大了,速度也很快。


一个小Tip,VirtualBox 4.2.16的Additions有点问题,要下载安装4.3.x的Additions。Maybe that’s for newer Linux!

Class.cast() vs. cast operator

A co-worker told me Class.cast() is better than cast opertor as it’s safer to handle null reference. Really?

Let’s take a look at the following code snippet. As you can see, basically, there is no difference. Both test cases can pass.

In the function of cast(), it does null and type check but still uses cast operator to cast object.

What’s the difference in byte code? See the source code and byte code (compiled by Java 7) of a simple test case.

Note: Internally, line index starts from 0.

For L1: Instruction of “CHECKCAST” will be invoked to do type casting. In JVM specification, you can find all details about it. Basically, it behaves the same as we expects. See more details here.

For L2: Function cast() will be invoke first and later “CHECKCAST” still needed. Why? I think Java compiler plays a trick. cast() is a generic function, which should return an object in T type. But in runtime, information of type will be erased. So compiler need to put an extra instruction here to do type casting, which should be the same for other generic functions. Actually, in cast(), “CHECKCAST” is not really invoked.

In that case, way to use case() has worse performance.

See a simple performance test.

And the difference is BIG.


I think in most cases, cast operator is safe and simple. But in some cases, when you only have Class object, such as some generic function/class, cast() is also a good choice.

When sharing SharedPreference among activities, pay more attention!

Generally, we update SharedPreference by its editor;

Then we use putXXX to update the value in it.

Finally, commit the change to save it to file. We often do it in onStop() or onDestroy()

It’s OK in one activity. But if multiple activities get the same preference, you need pay more attention. Since after committing, the previous settings, especially updated by other activities, may be lost. You may need a class to do updating/committing if you only want one preference. Or you can have multiple SharedPreference.

Manually uninstall OSGi bundle in the runtime

Sometimes in a RCP application, you may need to uninstall OSGi bundle in the runtime. With BundleContext, it’s doable. Here is a sample.

As you can see, you need to specify the bundle/plugin name.

Add watchpoint for variables in Eclipse

Sometimes, in debugging, we want program stopped when some variables are accessed or modified. To set traditional breakpoints for this case, you have to spend a lot of time to find all places to access or modify variables. It’s even harder when variables are passed to other object or the derivation hierarchy is complicated. In this case, watchpoint is a good helper.

In Eclipse, it’s quite easy to set watchpoint. In “Outline” view, you can right click on the variable you want to want and select “Toggle Watchpoint“. 2014-11-06_13-21-43

Then you can find a new watchpoint in “Breakpoints” view. You can see the icons of breakpoint and watchpoint are different.


By default, watchpoint will be hit when accessing or modifying the watched variable. To change it, we can simply right-click the watchpoing and select “Breakpoint Properties…“.2014-11-06_13-27-11





安然很简单,用下面的Update Link,

当打开二进制文件时,在Editor中选择“Hex Editor“,