Software Components Overview

Below is a list of links to and brief descriptions of common software components. It's useful to keep these in mind and reference them during software design as a shorthand for code that will be written to implement the design. Implementing a component could involve just a few or many lines of code.

A suggested way to use these components in solving/coding a computing problem is to include them using a Separation of Concerns design pattern folded into what I call Layered Logic Problem Solving that includes these steps:

  1. Describe in words the problem to be solved. This might include references to software components listed below. You might also include solution acceptance criteria, possibly in the form of formal acceptance tests.
  2. Draw a block diagram of the main problem solution pieces. For more complex problems, other types of diagrams can be used.
  3. Annotate the block diagram with references to components such as those below.
  4. Code the solution in your chosen programming language.

Communications

  • Client-Server Architecture: components include:
  • HTTP Requestindicates the desired action to be performed on an identified resource - actions include: 
    • GET: retrieve data
    • HEAD: retrieve without response body
    • POST: create new subordinate data
    • OPTIONS: retrieve supported actions
    • PUT: create/replace data
    • DELETE: delete the resource
    • CONNECT: convert connection to TCP/IP tunnel, usually to facilitate HTTPS SSL
  • Internet Protocol Suite:
    • Layers: Application/Transport/Internet/Link
    • Levels: Send/Receive, Controls/Routing, Values/Translations
  • Firewall: monitor/control of incoming/outgoing traffic
  • JSON: JavaScript Object Notation, Human Readable, Attribute-Value Pairs, Java JsonObject
  • Load Balancer: distributes workload across computing resources
  • Message: data sent across processes
  • Network: allows computers to exchange data
  • Protocol: Data Formats, Address Formats, Address Mapping, Routing, Error Detection, Acknowledgements, Sequence Control, Flow Control
  • REST: Representational State Transfer, Stateless, Client-Server, JSON data
  • Socket: endpoint of a connection across a computer network

Data

Algorithms & Processes

Objects

  • Class: object template
  • Container: collection of other objects
  • Design Patterns: reusable solutions to common software problems  
  • Object Oriented Design Patternsreusable solutions to common object oriented software problems
  • Generics: specify type or method to operate on objects
  • Cloud Computing: internet based computing that provides shared processing resources
  • Interface : all abstract methods
  • Mutability: mutable, immutable, strong vs. weak
  • Objects: variables, data structure or function referenced by an identifier
  • OOD: uses inheritance, abstraction, polymorphism, encapsulation, other design patterns

Views

  • Ajax: groups of technologies for client-side asynchronous web applications
  • Android Fragments: UI segmenting, own lifecycle, FragmentManager
  • HTML5 Canvas:  bitmap, javascript
  • CSS:  describes the presentation of information
  • HTML:  head, body, div, script
  • Widget: simple, easy to use applicator
  • XML: markup language that defines a set of rules for encoding documents

Type System

A type system is a collection of rules that assign a property called type to constructs such as variables, functions, expressions and modules. Here are the two main dimensions of typing and some programming language examples:

Static vs. Dynamic

  • static:  type is set during compile
  • dynamic: type is set during execution

Strong vs. Weak

  • strong: type cannot change during execution
  • weak: type can change during execution

Language Examples

Java Data Structures

There are a number of commonly used Java data structures. Here are links to additional documentation and highlights of structural aspects: 

  • Array: fixed size, best for primitives 
  • List: fixed size, interface, ordered, allows duplicate
  • ArrayList: resizable , add to top, preferred unless need the capabilities of another structure
  • Vector: resizable, synchronized, add to top
  • Stack: LIFO, push/pop
  • Queue: FIFO, add to bottom/remove from top, interface
  • LinkedList: doubly-linked, push/pop, many other methods
  • Set: no duplicates, interface
  • HashMap: random access
  • TreeMap: sorted, efficient search
  • Binary Tree: each node has <=2 children
  • Binary Search Tree: sorted, fast lookup/add/remove
  • k-d Tree: k dimensional, space-partitioning, nearest neighbor search
  • Red-Black Tree: self-balancing, binary search tree, extra bit per node
  • Iterator: move forward and backward through data
  • Collections: perform operations on collections of data
  • Working with Java Lists: methods, iterators, collections
  • Data Structure Decisions: change, access, indexing, sizing
  • Common Java Array Manipulation Constructs: split, sort, binary search, iteration
  • Common Java ArrayList Manipulation Constructs: add, indexOf, remove, sort, binary search, interator
  • B-tree and Binary Search Tree Data Structures: like TreeMap
  • Sorting Algorithms: Collections sort, exchange, hybrid, insertion, merge
  • Big O Notation: O(1), O(log (n)), O(n), O(n log(n))
  • Update and Access Overview: The diagram below indicates how elements and values are updated and accessed. This is a broad overview of commonly used data structure classes, interfaces and objects ... please see the links above and below for more details. Some general observations are:
    • Arrays are different than the other structures in that they are accessed using bracketed index [n] references, such as myStringArray[3] instead of methods and can only contain primitives, not objects.
    • ArrayLists are generally preferred over Lists as they allow resizing. It's a very commonly used structure.
    • Vectors are much like ArrayLists with the additional characteristic that they are synchronized.
    • Queues and Stacks are specialized for LIFO and FIFO access.
    • LinkedLists are powerful structures that require more space for storage and time to execute some operations but are efficient for inserting and deleting objects in the existing order.
    • Sets are simple structures that don't allow duplicates.
    • HashMaps are commonly used when rapid, direct access to elements is the primary requirement.
    • TreeMaps are preferred when rapid search is the primary requirement.
    • Iterators and Collections operate on whole data structures.
    • ( ) empty parameter methods generally operate on the ends of a structure.
    • (element | object) only parameter methods generally operate on sets or the ends of structures.
    • (index | key) and (index | key, element | object) parameter methods generally operate on specific places within a structure.

Working with Java Lists

As shown in the diagram below, there are three major Java class groups used for working with lists: Lists (such as List, ArrayList, LinkedList, AbstractList, Stack and Vector), Iterators (Iterator and ListIterator) and Collections. Together, these classes and their methods provide a wide spectrum options for list construction, examination and manipulation. For an example of using these classes, look here.

Common Java ArrayList Manipulation Constructs

ArrayList data structures (also called Dynamic Arrays) are a frequently used programming function. ArrayLists have an advantage over arrays - ArrayLists are not fixed in size and can be dynamically changed by adding and deleting elements. Below are some common Java array manipulation constructs. For an overview of working with Java lists, look here.

Creating a new ArrayList

Creating a new ArrayList is coded as shown below using the String type with an initial capacity of 20 entries:

ArrayList mArrayList = new ArrayList<String>(int 20);

Constructing an ArrayList from an Existing List

The example below shows how to construct an ArrayList from the individual words in a String using an intermediary List object. Notice that the sequence of objects created is: String -> String array -> List -> ArrayList

String wordString = "this is a string of words";
String[] wordsArray = wordString.split(" ");
List<String> wordsList = Arrays.asList(wordsArray);
ArrayList wordsArrayList = new ArrayList<String>(wordsList);

add( )

The example below shows how to use the ArrayList add() method to add a String to wordsArrayList::

wordsArrayList.add("Example2");

indexOf( )

The example below shows how to use the indexOf() ArrayList method find the index of an entry:

int index = wordsArrayList.indexOf("Example2");

remove( )

The example below shows how to use the ArrayList remove() method using the entry index or the entry itself:

wordsArrayList.remove(index);
wordsArrayList.remove("Example2");

sort( )

The Collections sort() methods provide a variety of options for sorting ArrayList entries. Note that the ArrayList is sorted in place without returning a new ArrayList. This can be done because the array parameter is a value pointing to the ArrayList of objects. For example, the following statement would sort the words ArrayList from the example above using a modified MergeSort algorithm in an average O(n log(n)) time performance:

Collections.sort(wordsArrayList);

binarySearch( )

The Collections binarySearch() methods provide an efficient way to find an entry in a sorted ArrayList. For example, the following statement would find the index of the wordsArrayList entry for the String Example1 in an average of O(log(n)) time performance:

int entryIndex = Collections.binarySearch(wordsArrayList, "Example1");

iterator( )

The Iterator Class and ArrayList interator() method can be used to iterate over the entries of an ArrayList as shown in the example below :

Iterator mIterator = wordsArrayList.iterator();
while(mIterator.hasNext()){
System.out.println(mIterator.next());
};

Common Java Array Manipulation Constructs

Working with array data structures is one of the most frequently used programming functions. Arrays are implemented in a number of Java classes, such as String, Integer, and Boolean. Those arrays can be manipulated using the Java Arrays class (note that the Arrays class name is a plural). Below are some common Java array manipulation constructs.

split( )

The String split() method separates string characters into array entries using a supplied regular expression. For example, the following statement would create entries in the String array wordsArray using a blank character as a regular expression separator for processing the String wordString:

String wordString = "this is a string of words";
String[] wordsArray = wordString.split(" ");

sort( )

The Arrays sort() methods provide a variety of options for sorting array entries. Note that the array is sorted in place without returning a new array. This can be done because the array parameter is a value pointing to the array of objects. For example, the following statement would sort the words array from the split() example above using a Quicksort process in an average O(n log(n)) time performance:

Arrays.sort(wordsArray);

binarySearch( )

The Arrays binarySearch() methods provide an efficient way to find an entry in a sorted array. For example, the following statement would find the index of the array wordsArray entry for the String entryValue in an average of O(log(n)) time performance:

int entryIndex = Arrays.binarySearch(wordsArray, entryValue);

for( )

The for() construct can be used to iterate over the entries in an array. For example, the following statement would iterate over and print every entry in wordsArray:

for (String word : wordsArray) {System.out.print(word);}

If you want to know and use the index of each entry, then this construct can be used:

for (int i=0; i<wordsArray.length; i++) {System.out.print(wordsArray(i);}

Android Data View Adapters Overview

Android APIs provide classes and methods to facilitate displaying data in various forms, such as lists, arrays and custom layouts. The graphic below shows how the various classes and methods interact to produce the desired result.

Some examples of coding and use are:

Data

The data to be displayed can be in such forms as an Array, List, File or SQLite database. If a database is used, a Cursor object is also employed. A simple array of String values might be created and converted to an ArrayList like this:

String[] mStringArray = new String[] { "blue", "green", "yellow",
        "red", "orange", "black", "white", "purple"};
List<String> mList = Arrays.asList(mStringArray);
ArrayList<String> mArrayList = new ArrayList<String>(mList);

Cursor

Cursor is an interface that provides random read-write access to the result set returned by a database query. Setting up a Cursor for an SQLite database might look like this:

MySQLiteOpenHelper mDatabaseHelper = new MySQLiteOpenHelper(this);
Cursor mCursor = mDatabaseHelper.getDataIntoCursor();
ListView mListView = (ListView) findViewById(R.id.mListView);
MyCursorAdapter mCursorAdapter = new MyCursorAdapter(this, mCursor);
mListView.setAdapter(mCursorAdapter);

class MyCursorAdapter extends CursorAdapter {

    public MyCursorAdapter(Context context, Cursor c) {
        super(context, c);
    }
    // Implement CursorAdapter bindView method.
    public void bindView(View view, Context context, Cursor cursor) {
        String name = cursor.getString(1);
        TextView textView = (TextView) view;
        textView.setText(name);
    }
    // Implement CursorAdapter newView method.
    public View newView(Context context, 
                         Cursor cursor, ViewGroup parent) {
        TextView view = new TextView(context);
        return view;
    }
}
private final class MySQLiteOpenHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "myDatabase";
    private static final int DATABASE_VERSION = 1;
    private static final String CREATE_TABLE_TIMELINE = 
        "CREATE TABLE IF NOT EXISTS table_name 
        (_id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar);";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_TIMELINE);
        db.execSQL("INSERT INTO ddd (name) VALUES ('Name1')");
        db.execSQL("INSERT INTO ddd (name) VALUES ('Name2')");
        db.execSQL("INSERT INTO ddd (name) VALUES ('Name3')");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, 
                          int oldVersion, int newVersion) {
    }
    public Cursor getDataIntoCursor() {
        String selectQuery = "SELECT  * FROM table_name;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
        return cursor;
    }
}

Adapters

An Adapter acts as a bridge between an AdapterView and the underlying data for that view. A custom array adapter defined in Java might look like this:

class MyArrayAdapter extends ArrayAdapter<String> {
    HashMap<String, Integer> mHashMap = new HashMap<String, Integer>();
    public MyArrayAdapter(Context context, int textViewResourceId,
        List<String> objects) {
      super(context, textViewResourceId, objects);
      for (int i = 0; i < objects.size(); ++i) {
        mHashMap.put(objects.get(i), i);
      }
    }
    @Override
    public long getItemId(int position) {
      String item = getItem(position);
      return mHashMap.get(item);
    }
    @Override
    public boolean hasStableIds() {
      return true;
    }
 }

The custom array adapter mArrayAdapter would be instantiated and linked to a ListView mListView with Java code like this:

setContentView(R.layout.mLayout);
final ListView mListView = (ListView) findViewById(R.id.listview);
final MyArrayAdapter mArrayAdapter = new MyArrayAdapter(this,
        android.R.layout.simple_list_item_1, mArrayList);
    mListView.setAdapter(mArrayAdapter);

AdapterView

An AdapterView is a view whose children are determined by an Adapter. You might use an AdapterView like this:

private OnItemClickListener mMessageClickedHandler = 
  new OnItemClickListener() {
    public void onItemClick(AdapterView parent, 
                            View v, int position, long id) {
        // Do something in response to the click
    }
};
listView.setOnItemClickListener(mMessageClickedHandler);

View

View is the basic building block for user interface components. A view occupies a rectangular area on the screen and is responsible for drawing and event handling. A ListView contained in a layout might look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/mListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>

ViewGroup

ViewGroup is a special view that can contain other views called children. A ViewGroup defined in XML might look like this:

<ViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/mViewGroup"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <TextView
        android:id="@id/mTextView"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
    </TextView>
</ViewGroup>

Layout

A layout defines the visual structure for a user interface. A layout might look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/mListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>

Activity

An Activity provides a screen with which users can interact.

public class MyActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    . . .
  }
}

Fragment

A Fragment represents a behavior or a portion of user interface an an Activity. Fragment code might look like this:

public class ArticleFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, 
                             ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.article_view, 
                                container, false);
    }
}

Android Fragments Overview

Android Fragments provide a mechanism to create modular sections of an Activity. You can see how Fragments fit into the overall Android structure in the blog post Android App Major Elements. You can see an example of Fragment use in the blog post Android Fragments.

Fragments provide a couple of significant benefits for Apps:

  • Fragments facilitate App adaptation to various screen sizes and dimensions. 
  • Fragments have their own life cycle that can be used to implement unique behavior for different App Fragments.

Below is an overview of Fragments and the Android elements they interact with for Fragment control.

Activity (Main)

The main Activity of an app uses the setContentView() method to establish a View.

Activity (for Fragment)

Activities can start and be started by Fragments.

View

The View class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). Views can be accessed via their ids or from the Root View.

Root View

The Root View is the base of the tree for all the Views for an app. It can be referenced using android.R.id.content.  

Layout (XML)

Layout XML can be used to define Views. When an app is compiled, the XML definitions are used to create View details. Note that this can include Fragment properties. If a Layout that includes a Fragment specification is used by the Activity setContentView() method, that Fragment will be automatically started by the Android operating system.

Fragment

A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity. Sub classes of Fragment include: PreferenceFragment, DialogFragment and ListFragment.

Fragment Manager

The FragmentManager class is an Interface for interacting with Fragment objects.

Fragment Transaction

The FragmentTransaction class is used for performing Fragment operations.

Java vs. Ruby Programming Language Comparison

Java and Ruby are two popular programming languages that represent two very different approaches to structure and syntax. Java has a more formal, strict syntax. Ruby syntax is more forgiving and provides many shortcuts and abbreviations. Java is compiled and Ruby is interpreted.

The table below shows a sampling of Java and Ruby programming language elements that highlight these differences.

JavaRuby
Block {
   . . .
}
def/class/do/if...
   . . .
end
Class
Definition
public class Hello {
   . . .
}
class Hello
   . . .
end
Class
Constructor
public Hello(Strng msg) {
    defaultMsg=msg;
}
def initialize(msg)
   . . .
end
Class
Instantiation
Hello mHello=new Hello();
mHello=Hello.new("Hello Ruby")
Class
Variable
static String myVariable; @@myVariable
Comment // Comment text. # Comment text.
Constant final static MY_CONSTANT; MY_CONSTANT
Conditional if (a>b) {
   . . .
}  else {
   . . .
}
if a>b
   . . .
else
   . . .
end
Exception
Handling
try { . . . }
catch { . . . }
raise . . .
 
Global
Variable
public class MyGlobals {
   public static String mG1
}
$mG1
 
 
Importing import java.sql.*; require 'extensions'
Inheritance extends MyClass < MyClass
Instance
Variable
// Declared outside methods
String mVariable;
@mVariable
 
Iteration for (i=0; i<5; i++) {
    . . .
}

for (myElement : myCollection){
    . . .
}
5.times do | i |
   . . .
end
Local
Variable
String myVariable; my_variable
Method
Definition
public void myIdea(String param) {
   . . .
}
def myIdea(param="Starter")
   . . .
end
Method
Use
myIdea(mParameter) myIdea m_parameter
Namespace
Reference
packageName;
: :
Null Value null
nill
Statement
Separator
;
new line
Variable String mString="Hello Java";
mString="Hello Ruby"

Algorithm Design

An algorithm is a step-by-step procedure for performing calculations. Types of algorithms include:

Sometimes it's hard to know where to start in designing an algorithm for a task at hand. Below are some elements to consider during algorithm design.

Performance

Consider factors such as the average and worst case performance of your algorithm.

Design Patterns

Find a code design pattern that fits the problem you're solving.

Data Structure

The data structure you choose should reflect your data access needs.

Database Structure

A database is often a good data storage choice when the data needs to be accessed using a variety of search, sort and display options.

Data Sort

There's a large selection of sorting algorithms to select from. See which one most closely fits the nature of your data and access requirements.

Java abstract Classes and Methods

The abstract modifier for classes and methods has to do with instantiation. Here's a summary:

abstract class

  • can't be instantiated
  • can be extended
  • must be declared abstract if it contains one or more abstract methods

abstract method

  • has only a declaration with no body, such as:
public abstract myMethod(String myString);

Java final, abstract and static Modifiers

The meaning of the final, abstract and static Java modifiers can be confusing and hard to remember. Here's a brief summary:

final

Generally means "can't be changed".

  • final class: can't be extended (sub-classed)
  • final method: can't be overridden or hidden by sub-classes
  • final variable: can only be initialized once 

abstract

Generally means "can't be instantiated".

  • abstract class: can't be instantiated, can be extended, must be declared abstract if it contains one or more abstract methods
  • abstract method: has only a declaration with no body
  • abstract variable: not allowed

static

Generally means "not associated with an instance".

  • static class: only nested inner classes can be static, they are not associated with any instance of the enclosing class
  • static method: doesn't use instance variables
  • static variable: is the same across all instances of it's containing class

additional notes

  • constants: use static final as variable modifiers
  • abstract static methods are not allowed