| b6b5b4 | ||||||||
| b3b2b1b0 | 000 (0-15) | 001 (16-31) | 010 (32-47) | 011 (48-63) | 100 (64-79) | 101 (80-95) | 110 (96-111) | 111 (112-127) |
| 0000 | nul | dle | space | 0 | @ | P | ` | p |
| 0001 | soh | dc1 | ! | 1 | A | Q | a | q |
| 0010 | stx | dc2 | " | 2 | B | R | b | r |
| 0011 | etx | dc3 | # | 3 | C | S | c | s |
| 0100 | eot | dc4 | $ | 4 | D | T | d | t |
| 0101 | enq | negAck | % | 5 | E | U | e | u |
| 0110 | ack | syn | & | 6 | F | V | f | v |
| 0111 | bell | etb | ' | 7 | G | W | g | w |
| 1000 | bksp | cancel | ( | 8 | H | X | h | x |
| 1001 | hTab | eom | ) | 9 | I | Y | i | y |
| 1010 | lineFeed | subs | * | : | J | Z | j | z |
| 1011 | vTab | esc | + | ; | K | [ | k | { |
| 1100 | formFeed | fileSep | , | < | L | \ | l | | |
| 1101 | carReturn | GrpSep | - | = | M | ] | m | } |
| 1110 | shOut | recrdSep | . | > | N | ^ | n | ~ |
| 1111 | shIn | unitSep | / | ? | O | _ | o | del |
Object.1
Essentially, a class is a set of objects having the same features, that is ,
supporting the same queries and commmands.
code attribute in the
<APPLET> tag to give a complete specification of where to
find the main applet class file: code specifies the name of the file, and
codebase specifies the URL of the directory containing the file.
// for single line or to the end of this line, /*...*/
for multiple lines, and /**...*/ for javadoc comments used to produce
the API.
new keyword.
Constructors differ from methods in that they return no data type, they have
the same name as the class, and have public visibility
(except for abstract classes which appropriately have protected
visibility).
|
Escaped character |
Meaning |
Escaped character |
Meaning |
Escaped character |
Meaning |
| '\b' | backspace | '\n' | newline | '\0' | null |
| '\f' | form feed | '\t' | tab | '\"' | quotation mark |
| '\r' | carriage return | '\'' | apostrophe | '\\' | backslash |
Object class.
Theif-thenstatement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates totrue. For example, theBicycleclass could allow the brakes to decrease the bicycle's speed only if the bicycle is already in motion. One possible implementation of theapplyBrakesmethod could be as follows:void applyBrakes(){ if (isMoving){ // the "if" clause: bicycle must be moving currentSpeed--; // the "then" clause: decrease current speed } }If this test evaluates to
false(meaning that the bicycle is not in motion), control jumps to the end of theif-thenstatement.In addition, the opening and closing braces are optional, provided that the "then" clause contains only one statement:
Deciding when to omit the braces is a matter of personal taste. Omitting them can make the code more brittle. If a second statement is later added to the "then" clause, a common mistake would be forgetting to add the newly required braces. The compiler cannot catch this sort of error; you'll just get the wrong results.void applyBrakes(){ if (isMoving) currentSpeed--; // same as above, but without braces }
Theif-then-elsestatement provides a secondary path of execution when an "if" clause evaluates tofalse. You could use anif-then-elsestatement in theapplyBrakesmethod to take some action if the brakes are applied when the bicycle is not in motion. In this case, the action is to simply print an error message stating that the bicycle has already stopped.void applyBrakes(){ if (isMoving) { currentSpeed--; } else { System.err.println("The bicycle has already stopped!"); } }
new operator followed by the class name. An
instance object contains all variables and methods for this particular
instance as well as access to all class data and methods. Each instance of
an object comes with memory allocation for its own variables and methods.
System.out.println(data)
| Name | Type | Range | Default Value |
| boolean | boolean | true or false | false |
| byte | byte integer | -128 to 127 | 0 |
| char | character data | any character | '\0' (null) |
| short | short integer | -32768 to 32767 | 0 |
| int | integer | -231 to 231 - 1 | 0 |
| long | long integer | -263 to 263 - 1 | 0 |
| float | real | -3.4028E38 to 3.4028E38 | 0.0 |
| double | double precision real | -1.7977E308 to 1.7977E308 | 0.0 |
9876 / 1 = __________ 9876 % 1 = __________ 9876 / 10 = __________ 9876 % 10 = __________ 9876 / 100 = __________ 9876 % 100 = __________ 9876 / 1000 = __________ 9876 % 1000 = __________
If you look for the pattern, you can see that integer division and modulo can be used to scale and shift integer values
Unlikeif-thenandif-then-else, theswitchstatement allows for any number of possible execution paths. Aswitchworks with thebyte,short,char, andintprimitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive types:Character,Byte,Short, andInteger(discussed in Simple Data Objects ).The following program,
SwitchDemo, declares anintnamedmonthwhose value represents a month out of the year. The program displays the name of the month, based on the value of month, using theswitchstatement.class SwitchDemo { public static void main(String[] args) { int month = 8; switch (month) { case 1: System.out.println("January"); break; case 2: System.out.println("February"); break; case 3: System.out.println("March"); break; case 4: System.out.println("April"); break; case 5: System.out.println("May"); break; case 6: System.out.println("June"); break; case 7: System.out.println("July"); break; case 8: System.out.println("August"); break; case 9: System.out.println("September"); break; case 10: System.out.println("October"); break; case 11: System.out.println("November"); break; case 12: System.out.println("December"); break; default: System.out.println("Invalid month.");break; } } }In this case, "August" is printed to standard output.
The body of a
switchstatement is known as a switch block. Any statement immediately contained by theswitchblock may be labeled with one or morecaseordefaultlabels. Theswitchstatement evaluates its expression and executes the appropriatecase.Of course, you could also implement the same thing with
if-then-elsestatements:int month = 8; if (month == 1) { System.out.println("January"); } else if (month == 2) { System.out.println("February"); } . . . // and so on
int or Object, and a scope. A
variable is a name for a location in memory. A variable must be declared,
specifying the variable's name and the type of data that will be held in it.
A variable can be given an initial value in the declaration.
This value can be changed later in variables not declared final (constant),
using the assignment operator (=). See also class
variable, instance
variable, local
variable, constant variable, attributes.
get and set indicating the raw
offset from GMT in milliseconds.
1These definitions are as found in the Sun Glossary at http://java.sun.com/docs/books/tutorial/information/glossary.html
2Java Software Solutions Foundations of Program Design by John Lewis and William Loftus, Addison Wesley Longman Inc., p529.