键入 Java 代码时,可键入缩写以通过模板来生成代码,从而减少按键数。按 Tab 键后,缩写将展开为模板中的相应文本。编辑 Java 文件时,如果使用代码完成,则也会显示代码模板。
IDE 提供了一组代码模板。您也可以创建自己的代码模板。
下面是 IDE 缺省提供的代码模板列表。
缩写 | 代码模板 |
---|---|
En | Enumeration |
Ex | Exception |
Ob | Object |
Psf | public static final |
Psfb | public static final boolean |
Psfi | public static final int |
Psfs | public static final String |
St | String |
ab | abstract |
bo | boolean |
br | break |
ca | catch ( |
cl | class |
cn | continue |
df | default: |
dowhile | do { } while (condition); |
eq | equals |
ex | extends |
fa | false |
fi | final |
fl | float |
forc | for (Iterator it = collection.iterator(); it.hasNext();) { Object elem = (Object) it.next(); } |
fore | for (Object elem : iterable) { } |
fori | for (int i = 0; i < SCRAMBLED_WORD_LIST.length; i++) { } |
fy | finally |
ie | interface |
ifelse | if (condition) { } else { } |
im | implements |
iof | instanceof |
ir | import |
le | length |
newo | Object name = new Object(args); |
pe | protected |
pr | private |
psf | private static final |
psfb | private static final boolean |
psfi | private static final int |
psfs | private static final String |
pst | printStackTrace(); |
psvm | public static void main(String[] args) { } |
pu | public |
re | return |
serr | System.err.println("|"); |
sout | System.out.println("|") |
st | static |
sw | switch ( |
sy | synchronized |
tds | Thread.dumpStack(); |
th | throws |
trycatch | try { } catch (Exception e) { } |
tw | throw |
twn | throw new |
wh | While ( |
whilei | while (it.hasNext()) { Object elem = (Object) it.next(); } |
缩写 | 代码模板 |
---|---|
ag | application.getAttribute("|") |
ap | application.putAttribute("|",) |
ar | application.removeAttribute("|") |
cfgi | config.getInitParameter("|") |
jspf | <jsp:forward page="|"/> |
jspg | <jsp:getProperty name="|" property="|"/> |
jspi | <jsp:include page="|"/> |
jspp | <jsp:plugin type="|" code="" codebase=""> </jsp:plugin> |
jsps | <jsp:setProperty name="|" property=""/> |
jspu | <jsp:useBean id="|" type=""/> |
oup | out.print("|") |
oupl | out.println("|") |
pcg | pageContext.getAttribute("|") |
pcgn | pageContext.getAttributeNamesInScope("|") |
pcgs | pageContext.getAttributesScope("|") |
pcr | pageContext.removeAttribute("|") |
pcs | pageContext.setAttribute("|",) |
pg | <%@page |%> |
pga | <%@ page autoFlush="false"%> |
pgb | <%@ page buffer="|kb"%> |
pgc | <%@page contentType="|"%> |
pgerr | <%@page errorPage="|"%> |
pgex | <%@page extends="|"%> |
pgie | <%@page isErrorPage="true"%> |
pgim | <%@page import="|"%> |
pgin | <%@page info="|"%> |
pgit | <%@page isThreadSafe="false"%> |
pgl | <%@page language="java"%> |
pgs | <%@page session="false"%> |
rg | request.getParameter("|") |
sg | session.getAttribute("|") |
sp | session.setAttribute("|", ) |
sr | session.removeAttribute("|") |
tglb | <%@taglib uri="|"%> |