欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Java筆記

Java筆記- -

                                      

譯者注:

    原作作者為一位以100%的好成績(jì)通過(guò)SCJP的牛人,作者的詳細信息已經(jīng)無(wú)從考
證。本文是這位大牛復習期間的筆記,對正在準備考SCJP的同志們很有裨益。

                                                          JETIC . HOVER
                                                     完成于2001年11月30日

 


========================================================================
I sat for the "Sun Certified Programmer for the Java 2 Platform" exam in
 December 1999 and scored 100%.

1999年12月我參加了SCJP考試并取得了100%的好成績(jì)。

This document contains my study notes for the exam. I do not guarantee
the veracity of the notes and please contact me if you disagree with
anything in them.

本文檔包含了我學(xué)習的筆記。我不敢保證筆記的正確性,如果你對其中的任何東西
有不同的意見(jiàn),請聯(lián)系我。

The notes should not be taken as a general or complete preparation for
the exam and instead reflect my own priorities and previous knowledge.
The sections on AWT and threads are particularly brief. These notes
predate my taking of the exam and are therefore not based in any way
on the exam itself.

你不應該將此筆記作為一份完整的復習資料,因為它只是反映了我較早時(shí)期的知識
。抽象窗口工具包和線(xiàn)程部分尤為簡(jiǎn)短。本筆記在我考試之前已經(jīng)完成,并未反映
任何考試的內容。

------------------------------------------------------------------------

Initialization

初始化

* All class-level (member) variables are initialized before they can
  be used.
  All local variables are not initialized until it is done explicitly.


* 所有的主成員在他們使用之前被初始化
  所有的局部變量必須通過(guò)顯式的賦值來(lái)初始化

* 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.

* 需要處理異常的成員初始化
- 不能調用會(huì )拋出異常的方法
- 不能對基本異常做任何處理
- 如果你需要處理錯誤,將初始化的代碼放到構造器或者靜態(tài)初始化塊的
  try/catch塊中,當然,你也可以放到非靜態(tài)的代碼塊中,但是構造器似乎更為通用。

------------------------------------------------------------------------

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‘

* 類(lèi)String
  - 類(lèi)String是不可變的,即使他的某些方法看起來(lái)會(huì )改變字符串的內容,但實(shí)際
    上他們返回的是一個(gè)新的字符串,而不是改變原來(lái)的字符串
  - 類(lèi)String的方法:cancat(String),trim(),replace(char,char)
  - 類(lèi)String的靜態(tài)方法valueOf能處理所有的基本類(lèi)型和對象(調用對象的
    toString()方法)
  - 在substring(int,int)方法中,第二個(gè)參數是"不包括"的(譯者注:第一個(gè)參
    數是"包括"的,例如substring(1,4)將會(huì )返回字符串從第二個(gè)字符開(kāi)始(包括
    第二個(gè)字符),到第五個(gè)字符結束(不包括第五個(gè)字符)的子字符串)
  - 如果沒(méi)有找到,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 ‘==‘.

* 字符串池
  虛擬機有一個(gè)字符串池,保存著(zhù)幾乎所有的字符串對象。字符串表達式總是指向
  字符串池中的一個(gè)對象。使用new操作創(chuàng )建的字符串對象不指向字符串池中的對象
  但是可以使用intern方法使其指向字符串池中的對象(譯者注:如果池中已經(jīng)有
  相同的字符串--使用equals方法確定,則直接返回池中的字符串,否則先將字符串
  添加到池中,再返回)。池中兩個(gè)相等的字符串如果使用‘==‘來(lái)比較將返回真

* StringBuffer doesn‘t override equals.

* 類(lèi)StringBuffer沒(méi)有覆蓋equals方法

------------------------------------------------------------------------

Arrays

數組

* Arrays are objects .. the following create a reference for an int array.
    int[] ii;
    int ii[];

* 數組是一個(gè)對象 .. 下面的代碼創(chuàng )建一個(gè)整型數組的引用:
    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.

* 你可以通過(guò)new操作或者顯式的初始化創(chuàng )建一個(gè)數組對象:
    ii = new int[3];
    ii = new int[] { 1,2,3 };
    int[] ii = { 1,2,3 }; // 只有聲明的時(shí)候

* CAREFUL: You can‘t create an array object with:
    int iA[3];

* 小心:你不能象下面這樣創(chuàng )建一個(gè)數組對象:
        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,基本類(lèi)型數組的元素
總是初始化成零

------------------------------------------------------------------------

Primitive Types

基本類(lèi)型

* 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.

* 基本類(lèi)型:
  - short和char的長(cháng)度是兩個(gè)字節。
        int和float的長(cháng)度都是四個(gè)字節。
        long和double的長(cháng)度都是八個(gè)字節。
  - char是唯一的無(wú)符號基本類(lèi)型

* 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和字符串的表達式;沒(méi)有byte
  和short的表達式
- 字符(char)表達式:‘d‘、‘\u0c20‘(0c20必須是四位的十六進(jìn)制數字)
- 整型(int)表達式:0x3c0是十六進(jìn)制形式,010是八進(jìn)制形式
- 可是使用合法范圍內的整型表達式對byte、short和char變量初始化

* CAREFUL: can‘t assign a double literal to a float .. float fff = 26.55;

* 小心:不能將一個(gè)double表達式賦給一個(gè)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.

* 基本類(lèi)型的包裝類(lèi)
  - 不可變的
  - 覆蓋equals方法
  - 靜態(tài)方法valueOf(String)返回的是包裝類(lèi)而不是基本類(lèi)型

------------------------------------------------------------------------

Conversions and Promotions

類(lèi)型轉換

* 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不能跟其它的任何類(lèi)型相互轉換,但是boolean->String是允許的
* 所有的基本類(lèi)型之間可以通過(guò)顯式的類(lèi)型轉換而轉變成其它類(lèi)型
* char/byte/short/int/long到float/double的轉換是寬轉換,即使有可能丟掉部
  分信息
* 窄轉換需要顯式的轉換
  - 整型的窄轉換只簡(jiǎn)單的去掉高位比特
  - 所有到char的轉換都是窄轉換(包括byte)因為轉換是從有符號數到無(wú)符號數
    的轉換,負數將會(huì )得到一個(gè)混亂的結果

* Widening primitive and reference conversions are allowed for assignment
  and in matching the arguments to a method (or ctor) call.

* 對象和基本類(lèi)型的寬轉換允許在賦值和匹配的方法調用中(非顯式的)使用

* For assignment (but not method invocation), representable constant
  int expressions can be converted to byte, char or shorts (eg. char c =
  65).

* 賦值時(shí),合法的整型表達式能被自動(dòng)轉換成byte、char或者short(例如:
  char c = 65)

* Unary numeric promotions: byte/short/char to int

* 一元運算時(shí),byte/short/char將自動(dòng)轉換成int

* Binary numeric promotions:
  - both arguments are made (in order of preference)
    double/float/long/int.
  - include (in)equality operators.

* 二進(jìn)制數據類(lèi)型轉換:
  - 所有的參數自動(dòng)轉換成(按循序的)double/float/long/int
  - 包括比較運算

* char/byte/short are promoted to int for nearly every operator ... be
  careful not to assign the uncast int return value to a narrower type,

     bytesum = byte1 + byte2; // won‘t compile without a cast.
     bytesum += byte2; // is ok.
  - applies to bitshift operators (as a unary promotion on each arg).
  - applies to unary + and - (eg. byte b = +anotherByte; needs a cast).

  - there are no promotions for ++, --, += etc.

        byte b=10;
        char c = b++; //explicit cast needed to convert byte to char
        char c = b++ +10; //explicit cast needed to convert int to char
        char c = b++ +10L; //explicit cast needed to convert long to char

* char/byte/short幾乎在所的運算中都被轉換成int ... 要當心不要將int類(lèi)型的
  返回值在沒(méi)有顯式轉換之前賦給一個(gè)更小的類(lèi)型:
        bytesum = byte1 + byte2; //沒(méi)有顯式的轉換不能通過(guò)編譯
        bytesum += byte2; // 沒(méi)有問(wèn)題
  - 本規則適合于位運算(以及每個(gè)一元運算的參數)
  - 本規則不適用于++,--,+=等操作

        byte b = 10;
        char c = b++; //需要顯式的將byte轉換成char
        char c = b++ + 10; //需要顯式的將int轉換成char
        char c = b++ + 10L; //需要顯式的將long轉換成char

* A switch argument can be any type that can implicit-cast to an int
  (byte/char/short/int but not boolean or long).
  - The argument and cases can also be compile-time constant
    expressions.

* switch的參數可以是任何可以自動(dòng)轉換成int型的基本類(lèi)型(
  byte/char/short/int是合法的參數,但是boolean和long型是不合法的)
  - switch的參數和case的參數可以是常量表達式

* Explicit Casting:
  - Impossible casts are detected at compile time.
    Other bad casts cause runtime exceptions rather than messes.

* 顯式的轉換
  - 不可能的轉載編譯期間就能檢測到。其他錯誤的轉換將拋出異常以防止數據的
混亂

* Array casts:
  - The only implicit conversion for arrays is: Base[] base = new Der[5];
    - a runtime exception is thrown if you try to add anything but Derived
  - There are no implicit casts for arrays of primitives.
  - You can make an explicit array cast:
         String[] strs = (String[]) ObjectArray;


* 數組轉換:
  - 對象數組唯一的自動(dòng)轉換的情況是:Base[] base = new Der[5];
    - 如果你嘗試添加Derived以外的對象,將會(huì )得到一個(gè)運行期異常
  - 基本類(lèi)型數組沒(méi)有自動(dòng)轉換的情況
  - 可以使用顯式的數組類(lèi)型轉換:
                String[] strs = (String[]) ObjectArray;

------------------------------------------------------------------------

Bitshift operators

位移操作

- The left-hand argument to a bitshift operator can be an int, long
  or any type that can be implicit cast to int (byte,char,short).

- 左側的參數必須為int,long,或者任何可以自動(dòng)轉換成int的類(lèi)型(byte,
  char,short)

- char, byte, or short arguments will be promoted to int before the shift
  takes place, and the result will be an int (so has to be cast to get back
  to the original type).

- char,byte或者short型的參數在位移操作之前被自動(dòng)轉換成int型,結果類(lèi)型為
  int(所以你需要顯式的將返回類(lèi)型轉換成原來(lái)的類(lèi)型)

- You can‘t shift futher than the number of bits in the left-hand argument
  (int or long). Only the five (six) low-order bits of the right-hand
  argument will be used to shift an int (long).

- 你不能移動(dòng)比左側參數(int或者long)的長(cháng)度長(cháng)的位數。右邊參數只有低五(

  六)位被用來(lái)移動(dòng)左側的int(long)類(lèi)型數據

- Each left-shift (signed-right-shift) for positive numbers is equivalent
  to multiplication (division) by 2. The division is rounded down.

- 左移(有符號數右移)操作相當于乘(除)二運算。(...)

------------------------------------------------------------------------

------------------------------------------------------------------------

Object-oriented concepts

面向對象的概念

* The signature of a method is its name, argument type and argument order.
  - an overload is legal provided the two methods have different signatures.
  - an override must have the same signature and return type, throw no new
    checked exceptions and be at least as accessible as the method it is
    overriding.

* 一個(gè)方法通過(guò)它的名字,參數類(lèi)型以及順序來(lái)標識
  - 有不同標識的方法重載是合法的
  - 方法覆蓋必須有相同的標識和返回值,不能拋出新的普通異常,不能比他要覆
    蓋的方法擁有更少的權限

* Fields do not act polymorphically:
  - whenever you access a field from outside the class, the declared type of
    the reference is used rather than the type of the object it refers to.
  - regardless of the type of the reference, a method will always access its
    own fields rather than those of a derived class.

* 變量成員沒(méi)有多態(tài)性
  - 當你從類(lèi)外面引用變量成員時(shí),你總是得到定義的類(lèi)型,而非實(shí)際指向的類(lèi)型

  - 不管變量成員的類(lèi)型是什么,方法總是使用類(lèi)自己的變量成員,而不是其他的
    繼承過(guò)來(lái)的變量成員

* Private method calls are statically bound ... a method will call
  the private method in the class where it is defined .. even if the
  calling method is inherited by a derived class and the derived
  class defines a method with the same signature as the private method.


* 私有方法的調用是靜態(tài)綁定的 ... 方法可以調用他所在類(lèi)之內的私有方法 .. 即
  使調用的方法的夫類(lèi)中有與此私有方法標識相同的方法

* Calls to public and protected methods in the same class are dynamically
  bound ... even for constructors (and from private methods). This is
  different to C++.

* 對公共的和保護的方法的調用是動(dòng)態(tài)綁定的 ... 同樣構造函數(不同于私有方法?)
  也是動(dòng)態(tài)綁定的。這是與C++不同的地方

* Re-using a static method‘s name in a derived class:
  - A static method cannot be overriden by a non-static method
  - A static method can be overriden by a static method but does not
    dynamically bind (therefore static methods can‘t be abstract)
  - You can overload a static method with a non-static method.
  * note also that a static method can be inherited.
  * note that a static var can be ‘overriden‘ by a non-static var.

* 重用夫類(lèi)中的靜態(tài)方法的名字:
  - 靜態(tài)方法不能被非靜態(tài)的方法覆蓋
  - 靜態(tài)方法可以被靜態(tài)方法覆蓋,但是不能動(dòng)態(tài)綁定(所以靜態(tài)方不能是抽象的)
  - 可以使用非靜態(tài)的方法重載靜態(tài)的方法
  * 注意靜態(tài)方法是可以繼承的
  * 注意靜態(tài)的變量可以被非靜態(tài)的變量"覆蓋"

* It‘s legal to assign any reference type including an Interface reference
  to an Object reference .. which makes sense because the interface ref
  must point to an Object (or null).

* 講任何類(lèi)型的引用包括接口的引用付給一個(gè)Object的引用是合法的 .. 應為一個(gè)
  接口的引用總是指向一個(gè)Object(或者null)

------------------------------------------------------------------------

Nested classes

-> from the Java Language Specification
-> from Sun‘s Java Tutorial

嵌套類(lèi)

-> 來(lái)自Java語(yǔ)言規范
-> 來(lái)自Sun的Java教程

*** A nested class is a class that is defined inside another class.

*** 嵌套類(lèi)是定義在另外一個(gè)類(lèi)的內部的類(lèi)

* There are two distinct types of nested classes:
  - static nested classes (or top-level nested classes)
  - inner classes (which are always associated with an instance of
    an enclosing class).

* 有兩種截然不同的嵌套類(lèi)
  - 靜態(tài)的嵌套類(lèi)(或者說(shuō)頂層的嵌套類(lèi))
  - 內部類(lèi)(總是定義在其他類(lèi)的實(shí)例里面)

* (Nested) inner class types:
  - member classes,
  - local classes (method or code block),
  - anonymous classes.

* (嵌套的)內部類(lèi):
  - 成員類(lèi)
  - 局部類(lèi)(方法或者代碼塊)
  - 匿名類(lèi)

* Top-level classes (all classes are either top-level or inner)
  - static nested classes,
  - package member classes.

* 頂層類(lèi)(所有的類(lèi)不是頂層類(lèi)就是內部類(lèi))
  - 靜態(tài)的嵌套類(lèi)
  - 包成員類(lèi)

* Access to enclosing class:
  - all outer-class members (inc. private) are accessible to an inner
    class [Usually without scope modifiers, but if they are hidden by
    an inner class name, you can use Outer.this.outerVar]
  - static nested classes cannot acccess instance variables from enclosing
    classes (there is no instance), but can access their static variables
    (and classes i would think).

* 內部類(lèi)的權限
  - 外部類(lèi)所有的成員(比如私有的)都有權限訪(fǎng)問(wèn)內部類(lèi) [通常沒(méi)有任何的權限
    修飾,但是如果對內部類(lèi)是隱藏的,可以通過(guò)Outer.this.outerVar來(lái)引用]
  - 靜態(tài)內部累不可以引用外部類(lèi)的實(shí)例變量(沒(méi)有實(shí)例),但是可以引用外部類(lèi)
    的靜態(tài)變量(我想,引用靜態(tài)的類(lèi)也是允許的)

* Instantiation:
  - For accessible inner classes: Outer.Inner i = new Outer().new Inner();
    Even if you are in Outer‘s scope, you need to have an Outer instance.
  - For accessible static nested classes:
    Outer.Nested nested = new Outer.Nested();

* 實(shí)例化:
  - 內部類(lèi)的引用:Outer.Inner i = new Outer().new Inner();
    即使在外部類(lèi)的范圍內,你也需要一個(gè)外部類(lèi)的實(shí)例
  - 靜態(tài)內部類(lèi)的引用:Outer.Nested nested = new Outer.Nested();

* Local inner classes cannot access non-final local variables or method
  arguments.

* 局部?jì)炔款?lèi)不能引用非最終(final)的局部變量和方法參數

* Nested classes generally have the same options with regard to
  modifiers as do variables declared in the same place.

* 嵌套類(lèi)可以與同等位置上的變量擁有相同的權限修飾

* Unlike class-level nested classes, local classes are executed in the
  method‘s sequence of execution so you can‘t create an instance of the
  local class before it is declared.

* 與類(lèi)一級的內部類(lèi)不同的是,局部類(lèi)是按次序執行的,所以你不能在定義之前創(chuàng )
  建一個(gè)類(lèi)的實(shí)例

* The static keyword marks a top-level construct (class, method or
  field) and can never be subject to an enclosing instance.
  - no inner class can have a static member.
  - no method can have a static member.

* 關(guān)鍵字static使一個(gè)頂層的構造(類(lèi),方法或者成員變量)不屬于他的外部類(lèi)實(shí)例
  - 內部類(lèi)不能有靜態(tài)成員
  - 方法不能有靜態(tài)成員

* Interfaces automatically attach ‘public static final‘ to field and
  class members (thus making them top-level nested rather than member
  inner classes).

* 接口自動(dòng)將"public static final"的權限修飾賦予所有的成員變量和方法(這
  將保證它們是頂層嵌套的而不是內部成員類(lèi))

* A nested class cannot have the same simple name as any of its
  enclosing classes (note: there is no similar restriction on method
  or variable names).

* 嵌套類(lèi)不能使用與它的任何外部類(lèi)的名字相同的名字來(lái)命名(注意:方法和變量
  并沒(méi)有這個(gè)限制)

------------------------------------------------------------------------

------------------------------------------------------------------------

Threads

線(xiàn)程

* Know where the basic thread methods are:
  - wait, notify and notifyAll are Object instance methods.
  - start, stop, suspend, resume and interrupt are Thread instance methods.
  - sleep and yield are Thread static methods

* 了解基本的線(xiàn)程方法的位置:
  - wait,notify和notifyAll是Object的實(shí)例方法
  - start,stop,suspend,resume和interrupt是Thread的實(shí)例方法
  - sleep和yield是Thread的靜態(tài)方法

* Thread states:
  - Bruce Eckel lists 4 thread states: new, runnable, blocked, dead.

* 線(xiàn)程的狀態(tài)
  - Bruce Eckel 列出四種線(xiàn)程狀態(tài):創(chuàng )建,可運行的,堵塞的,死亡

* Blocking
  - There are 5 ways a thread can be blocked - sleep, wait, suspend,
    synchronization, io blocking.
  - sleep and suspend do not release locks held by the thread.

* 堵塞的
  - 有五種方法可以使一個(gè)線(xiàn)程堵塞 - sleep,wait,suspend,同步,io堵塞
  - sleep和suspend期間線(xiàn)程不釋放對象的鎖

* Deprecated methods
  - stop is unsafe because it releases all locks and may leave objects in
    an inconsistent state.
  - suspend is deprecated because its failure to release locks makes it
    prone to deadlock. Calling wait in a sync block is safer.

* 不推薦使用的方法
  - stop方法因為釋放所有的鎖而導致有可能使線(xiàn)程進(jìn)入不一致的狀態(tài),不安全
  - suspend不推薦使用是因為它不能釋放鎖而導致有可能進(jìn)入死鎖狀態(tài)。在同步
    代碼里使用wait會(huì )更安全

* The isAlive method returns false for new threads as well as dead threads.

* isAlive方法在線(xiàn)程創(chuàng )建和死亡的狀態(tài)下都返回false

* Threads inherit their priority from the thread that calls their ctor.

* 線(xiàn)程繼承調用他們的構造函數的線(xiàn)程的優(yōu)先級

------------------------------------------------------------------------

Exceptions

異常

* Non-runtime exceptions are called checked exceptions.

* 非運行期異常叫普通異常

* Even if a method explicitly throws a runtime exception, there is no
  obligation for the caller to acknowledge the exception. One consequence
  of this is that the restriction on exceptions thrown by an overriding
  method only applies to checked exceptions.

* 如果方法拋出運行期異常,調用者沒(méi)有必要知道。由此推論出,方法覆蓋拋出異
常的限制只適用于普通異常

* A try block‘s finally clause is called unless the JVM is exited (i think).
  - a return in try or catch does not prevent finally from being executed.

* try塊的fanally字句總是被執行,除非程序推出虛擬機(我想是這樣的)
  - try或者catch里面的語(yǔ)句不能阻止finally字句的執行

* A try block‘s finally statement will be executed (unless the thread dies)
  before control leaves the try/catch/finally scope. It will be executed
  before unhandled exceptions (from try or catch) are passed back up the
  calling stack.

* try塊的finally字句在退出try/catch/finally之前執行(除非線(xiàn)程已經(jīng)死亡)。
  它將會(huì )在將沒(méi)有捕捉的異常(產(chǎn)生于try或者catch)送回調用堆棧之前執行

* If you return from a try and finally does not return ... 1) the return
  value is calculated, 2) finally executes and 3) the method returns with
  the value calculated prior to executing finally.

* 如果你從try字句返回并且finally字句不包含返回 ... 1) 計算返回值,2) 執行
  finally字句, 3) 方法返回執行finally之前計算的結果

* If you have a return in both try and finally, the finally‘s value
  is always returned.

* 如果你同時(shí)在try和finally中返回,則總是返回finally中的返回值

* If try/catch excludes continuation following finally, it is a compile
  error to have any statements there.

* 在try/catch和finally之間放置任何語(yǔ)句將會(huì )導致編譯錯誤

* Primitive floating point operations do not throw exceptions. They use
  NaN and infinity instead.

* 基本的浮點(diǎn)運算不會(huì )拋出異常,它們使用NaN和infinity來(lái)表示異常的結果

* A constructor can throw any exception.

* 構造函數可以?huà)伋鋈魏萎惓?/p>

------------------------------------------------------------------------

Streams

* System.in is an InputStream and out and err are PrintStreams.

* System.in是一個(gè)InputStream,out和err是PrintStream

* Beware of instances of the abstract OutputStream and InputStream.

* 慎防實(shí)例化抽象的OutputStream和InputStream

* Some OutputStreams:
  OutputStream
    - write(int) writes the eight low-order bits to the underlying stream
    - write(byte[]) write(byte[],int off,int len)
    - flush()
    - close()
  BufferedOutputStream
    - has two ctors: (OutputStream) (OutpuStream, int size)
  DataOutputStream
    - writes primitives and strings to a byte-based stream.
  ObjectOutputStream
    - writes primitives, strings and serializable objects (inc arrays).
    - is not a FilterOutputStream (seems strange).
  PrintStream
    - two ctors: (OutputStream) (OutputStream, boolean autoflush)
    - never throws IOExceptions (sets internal flag instead)
    - print and println for primitives and strings.
    - print(Object) prints Object.toString().
    - System.out and System.err are printstreams.
  FileOutputStream
    - 4 constructors: (File) (FileDescriptor) (String)
      (String, boolean append)
  PipedOutputStream
    - two ctors: () (PipedInputStream)
    - method to connect(PipedInputStream)
  ByteArrayOutputStream
    - 2 ctors: () (int size)

* 一些OutputStream:
  OutputStream
    - write(int) 將int的低八位寫(xiě)入底層的流
    - write(byte[]) write(byte[],int off,int len)
    - flush()
    - close()
  BufferedOutputStream
    - 兩個(gè)構造函數:(OutputStream) (OutpuStream, int size)
  DataOutputStream
    - 將基本類(lèi)型和字符串寫(xiě)入基于字節的流
  ObjectOutputStream
    - 寫(xiě)入基本類(lèi)型,字符串和串行化的對象(例如數組)
    - is not a FilterOutputStream (seems strange).
  PrintStream
    - 兩個(gè)構造函數:(OutputStream) (OutputStream, boolean autoflush)
    - 永遠不會(huì )拋出IOException(取而代之的是設置某些標記位)
    - print and println的參數可以是基本類(lèi)型和字符串
    - print(Object)打印Object.toString().
    - System.out和System.err是PrintStream
  FileOutputStream
    - 四個(gè)構造函數:(File) (FileDescriptor) (String)(String, boolean append)
  PipedOutputStream
    - 兩個(gè)構造函數:() (PipedInputStream)
    - 方法connect(PipedInputStream)
  ByteArrayOutputStream
    - 兩個(gè)構造函數:() (int size)

* Some Writers
  - OutputStreamWriter
  - StringWriter, CharArrayWriter - like ByteArrayOutputStream
  - FileWriter, BufferedWriter, PrintWriter, FilterWriter
  - There is no ObjectWriter, DataWriter.
  - PrintWriter can be constructed with an OutputStream or Writer.

* 一些Writer
  - OutputStreamWriter
  - StringWriter, CharArrayWriter - 與ByteArrayOutputStream相似
  - FileWriter, BufferedWriter, PrintWriter, FilterWriter
  - 沒(méi)有ObjectWriter, DataWriter.
  - PrintWriter可以使用OutputStream或者Writer來(lái)構造

* Some Readers:
  - LineNumberReader doesn‘t attach numbers, it has getLineNumber().
  - CharArrayReader is ctd with the char[] that it reads from and
    optional int start position and length args.

* 一些Reader:
  - LineNumberReader并不會(huì )附加行號,可以通過(guò)getLineNumber()方法取得行號
  - CharArrayReader使用char[]來(lái)構造,從char[]中讀取數據,參數int start和
    length是可選的

* RandomAccessFile
  - does not extend File or any type of stream.
  - two ctors: ( File or String name, String mode="r","rw" )
  - checks for read/write access at construction (unlike File).
  - has read/write methods for primitives and strings (and a couple of
    others).
  - has a (long//mahachanged fm byte to long) file-pointer: seek(long),
    long length().

* RandomAccessFile
  - 并非繼承自File或者任何類(lèi)型的流
  - 連個(gè)構造函數:( File or String name, String mode="r","rw" )
  - 在初始化時(shí)檢查文件的讀寫(xiě)權限(不同于File)
  - 對基本類(lèi)型和字符串(還有其他的)有專(zhuān)門(mén)的讀寫(xiě)方法
  - 有一個(gè)long型的文件指針:seek(long), long length().

* FileDescriptor
  - just a handle to a sink/source of bytes.
  - only has two methods: sync() and valid()

* FileDescriptor
  - 只是作為字節接收器/源的一個(gè)句柄
  - 只有兩個(gè)方法:sync() and valid()

* File
  - represents an abstract file or dir pathname (file/dir doesnt have
    to exist).
  - 3 ctors: (File or String parent, String child) (String pathname)

* File
  - 對抽象的文件或者目錄的描述(文件/目錄不一定存在)
  - 三個(gè)構造函數:(File or String parent, String child) (String pathname)

------------------------------------------------------------------------

Collections

集合

* The Collection interface is extended by Set and List (and SortedSet).
  - a set contains no duplicates.
  - a list is a sequence and can have duplicates.
* The Map interface does not extend Collection and is extended by
  SortedMap.

* Set、List和SortedSet繼承自Collection
  - Set不包含重復的元素
  - List是有序的,可以包含重復的元素
* Map并非Collection的子類(lèi),SortedMap繼承自Map

* There are abstract classes for each of the main interfaces (Collection,
  Set, List and Map) and implementations extend these.

* 主要的接口都有相對應的抽象類(lèi),具體的實(shí)現從抽象類(lèi)繼承

* Set implementations
  - HashSet
  - TreeSet (implements SortedSet)
* List implementations
  - ArrayList
  - LinkedList
* Map implementations
  - HashMap
  - TreeMap (implements SortedMap)

* 實(shí)現Set的類(lèi)
  - HashSet
  - TreeSet(實(shí)現SortedSet)
* 實(shí)現List的類(lèi)
  - ArrayList
  - LinkedList
* 實(shí)現Map的類(lèi)
  - HashMap
  - TreeMap(實(shí)現SortedMap)

* Vector and Hashtable (extends Dictionary) are older collection classes.
  - Vector has been made to extend AbstractList and is like a sync‘d
    ArrayList (maha:set)z.
  - Hashtable still extends Dictionary but it implements Map.
  - In contrast to other collection types, Vector and Hashtable are
    synchronized.

* Vector和Hashtable(繼承自Dictionary)是較老的集合類(lèi)
  - Vector繼承自AbstractList,與同步的ArrayList相像
  - Hashtable仍然繼承自Dictionary但是實(shí)現了Map接口
  - 與其他集合類(lèi)型相比較,Vector和Hashtable是同步的

* There are Collections and Arrays classes to provide static methods for
  general algorithms on collections and arrays.

* Collection和Array都提供了靜態(tài)的方法處理集合和數組的運算

* Stack extends Vector
  - it has methods push(Object), pop, peek and search(Object).
  - Push is identical to addElement but also returns the added Object.
  - The top of a stack is the last element in the vector (and has index 1 as
    far as the search method is concerned).

* Stack繼承自Vector
  - 方法:push(Object),pop,peek和search(Object)
  - push方法與addElement的效果相似,同時(shí)返回剛剛添加過(guò)的對象
  - 棧頂是Vector里面最后一個(gè)元素(search方法將返回1)

------------------------------------------------------------------------

Math methods

Math的方法

* most act on and return double values
 - note that floor(double), ceil(double) and rint(double) return doubles
   not ints

* 大部分的方法都是對double類(lèi)型數據作處理并返回double型的結果
  - 注意floor(double),ceil(double)和rint(double)返回的是double類(lèi)型而不
    是int

* abs, max and min can take double, float, int or long arguments and the
  return type matches the argument type.

* abs,max和min方法可以處理double,float,int或者long型的參數并且返回與
  參數類(lèi)型一樣的返回值

* There are three rounding methods:
  - int round( float ); // note both are 32-bit
  - long round( double ); // note both are 64-bit
  - double rint( double );

* 三個(gè)取整方法:
  - int round(float); // 注意兩者都是32位
  - long round(double); // 注意兩者都是64位
  - double rint(double);

* log returns natural log.

* log方法返回自然對數

* trig functions take double arguments in radians.

* trig函數的參數是double型的弧度

------------------------------------------------------------------------

------------------------------------------------------------------------

AWT

抽象窗口工具包

* Component is abstract ... Container is not abstract.

* Component是抽象的 ... Container不是抽象的

* Checkbox has 5 ctors: no-arg + four with String as first arg and
  combinations of boolean initialState and CheckboxGroup.

* Checkbox有五個(gè)構造函數:一個(gè)沒(méi)有任何參數,其他四個(gè)都以字符串為第一個(gè)參
  數,以及boolean型的初始化狀態(tài)、CheckboxGroup

* CheckboxMenuItem has nothing to do with Checkbox or CheckboxGroup.
  - i think they generate both Item- and ActionEvents.

* CheckboxMenuItem與Checkbox和CheckboxGroup沒(méi)有任何關(guān)系
  - 我想他們都產(chǎn)生ItemEvent和ActionEvent

* Listeners:
 - InputEvent (super for MouseEvent and KeyEvent) has a ‘long getWhen()‘
   method.
 - MouseEvent has ‘int getX‘, ‘int getY‘ and ‘Point getPoint‘ methods.
 - ActionEvent and ItemEvent are not ComponentEvents so have to use
   getSource().
 - MenuItems (inc. menus) can produce ActionEvents but not ItemEvents.
 - ActionListener,Adjustment, ItemListener and TextListener only have
   one method and therefore don‘t have Adapters.
 - KeyListener: Pressed/Released/Typed
 - FocusListener: Lost/Gained
 - ComponentListener: Shown/Hidden   Moved     Resized
 - ContainerListener: component- Added/Removed
 - WindowListener: Opened/Closing/Closed
                   Activated/Deactivated ... keyboard focus.
                   Iconifed/Deiconified
 - MouseListener: Pressed/Released/Clicked
                  Entered/Exited
 - MouseMotionListener: Dragged/Moved

* 接收器:
 - InputEvent(MouseEvent和KeyEvent的父類(lèi))有方法:long getWhen()
 - MouseEvent的方法:int getX,int getY,Point getPoint
 - ActionEvent和ItemEvent不屬于ComponentEvent,只能使用getSource()
 - MenuItem(例如菜單)產(chǎn)生的是ActionEvent而不是ItemEvent
 - ActionListener,Adjustment,ItemListener和TextListener只定義了一個(gè)方法
   ,所以不需要適配器
 - KeyListener:鍵的按下/釋放/敲擊
 - FocusListener: 焦點(diǎn)的失去/獲得
 - ComponentListener: 顯示/隱藏,移動(dòng),改變大小
 - ContainerListener: 添加/刪除組件
 - WindowListener: 打開(kāi)/關(guān)閉中/已經(jīng)關(guān)閉
                   激活/無(wú)效 ... 鍵盤(pán)焦點(diǎn)
                   最小化/恢復
 - MouseListener: 鍵的按下/釋放/點(diǎn)擊
                  鼠標進(jìn)入/退出
 - MouseMotionListener: 拖動(dòng)/移動(dòng)

------------------------------------------------------------------------

Layout

布局

* BorderLayout is the default layout for Window/Frame/Dialog.
  - add( component, BorderLayout.NORTH ) == add( "North", component )
  - adding a component without an explicit position is identical to
    adding a component at BorderLayout.CENTER.
  - if more than one component is added to the same position, the most
    recently added component is displayed there.
  - north,south,east and west components only expand on one axis.

* BorderLayout是Window/Frame/Dialog的默 喜季 管理器
  - add(component,BorderLayout.NORTH) == add("North",component)
  - 如果不說(shuō)明位置,組件將按默認的設置添加到CENTER的位置
  - 如果超過(guò)一個(gè)組件添加到一個(gè)位置上,最后添加的將被顯示
  - north,south,east和west上的組件只在一個(gè)方向上延伸

* FlowLayout is the default layout for Panels (including Applets).
  - if the panel is bigger than its components, they are centered
    horizontally and at the top (ie. north position).

* Panel(包括Applet)的默 喜季 管理器是FlowLayout
  - 如果panel比組件大,組件將被水平居中并置于頂端

* GridLayout with container larger than components expands to fill its
  container provided that the number of components matches the
  rows*columns.
  - Empty rows are given space, while empty cols are not.
  - If there aren‘t enough components, it will try to fill its rows first.

* 當GridLayout的容器比組件大時(shí),組件將被擴充到填滿(mǎn)整個(gè)容器,需要提供
  rows*columns個(gè)組件
  - 空行將被分配空間,但時(shí)空列不分配空間
  - 如果組建的數目不夠,首先嘗試填充所有的行

* Ctors for BorderFlow- and GridLayout can take int hgap and vgap args.
  - FlowLayout(int align, hgap, vgap)

* BorderFlow以及GridLayout的構造函數可以帶參數hgap和vgap
  - FlowLayout(int align, hgap, vgap)

* Be careful with nested layout questions ... eg Button to panel to frame,
  the panel fills the whole frame, but the button will be its preferred size
  at north position in the panel (and thus the frame).

* 對嵌套的布局管理器要小心 ... 例如一個(gè)frame包含一個(gè)panel,panel包含一個(gè)
  Button,panel填充整個(gè)frame,但是button仍然只有預定的大小,位于frame的
  北面

* GridBagLayout
  - There are two ways to set the constraints for a component in a gbl:
      container.add( Component c, Object gbc ) or
      gbl.setConstraints( Component c, GridBagConstraints gbc )
  - weightx and weighty are doubles (0 to maxDouble, default 0) and determine
    where extra width or height is added if a row or column is smaller than
    the container.
  - gridwidth and gridheight are ints (1 to maxInt) ... RELATIVE, REMAINDER.
  - gridx and gridy are ints (0 to maxInt) ... RELATIVE
  - RELATIVE can apply to gridx/gridy (=next) or
    gridwidth/gridheight (=second last)

* GridBagLayout

  - 有兩種方法可以將一個(gè)組件使用constraints添加到GridBagLayout中去:
                container.add(Component c,Object gbc) 或者
                gbl.setConstraints(Component c,GridBagConstraints gbc)
  - weightx和weighty是double類(lèi)型(0到maxDouble,默認是0)的屬性,它們決
    定額外的寬度或者高度是否添加到當前的行或者列
  - gridwidth和gridheight是整型的數據類(lèi)型(從1到maxInt) ... 相對的,剩余
    的
  - gridx和gridy是整型的(從0到maxInt) ... 相對的
  - ...

* A Component added to a null layout won‘t display unless you set its
  bounds ... this is the only place where a component can control its
  parent‘s layout directly.

* 如果將一個(gè)組件添加到一個(gè)空的布局管理器中,只有設置組件的范圍才能夠顯示

* Illegal arguments (eg. adding a container‘s parent to the container, adding
  a window) get through the compiler but throw an exception at runtime.


* 不正確的參數(例如,添加一個(gè)容器的容器到自身,添加一個(gè)window)可以通過(guò)
  編譯,但是將會(huì )在運行期間拋出異常

------------------------------------------------------------------------

------------------------------------------------------------------------

Miscellaneous

雜錦

* A class type‘s name is valid as an identifier, eg. int Boolean = 5;
* Modifiers:
  - Automatic variable = local variable = variable declared in a method.
  - Transient fields are not written out when a class is serialized.
  - Transient and Volatile can only be applied to fields.
  - Native can only be applied to methods.
  - You can have a static synchronized method .. it is synchronized on the
    class object.
  - static transient is legal but doesn‘t effect anything.

* 一個(gè)類(lèi)的名稱(chēng)是合法的標識名,例如:int Boolean = 5;
* 修飾符:
  - ...
  - 當序列化一個(gè)類(lèi)時(shí),以transient修飾的字段不會(huì )寫(xiě)進(jìn)數據流
  - transient和volatile只能修飾字段
  - native修飾符只能用于方法
  - 可以有同步的靜態(tài)方法,它使用類(lèi)對象作為同步鎖
  - static transient是合法的,但是并不去起作用

* The right-hand-side of an assignment can be a reference to null.
   - You can println a null reference (and add it to another string).
   - What you can‘t do with a null reference is ... nullRef.aMethod();


* 賦值操作的右側可以是null
  - 可是打印空的引用(還可以賦給一個(gè)字符串變量)
  - 你不能做的是 ... nullRef.aMethod();

*
        1.      ++,--,unary +,unary -,~,!,()
        2.      *,/,%
        3.      +,-
        4.      >>, >>>, <<
        5.      >, >=, <, <=, instanceof
        6.      == , !=
        7.      &
        8.      ^
        9.      |
        10      &&
        11      ||
        12      ? :
        13      =,+=,-=,*=,/=,%=, &=,^=,|=, >>= ,<<= ,>>>=
* Order of Operation
  - arithmetic before &^|
  - & then ^ then |

* 運算順序
  - 先數學(xué)運算,后&^|
  - 先&然后^最后|

* Garbage Collection
  - unreachable objects can become reachable (if their finalize method
    causes another object to have a reference to them) .. but i think
    finalize if guaranteed to not run again.
  - objects referenced by block-level variables are probably not available
    for garbage collection until their enclosing method‘s scope is exited.

* 內存回收
  - ...
  - ...

* The compiler never object to creating a local instance of the
  the class being constructed in its constructor. If the call produces
  an infinite loop, a runtime error will occur.

* 編譯器從不反對在構造函數中創(chuàng )建一個(gè)本類(lèi)的實(shí)例,但是如果這導致無(wú)限的循環(huán)
,一個(gè)運行期間的錯誤將會(huì )被拋出

* Labelled break and continue statements:
  - The label referred to by a labelled break statement is attached to
    a statement block, which could be a loop or switch but doesnt have
    to be.
  - The label referred to by a labelled continue statement must be
    attached to a loop.(A "continue" statement must be enclosed in a "while",
    "do" or "for" statement.)

* 帶標號的break和continue聲明
  - 帶標號的break可用于標識循環(huán)和開(kāi)關(guān)語(yǔ)句,但不是必須的
  - 帶標號的continue只能用于循環(huán)語(yǔ)句(continue必須出現在while、do或者
    for子句中)

------------------------------------------------------------------------

------------------------------------------------------------------------

Things to look out for

*** Read the answers before going through code samples.

****** LOOK FOR NON-STATIC METHODS/VARS ACCESSED FROM MAIN

****** WHEN YOU FINISH THE EXAM GO BACK AND CHECK FOR NON-STATIC
       METHODS/VARS FROM MAIN AND OTHER STATIC METHODS

* if (...)
    statement1;
    statement2; //...always executed

* Beware of an otherwise legal override having a more restrictive
  access modifier.


* Beware of missing return statements.

* Look for static modifiers and make sure they don‘t contain refs to
  instance vars.

* Beware of standard methods (eg. main, paint, run) with the wrong
  args or return type.

* With array declarations, look out for "int intArray[5] = ..."

* Beware of adding a primitive to a Vector.
  - more generally, you can‘t use a primitive where an Object is
    required (eg. the equals method).

* System.out.println( aReferenceToNull ); // is fine

* Beware of local vars from a try block used in its catch block
  (out of scope).

需要留意的

*** 先讀答案在看代碼段

****** 尋找在main中調用的非靜態(tài)的變量和方法

****** 當你完成考試時(shí),回頭檢查main和其他靜態(tài)方法中的非靜態(tài)變量和方法調用

* if (...)
    statement1;
    statement2; //...總是運行

* 留意那些合法的方法覆蓋,即使它們的權限變小

* 留意沒(méi)有返回值的方法

* 保證靜態(tài)代碼不能引用類(lèi)實(shí)例變量


* 留意標準方法(例如,main,print和run)的不正確的參數類(lèi)型和返回值

* 數組聲明,留意形如"int intArray[5] = ..."的語(yǔ)句

* 小心不要將基本類(lèi)型添加到Vector中
  - 更普遍的情況,當需要用Object的時(shí)候不要用基本類(lèi)型(例如equals方法)

* System.out.println( aReferenceToNull ); // 代碼將運行得很好

* 小心不要在catch中使用try中定義的局部變量(超出范圍)

--
  -= HOVER =-
 
 

--

* Beware of adding a primitive to a Vector.
  - more generally, you can‘t use a primitive where an Object is
    required (eg. the equals method).

* System.out.println( aReferenceToNull ); // is fine

* Beware of local vars from a try block used in its catch block
  (out of scope).

需要留意的

*** 先讀答案在看代碼段

****** 尋找在main中調用的非靜態(tài)的變量和方法

****** 當你完成考試時(shí),回頭檢查main和其他靜態(tài)方法中的非靜態(tài)變量和方法調用

* if (...)
    statement1;
    statement2; //...總是運行

* 留意那些合法的方法覆蓋,即使它們的權限變小

* 留意沒(méi)有返回值的方法

* 保證靜態(tài)代碼不能引用類(lèi)實(shí)例變量


* 留意標準方法(例如,main,print和run)的不正確的參數類(lèi)型和返回值

* 數組聲明,留意形如"int intArray[5] = ..."的語(yǔ)句

* 小心不要將基本類(lèi)型添加到Vector中
  - 更普遍的情況,當需要用Object的時(shí)候不要用基本類(lèi)型(例如equals方法)

* System.out.println( aReferenceToNull ); // 代碼將運行得很好

* 小心不要在catch中使用try中定義的局部變量(超出范圍)

--
  -= HOVER =-

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
java經(jīng)典選擇題100例及答案
淺析java反射機制
討論關(guān)于Java占用內存的研究
C#面試題(英文)
java 反射知識總結
Java的反射機制
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久