国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SCJP培訓筆記

2019-11-18 11:46:56
字體:
來源:轉載
供稿:網友

  Initialization
  
  初始化
  
  * All class-level (member) variables are initialized before they can
  be used.
  All local variables are not initialized until it is done eXPlicitly.
  
  
  * 所有的主成員在他們使用之前被初始化
  所有的局部變量必須通過顯式的賦值來初始化
  
  * An array object (as distinct from reference) is always initialized
  (with zeroes or nulls)
  
  * 數組對象總是能夠初始化(零或者null)
  
  * Member initialization with the declaration has exception PRoblems:
  - cannot call methods that throw a checked exception.
  - cannot do error recovery from runtime exceptions.
  - If you need to deal with errors you can put the initialization code
  along with try/catch statements in either a ctor (for instance fields)
  or in a static initialization block for static fields. You can also have
  instance (non-static) initialization blocks but ctors are more
  recognizable.
  
  * 需要處理異常的成員初始化
  - 不能調用會拋出異常的方法
  - 不能對基本異常做任何處理
  - 假如你需要處理錯誤,將初始化的代碼放到構造器或者靜態初始化塊的
  try/catch塊中,當然,你也可以放到非靜態的代碼塊中,但是構造器似乎更為通用。
  
  ------------------------------------------------------------------------
  
  Strings
  
  字符串
  
  * The String class
  - Because string is an immutable class, its instance methods that
  look like they would transform the object they are invoked upon,
  do not alter the object and instead return new String objects.
  - String has methods concat(String),trim(),replace(char,char)
  - String has static valueOf methods for a whole bunch of primitives
  and for Object too (equivalent to Object.toString()).
  - in substring(int,int), the second arg is exclusive.
  - indexOf methods returns -1 for 'not found'
  
  * 類String
  - 類String是不可變的,即使他的某些方法看起來會改變字符串的內容,但實際
  上他們返回的是一個新的字符串,而不是改變原來的字符串
  - 類String的方法:cancat(String),trim(),replace(char,char)
  - 類String的靜態方法valueOf能處理所有的基本類型和對象(調用對象的
  toString()方法)
  - 在substring(int,int)方法中,第二個參數是"不包括"的(譯者注:第一個參
  數是"包括"的,例如substring(1,4)將會返回字符串從第二個字符開始(包括
  第二個字符),到第五個字符結束(不包括第五個字符)的子字符串)
  - 假如沒有找到,indexOf方法將返回-1
  
  * String Pool:
  A JVM has a string pool where it keeps at most one object of any
  String. String literals always refer to an object in the string
  pool. String objects created with the new Operator do not refer to
  objects in the string pool but can be made to using String's intern()
  method. Two String references to 'equal' strings in the string pool
  will be '=='.
  
  * 字符串池
  虛擬機有一個字符串池,保存著幾乎所有的字符串對象。字符串表達式總是指向
  字符串池中的一個對象。使用new操作創建的字符串對象不指向字符串池中的對象
  但是可以使用intern方法使其指向字符串池中的對象(譯者注:假如池中已經有
  相同的字符串--使用equals方法確定,則直接返回池中的字符串,否則先將字符串
  添加到池中,再返回)。池中兩個相等的字符串假如使用'=='來比較將返回真
  
  * StringBuffer doesn't override equals.
  
  * 類StringBuffer沒有覆蓋equals方法
  
  ------------------------------------------------------------------------
  
  Arrays
  
  數組
  
  * Arrays are objects .. the following create a reference for an int array.
  int[] ii;
  int ii[];
  
  * 數組是一個對象 .. 下面的代碼創建一個整型數組的引用:
  int[] ii;
  int ii[];
  
  * You can create an array object with new or an explicit initializer:
  ii = new int[3];
  ii = new int[] { 1,2,3 };
  int[] ii = { 1,2,3 ); // only when you declare the reference.
  
  * 你可以通過new操作或者顯式的初始化創建一個數組對象:
  ii = new int[3];
  ii = new int[] { 1,2,3 };
  int[] ii = { 1,2,3 }; // 只有聲明的時候
  
  * CAREFUL: You can't create an array object with:
  int iA[3];
  
  * 小心:你不能象下面這樣創建一個數組對象:
  int iA[3];
  
  * If you don't provides values, the elements of obj arrays are
  always initialized to null and those of primitive arrays are
  always initialized to 0.
  
  * 假如你不提供初始值,對象數組的元素總是初始化成null,基本類型數組的元素
  總是初始化成零
  
  ------------------------------------------------------------------------
  
  Primitive Types
  
  基本類型
  
  * Primitive types:
  - short and char are both 2 bytes.
  int and float are both 4 bytes.
  long and double are both 8 bytes.
  - char is the only unsigned primitive type.
  
  * 基本類型:
  - short和char的長度是兩個字節。
  int和float的長度都是四個字節。
  long和double的長度都是八個字節。
  - char是唯一的無符號基本類型
  
  * Literals:
  - You can have boolean, char, int, long, float, double and String
  literals.
  You cannot have byte or short literals.
  - char literals: 'd' '/u0c20' (the 0c20 must be a 4-digit hex number).
  - int literals: 0x3c0 is hex, 010 is octal(for 8).
  - You can initialize byte, short and char variables with int literals
  (or const int expressions) provided the int is in the appropriate range.
  
  * 表達式
  - 只有boolean,char,int,long,float,double和字符串的表達式;沒有byte
  和short的表達式
  - 字符(char)表達式:'d'、'/u0c20'(0c20必須是四位的十六進制數字)
  - 整型(int)表達式:0x3c0是十六進制形式,010是八進制形式
  - 可是使用合法范圍內的整型表達式對byte、short和char變量初始化
  
  * CAREFUL: can't assign a double literal to a float .. float fff = 26.55;
  
  * 小心:不能將一個double表達式賦給一個float變量 .. float fff = 26.55;
  
  * The only bit operators allowed for booleans are &^ (cant do ~ or
  shift ops)
  
  * 位運算只有&^(不能使用~或者移位操作)
  
  * Primitive wrapper classes
  - are immutable.
  - override equals.
  - the static valueOf(String) methods in primitive wrapper classes return
  wrapper objects rather than a primitives.
  
  * 基本類型的包裝類
  - 不可變的
  - 覆蓋equals方法
  - 靜態方法valueOf(String)返回的是包裝類而不是基本類型
  
  ------------------------------------------------------------------------
  
  Conversions and Promotions
  
  類型轉換
  
  * boolean->anything but boolean or string is not allowed.
  * All other primitive conversions are allowed with an explicit cast.
  * char/byte/short/int/long to float/double is a widening conversion even
  if some precision is lost (the overall magnitude is always preserved).
  * Narrowing conversions require an explicit cast.
  - integral narrowing conversions simply discard high-order bits.
  - anything to char is a narrowing conversion (inc byte) because its
  signed to unsigned and negative numbers get messed up
  
  * boolean不能跟其它的任何類型相互轉換,但是boolean->String是答應的
  * 所有的基本類型之間可以通過顯式的類型轉換而轉變成其它類型
  * char/byte/short/int/long到float/double的轉換是寬轉換,即使有可能丟掉部
  分信息
  * 窄轉換需要顯式的轉換
  - 整型的窄轉換只簡單的去掉高位比特
  - 所有到char的轉換都是窄轉換(包括byte)因為轉換是從有符號數到無符號數

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通海县| 凉山| 沈阳市| 星座| 黔南| 钟山县| 贞丰县| 廉江市| 衢州市| 沅陵县| 丹棱县| 武强县| 天气| 育儿| 临潭县| 南宫市| 舒城县| 平山县| 马公市| 曲水县| 兴仁县| 连州市| 铜陵市| 衡水市| 临清市| 苏尼特右旗| 含山县| 天全县| 仲巴县| 哈巴河县| 黄冈市| 元谋县| 阳曲县| 安多县| 兴业县| 德化县| 江油市| 黄龙县| 北宁市| 沂南县| 文化|