Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Maven Exercise

 Convert your already created project into mavenize project.


 Also use maven to configure different build setting for DEV,UAT and PROD.

JUnit Exercise 2 - Mockito


 Use JUnit to write test cases for Order Service. Please refer Spring Exercise 5 – Hibernate
 Write test cases with the help of any mocking framework.

Java Concurrency Exercise 9 - Lock


1. Write a communication channel where clients can connect to server and it should satisfy the
following conditions :
 If one client is connected to server other should wait for their turn.
 Client can also configure the wait time (the time duration for which the client will wait and after
the expiry of this time duration it will return some status(either a Boolean flag or exception))
2. Enhance the above mentioned exercise with the functionality to prioritize the client request (A
higher priority request will be treated before other client requests).
3. Enhance this program so that server can process multiple client requests concurrently.

(Hint :- Use Lock and Condition to implement the above problem.)

Java Concurrency Exercise 8 -


Exchanger
 Write a simple problem in which you try to exchange an object ( in this case an array of int) between two task
: Producer and Consumer. The Producer class produces an array of int and then it tries to exchange it with
the Consumer array ( which is an empty array) using an Exchanger object.

Java Concurrency Exercise 7 - Cyclic


Barrier
Implement the parallel sort using Cyclic Barrier.

Java Concurrency Exercise 6 -


Countdown Latch
 Matching Engine need to produce a trade report at the end of the day.
 This Trade Report will capture multiple details like total stocks traded in the day, maximum
market price of the stock on which trade happened, how many buy orders came to the system,
how many sell orders came to the system, total invalid order, etc. All of the required
information are independent to each other and can be processed concurrently.
 We need to send this report to Trade Manager for review only when we get response for all the
required infomrmation.
 Implement the solution for the above mentioned problem with the suitable concurrent
mechanism.

Java Concurrency Exercise 5 -


Semaphore
In the Matching engine, we need to make sure that not more than 5 clients should send the
orders at same time. If 6th client is trying to connect then that client should wait until one of the
existing client disconnect from the matching engine.

Java Concurrency Exercise 4 -


Executor
 In the Matching Engine, For each new Order
o If order type is Limit order, we need to search the matching order(with same price and same
security) in the Order Pool
 If matching order is found, execute the order and send the execution reports to clients
 If no matching order is found, put the order in the order pool
o If order type is Market order, we need to get the market price for security and need to search
the matching order(with market price and security) in the order pool
 If matching order is found, execute the order and send the execution reports to clients
 If no matching order is found, send the cancel response to the client.
o If order type is TimeOut order, we need to treat this order as a limit order. If order is not able to
execute till the specified time then remove the order from the order pool and send cancel
response to the client.
o If order type is Limit with Time or Market with Time, After the specified time, then these order
will be treated as Limit Order or Market Order.

(Hint: Use different ThreadPools from Executor Service, Callable, Future to achieve given
task.)
Java Concurrency Exercise 3C -
Queue
1. We have to write a program which reads the data from database and storing them in the file.
We will provide 2 types of threads – reading threads and writing threads.
o Reader threads will read the data from database and push them to queue
o Writer threads will pop the data from queue and write it to a file
The program should satisfy the following condition:-
o If reader thread is slower than writer thread, writer thread needs to wait until data is made
available in queue.
o If writer thread is slower than reader thread, reader thread needs to wait until writer thread
consumes data from queue.

2. Implement the above exercise using SynchronousQueue.

3. Enhance the Java Concurrency Exercise 3A to store the LimitWithTime() and


MarketWithTime () orders. Use appropriate data structure to store such orders. (Hint:
DelayQueue can be used).

Java Concurrency Exercise 3B - List


and Set
 Write a program that uses CopyOnWriteArrayList and CopyOnWriteArraySet assuming that the
program can be accessed using multiple threads.
 Please write JUnit test cases which compare the performance
of Vector, SynchronizedList and CopyOnWriteArrayList for insert, remove and search
operations.

Java Concurrency Exercise 3A


 Create a data structure which stores Order based on Price and Security Id.
 User should be able to get all orders for a given Price or all orders for a Security or all order for
a particular price and security.
 Multiple threads will try to insert, delete or search the orders in the data structure.
(Hint: use concurrent hash map).
 Implement the version by using ConcurrentSkipListMap<K,V> for better performance.

Web Exercise 2
 Please design the user screen for ‘Create Order’ by which user can create buy/sell orders.
 Please make sure you are taking care of client side validations
 Quantity should be greater than zero
 Implement dropdown of order type like Market, Limit, Limit with Condition, Market with
Condition, Limit with Time, Market with Time, Time Out, Special Limit Order and Enhanced
Limit order.
 Implement the double submit validation.

Web Exercise 1
 Using Any MVC Framework, design and develop UI for User authentication. Please refer
Hibernate Exercise 1.
 Please design the user screen for Stock Watch Service. Please refer Hibernate Exercise 2.
 Please write JUnit to test the above feature.

Java Concurrency Exercise 2


 In Level 1, you have created a data structure called order Pool(Java 5 - Data Structure)
 You need to enhance it so that it can be thread safe. Consider multiple threads will try to search
data and same time few threads will try to put/remove data.

Java Concurrency Exercise 1


 Write a Producer Consumer Application where Producer creating objects of Order class and
consumer will print the Order object with some delay.
 Enhance it where you are having single producer and multiple consumers.
 Enhance it where you are having multiple producers and multiple consumers where a consumer
can take object from any producer.

Design Pattern Exercise: - Flyweight


 To test matching engine, we need to create multiple buy and sell orders (in the range of millions)
with different prices, different client ids and different orders id. But we need to make few
properties same for most of the orders like security which is a heavy object, order type(ENUM)
and few other properties so that we can minimize the load on system.
 Use fly weight pattern to solve this problem so that test program does not go out of memory.

Design Pattern Exercise: - Observer


 In the Matching Engine, As soon as any order executed, we need to send notification to different
listeners with Order Details. Listeners responsibility to do post trade job like send
notification(email and sms) to client, send notification(email and sms) to client manager, send
notification(email and sms) to portfolio manager, log the order details for audit, etc.
 Configure few listeners to demonstrate Observer design pattern.

Design Pattern Exercise: - Prototype


 Suppose we have one object in your application which is taking lots of time in creation because
of its reading lots of data from config files or lots of data from database before it creates final
object.
 You need to demonstrate prototype pattern where object can be created by copy of the
existing object with lesser time.

Design Pattern Exercise: - State


 This exercise is an enhancement on existing Portfolio manager functionality.
 Before sending order to matching engine, Order should go to multiple approvals from different
teams like portfolio manager, client manager, business manager etc.
 The basic approval cycle would define multiple states of order object like
New -> Approved by Portfolio Manage -> Approved by Client Manager-> Approved by Business Manager
->Ready to Send.
 All the new Order which create will be in New state.
 Order can be send to Matching engine only when its state is ‘Ready to Send’.
 Use state design pattern to define multiple states of Order object and there transition.
 It time allows you can use observer design pattern to attach listeners to each state.

Design Pattern Exercise: - Visitor


 TradeHome application provides Portfolio Manager service for all the clients to use. But to use
that it is charging some commission based on the executed orders.
 At the end of each day, its calculating how much commission to be charged to user based on
the orders executed in a day.
 All the executed “Limit Orders” will be charged 0.1% of executed amount. i.e. If Limit Order of
Buy 100 ICICI is executed @ 34.56 then 0.1% will be charged from the client on amount 3456.
 All the executed “Market Orders” will be charged 0.5% of executed amount.
 All the executed “With Condition” orders will be charged 1% of executed amount.
 Please use visitor pattern to achieve above task.

Design Pattern Exercise: - Factory


 In the Matching Engine, User can ask for a market price which is retrieved from different sources
like Reuters, Bloomberg, XYZSource and customdatasource for any security.
 You need to write a program which can get the market price based on provided data source.
 You can use enum to configure factory.
Design Pattern Exercise - Abstract
Factory
 User can extract multiple report from Portfolio Manager for analysis purpose like
o My Execution Details – All the execution happened for today.
o Top 10 Securities for the Day By Price
o Top 10 Securities for the Day by Volume
o My Portfolio Reports – Listing of all Stock by user with their current value.
 User can extract these reports in multiple formats like Text, XLS, HTML or PDF.
 You need to write a module which can extract out specified report in specific format.
 Design should be flexible enough to add new report or new extract type.

Design Pattern Exercise: - Adapter


 In the Matching Engine, different JMS clients can send messages in different ways like XML, Map
Message but Matching engine accepting messages only in FIX format
(http://fixprotocol.org/FIXimate3.0/en/FIX.4.2/fields_sorted_by_tagnum.html).
 Write Message Adapters so messages from different formats like XML, Map, JSON can be
changed in FIX for matching engine.
 Sample XML message
<FixOrder>
<OrderId>02433343421343-01</OrderId>
<ClientId>CL-001-3456-7869-01</ClientId>
<Side>Buy</Side>
<SecurityCode>0001.HK</SecurityCode>
<Quantity>100</Quantity>
<OrderType>Market</OrderType>
<Price>34.54</Price>
</FixOrder>
 Sample Fix Message could be
37=02433343421343-01|11=CL-001-3456-7869-01|38=100|40=Market|44=34.54|54=Buy|55=0001.HK

Design Pattern Exercise: - Bridge


 Portfolio Manager can send the order request to matching engine in different formats like Map
Message, XML Message, Simple Text message or encrypted message.
 You need to write a module using Bridge pattern to decode messages from portfolio manager
into Order Object for matching engine.
 Order Object will have few fields like OrderId, ClientId, Side, Quantity, Price, Security, etc.

Design Pattern Exercise: - Builder


 One of the responsibilities of the Portfolio Manager to create order and send that to matching
engine for matching.
 You need to write a class which will create Order Object based on the order properties provided
by user. Please try to use builder pattern to create Order object.
 Order Properties could be Order Id, Client Id, Side, Quantity, Order Type, Price, Security, Order
Creation Time, Order Condition, Order TimeLimit, etc
 For Example, User wants to create a Buy Order of 100 shares of Limit Type for ICICI Security @
34.54 or Sell order of 1000 shares of Market Type for Reliance.

Design Pattern Exercise: - Façade


 Write a MarketDataService as a Façade which can get the market price of a security based on the
last price.
 This Market Data Service need to connect to different market data sources like Reuters Market
data Source, Bloomberg Market Data Source, Custom Market Data Source, etc to get latest
market price of a security.
 This façade will take security and market data source (optional) as an input and return a double
number as output.
 Assumption: - Use your own custom algorithm to get the market prices based on the last price
of security. i.e. like reuters data source will increase/reduce the market price with some
random number between 0 – 1.

Design Pattern Exercise: - Decorator


You need to develop a subsystem, where employees are working with different responsibilities
(such as team members, team leads and a manager). A team member is responsible to do his
assigned tasks and to coordinate with other members for the completion of group tasks. On the
other hand, a team lead has to manage and collaborate with his team members and plan their
tasks. Similarly, a manager has some extra responsibility over a team lead such as employee
profiling, work assignment.
 Following are the system entities and their behaviors:
a. Employee: calculate salary, join, terminate.
b. Team member: perform task, coordinate with others.
c. Team lead: planning, motivate.
d. Manager: assign task, employee profiling, create requirements.

Design Pattern Exercise: - Command


 Portfolio Manager can send different type of orders to Matching engine for matching. We need
to encapsulate the execution of order logic in order itself. We also need to encapsulate its
cancel and activation(in case of oncondition and withtime orders) logic in order object.
Different Order types could be
 Market
Market orders are executed at market price and if there are no opposite side
orders with the market price then it will be cancelled.
 Limit
Limit orders are executed with the price associated with the Order. If there is
no opposite side orders exist then it remains in order book till end of the day.

 TimeOut Order
This order will be treat as a limit order until time specified is occurred. After
specified time it will cancel automatically.

 LimitWithCondition
This order will wait in the matching engine for a specific condition to happen
and after that it will become limit order. This order should not execute till
given condition match. User should be able to cancel this order. Condition
like Reliance Share price crossing 95.5

 LimitWithTime
This order will wait in the matching engine for a specific time and after that
time it will become limit order. This order should not execute till given time.
User should be able to cancel this order.

 MarketWithCondition
This order will wait in the matching engine for a specific condition to happen
and after that it will become market order. This order should not execute till
given condition match. User should be able to cancel this order. Condition like
Reliance Share price crossing 95.5

 MarketWithTime
This order will wait in the matching engine for a specific time and after that
time it will become market order. This order should not execute till given time.
User should be able to cancel this order.

 You need to write a program which can encapsulating the different type of order execution
logic in an object.

Design Pattern Exercise: - Chain of


Responsibility
 In the Crossing Engine, Multiple users/clients can send orders. But before order actually goes to
Order service, we need to make sure order get validated on multiple fields i.e.
 Order Size should be greater than Zero
 Order Side should be either Buy or Sell
 In Limit Order price should be in range of +10% to -10% of Market Price of Security.
 Order should have valid Order Type like Limit, Market, etc. We should be able to add more
Order Types.
 Client Id should be valid. Please validate it with Client Cache Data.
 You need to write a module to do these validations on order object. You need to design your
module in such a way that we can add as many validation rules as we want
 For fail in any validation, system will throw an Exception i.e. OrderValidationFailException and
won’t validate other validation.

Design Pattern Exercise: - Template


 User can generate multiple reports from portfolio manager like
 Please use Template design pattern to define report template like Report Header, Report
Footer, Report name font and font size, report background color.
 This Report Template will use for all the reports which are extracted from the system.

Design Pattern Exercise: - Strategy


Matching engine is able to execute multiple types of order coming from portfolio manager. All
the orders coming in the matching engine is either executed with matching engine in order pool
or stored in the order pool. Please refer Java 5 - Data Structure to understand structure of order
pool.
 Each Order Type having a different matching algorithm
o Limit Order:
 User send to buy 200 stocks of ICICI at price 34.56 and then is no sell order exist of ICICI with
the price 34.56(In this case this order will be stored in the buy side of order pool.)
 User send to buy 200 stocks of ICICI at price 34.56 and then is one sell order of 200 shares exist
of ICICI with the price 34.56
Order will execute and executions report will sent to portfolio manager.
 User send to buy 200 stocks of ICICI at price 34.56 and then is one sell order of 100 shares exist
of ICICI with the price 34.56
100 order will execute and remaining 100 will be stored in the order pool
 User send to buy 100 stocks of ICICI at price 34.56 and then is one sell order of 200 shares exist
of ICICI with the price 34.56
100 quantities of orders will execute and remaining 100 will be stored as it
is in the order pool
 User send to buy 200 stocks of ICICI at price 34.56 and then is two or more sell orders of 100
shares exist of ICICI with the price 34.56
Order will execute and list of execution report will send to portfolio
manager
o Market Order:
 User send to buy 200 stocks of ICICI at market where market price is 34.56 and then is no sell
order exist of ICICI with the price 34.56
Order will be cancelled
 User send to buy 200 stocks of ICICI at market where market price is 34.56 and then is one sell
order of 200 shares exist of ICICI with the price 34.56
Order will execute and execution report will send to portfolio manager
 User send to buy 200 stocks of ICICI at market where market price is 34.56 and then is one sell
order of 100 shares exist of ICICI with the price 34.56
100 orders will execute and 100 orders will be cancelled.
 User send to buy 200 stocks of ICICI at market where market price is 34.56 and then is two or
more sell orders of 100 shares exist of ICICI with the price 34.56
Order will execute.
o Time Out Order: - This order will be in treat as a Limit Order in the Order Pool till the defined
time in the TimeOut field. After the time out, this order will be cancelled.
o Market with Condition:-This order will be in the Pending Order list until it matched the
condition. Once condition occurs (i.e. Reliance should be greater than 45) this order will be
treated as market order by matching engine.
o You have to implement 2 – 3 strategies here and put skelton for others. You can work on other
order type in mock project development.

Design Pattern Exercise: - Singleton


 You need to write a class which will fetch all the Security Master Data(Please use your own
custom security object with more than 10 fields) from DB and Store them in the in memory data
structure.
 Provide an API so that user can find any security by Security Code or RIC Code or Bloomberg
Code
 You need to prevent so that user should not be able to create multiple instance of this class.
 If possible, provide demonstration of both lazy and eager loading of security data.

Design Pattern Exercise: - Proxy


 MarketDataService is getting Market data as a Market Data Object which in terms of heavy object
having more than 50 fields. You need to create your own custom market data object with specified
fields.
 We need to attach this object to the order object because it contains price details and few
more details in it.
 But we may not need all 50 fields until user explicitly wants to see complete details on market
price and this is very rare. Instead most of the time we only require price from that object to
show to the user.
 Please use Proxy pattern to create Proxy object of Market Data Object so it can be light weight
when we are attaching it with security.
Java 5 – Enum
Write enum for different order types like Limit, Market, MarketWithTime, MarketWithCondition,
LimitWithTime, LimitWithCondition and TimeOut.

Java 5 – Generics
 Write your own map implementation using generics assuming that java does not provide its own
map implementation.
 Write a class which is demonstrating Covariance and Contravariance.

Spring Exercise9 : - Web Service -


REST
 Write a web service which is exposing market data service.
 Any Application want to get market price for a security or securities can send request to get
price with specified market data source and list of securities
 Implement a method in market service which will accept the execution details with executed
price. This will be use PUT.

Spring Exercise8 : - JMS


 Setup Active MQ and create 2 queues - >orderQueue and executedOrderQueue.
 Write Spring JMS code to send/listen/receive message
 Demonstrate different Acknowledgement types
 Demonstrate Message Converter to change XML message into Order Object.
 Setup marketDataTopic as a Topic and Write at least 5 clients connected to topic and getting
market Data. Market Data POJO would be Id, Security Code, Price, change.

Hibernate Exercise 6 - Custom User


Type
 Portfolio Manager can create Buy and Sell Order for a user.
 Each Order is having Order Type Associated with it which is of Enum Type
 Please user UserType of hibernate to store Order Type Enum in database

 Portfolio manager is sending orders with client id. This client id is combined of multiple fields like
ClientCategory(1,2,3)-clientId. Please use Custom user type to build and store these in database.

Hibernate Exercise 5: - Versioning


 An order requires a change and the production support team receives this request. The order can
also be modified by the user who had placed the order. There exists a scenario in which both the
user as well as the support team ends up modifying the order at the same time. The system
should guard against this scenario. (Hint: Please use versioning to introduce concurrency by
locking.)

Hibernate Exercise 4: - Caching


 In Portfolio Manager, we are storing security master data which is used to build order or to watch
stock.
 Storing huge data in-memory is creating issues for the system.
 Use Hibernate Caching to fetch and store the security data in Cache.
 Also update the market price of stock in cache itself.
 Write JUnit to measure the performance of the application. (Hint :Demonstrate the Hibernate
Performance metrics cache)

You might also like