This repository contains code examples from Software Construction in Java SCiJ and Java: How To Program JHTP. My work in this Repo has also acted as revision of the following MOOCs.
- An Introduction to Interactive Programming in Python
- Coding the Matrix: Linear Algebra through Computer Science Applications
- Product Management Specialisation
- Human-Computer Interaction
- Startup Engineering
- Software Defined Networks
- Algorithms I & II
- Programming Languages
- Compilers
- Functional Programming in Scala
- Programming Mobile Applications Specialisation
- Cryptography
- Agile Development using Ruby on Rails
Constructing good code is a Mens et Manus discipline and if you want to be a competent programmer, I think it is important to Learn By Coding. After a while, regardless of programming languages, familiar Design Patterns and Development Processes emerge and the art of coding begins to become natural.
All the examples were written using Java 8, Eclipse, and Git.
- Containment
- Example: Graphical User Interfaces, e.g. Java Swing and Android
- Most GUI applications have a single thread, called the event dispatch thread, to handle interactions with the application's GUI components
- Here multi-threading is achieved by using thread containment
- There are three important Design Patterns used in GUI development:
- View Tree: central feature in the architecture of most GUI toolkits
- Model-View-Controller: Separates data, output, and input
- Listener: Decouples the model from the View and Controller
- Immutability
- Ideal for concurrency because it is not possible to alter the Data Types and recursion is a special case of Reentrant Code
- Example: Immutable Lists
- Recursive Data Types in Java 8 are similar to the same feature in Scala
- Two important Design Patterns used in constructing Recursive Data Types:
- Interpreter Pattern: pattern of implementing an operation over a recursive data type
- Sentinal Objects Pattern: to signal the base case or end-point of a data structure
- Thread Safe Data Types
- Example: Library Data Structures which use the Shared Memory Model in the form of the Monitor Pattern
- List, Set, & HashMap are Sequential Data Types but they all have Concurrent versions
- Example: Map<Integer, Boolean> cache = Collections.synchronizedMap( new HashMap<Integer, Boolean>());
- Synchronisation (syntactic sugar for Locks and Conditions)
- An example of Synchronisation is the Message Passing Model in the form of the Producer / Consumer Pattern
- Another example of the Message Passing Model is the Client / Server Pattern found in Networking
- Programmers can apply a Monitor directly to a data Type by using the keyword Synchronize or by "going under the hood" and using the Lock and Condition Interfaces
- Example: Mutable Data Structures use Coarse-grain locking
- Example: Operating Systems use Fine-grain locks for high-performance and Lock Ordering to deal with Deadlocks
- Creating and Executing Threads
- Code example: package "concurrency.runnable"
- Thread Management with the Executor Framework
- Code example: package "concurrency.executor"
- Containment
- Code example: package "concurrency.GUI.backgroundCalculator
- Immutability
- Code example: package "recursion.datatypes"
- Synchronisation: Message Passing Model
- Example: Producer / Consumer Pattern
- Code example: package "concurrency.producerconsumer" which contains two main examples:
- SynchronizedBuffer.java (Synchronisation using keyword Synchronize)
- SynchronizedBufferLocks.java (Synchronisation using Locks and Conditions)
- Another example of a Message passing Model is the Client / Server Pattern (Non Multi-threading):
- Stream Socket Connections (TCP): package "sequential.message_passing.client_server.TCP"
- Connectionless Datagrams (UDP): package "sequential.message_passing.client_server.UDP"
- Multi-threading Client / Server example
- Code example: package "concurrent.message_passing.client_server.TCP"
- Synchronisation: Shared Memory Model
- An example of Synchronisation in the form of the Monitor Pattern
- Code example: package "concurrency.shared_memory.monitor"
- Contains the method findReplace which is an example of Serialisability. Found in Editor.java