分類
Java

可檢測異常與非檢測異常(Checked Exception and Unchecked Exception)

可檢測異常(Check Exception)與非檢測異常(Uncheckecd Exception)

 

1.非檢測異常不需要強制處理或聲明,為 Error RuntimeException 2個類別。e.g.

public void throwUncheckedException(String target)
{
        if(target == null)
        {
            throw new NullPointerException();
        }
}

throwUncheckedException 方法為很常見的檢查方法參數有效性的動作,在方法中(第5行)會拋出NullPointerException。
 
因為 NullPointerException 為 Unchecked Exception,所以不需要在方法宣告位置(第1行)加上聲明的處理 e.g.

public void throwUncheckedException(String target) throws NullPointerException
{
        if(target == null)
        {
            throw new NullPointerException();
        }
}

Unchecked Exception 不需要強制呼叫端處理,可以直接呼叫沒問題。e.g.

@Test
public void testThrowUncheckedException()
{
        throwUncheckedException(null);
}

 
 


 

2.可檢測異常必須強制處理或聲明,主要為 Exception 及其子類別(除了RuntimeException以外)e.g.

public void throwCheckedException(String target) throws IOException
{
        if(target == null)
        {
            throw new IOException();
        }
}

throwCheckedException 在方法中(第5行)會拋出IOException,因為 IOException 屬於 Checked Exception,必須強制處理。
所以可以選擇在方法宣告聲明 IOException,讓呼叫端去處理或是在原始位置處理 e.g.

public void throwCheckedException(String target)
{
        if(target == null)
        {
            try {
                throw new IOException();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}

 
如果選擇在方法宣告聲明IOException , 那呼叫端就必須去處理 IOException e.g.

@Test
public void testThrowCheckedException()
{
        try {
            throwCheckedException(null);
        } catch (IOException e) {
            e.printStackTrace();
        }
}

 

分類
eclipse plugins

安裝並使用 ObjectAid

ObjectAid 可以讓 code 產生對應的 uml。對於理解 Software Architecture 有相當程度的幫助。
 
1. Install ObjectAid
open eclipse(Kepler) -> Help -> install new software -> add -> type name : ObjectAid ,
type Location : http://www.objectaid.com/update ->  press next
 
2. Run ObjectAid
open eclipse(Kepler) -> select StarNetXMPPTransportBundle -> create ObjectAid UML Diagram ->
drag class from package explorer to objectAid UML Diagram
 

分類
eclipse plugins

安裝並使用 AceJump

AceJump 可以幫助在eclipse Editor 中快速移動,使用這個插件基本上不再需要滑鼠移動了。
 
1.安裝AceJump
open eclipse(Kepler) -> Help -> install new software -> add -> type name : AceJump ,
type Location : http://tobiasmelcher.github.io/acejumpeclipse/ -> press next
 
2.Run AceJump
open eclipse(Kepler) -> press “ctrl + ,” in Editor -> type which char your want to move in Editor ->
type hint char
 
3. config AceJump HotKey
Window -> Preferences -> General -> Key -> find AceJump

分類
eclipse plugins

安裝並使用 EclEmma 計算測試覆蓋率

1.Install EclEmma
open eclipse(Kepler) -> Help -> install new software -> add -> type name : EclEmma,
type Location : http://update.eclemma.org/ ->  press next
 
2.Run EclEmma
open eclipse(Kepler) -> right click project on Package Explorer -> Coverages As -> JUit Test
 
3.view unit test coverage
open eclipse(Kepler) -> open coverage view

分類
Android Uncategorized

eclipse 設定 code style

1.set customize code style

Window -> Preferences -> java -> code style -> Formatter -> import -> select your own rule xml

分類
eclipse plugins

安裝Metrics plugin on eclipse(Kepler)

1. Install Metrics:

open eclipse(Kepler) -> Help -> install new software -> add -> type name : Metrics ,
type Location : http://metrics.sourceforge.net/update -> select metrics and press next
 

2. How to use Metrics

in eclipse Package explorer -> right click project -> Properties -> Metrics -> click Enable Metrics -> Apply -> Ok
 

分類
eclipse plugins

安裝PMD plugin on eclipse(Kepler)

1. Install PMD:

open eclipse(Kepler) -> Help -> install new software -> add -> type name : PMD ,
type Location : http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/ -> select PMD for eclipse 4 and press next

分類
Ubuntu tools

安裝並設定 autojump

1.安裝 autojump

可以先安裝 zsh  以及 oh-my-zsh 再來安裝 autojump
直接使用 apt-get 來安裝。
sudo apt-get install autojump
 

2.安裝完成後設定shell 的配置檔

zsh: 到~/.zshrc 加入以下設定

...
plugins=(git copydir copyfile autojump)
...
...
[[ -s ~/.autojump/etc/profile.d/autojump.zsh ]] && . ~/.autojump/etc/profile.d/autojump.zsh

 

3.重新啟動 zsh,輸入以下指令並重新啟動 terminal

. ~/.zshrc

 

分類
Ubuntu tools

安裝並設定tmux

1.安裝 tmux

sudo apt-get install tmux

若出現

Package 'xclip' has no installation candidate

請輸入以下指令以更新apt

sudo apt-get update

完成後應該可以繼續安裝xclip了。

2.設定 tmux 配置檔(config file)

配置檔位於~/.tmux.conf

參考以下設定

setw -g mode-keys vi
set -g default-terminal "screen-256color"
bind r source-file ~/.tmux.conf \; display "Reloaded!"
set -g status-fg white
set -g status-bg black
setw -g window-status-fg cyan
setw -g window-status-bg default
setw -g window-status-attr dim
set -g status-justify centre
setw -g monitor-activity on
set -g visual-activity on
bind a run " tmux save-buffer - | xclip -i -sel clipboard"
bind v run " tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"

3.讓 tmux 剪貼簿和系統剪貼簿(ubuntu)相通

tmux剪貼簿和系統剪貼簿並不一樣,相連的方式藉由 xclip 來達成

3-1.首先安裝 xclip

sudo apt-get install xclip

3-2.在 tmux config file 加入以下2行

bind a run " tmux save-buffer - | xclip -i -sel clipboard"
bind v run " tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"

3-3. 複製 tmux 剪貼簿內容到系統剪貼簿內容的步驟為

3-3-1.
已在tmux 複製相關內容

3-3-2.
ctrl + b -> a

3-3-3.
在系統任一部分進行貼上動作。

3-4. 複製系統剪貼簿內容到 tmux剪貼簿內容

3-4-1.
已在系統複製相關內容

3-4-2.
到 tmux 中,ctrl + b -> v

4.Tmux的操作請參考以下兩篇

http://www.ruanyifeng.com/blog/2019/10/tmux.html

http://louiszhai.github.io/2017/09/30/tmux/

分類
eclipse plugins

CheckStyle error : Unable to instantiate RedundantThrows

Description:

Run “check code with checkstyle” and show follow message

cannot initialize module TreeWalker - Unable to instantiate 'RedundantThrows' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.RedundantThrows,
...

 

Solution:

edit checkstyle config xml and comment follow tag

...
<!--<module name="RedundantThrows">
      <property name="suppressLoadErrors" value="true"/>
</module>-->
...