Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

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 Class, NodeList 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 + SPACE) to 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

Friday, 6 June 2014

Progress Update - Keepal, iOS, Android SDK, MBT, Swift, Photography Masterclass

Progress @ Keepal
  • Reviewed iOS - DONE
  • ObjectAid UML Explorer for Eclipse IDE - Testing
    • Class Diagrams
    • Sequence Diagrams

Progress @ Lynda.com

Android SDK Essential Training (with David Gassner) -DONE
  • Android Market Fragmentation Recent Statistics { OS, Screen Size, Pixel Density, Vendors } and Strategies { DP, Multi-Screen Drawable Resources }
    • 9 Patch Resizer Tool 
      • Converts Multiple Images into Multiple Sizes that Map to the Multiple Drawable Folders in the Resources Directory of Package Explorer to enabling Graphics selected by Application Framework correctly for any Device
    • 9 Patch Drawable Graphics { stretch and adapt automatically to different screen densities and sizes }
    • Simple Nine-Patch Generator (Android Asset Studio) { regardless of screen size and pixel density it always positions graphic with correct aspect ratio on screen by handling both borders and multiple versions of pixel densities }
  • Android Development Toolkit (ADT) Plugin
  • Android Debug Bridge (ADB) Platform Tool
    • Debug Perspective Tools
      • LogCat Tool (Custom Messages, Filtering)
        • Tracing State Changes (Lifecycle Debugging where Events triggered by moving between Activities that are associated with a Method)
      • Toast Messages
      • Breakpoints 
      • Watchlists
    • Refactoring with Extract to Constants (CMD+1) 
    • Dalvik Debug Monitor Service (DDMS) Perspective 
      • Screen Captures
      • Heap Memory Usage of Device at Runtime by causing Garbage Collection (GC)
      • Persistent Data Storage 
      • Emulator Control (SMS, Voice)
  • Eclipse Java IDE
  • Manifest File (Activities, Intent Filter, Themes)
    • Custom Themes (using Android SDK)
  • Multiple Activities and Layouts 
    • Types (Linear, Relative, and Containers)
    • Layout Manipulation (Margins, Padding, Gravity, Nesting)
    • Java Views (Visual Widgets)
    • Content Assistant (CTRL+SPACE)
    • Java Classes, Importing (CMD + Click) or Quick Fix (CMD + 1) and XML elements mapping
    • Java Code to display Visual Objects, resize, or reposition in View Layouts at Runtime
    • Creating Binding Multiple Layouts (XML) and Activities (Java Classes)
    • Overriding existing Methods of the Super Class with new Method Stubs
    • Cross-Browser Compatibility including Scale-Independent Pixels, Device-Independent Pixels (DP), and Conversion
    • Resources (String, Image) and Literals
    • Resources Identifiers and the dynamically generated R Class
    • Downcasting to Classes
    • Navigating between Multiple Activities and Layouts
      • Explicit Intents
      • Implicit Intents
    • Event Handler Custom Methods
      • Inline Event Handlers with all Code in Java File (easier for Debugging instead of Splitting code between Event Handlers Declared in XML file and Event Handler Methods in Java File)
      • Options Menu { Refactor Architecture by Replacing Buttons with Items in Options Menu using Switch Statement for Event Handling of each Intent } 
    • System Level Event Handling with Broadcast Receiver
      • Permission Granting
      • Extend Java Class BroadcastReceiver to Phone State Change and subsequent Intent generated by OS to Manage Switch b/w Phone and App
      • Debugging Reference to Extras KVPs (i.e. TelephonyManager) that describe State (i.e. Ringing) and comprise each Instance of Class Bundle
      • Registering Broadcast Receiver Class in Manifest with Intent Filter with Actions for Phone State Changes
      • Testing Virtual Device in Emulator with DDMS Emulator Control (i.e. Ringing) and LogCat
    • Constructors and Arguments (Current Context Activity "This", Class Fields i.e. "DetailedActivity.class") 
    • Action Bar and Options Menu
      • Converting Launcher Button of Action Bar into an Up Button (Strategy Complies with Android Design Guidelines)
      • Displaying Menu Items in Action Bar in Primary and Secondary Activities (Never, Always, IfRoom)
    • Activity Lifecycle and Activity Stack Rules
      • Stages { Created, Started, Resumed, Paused, Stopped, Destroyed }
      • Methods { onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), onDestroy() }
      • Tasks containing Activities, which are Grouped into Stacks
      • Second Activity launched to Top Stack pushes Primary Activity to Back Stack
      • Starting and Finishing Activities
      • Transient and Resting States
        • States associated with Events that are associated with Methods containing Code
        • Note: Running App after "Home" button bypasses onCreate method. Running App after "Back" button does not, and removes memory. 
    • Custom Styles defined in single XML file with Attributes to control appearance of Widgets in Activity Layouts for the User Interface (similar to web page CSS) and apply throughout the app
      • Parent Attribute to Inherit Existing Styles (including Android SDK Pre-Defined Styles)
    • Widgets
      • ScrollView in Composite Category
      • ListView 
        • ArrayAdapter Class that grabs the Data to add to List and expects Arguments Context, Resource, and List of Data. Use of Layout for each List Item (from R Class, part of Android SDK, Simple List Item  that Displays a Single String) to pass Resource Argument
        • Customise Appearance of ListView MainActivity by creating a Custom Item Layout, Creating a Custom Adaptor Class (Subclass of ArrayAdapter), and Saving Private References to the Context and List of Data so it Persists for Life of Adapter, and using Layout Inflators to present instance View Objects containing Data (i.e. Image and TextView)
    • Fragments API { Architect Adaptable Multiple Fragment Screen Layouts for flexibility across Multiple Device Screen Sizes }
      • Master/Detail Flow Template with Modifiable Dummy Content for Data-Centric Apps
    • Multi-Activity Data Transfer using Intent Extras (KVPs)
      • Sending and Receiving Data between Secondary and Calling Activities using startActivityForResult method (i.e. Add to Shopping Cart)
  • Auto-Indentation ( CMD + I )
  • Emulation and Testing with Launch Configuration to Run on Multiple Virtual Devices Concurrently (Phones, Tablets)
    • Rotate 90 Degrees ( LEFT CTRL + F12 ) Tests Adaptability to Orientation Changes
    • Prevent Recreation on each Orientation Change
      • Override Auto Recreation on Orientation Configuration Change in Manifest File
      • Override Configuration Changed Class with Event Handler to Add Custom Code on each Configuration Change
      • Debug with Toast Messages 
  • Links
  • Curiosity
    • Advanced Intents - Handling Implicit Intents with Custom Activities registered for Own Standard and Custom Actions

Progress @ Teamtreehouse.com
  • Diary App with Core Data- DONE

Progress @ Harvard Business Publishing 
  • Management Communication: Presenting - DONE


  • Final Presentation (Peer Reviewed Oral Presentation) - DONE
    • Presentation Draft - DONE
    • Peer Review - DONE
    • Final Submission -  DONE

Events
  • BOOKED Olympus Photography Masterclasses with Vogue Australia, Vogue Living, GQ Australia, and Olympus Photography Specialists (Portraiture, Fashion, Still-Life) - Sat 7 June 2014

Curiosity