`
Odysseus_110
  • 浏览: 120623 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

SCJP 5.0 Study Notes(3)

    博客分类:
  • J2SE
阅读更多

 

Enums

<!---->·    <!---->myEnum.valueOf(String) – returns value of corresponding enum value

<!---->·    <!---->yourEnum.values() lists all the possible values of yourEnum

<!---->·    <!---->Enums can have instance/member variables, constructors, and methods

<!---->·    <!---->Enums constructors can have a constant specific class body (a method that overrides one of the methods), but not any new methods? or any method calls

<!---->·    <!---->In an enum declaration, multiple constant-specific methods for each enumerated type must be separated by commas and terminated by a semi-colon:  e.g.      enum VALUE{ MAX {int returnIt(int x) {return 10}; },

                                                 MIN {int returnIt{(int x) {return 1};};}

<!---->·    <!---->enums can be imported using “import package.EnumClass.*”, “import package.EnumClassor.EnumName”, “import static” versions

<!---->·    <!---->enum constructors can neber be invoked directly from code

 

Simple Example

enum Month{NOV, DEC, JAN};  // The semi-colon at the end in this case is optional

 

More Complex

enum Month {                       // Any access mod -- SAME class, default/pub – own class

         NOV, DEC(11), JAN, FEB; //  Must end in semicolon if more than just declarations

         Month(){}           //  No-arg constructor only auto-created by JVM     

         Month(int index) {                 //  if no other constructor provided – just like classes

                   this.index = index;

         }

         int index;                       // Initialized automatically, can have any access modifier     

};                                  // This semicolon is optional

        

for (Month month: Month.values()) {      //notice values() method

         System.out.println("Day = " + month);

}                

Month month = Month.DEC;        

switch (month) {

         case DEC : System.out.printf("%s %d %b","November", 264, true);    //CAN’T use Month.DEC in case – won’t compile

}

 

Really Complex

         enum Month {

                   NOV("November", 11),                          // Notice various constructor formats that all compile and run

                   DEC("December"),

                   JAN {int getIndex(){return 55;}},                    // Notice overriden method here.   CAN’T be new method – doesn’t compile

                   FEB(),

                   MAR;

                  

                   Month(){}          

                   Month(String name, int index) {

                            this.index = index;

                   }

                   Month(String name) {

                            this.name = name;

                   }

                   protected int index;

                   String name;

                   int getIndex(){    

                            return this.index;

                   }

                   String getName(){

                            return this.name;

                   }

         };

 


Gotchas (very tricky stuff)

<!---->·    <!---->Watch for faulty method returns, either returning types different than declared type or failing to return something, or returning something when void is declared, or not returning something if a return type was specified.

<!---->·    <!---->Watch for methods parading as constructors – constructors do not have return values!

<!---->·    <!---->If there is a method call to methods with the same name and with (String[] args) and (String… args), the code won’t compile b/c it won’t know which method to call

<!---->·    <!---->Remember that after threadName.start() is declared, the thread my not enter the running state until all the code after it has been executed

<!---->·    <!---->The class has a lock, and each object has a lock, and notify() and notifyAll() only notify threads waiting for the SAME LOCK

<!---->·    <!---->Static methods can’t override non-static methods and vice-versa – will not compile

<!---->·    <!---->Watch out for statements that the compiler knows will never be reached (like after throwing an exception) – this code will not compile

<!---->·    <!---->new Boolean(“TRue”) results in true, new Boolean(“AnythingOtherThanCaseInsensitiveTrue”) is false, boolean x = true or false (boolean x=True or boolean x=TRUE will not compile)

<!---->·    <!---->in System.out.format/printf(“%b”, varX) will print true if varX has any value

<!---->·    <!---->If Subclass is in a different package than Superclass, any protected variables in Superclass can only be reached from the main(0 in Subclass using an object reference to Subclass, not Superclass

<!---->·    <!---->When wait() and notify() methods are called from non-sychronized context, code will compile, but IllegalMonitorStateException will be thrown at runtime

<!---->·    <!---->HashMap and LinkedHashMap can have 1 null key and multiple null values, but TreeMap can’t have any null keys (can have null values), and Hashtable can’t have any null keys or values (will result in NullPointerException)

<!---->·    <!---->Use of collectionType.toArray() and trying to use as array as specific types, without casting, when toArray() returns Objects.

<!---->·    <!---->Static member variables are automatically initialized, final member variables must initialized by the time the constructor finishes, and static final member variables must be assigned at time of declaration or in a static initialization block.  Breaking these rules results in failed compilation

<!---->·    <!---->Classes can have multiple static initialization blocks and instance initialization blocks, which I think run in the order listed

<!---->·    <!---->Can’t assume from listed code that a property value hasn’t already been set for use of System.getProperty(stringKey, stringDefaultValue), so can’t tell if property will be set to stringDefaultValue or not

<!---->·    <!---->Watch out for trying to use elements of raw type (non-generic) collections without casting

<!---->·    <!---->Watch out for static methods trying to make a reference to “this”

<!---->·    <!---->Illegal to try to return literal 1.2 when return type is a float (the literal 1.2 is a double)

<!---->·    <!---->Any methods implemented from an interface MUST be public since an interface’s methods are always public

<!---->·    <!---->Get suspicious when you see the protected access modifier – they are probably going to try to illegally access it from outside the package (you can only acces it through inheritance, not through an instantiation of the object with the protected member

 

Exam Tips

<!---->·    <!---->After finishing, go back and check every question for:

         --calling non-static methods or using non-static variables in main

         --for any Thread question, all wait(), sleep(), and join() methods handle the InterruptedException

         --modifying strings but not having a reference to new modified string

<!---->·    <!---->Get suspicious when there is a mix of raw type collections and generic type collections

<!---->·    <!---->If question code contains packages and imports, watch out for probable errors using these.

 

转自:

http://holoquest.org/other/scjp5_webnotes.html

 

分享到:
评论

相关推荐

    SCJP 5.0考试模拟机

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java编程领域的一个重要认证,由Sun Microsystems(后被Oracle收购)推出,旨在验证开发者对Java SE 5.0平台的基础知识和编程...

    SCJP5.0真题题库

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司推出的针对Java SE 5.0平台的程序员认证考试。这个题库是为准备SCJP 5.0考试的考生提供的资源,包含了大量实战题目,...

    SCJP5.0(310-055)LatesDump.rar_scjp

    【SCJP5.0(310-055)LatesDump.rar_scjp】这个压缩包文件主要包含的是关于Sun Certified Java Programmer(SCJP)5.0考试的最新模拟试题和复习资料。SCJP,也被称为Java SE Certified Programmer,是Oracle认证的一项...

    绝对值得收藏的scjp5.0考试模拟器(免安装,实用,经典)

    最经典的scjp5.0考试模拟器(免安装,实用,经典) 绝对值得收藏!

    Whizlabs SCJP 5.0

    【标题】"Whizlabs SCJP 5.0" 是一个专门为准备Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 (SCJP 5.0)认证考试的学员设计的学习资源。这个课程旨在帮助考生深入理解Java SE 5.0编程...

    scjp 5.0(310-055)认证指南

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java编程领域的一个重要认证,旨在验证开发者对于Java SE 5.0平台的基础知识和编程能力。这个认证对于那些希望深入理解Java语言...

    SCJP5.0 310-055 认证题库 09年版本

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司为Java程序员提供的一项专业认证,旨在验证考生对Java SE 5.0编程语言的掌握程度。310-055是这个认证的考试代码,对应...

    SCJP5.0全套资料(个人心血笔记&2套题库)

    SCJP(Sun Certified Java Programmer)5.0是Java编程领域的一个重要认证,它验证了开发者对Java SE 5.0平台的基本理解与编程能力。这个认证对于那些希望深入理解Java语言特性和准备进入IT行业的专业人士来说,是...

    SCJP5.0模拟器

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司(原Sun Microsystems)为Java开发者设立的一项认证考试,旨在验证考生对于Java SE 5.0编程语言的理解和应用能力。...

    SCJP5.0 java考试资料5.0版

    scjp考试辅导,包含各个要点,与真实考题相近

    SCJP5.0(Sun Certified Programmer for the Java 2 )

    Java SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java开发者认证的一个重要里程碑,由Sun Microsystems(后被Oracle收购)推出,旨在验证程序员对Java SE 5.0(也称为Java ...

    scjp5.0

    scjp最新版,对于考scjp有很大帮助,

    SCJP5 study guaid

    《SCJP5 Study Guide》是Java程序员为了通过Sun Certified Programmer for Java 5 (SCJP5)认证考试的重要参考资料。SCJP是Java开发人员基础技能的一种官方认可,它验证了开发者对Java语言核心概念的理解和应用能力。...

    SCJP模拟器及考题

    这个认证曾经基于Java SE 5.0(即SCJP 5.0),而现在已被更新的OCPJP(Oracle Certified Professional, Java Programmer)所替代,尽管如此,SCJP 5.0仍然是学习Java基础知识的重要参考。 提供的资源包括"SCJP5.0....

    SCJP模拟器+JDK5.0+复习资料

    这个压缩包文件包含了一个SCJP模拟器和JDK 5.0,这对准备SCJP认证考试的考生来说是非常有价值的资源。 SCJP模拟器310-055是专门为SCJP 310-055考试设计的练习工具。这个模拟器通常包含了大量的模拟试题,这些试题...

    scjp真题

    文件"310-055_Certkiller.pdf"和"310-055-Q&A-Troytec.pdf"很可能包含了针对SCJP 5.0考试的模拟试题和答案解析。310-055是SCJP 5.0考试的代码,Certkiller和Troytec可能是提供这些资源的培训机构或个人。 SCJP 5.0...

    SCJP考试资料(包含大部分原题)

    在提供的压缩包文件中,"scjp 5.0(310-055)认证指南.chm"很可能是一个包含SCJP 5.0考试复习资料的离线帮助文档。这类文档通常会详细介绍考试大纲,提供练习题,并解释各种Java编程概念。考生可以通过阅读此文档来...

    Java程序员5.0升级版本简介

    - **考试内容**:SCJP 5.0认证考试代码为CX-310-055,考试形式为多选题和拖放题,旨在测试考生对Java语言核心概念的理解以及J2SE 5.0的应用能力。 - **考试准备**: - 参加有教员指导的培训课程(如SL-275:Java...

    scjp(jdk5.0)认证

    ### SCJP (JDK 5.0) 认证知识点解析 #### 题目一:接口中的变量声明 **题目描述**: 考虑以下代码片段: ```java public interface Status { /* insert code here */ int MY_VALUE = 10; } ``` 在第12行插入哪些...

Global site tag (gtag.js) - Google Analytics