Sun Certified Programmer for Java 6 Study Guide SCJP Exam 310-065 Kathy Sierra

Sun Certified Programmer for Java 6 Study Guide SCJP Exam 310-065 Kathy Sierra Bert Bates McGraw Hill ISBN: 978-0-07-159106-5 Study Notes by Mahanthi Bukkapatnam SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 2 of 69 Table of Contents Introduction: Why these notes ............................................................................................ 5 Chapter 1: Declaration and Access Control........................................................................ 6 Identifiers and JavaBeans ............................................................................................... 6 Declare Classes ............................................................................................................... 7 Declare Interfaces ........................................................................................................... 8 Declare Interface Constants........................................................................................ 9 Declare Class Members .................................................................................................. 9 Variable args ............................................................................................................. 10 Constructors.............................................................................................................. 10 Modifiers allowed only on methods ......................................................................... 11 Modifiers allowed only on instant variables............................................................. 11 Modifiers allowed only on local variables................................................................ 11 Transient variables.................................................................................................... 12 Volatile variables ...................................................................................................... 12 Enums ........................................................................................................................... 13 Chapter 2: Object Orientation........................................................................................... 14 Polymorphism............................................................................................................... 14 Overriding and Overloading ......................................................................................... 14 Overriding................................................................................................................. 14 Overloading............................................................................................................... 15 Reference variable casting............................................................................................ 16 Legal Return Type ........................................................................................................ 17 Constructors and Initialization...................................................................................... 19 Statics............................................................................................................................ 20 Coupling and cohesion.................................................................................................. 20 Chapter 3: Assignments .................................................................................................... 21 Literals, Assignments and Variables............................................................................. 21 Passing variables into methods..................................................................................... 21 Array declaration, Construction and Initialization........................................................ 21 Initialization .............................................................................................................. 21 Wrapper classes and Boxing......................................................................................... 22 Boxing, == and equals()............................................................................................ 22 Overloading................................................................................................................... 23 Garbage Collection ....................................................................................................... 23 Chapter 4: Operators......................................................................................................... 24 Chapter 5: Flow control, Exceptions and Assertions........................................................ 25 If statements.................................................................................................................. 25 Switch statements.......................................................................................................... 25 Loops and Iterators ....................................................................................................... 26 Basic for Loop........................................................................................................... 26 Enhanced for Loop (for arrays)................................................................................. 26 Labeled Statements................................................................................................... 26 Exception handling ....................................................................................................... 27 SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 3 of 69 Assertion ....................................................................................................................... 28 Chapter 6: String, I/O, Formatting and Parsing................................................................ 29 String, StringBuffer and StringBuilder......................................................................... 29 File and I/O ................................................................................................................... 29 Serialization .................................................................................................................. 29 Dates, Numbers and Currency...................................................................................... 29 Parsing, Tokenizing and Formatting............................................................................. 29 Chapter 7: Collections....................................................................................................... 30 hashCode() and equals() ............................................................................................... 30 Collections .................................................................................................................... 31 Operations on a collection ........................................................................................ 31 Key Interfaces and Concrete classes......................................................................... 31 Ordered and Sorted ................................................................................................... 32 List interface ............................................................................................................. 33 Set Interface .............................................................................................................. 34 Map interface ............................................................................................................ 35 Queue Interface......................................................................................................... 36 Sorting Collections and Arrays................................................................................. 36 Comparable Interface................................................................................................ 36 Comparator Interface ................................................................................................ 37 Key Sort methods...................................................................................................... 37 Searching Arrays and Collections............................................................................. 37 Converting Arrays to Lists to Arrays........................................................................ 38 Using Lists ................................................................................................................ 39 Using Sets ................................................................................................................. 39 Using Maps............................................................................................................... 39 Using Navigating (Searching) TreeSets and TreeMaps............................................ 39 Polling....................................................................................................................... 40 Descending Order ..................................................................................................... 40 Backed Collection..................................................................................................... 40 Using PriorityQueue class......................................................................................... 40 Method overview for Arrays and Collections........................................................... 40 Method overview for List, Set, Map and Queue....................................................... 40 Chapter 7: Generics........................................................................................................... 41 Generics and Collections .............................................................................................. 41 Before Java 5............................................................................................................. 41 Generics and Legacy Code ....................................................................................... 42 Polymorphism and Generics..................................................................................... 43 Generic Methods....................................................................................................... 43 Parameterized Types..................................................................................................... 44 Class.......................................................................................................................... 44 Methods..................................................................................................................... 45 Chapter 8: Inner Classes ................................................................................................... 46 Overview and Key Points ............................................................................................. 46 Regular Inner class........................................................................................................ 47 Method Local inner class.............................................................................................. 48 SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 4 of 69 Anonymous inner class................................................................................................. 50 Static Nested class......................................................................................................... 51 Chapter 9: Threads............................................................................................................ 52 Overview....................................................................................................................... 52 Distinguish Thread and Thread of Execution............................................................... 53 The Thread class ........................................................................................................... 53 Thread and the Runnable interface ............................................................................... 54 Defining Threads .......................................................................................................... 55 Instantiating Threads..................................................................................................... 56 Starting Threads............................................................................................................ 57 Getting the name of the Thread .................................................................................... 57 Starting multiple threads............................................................................................... 58 Thread Scheduler .......................................................................................................... 58 Thread States and Transitions....................................................................................... 59 Sleeping......................................................................................................................... 60 Thread Priorities............................................................................................................ 61 Yielding from a thread.................................................................................................. 61 Join() method ................................................................................................................ 62 Synchronization Code................................................................................................... 63 Key points about locking and synchronization............................................................. 64 Synchronizing static methods ....................................................................................... 65 More Synchronization points........................................................................................ 66 Thread interaction......................................................................................................... 67 Exceptions related to threads ........................................................................................ 67 Summary - Points to keep in mind................................................................................ 68 Heading......................................................................................................................... 69 SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 5 of 69 Introduction: Why these notes To develop the habit of taking good notes. Help me in visualizing the concept and the relationship with other concepts. Help me pass the exam Help me to overcome my fear of taking exam. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 6 of 69 Chapter 1: Declaration and Access Control Identifiers and JavaBeans Legal Identifiers Legal Identifier First char 1. $ 2. _ 3. Letter Subsequent chars 1. $ 2. _ 3. Letter 4. Number Size Unlimited Restrictions Java Keywords cannot be used Case Case sensitive Valid JavaBean method signatures get set isMyStatus() public void addMyListener(MyListener m) public void removeMyListener(MyListener m) SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 7 of 69 Declare Classes Access modifiers for a class private, default, protected and public, Non-access modifiers for a class strictfp final abstract Strictfp applicable to: Only applicable to: 1. Class 2. Method SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 8 of 69 Declare Interfaces Interface methods: How to think about methods in an interface? All the methods in an interface are abstract. No non-abstract method in an interface Methods of an interface are public and abstract. Interface constants: Constants in an interface Public, static and final (in any combination) Static methods in an interface? No – not allowed Restrictions for the methods in an interface Cannot be 1. final 2. strictfp 3. native Extends and interfaces Interfaces can extend other interfaces. Only interfaces. An Interface can extend multiple interfaces. Weird – it is mentioned in page 123 Inplement and interface No implementing of other interfaces or classes Can a interface method be protected? No. It can only be public. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 9 of 69 Declare Interface Constants One key rule to remember Constants in an interface are: public static and final Declare Class Members final arguments Final arguments cannot be modifying the argument in the method. What modifiers cannot go together. Abstract and static cannot go together. Why? Abstract needs an object, static means no object is necessart. The intention can be conflicting if you use both abstract and static together. Other method modifiers synchronized - Threads strictfp - floating point, scientific computing native - integrating legacy code. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 10 of 69 Variable args Key rules Only 1 argument as var args Last argument Declared like the following: int… x not like the following: int x… How many arguments can be passed to a var arg variable? 0 or more. Constructors Return type of a constructor Nothing. What happens if a return type is specified If a return type is specified, it becomes a method. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 11 of 69 Modifiers allowed only on methods Modifiers allowed only for methods 1. abstract 2. synchronized 3. strictfp 4. native Modifiers allowed only on instant variables Only for the instance variables 1. transient 2. volatile Modifiers allowed only on local variables Only for local variables 1. final SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 12 of 69 Transient variables Transient means Please do not serialize this variable. Volatile variables Volatile means In a multi-threading situation, please do not perform any caching for there variables. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 13 of 69 Enums 2 places enums can be declared Outside a class Inside a class Can be declared in a method? No – Never Access modifier rule when declared outside a class Not private or protected. Public or default allowed Semicolon rule Semicolon at the end of an enum declaration is optional Method to get all the enums as an array? values()     returns the enum values as an array Does the values() method return the enums in the order by which they are declared? Yes Block and overriding for individual enum You can start a block and override specific methods for that particular enum. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 14 of 69 Chapter 2: Object Orientation Polymorphism Extends rule A class can extend only one class. Abstract methods requirement Declaration should end with a semi colon. Overriding and Overloading Overriding Some rules Arguments must be the same Return type must be the same or must be a subtype access level can be less restrictive overriding method can throw any number of unchecked exceptions. Checked exceptions must be narrower or fewer. Can you override methods that are final or static No. Final means you cannot override it. Compiler Error If it is private in the super class, then you can redefine it. Static – If the subclass has a method by the same name, it is called redefining, not overriding. No compiler error. SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 15 of 69 Overloading Some rules Must Change Arguments must change Optional 1. Return type 2. Access modifier 3. Throw new or broader exceptions See Page 115 SCJP 6.0 Study Guide - CNTS Mahanthi Bukkapatnam Page 16 of 69 Reference variable casting Compiler while casting The compiler makes sure that the two types belong to the same inheritance tree Animal animal = new Animal() Dog dog = (Dog) animal; The above code, compiles but fails at runtime. Downcast You want to call a specific method. How to think about downcast Watch out for this point. (I was not aware of this before) The compiler checks to see if the class is uploads/S4/ scjp-studyguide.pdf

  • 21
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager
  • Détails
  • Publié le Fev 15, 2021
  • Catégorie Law / Droit
  • Langue French
  • Taille du fichier 0.1701MB