Saturday, February 1, 2014

Training Syllabus

Welcome to the Java Training program


This training course is intended to give you knowledge and hands-on experience with elementary Java skills and Best practices of software design.
This course should be done with an appointed mentor, that will guide you through the material, answer your questions and review your exercise code.
You shouldn't start the course before you have a mentor.
Development Environment Setup:
Follow the next guide that will help you to setup your development environment.
Exercises
The exercises in this course are incremental:
You are going to build an Encryption application that mainly handles the process over files.
When completing a chapter - you will augment your project with the new material.
As said before - after you finish an exercise, go to your coach and ask him to review your new code and give you feedback.
The solutions to the exercises can be found at GitHub (Add link).
Each exercise has it’s own project (called “encryptorX”, when X is the exercise number).
It is very important that you use Version Control when you are doing your exercises.
Use the VCS that your team uses (ask your mentor). If you’re using Git, you can work locally, without any communication with a remote server.
In case you would like to learn more about Git SCM, you can find tutorials and guides on the Git official documentation site, or at this Tutorial by Lars Vogel.
As well, It is very important that you start off with using Maven, to not be dependent upon any IDE.
Mentors Only!
This part is for mentors only, download this Excel (Soon to come) for guidance to each exercise.
There are many pointers to your code reviews and code design.
For your convenience you can use the schedule Excel (Soon to come) document.
Course schedule
1.    Introduction with Java
Estimated time: 2 days.
2.    Object Oriented Programing In Java
Estimated time: 1 days.
3.    JUnit, Mocking, Unit Testing
Estimated time: 3 days.
4.    Exceptions In Java
Estimated time: 1 days.
5.    Generics & Listeners
Estimated time: 2 days.
6.    MultiThreading
Estimated time: 3 days.
7.    XML Tools in Java
Estimated time: 3 days.
8.    Reflection & Dependency Injection
Estimated time: 2 days.
9.    Final Test. (Soon To Come)
Estimated time: 1 day.
Total estimated time: 18 days (~1 month).

Chapter 8 - Reflection & Dependency Injection

Reading Materials
·         Jenkov Tutorial - Reflection API
·         SOLIDprincipals
·         Google- Guice – Read the users guide

Exercise:

In the previous exercises we used Constructor Injection to pass the algorithm implementation of choice.
Replace this method of DI with Google Guice’s @Inject annotation.
Everything should be defined in Guice’s AbstractModule (you should inherit from it).
Update the automatic tests to work with the injection configuration using Guice (it is possible to implement this using an inner class in the tests).

The key creation method should be changed to the following method (instead of a random key):
-       Read the method names of all the methods in the implementation class of the algorithm (e.g. DoubleEncryption) using reflection API.

-       Write a hash function that transforms the list of strings (method names) to the key.

Chapter 7 - XML Tools in Java

XML, XSD (JAXB, SAX, DOM, STAX)

Reading Materials
·         XML and XSD
·         Oracle Java Tutorial – JAXB – read all.
·         Jenkov Java& XML Tutorial (DOM, SAX, STAX) – read all.

Exercise:
We want to be able to read program parameters from an XML file instead of getting it from the user (through the console).
And we want to print the run results to an XML file.
·         We shall implement this functionality in 3 different ways: DOM, SAX, JAXB.
o    3 different classes should be created for the 3 methods.
·         The writing will be performed through JAXB only.
·         An example for an input file is given in the end of this document (this is only an example. You may choose a different format).
·         Add a validation option with XSD of the XML. You will write the XSD.

Emphasis:
·         Read about the xjc command. What can it do?
·         The classes should implement interfaces. This should improve flexibility and allow integration in our code

XML configuration example:
<ProcessSettings>
      <Algorithm>DoubleShiftUp</Algorithm>
      <KeyPath>c:\temp\encryptor</KeyPath>
      <SourceDirectory>c:\temp\encryptor\source</SourceDirectory>
      <SourceFileName>c:\temp\encryptor\file.txt</SourceFileName>

</ProcessSettings>

Chapter 6 - Multithreading

Reading Materials
·         Head First - Java (Read all the listed chapters)
o    15 - Networking And Threads (pages 489 – 528)
·         Effective.Java.2nd.Edition
o    Chapter 4 - Methods Common to All Objects (Item 15)
o    Chapter 10 - Concurrency
·         Oracle Java Tutorial
§  Interfaces: Condition, Lock, ReadWriteLock.
§  Classes: ReentrantLock, ReentrantReadWriteLock.
o    Java Concurrency Tutorial (All of the subjects)

Exercise:
·         Add an option to encrypt an entire directory.
The directory may contain several files, and the system should encrypt them all with the same key (and the same algorithm).
The encrypted files shall sit under a sub-directory named “encrypted”. File names shall not be changed.
Only files with .txt extension should be encrypted. Do not encrypt any sub directories. The key will be saved inside the directory, as key.txt.
·         After a single file encryption has completed – inform the user of the event and its duration. After all files have been encrypted – inform the user about the event and its whole duration.
·         Because we are dealing with a large number of files, and some may be heavy, you have decided that you want to use multithreading to try and improve the speed of directory encryption.
o    Write an interface named DirectoryProcessor and implement the following classes:
§  SyncDirectoryProcessor – responsible of encrypting a directory “normally”, with a single thread.
§  AsyncDirectoryProcessor – responsible of encrypting a directory concurrently.
o    Think: what changes have to be made in EncryptionLogger? (pay attention to locking and the way it has to be done – synchronized? on what?)
·         Implement the reverse functionality – decryption of a whole directory, similarly.
·         Compare the running time of each method. Apply each encryption method on a directory with some big files (each file should be ~5MB). Selection of the method should be done in the main method.
o    Which method is faster? Why?

Emphasis:
·         In the final implementation you should perform encryption and decryption of a directory asynchronously (AsyncDirectoryProcessor).
·         Pay attention to how are the threads being run? Thread? Executor?

·         For the sake of testing you probably should write something that generates large files. You can write a little Java program for this task.

Chapter 5 - Generics & Listeners

Reading Material:
1.     Head First – Java
Chapter 16 – Data Structures
2.     WikipediaObserver Pattern
a.     Chapter 3 – Methods Common to All Objects (items 8, 9)
b.    Chapter 5 – Generics (Item 25)

Exercise:
·         Add the following events to FileEncryptor (choose correct parameter types of each event):
o    encryptionStarted
o    encryptionEnded
o    decryptionEnded
o    decryptionStarted
Activate them in the appropriate places (the events are supposed to be expressed as methods in the interface, as you read in the Observer Design Pattern – which is the Observer and which is the Subject).
How would you know what is the time? (System class).
·         Create the class EncryptionLogger that registers to these events and writes messages like: “the encryption for file X with algorithm Y took Z miliseconds. The encrypted file is located in file F”.
o    Create EncryptionLogEventArgs class that includes the relevant information for each message.
o    For now, the log messages will go into the console.
·         Create a class called EncryptionLog4JLogger that writes to Log4J’s Logger (you must add the Log4J dependency to your pom file).
·         Implement equals and hashCode for EncryptionLogEventArgs (what is the difference between equals and ==? How can we ensure that both options behave the same?)
·         Change the Key definition In EncryptionAlgorithm, add a generic parameter that will be the key.
You will have to change all the implementations of the interface and the automatic tests. (Look again at
DoubleEncryption. You will have to create a new class that is a key and has 2 keys).

·         Explain what does “covariant” mean?

Chapter 4 - Exceptions In Java

Reading Materials
·         Head First - Java (Read all the listed chapters)
o    10 - Numbers Matter
o    11 - Risky Behavior

Excercise:

1.     Add exception handling to your encryption program.
·         Your encryption algorithms should throw InvalidEncryptionKeyException in case the key is not in the correct format.
                                          i.    Show the user an appropriate error message in that case.
·         Your program should throw another kind of exception in case the paths that were passed are not valid.
2.     Add a method to EncryptionAlgorithm that is called getKeyStrength that describes that maximal length (number of digits) of the key for the algorithm.
For example if the key is between 0-256 then the value of the algorithm should be 3.
·         Implement the property for each and one of you algorithms.
·         Create a class that implements “Comparator<T>” and compares between two algorithms by their key strengths.
·         Add suitable unit test accordingly

                                          i.    Do you know how to check if an exception is thrown via JUnit? 

Chapter 3 - JUnit, Mocking, Unit Testing

Reading Materials
·         JUnit TutorialGettingStarted
o    JUnit Usage and Idioms – Read all of the listed items under the JUnit Wiki
·         MockitoDocumentationsand Examples
·         TDD Wiki Value
·         Unit Testing Wiki Value

Excercise:

1.     Write unit testing planning for your previously written code and review it with our mentor before starting to implement it.
2.     Write all of your tests via the framework of JUnit (We’re talking about unit testing) that performs the coverage to all of your specifications in the previous section.
a.     Use Maven to add the dependencies to JUnit 4 and Mockito (You should use the most current versions available).
b.    Write unit tests to all of the implementations of EncryptionAlgorithm interface.
(Make sure that the tests run each time you make a build with maven)
c.      Try writing your tests without code duplication, think how you can reuse your code to the different encryption algorithms.