![](https://img-blog.csdn.net/20130614174401968)
String[] greeting = new String[3];
greeting[0] = "Welcome to Core Java";
greeting[1] = "by Cay Horstmann";
greeting[2] = "and Gary Cornell";
for (String g : greeting)
System.out.println(g);
相当于as3中的
for each(var g :String in greeting) trace(g);
-----------------------------------------------
data types
必须初始化
After you declare a variable, you must explicitly initialize it by means of an assignment statement—you can never use the values of uninitialized variables.
int vacationDays;
System.out.println(vacationDays); // ERROR--variable not initialized
const is a reserved Java keyword, but it is not currently used for anything. You must use final for aconstant.
关于strictfp
If you tag a class as strictfp, then all of its methods use strict floating-point computations.
public static strictfp void main(String[] args)
外链拓展
>>>and>>
a >>> operator fills the top bits with zero, whereas >> extends the sign bit into the top bits. There is no <<< operator.
CAUTION: The right-hand side argument of the shift operators is reduced modulo 32 (unless theleft-hand side is a long, in which case the right-hand side is reduced modulo 64). For example, the value of1 << 35 is the same as 1 << 3 or 8.
* If either of the operands is of typedouble, the other one will be converted to a double.
* Otherwise, if either of the operands is of type float, the other one will be converted to a float.
* Otherwise, if either of the operands is of type long, the other one will be converted to a long.
* Otherwise, both operands will be converted to an int.
枚举
enum Size { SMALL, MEDIUM, LARGE, EXTRA_LARGE };
Now you can declare variables of this type:
Size s = Size.MEDIUM;