Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : J words : Java Cheat Sheet.
I have most of these common patterns built in as SlickEdit macros so I don't have to remember the patterns. I just click a custom icon for the pattern I want. Unfortunately, I thus don't remember them. Without my editor, I would be at a loss to remember where the parentheses and semicolons go.
// I F / E L S E if ( a > b ) { System.out.println( a ); } else { System.out.println( b ); } // I F / E L S E : is x in range low .. high? if ( low <= x && x <= high ) { System.out.println( "in range" ); } else { System.out.println( "out of range" ); } // S W I T C H / C A S E 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)
The variables used in the while (boolean) clause can't be declared inside the while loop. The inside of the loop is considered a separate inner block.
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 dangerMethod } // end class Test
To help you remember the syntax of catch, think of it as like a method, that gets passed an exception as a parameter.
try { somethingDangerous(); } catch ( IOException e ) { System.out.println( "oh oh" ); throw new BadDataException(); } finally { file.close(); // always executed }
Beware! A lead 0 on an integer implies OCTAL. That was a major design blunder inherited from C, guaranteed to introduce puzzling bugs. Be especially careful when specifying months or days, where you naturally tend to provide a lead 0.
Note floating point literals without the explicit trailing f, F, d or D are considered double. In theory you don't need a lead 0, e.g. 0.1d may be written .1d, though the Solaris and Symantec compilers seem to require it.
String s = "abc" + "def";There is no speed penalty for the + concatenation. It is done at compile time. String literals can be used anywhere you might use a String reference. e.g. "abc".charAt(1) is legal. For problematic characters like embedded ", see escape sequences below.
| Type | Signed? | Bits | Bytes | Lowest | Highest | Mnemonic |
|---|---|---|---|---|---|---|
| boolean | n/a | 1 | 1 | false | true | zero/one |
| char | unsigned Unicode | 16 | 2 | '\u0000' [0] aka Character.MIN_VALUE | '\uffff' [216-1] aka Character.MAX_VALUE | Unicode chars are twice as big as C's. |
| byte | signed | 8 | 1 | -128 [-27] aka Byte.MIN_VALUE | +127 [27-1]aka Byte.MAX_VALUE | Bytes are signed, so half the usual 255 range. |
| short | signed | 16 | 2 | -32,768 [-215] aka Short.MIN_VALUE | +32,767 [215-1] aka Short.MAX_VALUE | 32K |
| int | signed | 32 | 4 | -2,147,483,648 [-231] aka Integer.MIN_VALUE | +2,147,483,647 [231-1] aka Integer.MAX_VALUE | 2 gig |
| long | signed | 64 | 8 | -9,223,372,036,854,775,808 [-263] aka Long.MIN_VALUE | +9,223,372,036,854,775,807 [263-1] aka Long.MAX_VALUE | 9 exabytes, or 9 billion gig |
| float | signed exponent and mantissa | 32 | 4 | ±1.40129846432481707e-45 | ±3.40282346638528860e+38
with 6 to 7 significant digits of accuracy. |
rough float |
| double | signed exponent and mantissa | 64 | 8 | ±4.94065645841246544e-324 | ±1.79769313486231570e+308
with 14 to 15 significant digits of accuracy. |
high precision float |
| Mutable Primitives | Immutable Objects |
|---|---|
| boolean | Boolean |
| ordinary signed byte | Byte |
| unsigned byte | Byte |
| short | Short |
| char | Character |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| char[] | String |
| Java Keywords | ||||
|---|---|---|---|---|
| abstract | do | import | public | throws |
| boolean | double | instanceof | return | transient |
| break | else | int | short | try |
| byte | extends | interface | static | void |
| case | final | long | strictfp | volatile |
| catch | finally | native | super | while |
| char | float | new | switch | |
| class | for | package | synchronized | |
| continue | if | private | this | |
| default | implements | protected | throw | |
| Reserved keywords (not currently in use) | ||||
| const | goto | |||
| Reserved Literals | ||||
| null | true | false | ||
/** FormattedTextField.java * @author Roedy Green * @version 1.34 1998 January 18 * @deprecated Noreplacement * @deprecated Replaced by otherMethod(int) * @see otherMethod * @see #otherMethod * @see java.awt.Component#repaint * @see <a href="http://mindprod.com/gloss.html">Java & Internet Glossary</a> * @see "design patterns by Gamma et. al" * @param x <b>pixels</b> right of the origin. * @return number of oranges. * @exception java.beans.PropertyVetoException when mask is invalid * @since JDK1.1 */
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 39036. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/jcheat.html | J:\mindprod\jgloss\jcheat.html | |||