Stock Trading Application
Having used Java as my main development language and platform for more than 6 years, it was very exciting when a friend talked about writing a sample trading application in Java and see how effective and efficient it would be. The main reason I decided to write it was to prove that Java is not as slow as most people still think. So, we came up with a very simple and easy to understand application.
Requirements
1. Create a server-side Java application that does the following: -
1. Accepts client TCP/IP socket connections on port 1234.
2. Once a new socket connection has been accepted, the
application should generate a random integer between
0 and 999 every 5 seconds, and it should send the
generated number down the socket.
2. A client-side Java Swing application that does the following: -
1. Makes a TCP/IP socket connection to the server application (i.e.
to port 1234).
Note: you may run the server and client applications on the same
machine.
2. Receives the random numbers from the socket that are being generated
by the server
3. Displays the most recent number that has been received
4. Updates the display as soon as a new number is received (i.e.
so we can see the numbers updating in real-time)
5. Displays the number in red if it is less than 300.
6. Displays the number in green if it is between 300 and 600
7. Displays the number in blue if it is greater than 600
8. The background of the display should be white.
9. The background of the display should flash yellow for 1 second every
time the number changes.
As the requirements have been laid out above, its very important that we follow the steps one by one, and test as we go. First, we have to create a very simple application that accepts connect on the port specified, and then proceed to making that server class a multi-threaded class because as the requirements stipulates, it should accepts multiple clients.
public class StockServer implements Runnable { private boolean done = false; private int randomIndex; private static final int PERIOD = 5000; // repeat every 5 seconds private static final int RANDOM_NUMBER = 999; Socket socket; // the socket PrintWriter out; // the output and input streams BufferedReader in; static Vector vector; // current connections public static void main (String[] args){ ServerSocket ss = null; Socket s = null; vector = new Vector (); try{ ss = new ServerSocket (1234); while ((s = ss.accept ()) != null){ // Connection received - now create a thread StockServer now;
The piece of code shown above implements a Runnable interface bacause it has to be a threaded application.
On the left hand column, I have listed some of the modules and packages that I use daily on my Python development. To learn more about them, click on each to go the website with information on how to download and start developing with them. If you are a Java developer and an Eclipse fan, you might find the PyDev handy as it is a plugin for Eclipse. This allows you to develop all your Python and Jython code on the Eclipse platform complete with syntax highlighting, refactoring, syntax analysis and debugging.
Which Python Book To Buy?
Almost every other day on the tutor mailing list, you see people asking about books to buy to help them learn to program in Python. But the response is always the same: we do not have the magic book that will help you learn. Some of us used the documentations on the Python main website, while others have access to O'Reilly's Safari service through their work or educational institution.
The file can be downloaded here
Don't get me wrong, there are times when I can positively recommend a book or resource based on the area or domain that you are interested in. For example, I'm currently reading the Definitive Guide to SQLite, to write my first database app, you might want to pick up wxPython in Action if you're going to start writing wxPython GUIs; or Python & XML if you're doing XML work; etc. The reason for this exception is to help you to narrow your search and effort to a domain-specific area. Apart from that, I will not recommend any book as we all learn differently.
IDE
Another question that we come across often is which IDE is the best to use. Again, there are no right answers here. If you are on windows and you downloaded your Python installation from Python.org, then you do not need any other IDE as it installs IDLE by default. This is the official IDE that most guys on the mailing list probably use on their Windows environment. Having said that, other 3rd-parties also produce their own IDEs. A typical example is Pythonwin from ActiveStates' ActivePython distribution (which is not open source).
The list of all available IDEs can be found here is you are more interested on learning about the IDEs than the language. Finally, I have decided to list the books here to help you with your quest for that killer Python book :-) One of those excellent online books is this, it contains all the information that a new Python programmer will find very useful. But if you have a few quid and you want something you could have on your bookshelf, here are my recommendations:Find out more about Me.