Last updated by Roedy Green ©1996-1999 Canadian Mind Products.
This document is a quick summary of the Java language syntax. It is not complete. It just contains the things you may be likely to forget.
if (a > b) {
System.out.println(a);
}
else {
System.out.println(b);
}
switch (n) {
case 1:
System.out.println("one");
break;
case 2:
System.out.println("two");
break;
default:
System.out.println("something else");
} // end switch (n)
for (int i=0; i<n; i++) {
System.out.println(i);
}
for (int i=0,j=0; i<n; i++,j++) {
System.out.println(i);
}
// However, this is illegal!
for (int i=0,float r=1.0; i<n; i++,r=r*2.0) {
System.out.println(i);
}
for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
System.out.println(key);
}
while (moreData()) {
readIt();
}
do {
readIt();
if (done) break;
if (bypassThisOne) continue;
processIt();
}
while (moreData());
public class Test extends StandardTest {
public static void main (String[] args) {
try {
dangerMethod();
}
catch (StrangeException e) {
System.out.println("oops " + e.getMessage());
}
} // end main
void dangerMethod() throws StrangeException {
if (unexpected) throw new StrangeException ("oh oh");
} // end dangeMethod
} end class Test
| Type | Signed? | Bits | Bytes | Lowest | Highest |
|---|---|---|---|---|---|
| boolean | n/a | 1 | 1 | false | true |
| char | unsigned Unicode | 16 | 2 | '\u0000' | '\uffff' |
| byte | signed | 8 | 1 | -128 | +127 |
| short | signed | 16 | 2 | -32,768 | +32,767 |
| int | signed | 32 | 4 | -2,147,483,648 | +2,147,483,647 |
| long | signed | 64 | 8 | -9,223,372,036,854,775,808 | +9,223,372,036,854,775,807 |
| float | signed exponent and mantissa | 32 | 4 | ±1.40129846432481707e-45 | ±3.40282346638528860e+38 |
| double | signed exponent and mantissa | 64 | 8 | ±4.94065645841246544e-324 | ±1.79769313486231570e+308 |
| Precedence | Operator | Association |
|---|---|---|
| 1 | ++ --
(unary) + - ~ ! (cast) |
Right |
| 2 | * / % | Left |
| 3 | + - | Left |
| 4 | << >> >>> | Left |
| 5 | < > <= >= | Left |
| 6 | == != | Left |
| 7 | & | Left |
| 8 | ^ | Left |
| 9 | | | Left |
| 10 | && | Left |
| 11 | || | Left |
| 12 | ? : | Right |
| 13 | = *= /= += -=
<<= >>= >>>= &= ^= |= |
Right |
/** * @(#)FormattedTextField.java 1.34 98/01/27 * @author Roedy Green * @version 1.34 1998 January 18 * @deprecated No replacement * @deprecated Replaced by otherMethod(int) * @see otherMethod * @see #otherMethod * @see java.awt.Component#repaint * @see <a href="http://mindprod.com/gloss.html">Java glossary</A> * @param x >B<pixels>/B< right of the origin. * @return number of oranges. * @exception java.beans.PropertyVetoException when mask is invalid * @since JDK1.1 */
![]() |
You are visitor number
. |
![]() | ||
| Canadian Mind Products | You can get an updated copy of this page from http://mindprod.com/jcheat.html | The Mining Company's
Focus on Java Best of the Net Award | ||