最近比较关注如何提高自己的工作效率,比如Launchy的使用。Eclipse作为最常用的IDE,掌握一些常用的快捷键和输入模板,会很大的提高工作效率

常用快捷键

Shift+Enter:在当前行下插入新行,当光标正在一行的中间时才体现其价值

Ctrl+Shift+Enter:在当前行上插入新行

Ctrl+D:删除整行

Ctrl+Alt+J:合并行,相当于vi中的J

Ctrl+Alt+UP/DOWN:向上/下复制行

Alt+UP/DOWN:行向上/下移动

F2:显示Tip

Ctrl+Shift+F:Format,对文档进行格式整理

Ctrl+Alt+/:word自动完成

Ctrl+1:快速解决(quick fix)

Alt+/:内容帮助(Content Assist),用于激活输入模板等

输入模板(Java)

使用方式:输入模板的名字,然后使用Alt+/快捷键

cast:

${type} ${new_name} = (${type}) ${name};

catch:

catch (${Exception} ${exception_variable_name}) {
${cursor}// ${todo}: handle exception
}

do:

do {
${line_selection}${cursor}
} while (${condition:var(boolean)});

else:

else {
${cursor}
}

elseif:

else if (${condition:var(boolean)}) {
${cursor}
}

for:

for (int ${index} = 0; ${index} < ${array}.length; ${index}++) {
${line_selection}${cursor}
}

foreach:

for (${iterable_type} ${iterable_element} : ${iterable}) {
${cursor}
}

if:

if (${condition:var(boolean)}) {
${line_selection}${cursor}
}

instanceof:

if (${name:var} instanceof ${type}) {
${type} ${new_name} = (${type})${name};
${cursor}
}

main

public static void main(String[] args) {
${cursor}
}

new:

${type} ${name} = new ${type}(${arguments});

private_method:

private ${return_type} ${name}(${}) {
${cursor}
}

private_static_method:

private static ${return_type} ${name}(${}) {
${cursor}
}

protected_method:

protected ${return_type} ${name}(${}) {
${cursor}
}

public_method:

public ${return_type} ${name}(${}) {
${cursor}
}

runnable:

new Runnable() {
public void run() {
${line_selection}
}
}

static_final:

${visibility:link(public,protected,private)} static final ${type:link(String,int)} ${NAME};

switch:

switch (${key}) {
case ${value}:
${cursor}
break;

default:
break;
}

synchronized:

synchronized (${mutex:var}) {
${line_selection}
}

syserr

System.err.println(${word_selection}${});${cursor}

sysout

System.out.println(${word_selection}${});${cursor}

systrace

System.out.println("${enclosing_type}.${enclosing_method}()");

test

public void test${name}() throws Exception {
${cursor}
}

toarray

(${type:elemType(collection)}[]) ${collection}.toArray(new ${type}[${collection}.size()])

try:

try {
${line_selection}${cursor}
} catch (${Exception} ${exception_variable_name}) {
// ${todo}: handle exception
}

while:

while (${en:var(java.util.Enumeration)}.hasMoreElements()) {
${type:argType(en)} ${elem:newName(type)} = (${type}) ${en}.nextElement();
${cursor}
}

全部的快捷键和模板见Eclipse的帮助文件,当然你也可以根据自己的习惯定义自己的快捷键和模板

整理完了以后才发现以前浪费了多少时间啊,浪费可耻!

-----debug

1.StepInto(alsoF5)跳入
2.StepOver(alsoF6)
跳过
3.StepReturn(alsoF7)
执行完当前method,然后return跳出此method
4.stepFilter
逐步过滤一直执行直到遇到未经过滤的位置或断点(设置Filter:window-preferences-java-Debug-stepFiltering)
5.resume
重新开始执行debug,一直运行直到遇到breakpoint
6.hitcount
设置执行次数适合程序中的for循环(设置breakpointview-右键hitcount)
7.inspect
检查运算。执行一个表达式显示执行值
8.watch
实时地监视变量的变化
9.variables
视图里的变量可以改变变量值,在variables视图选择变量点击右键--changevalue.一次来进行快速调试。
10.debug
过程中修改了某些code--save&build-->resume-->重新暂停于断点

B.
断点类型
Linebreakpoint
在断点行暂停
fieldbreakpoint(
也叫watchpoint)
fieldbreakpoint
也叫watchpoint(监视点)当成员变量被读取或修改时暂停
methodbreakpoint,
添加methodbreakpoint进入/离开此方法时暂停(Run-methodbreakpoint)
exceptionbreakpoint.
添加Exceptionbreakpoint捕抓到Execption时暂停(待续...)
javaclassloadbreakpoint
load指定的class时发生,有对话框让你指定的class.


C
断点属性:
breakpointproperty对话框里编辑
1.hitcount
执行多少次数后暂停用于循环
2.enablecondition
遇到符合你输入的条件时(ture/改变时)就暂停
3.suspendthread
多线程时暂停此线程
4.suspendVM
暂停虚拟机
5.Filter