[Core Java. Volume I. Fundamentals, 8th Edition]-2,3

 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 


In Java, it is considered good style to declare variables as closely as possible to the point  where they are first used

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; 




發佈了35 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章