SCJP總結 2

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

          11. hashCode
          • If you don’t override equals(), your objects won’t be useful hashtable/ hashmap keys.
          • Classes HashMap, Hashtable, LinkedHashMap, and LinkedHashSet use hashing.
          • An efficient hashCode() override distributes keys randomly across a wide range of buckets.
          • To reiterate: if two objects are equal, their hashcodes must be equal
          12. Collections
          • HashMap: Fastest updates (key/value pairs); allows one null key, many null values. Hashtable: Like a slower HashMap, No null values or null keys allowed
          13. Garbage Collecter
          • All objects in Java live on the heap.
          • The finalize() method is guaranteed to run once and only once before the garbage collector deletes an object.
          • You can uneligibilize an object from within finalize().
          14. Inner Class
          • From code within the inner class, the keyword this holds a reference to the inner class instance. To reference the outer this (in other words, the instance of the outer class that this inner instance is tied to) precede the keyword this with the outer class name
          • Technically, a static nested class is not an inner class, but instead is considered a top-level nested class.
          • Instantiating a static nested class requires using both the outer and nested class names as follows:BigOuter.Nested n = new BigOuter.Nested();
          15. Thread
          • You can call start() on a Thread object only once. If start() is called more than once on a Thread object, it will throw a RuntimeException.
          • There is no guarantee that the order in which threads were started determines the order in which they’ll run.
          • A running thread may enter a blocked/waiting state by a wait(), sleep(), or join() call.
          • The sleep() method is a static method that sleeps the currently executing thread. One thread cannot tell another thread to sleep.
          • If not explicitly set, a thread’s priority will be the same priority as the thread that created this thread
          • The yield() method may cause a running thread to back out if there are runnable threads of the same priority. There is no guarantee that this will happen, and there is no guarantee that when the thread backs out it will be different thread selected to run. A thread might yield and then immediately reenter the running state.
          • The closest thing to a guarantee is that at any given time, when a thread is running it will usually not have a lower priority than any thread in the runnable state.
          • When one thread calls the join() method of another thread, the currently running thread will wait until the thread it joins with has completed.
          • When an object goes to sleep, it takes its locks with it.
          • Static methods can be synchronized, using the lock from the java.lang.Class instance representing that class.
          • All three methods—wait()/notify()/notifyAll()—must be called from within a synchronized context!
          16. Primitives
          • All six number types in Java are signed, so they can be positive or negative.A char is really a 16-bit unsigned integer.
          • Integers can be represented in octal (0127), decimal (1245), and hexadecimal (0XCAFE).
          • A char literal can also be represented as a Unicode value (‘\u0041’).
          • Floating-point literals are always double by default; if you want a float,you must append an F or f to the literal.
          17. Array
          • When you declare an array, the brackets can be to the left or right of the variable name.
          • It is never legal to include the size of an array in the declaration.You must include the size of an array when you construct it (using new) unless you are creating an anonymous array.
          • Elements in an array of objects are not automatically created(remain null), although primitive array elements are given default values.
          • The dimensions in a multidimensional array can have different lengths.
          • Just as with array elements, instance variables are always initialized with a default value. However, Local/automatic/method variables are never given a default value.
          18. Access Modifier
          • Inheritance is the only mechanism for a subclass outside the package to access a protected member of its superclass
          • final is the only modifier available to local variables.
          • Synchronized methods can have any access control and can also be marked final.Synchronized methods cannot be abstract.
          • It is legal to declare a local variable with the same name as an instance variable; this is called “shadowing.”
          • Final reference variables must be initialized before the constructor completes.
          • Static variables get the same default values as instance variables.
          • Static methods cannot be overridden, although they can be redeclared/redefined by a subclass. So although static methods can sometimes appear to be overridden, polymorphism will not apply
          • Import statements cause no performance hits and do not increase the size of your code.
          19. Interface
          • Interfaces can have constants, which are always implicitly public, static, and final.
          • Interfaces can extend one or more other interfaces.
          20. Operator
          • Compound assignments (e.g. +=) perform an automatic cast.
          • When floating-point numbers are divided by zero, they return positive or negative infinity.
          • When the remainder operator performs a floating-point divide by zero, it will not cause a runtime exception.
          • >>> fills the left bits with zeros (negative numbers will become positive).
          • The && and || operators are known as short-circuit operators. No others.

          posted on 2007-04-14 15:37 肥蟲 閱讀(436) 評論(0)  編輯  收藏 所屬分類: Java Language


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 库尔勒市| 南陵县| 洪泽县| 白河县| 巴中市| 长春市| 泸州市| 石河子市| 竹山县| 资源县| 黑水县| 沧源| 巴里| 五台县| 泽普县| 长阳| 德阳市| 河南省| 东兰县| 丰县| 藁城市| 綦江县| 即墨市| 锡林郭勒盟| 嘉定区| 九龙城区| 湘乡市| 岫岩| 牡丹江市| 资中县| 阿克| 义乌市| 九寨沟县| 桃园市| 建昌县| 宝丰县| 武鸣县| 都江堰市| 华蓥市| 于田县| 定州市|