DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
Correct brace style:
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
public class Foo {
public void foo(boolean a, int x, int y, int z) {
do {
try {
if (x > 0) {
int someVariable = a ? x : y;
} else if (x < 0) {
int someVariable = (y + z);
someVariable = x = x + y;
} else {
for (int i = 0; i < 5; i++) {
doSomething(i);
}
}
switch (a) {
case 0:
doCase0();
break;
default:
doDefault();
}
} catch (Exception e) {
processException(e.getMessage(), x + y, z, a);
} finally {
processFinally();
}
} while (true);
if (2 < 3) {
return;
}
if (3 < 4) {
return;
}
do {
x++
} while (x < 10000);
while (x < 50000) {
x++;
}
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
}
private class InnerClass implements I1, I2 {
public void bar() throws E1, E2 {
}
}
}
|
...
Sin embargo, el siguiente comportamiento funciona mejor con la mayoría de herramientas e IDEs y parece ser una práctica común, por lo que no observamos razón para negar dicha práctica, por ejemplo:
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
public interface MyInterface {
public static final int MY_INTEGER = 0;
public abstract void doSomething();
}
|
...
- Use trace level for detailed/diagnostic logging
- Use debug level for things an application developer would need to know
- Use info level for things an administrator would need to know
- Use warn level for things indicating an application or transient problem
- Use error level for things indicating a problem with the server itself
- Use fatal level for things that mean this instance is compromised
Example
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
private static final Log log = LogFactory.getLog(MyClass.class);
public void doSomeStuff(Stuff stuff) throws StuffException {
boolean logTrace = log.isTraceEnabled();
try {
if (logTrace) {
log.trace("About to do stuff " + stuff);
}
stuff.doSomething();
if (logTrace) {
log.trace("Did some stuff ");
}
} catch (BadException e) {
// don't log - leave it to caller
throw new StuffException("Something bad happened", e);
} catch (IgnorableException e) {
// didn't cache this as we don't expect to come here a lot
if (log.isDebugEnabled()) {
log.debug("Ignoring problem doing stuff "+stuff, e);
}
}
}
|
...
Abbreviations are all written in capitals in methods/classes/interfaces' names.
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
public final class J2EELoader {
public static EJBRef[] loadEJBRefs(Element parent) {
//...
}
}
|
...