SCJP總結 1

          前一陣子把scjp的資料又翻閱了一遍,這里把容易弄錯的要點摘出來備忘。(可能我以后相當一段長時間不會再碰java了)

          1. if and switch statements
          • Watch out for boolean assignments (=) that can be mistaken for boolean equality (==) tests
          • Switch statements can evaluate only the byte, short, int, and char data types.
          • The case argument must be a literal or final variable! You cannot have a case that includes a non-final variable, or a range of values.
          • If the condition in a switch statement matches a case value, execution will run through all code in the switch following the matching case statement until a break or the end of the switch statement is ncountered. In other words, the matching case is just the entry point into the case block, but unless there’s a break statement, the matching case is not the only case code that runs.
          • The default block can be located anywhere in the switch block

          2. Exception
          • Exceptions come in two flavors: checked and unchecked.
          • Checked exceptions include all subtypes of Exception, excluding classes that extend RuntimeException.Subtypes of Error or RuntimeException are unchecked, so the compiler doesn’t enforce the handle or declare rule.
          • The only exception to the finally-will-always-be-called rule is that a finally will not be invoked if the JVM shuts down.
          • Just because finally is invoked does not mean it will complete. Code in the finally block could itself raise an exception or issue a System.exit().

          3. Assertion
          • Do not use assertions to validate arguments to public methods.
          • Do not use assert expressions that cause side effects.
          • Do use assertions?even in public methods?to validate that a particular code block will never be reached. You can use assert false; for code that should never be reached, so that an assertion error is thrown immediately if the assert statement is executed.

          4. Overridding and Overloading
          • Polymorphism applies to overriding, not to overloading
          • Reference type determines which overloaded method will be used at compile time.

          5. Constructor
          • The constructor calls its superclass constructor, which calls its superclass constructor, and so on all the way up to the Object constructor. The Object constructor executes and then returns to the calling constructor, which runs to completion and then returns to its calling constructor, and so on back down to the completion of the constructor of the actual instance being created.
          • Constructors can use any access modifier (even private!).
          • The first statement of every constructor must be a call to either this() (an overloaded constructor) or super().The compiler will add a call to super() if you do not, unless you
          • have already put in a call to this().
          • this() and super() cannot be in the same constructor. You can have one or the other, but never both.
          6. String & StringBuffer
          • StringBuffer equals() is not overridden; it doesn’t compare values.
          • String methods use zero-based indexes, except for the second argument of substring().

          7. java.lang.Math
          • The random() method returns a double greater than or equal to 0.0 and less than 1.0.
          • The methods ceil(), floor(), and round() all return integer equivalent floating-point numbers, ceil() and floor() return doubles, round() returns a float if it was passed an int, or it returns a double if it was
          • passed a long. Round means the number add .5 and do a floor().
          • The method sqrt() can return NaN if the argument is NaN or less than zero.
          • NaN is not equal to anything, not even itself.

          8. Using Wrappers
          • Wrappers won’t pass equals() if they are in different classes.
          • Radix refers to bases (typically) other than 10; binary is radix 2, octal = 8, hex = 16.

          10. equals and ==
          • The compiler will not allow == if the classes are not in the same hierarchy.

          posted on 2007-04-13 19:21 肥蟲 閱讀(327) 評論(0)  編輯  收藏 所屬分類: Java Language


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2007年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 迁西县| 萨嘎县| 祁东县| 曲松县| 朝阳县| 南充市| 南京市| 旺苍县| 佛学| 得荣县| 荥经县| 嘉义市| 马公市| 福建省| 天柱县| 陇川县| 阿拉尔市| 南安市| 安仁县| 唐河县| 萍乡市| 宝应县| 韶山市| 清新县| 南漳县| 合作市| 仁怀市| 霍邱县| 华池县| 台前县| 饶阳县| 六枝特区| 宁城县| 玉溪市| 辽宁省| 高邑县| 保德县| 合山市| 历史| 海淀区| 大埔区|