Monday 23 June 2014

Android Development (Java JDK with Eclipse IDE)

Activities @ Lynda - 


Java Essential Training with David Gassner  DONE

JDK (Java Dev Kit)
  • Cross-Platform Java IDE { Eclipse (Open Source) JRE (Java Runtime Env) includes Google Android SDK }
    • XML Configuration Files (.classpath, .project)
    • Output Files to /bin
  • Eclipse Shortcuts
    • Hover Filename (popup appears with Filepath)
    • Move Rows Up and Down (PRESS OPT + UP or OPT + DOWN)
    • API References
      • Hover Class Name, PRESS FN + F2 (Mac) to Focus, Drag/Expand popup
    • Help View ( Double Click to select Class, Menu > Help > Dynamic Help )
    • Hover Properties (of Class) (popup appears, PRESS FN + F2 to Focus, Drag/Expand
    • Custom Perspectives ( Window > Save Perspective As )
    • Detached Views ( View > Detach )
    • Custom Appearance ( ADT > Prefs > General > Appearance ... )
    • Task Tags (i.e. // TODO)
    • Code Template proposals { PRESS CTRL + SPACE, TAB }
  • JVM (Java Virtual Machine) - protected and robust
    • JNI (Java  Native Interface) calls low-level native functions 
    • Memory Management 
      • Garbage Collection (GC) autonomy for expired Non-Referenced Objects (Retain Object until lifetime expired Scope of code block)
      • Fast Memory ( for Primitive Variables )
      • Heap Memory ( for Complex Objects )
      • Persistent Vars (Fields of Objects) Explicit Expire by set to Null (for GC)
      • Architect Bundling and Reuse of Objects for Efficiency
      • Runtime.freememory()
  • Javadocs { comments
    • Element Comments { comment on Classes, Methods, and Fields. Select Class Name > Menu > Source > Generate Element Comment i.e. /** }
      • Annotations { Type @ and Select from Drop-down }
      • HTML Tags { markup comments with HTML for appearance in Javadocs }
      • Exporting { File > Export > Java > Javadocs }
      • Exploring
        • PackageExplorer Right Click > Refresh. Navigate to Doc Folder > Open Index.HTML
        • Select Element and View Element Comments in Javadoc View (bottom)
  • File Manipulation { using Core Class Library with Try Catch Blocks (FileNotFound and IO Exceptions) Select PackageExplorer > Right Click > Refresh }
    • Input Stream { read file contents, Buffer Arrays for manageable bytes  }
    • Output Stream { write file contents }
    • Apache Commons { expanded Tools that are free and reusable Java components to eliminate complexity }
      • FileUtils { download JAR files and add to Library (lib) Folder, and add to Build Path (JRE System Library) Right Click > Build Path > Add to Build Path for all Classes to be available to Project }
      • Network Communications { Parsing RSS Feed from XML streams from network and with Document Object Model (DOM) Interface defined by W3C using Document Class (PRESS CTRL + SPACE) programming interface, Element ClassNodeList API, and DocumentBuilderFactory Factory API } 
    • JAR (Java Archive Files) { File > Export > JAR File > Select Entire App (Deselect Config Files). Rename .JAR to .ZIP to extract Package in Folder structure }
  • Declarations { Package, Class }
  • Compiling { portable b/w platforms compiling to Bytecode .class }
  • Object-Oriented Programming (OOP)
    • Encapsulation (wrap and overcome monolithic code complexity into Black Box) broken down and group functionality into maintainable Classes testable at granular level { enables restricted access, Abstraction with hidden data by calling protected methods with data stored in superclass (i.e. this.setSomething(1);) }
      • Architecturing Custom Class (hidden complexity within subclass class implementations) { declare private object, constructor method to pass data in from each created class instance, public method accessible throughout application encapsulating complexity, i.e. named ___Helper }
      • Loose-Coupling { Binding between functionality and data Classes }
      • Calling Customer Class (simple) { create instance, pass in args, call the Custom Class method to retrieve result } 
    • Inheritance Relationships { Java has Single Inheritance relationship between Superclass and Subclass that extends functionality (Subclass can only have one Superclass) }
      • Subclass Creation { Select Package > Right Click > New > Class > Browse (as Full Pathname required) } 
      • Subclasses Getting and Setting Specific Field Values for Types Declared in Superclass
      • Superclass Constructor Methods { Not Inherited by Subclasses. Subclasses require implementation of Explicit Constructor Methods Right Click > Source > Generate Constructors from Superclass... where super(); calls the Constructor Method of the Superclass }
      • Overriding Superclass Methods Inherited in Subclass { PRESS CTRL + SPACE in Subclass > Select "Override method in '....'" (Creates New Version of Superclasses Method with @Override using matching Data Type). Click Upward Arrow in Trough to transfer to respective Superclass Method }
      • Casting Objects { using Subclass Objects treated as Superclass }
        • Upcasting { Subclass upward conversion to Superclass } 
        • Downcasting { Superclass general form of Object to specific form of Object in Subclass achieved by telling compiler to treat it as the Subclass. i.e.  <class_name> <instance variable> = (<native_type_of_object>)<field_reference_to_object>.get(0) }
      • Interfaces { define a Class structure contract including public methods signatures (without implementation), methods, and final fields (constants). Instantiating Class implements Interfaces methods with @Override, adopting Inheritance and Polymorphism concepts. i.e. java.util Interface Collection (where ArrayList implements Collection Interface }
        • Flexibility gained by Upcasting Instances of a Superclass to Instances of an Interface (change Data Type PRESS CTRL + SPACE)
      • Custom Interfaces { use for modelling behaviour }
        • Interface Creation { Select Package > Right Click > New > Interface
      • Abstract Classes { improve definition of Class structure contract to promise that any Subclasses extending the Abstract Class must implement a certain specific concrete functionality (i.e. a method). Overcomes Downcasting in Superclass. Allows Anonymous Inner Type creation (PRESS CTRL + SPACEto Instantiate Superclass directly (if implement Abstract Method inline to satisfy contract) in Superclass. i.e. public abstract ...
        • Abstract Constructor Method Stub Creation { in Subclass Right Click > Source > Override/Implement Methods... }
    • Polymorphism { in an inheritance relationship between Superclass and Subclass, dealing with Objects instantiated from the Subclass declared either as its native type (from subclass) or as an inherited type (from its Superclass) to allow passing of the Subclass object to to other methods that calling the Superclass (i.e. using constructor method of the Subclass whilst using the data type of Superclass) }
  • UML (Unified Modelling Language)
  • Refactoring ( Menu > Refactor > Extract Method ) { include Runtime Exceptions option }
  • Packages { Sub Package (shallow) within Default Package containing Helper Methods of Project Classes with common characteristics }
    • Reverse Domain Notation { achieves universal uniqueness in organisation structure Right Click Class, Refactor > Rename i.e. com.ceenos.calc.helpers. Wildcard Import i.e. com.ceenos.calc.* }
    • Move Classes { Right Click Class, Refactor > Move . Adds a Package Declaration with Import i.e. #import helpers.InputHelpers }
  • Dates
    • java.util { i.e. Date Class, GregorianCalendar ( getTime() returns Instance. add() ) }
    • java.text { i.e. DateFormat ( getDateInstance(DateFormat.FULL) returns Instance (with extended formatting) and is Factory Method. format() }
  • Classes { Long-hand i.e. java.lang.String }
    • Explicit Importing of Classes required for some Packages (Click Class, PRESS CMD + SPACE, Select Package i.e. java.util). Fix Organising Imports Issues by PRESS CMD + SHIFT + O (Menu > Source > Organise Imports)
    • Import Class required if not in current Package
    • toString() is a Method of all Classes 
  • Methods 
    • Jump To Method ( Select Method, PRESS CMD + Click, Hover Over Method > Open Declaration )
    • Constructor Methods (no return type, accept Multiple Arguments) 
      • This { Current Instance of Current Class. Argument of Method is Not Prefixed with This }
      • Super { Call Super Method of the Constructor Class (Inheriting from) }
      • Eclipse Constructor Method Generation { Right Click > Source > Generate Constructor using Fields
      • No Arguments Constructor (Default action of nothing)
    • Class Methods (called from Definition of a Class, static) { use for Utility Function Library creation }
    • Instance Methods (called from Instance of a Class or Object static) { use for handling persistent data }
    • Getter and Setter Methods { Java uses Explicit Setters and Getters for validating, modifying and securing data (i.e. only current Class Sets, read-only so other Classes only allow Get) }
      • Generating Getter and Setter Methods { Right Click > Source > Generate Getters and Setters, use to Refactor code to Get and Set Fields through Centralised Methods }
      • Design for Set Incrementally versus Rewriting Values to Instance each time Called { i.e. replace =  to +=  }
    • Defaults { 'main' method automatically called by JVM }
    • Autocreate Method Signatures { i.e. type say testValues(s1, s2), Hover over Method name, select 'Create method ....' from Popup}
    • Arguments ( use quotes to overcome Delimiting due to spaces )
      • Eclipse Args ( Menu > Run > Run Configurations > Arguments
    • Arguments by Copy (rather than Reference) in Java
      • Passing by Copy { New Instance (Copy) made inside Function the Variable passed to. Note: Passing Primitives Wrapped in Complex Objects (which have Reference Variables pointing to Values both inside and outside Function) make copies of Object with Reference pointing to Value inside and outside Function }
    • Access Modifiers and Other Prefixes
      • public (allow call method from anywhere)
      • private (only avail within Class)
      • protected (avail to Class and Sub Class due to Inheritance)
      • <undeclared> protected package  (avail to Class and other Classes in same Package)
      • static (not require instance of Class to be created)
      • void (not return anything)
    • Factory Methods (of a Class) { return Instance of Class }
  • Custom Methods 
    • Variable Arguments Syntax Array (of same Data Type) <fn_name>(double ... values) { <loop_through>
    • Method Overload (different method signatures i.e. args qty, data type)
  • Variable (Field) Types 
    • Primitive Numeric Values (individual Value)
    • Complex Objects (capable of referencing many Objects) declared with new Class Constructor Method named to match Class name. Big Decimal Class (precision)
    • Class Fields (aka Class Variables access directly from Class Definition and defined by using static)
      • Constant Values achieved by using static final (Value cannot change after being Set) and Uppercase Constant Value
    • Instance Fields { aka Instance Variables / Properties assigned at the Class level (persistent data values, exist for lifetime of Object) } 
      • Declaration { Assess Modifier, Data Type, Name }
    • Characters 
      • Literal Chars (i.e. ' ')
      • Unicode Chars (i.e. '\u0024')
      • Wrapper Class is java.lang.Character  (i.e. toCharArray() )
    • Strings and Substrings (Immutable) { cannot change after Declared }
      • Changing String Variables { use less Memory and Objects by using Methods .insert() and .append() from Utility Class StringBuilder (Single-threading) and StringBuffer (Multi-threading) }
      • Strings within Strings ( substring() )
      • Removing Whitespace ( trim() )
    • Boolean
      • Wrap in parenthesis to eval before assign
      • Wrapper Class is java.lang.Boolean
    • Anonymous Objects { i.e. new myThing() }
  • Conversion of Variables
    • Simple Casting Syntax (avoids extra Objects in memory)
    • Helper Class Methods Wrapper from Java Class Library (long-term storage and usage) applied to Instance for Reference to Complex Object and access to its Methods
      • Upward Conversion Implicit (Safe and Reliable)
      • Downward Conversion Explicitly using Casting 
  • Operators and Comparison
    • Assignment and Math Operators
    • Post and Prefix Incrementing
    • Post and Prefix (Unary) Operation
    • Conditional Complex Operations and Ternary (Short-hand Conditional __ ? <true> : <false> )
    • Comparisons with String Class requires use of .equals() or contains()(unreliable to use ==)
    • Conditional { If, Switch (Break, Return), Enums, Loops (Numeric Counter), For Each, While, Do While }
  • Data Collections 
    • Simple Arrays (same Data Types, non-resizable)
    • Multi-Dimensional Arrays (same Data Types, non-resizable) { Top level and Child Arrays, Nested Loops }
    • ArrayList (ordered collection, resizable items, add(), remove(), .get() and .indexOf() to search features. Import java.util, i.e. ArrayList<insert_data_type_/class_name_instances_of> )
      • ListIterator { Iterators from Collections Framework .listIterator().hasNext().next()(with While Loop). Import java.util, i.e. ListIterator<insert_data_type> }
    • HashMaps {unordered collection, associative arrays, key-value pairs (KVP). map.put(K, V), map.get(K), map.remove(V), etc. Import java.util, i.e. HashMap<declare_data_type_key, declare_data_type_value>  }
      • ListIterator { iterate either keys or values .values()map.keySet() (set of keys of Set Class), keys.Iterator() (Iterator Class), .hasNext().next()(with While Loop). Import java.util, i.e. Set<insert_data_type>, Iterator<insert_data_type> }
  • Handling Errors and Debugging { Compile-Time, Runtime }
    • Exception Objects { Instance of Exception Class is created upon error }
    • Try Block { Wraps code to handle Exception Instances or sub class of it }
    • Catch Block { Handles the Exception. Clears error and continues running. Replace with Exception Class Subclass to only run for specific Exceptions }
    • Try-Catch Block { Select Code > Right Click > Surround with ... > Try/Catch Block
    • Throw { Refactor code anticipated to throw an Exception Class type into its own Method (Select "Declare thrown runtime exceptions" option)  }
  • Eclipse Debugger {
    • Unhandled Exceptions (defined in Java Documentation)
    • Breakpoint { inspect Exception Object structure by freezing app execution in Catch Block (where Exception Object in Scope available) to view information available }
      • Toggle Breakpoint (in trough)
      • Run in Debug Mode (uses Debug Perspective)
      • Variable 
    • Debug Perspective
      • Call Stack View
      • Variable and Breakpoint View { Click Exception Object 'e' to Expand and Inspect Details, Terminate Button, Return to Perspective Menu > Window > Open Perspective }
      • e.printStackTrace() and e.getMessage()
  • Command-Line
    • JAR File
      • Set the Class Path   java -classpath .:<jar_file.jar> com.<reverse_domain_notation>
      • Set the Class Path as Environment Variable (Semicolon separates Values)  set CLASSPATH=.:<jar_file.jar> (Bash Script is alternative)
      • Reverse Domain Notation followed by Class Name  java com.<reverse_domain_notation>.<class_name>
    • Version
      • java -version (Java verson)
      • javac -version  (Compiler version)
    • Commands Listing
      • cd /System/Library/Frameworks/
      • cd JavaVM.framework/
      • cd Commands
      • ls
    • Compiling
      • javac Main.java -d -verbose ..\bin  // create Main.class in \bin. verbose displays compiler background activities
      • cd bin 
      • java Main

No comments:

Post a Comment