Showing posts with label task. Show all posts
Showing posts with label task. Show all posts

Sunday, January 11, 2009

Your journey begins now

Congratulations !!! if you have reached here after completing all tasks. You have successfully completed the JavaInsights 101 course.

I hope it has given you insights about good coding practices, and the Java ecosystem.

This course consisted of writing code, reading code, and blogging. I personally believe (though some people may differ) that all these activities are extremely important to learn and become a successful software developer. I will urge you to continue with all of the above on a regular basis.

Since you are a software developer, your work will largely consist of writing code. This will help you sharpen your skills and learn more, but at the same time writing code at work is not the same as writing code to practice. You must perform periodic coding kata's to improve your programming skills further. Please read this blog post to learn more about coding kata's.

Your work will also offer you plenty of opportunities for reading code. You will often have to refactor existing code. Every time you so this, try to understand how the code functions and think if it same could have been implemented in a more efficient way. This simple exercise will help improve your programming skills. If you do not get such opportunities at work, then visit an open source project of your choice and either study it, or even better participate on the project.

Reading good books, blogs, and articles have helped me a lot. Here are some resources I frequent :
I also listen to the JavaPosse podcast. It is humurous, insighful, and it brings you the latest Java news.

Last but not the least, I would like to stress on the importance of writing. I started blogging so I could share my knowledge, and to improve my own skills. Blogging has helped me improve my communication and technical skills. Writing helps clarify my thoughts and also improve memory recall. Blogging forces me to think about the correctness of what I write. I do not want to embarrass myself by posting incorrect information on the web :-) This makes me think about various pros and cons, alternative solutions, and the like. The thought process which accompanies blogging has helped deepen my understanding of what I write.

I hope my experiences will help you and you will continue with all of these activities. Regardless of this I am sure you will become a very good software developer. As you scale new heights, don't forget to help others on the way, and share your knowledge freely :-)

Finally coming to this last task, write a blog post summarizing the most important things you have learned in this course. Then read some on line resource on programming (you can use the list I have mentioned above), and summarize it on your blog. If you liked the post, or if you have any thoughts on the topic, you may also leave a comment on the original post.

After completing this task, please leave a comment here with your post's URL.

Wish you good luck!

Task: Ensuring code quality with FindBugs

We have written a lot of code till now. We have used Java collections, Swing, as well as threading concepts.

However, cranking code is not all. Software that we write has to be bug free and it also has to be maintained over time. There are several reports which suggest that a bug caught early in the development lifecycle is orders of magnitude easier (and cheaper) to fix than one caught later in the development lifecycle.

Because of this we want to ensure code quality. There are several ways of doing this. Diligent coding, manual code reviews, and automated code reviews. I am already going to assume that everyone is writing their code diligently. We have also done manual code reviews. This task deals with setting up automated code reviews.

FindBugs is an excellent software which statically reviews Java code. Download and install FindBugs as a plugin for your IDE and see how many bugs it reports for your code.

Then understand and fix all the bugs.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Task: Build the project using ANT

Till now we have relied on our IDE to compile code. However, in most organizations, build systems use build scripts to generate a build.

This means that even though individual developers might continue to build using Eclipse's compiler (this does have a huge advantage due to it's on the fly error checking), the organization's nightly build system will most likely use build scripts written in ANT, or perhaps a full fledged build system like Maven. We will not talk about Maven in this course, but we will learn how to create simple build scripts in ANT.

First download ANT, and create a simple build script that will compile your project.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Wednesday, December 24, 2008

Task: Code review

Reading and reviewing code is as important to learn programming, as is coding itself. In this task we will review some code instead of writing it.

Review the code of some other participant on Java Insights 101, and leave a comment on their blog describing your findings. Please be careful to be constructive while commenting on someone else's code. Mention the things you likes, and offer clear reasons for things you did not like. If possible, also offer alternative ways to implementing the code.

I have listed some parameters for reviewing code. You may choose to follow them, or you may choose to use your own list of parameters.
  • Correctness
  • Clarity (of code logic, variable names, class names, etc)
  • Adherence to good coding standards
  • Consistency
  • Good design principles
  • Simplicity
  • Test coverage
  • Usage as well as level of Log4J debug statement

Sunday, November 30, 2008

Task: Use Log4J to print debug statements

I hope you have been printing debug messages as your code executes. I assume you must be using System.out.println(msg); to print the debug messages.

In this task we will replace use Log4J to print debug messages.

There is a much better way to print debug messages, because Log4J allows us to redirect the messages to any arbitrary destination, such as console, file, log server, etc. Log4J also allows us to associate levels such as 'error', 'warning', etc with these messages. Besides these there are a few other advantages to using Log4J as well.

Download Log4J and replace all instances of System.out.println() with Log4J debug messages.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Task: Determine how much code your unit tests cover

So now, we have unit tests for all our code. But do the unit tests cover the code sufficiently. Do they they cover all paths in the programs logic? Do they cover all classes and methods?

Download EMMA, which is a free and open source code coverage tool, and find out how well your unit tests cover the tested code. Then try and increase your test coverage to 100%.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Saturday, November 29, 2008

Task: Unit testing the Swing GUI

We created a Swing GUI in task 9, but did not unit test it. Going with the philosophy of test driven development, we should have first written unit tests for the GUI and then implemented it. Well we will bend the rules this one time and write the tests after creating the GUI.

Download FEST. This is a Swing unit testing library, that uses JUnit 4.0. Write unit tests for the GUI you created in task 9, using FEST.

Some Thoughts:
FEST depends on JUnit 4.0, which uses Java Annotations. If your Annotations knowl
Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Task: An exercise with Swing

Add a Swing GUI to task 8. The GUI should provide a means for the user to choose all the files they want to parse. We will print the word count as well as the line count of all the chosen files. So the user no longer needs to specify that.

The output should be printed in a read-only scrollable JTextArea on the GUI.

The design of the GUI is left as an exercise to the developer.

Coding Requirement:
Be sure that initialization of the GUI happens on the Event Dispatch Thread (EDT). Understand why it must happen on the EDT (what is the EDT?). At the moment you do not need to write any test code for the GUI.

Display a title for the application in the titlebar.

Be sure to print the debug log to the console as your program executes.

Some Thoughts:
Even though we are not testing the GUI, it is also part of the software we are building, and must be tested. Think about how you can test the GUI. We will work on this in the next exercise.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Resources:
  1. The Swing Single Thread Rule - Cay Horstman
  2. Threads and Swing

Tuesday, November 11, 2008

Task: An exercise with threads

Refactor task 7 to allow the user to specify multiple input files. Parse each file and print either the word count or the line count as specified by the user.

Processing of each file should be done in a separate thread. Do not print the output from individual threads, because the output from different threads may overlap, making it difficult for the user to read. Instead each thread should give its output to the main thread as an object and the main thread should print it after all threads have finished processing their files.

Coding Requirements:
Be sure to print the debug log to the console as your program executes.

Some thoughts:
How will you do test driven development for multi-threaded code? Are there any standard paradigms?

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Task: An exercise with Collections

Refactor task 6 to add a feature. Over and above what we did in task 6, we also want to print the number of times each word occurs in the input text file. This detail should be printed such that the word count appears in the same order as the words are encountered in the input file. The program will also accept an ignore file containing words that should be ignored for the count.

Output for the text appearing above will be something similar to this:
Refactor - 1
task - 2
6 - 2
...

Coding Requirement:
In the code, you must use a Map to store the words as keys and the count as it's value. From this exercise onwards we will also print a debug log as the program code executes. What this means is, you should print something to the console at important points in the program logic. These statements should show the progression of the program. In case the program fails, the debug log might help you determine the source of error quickly without having to debug the code.

Monday, November 10, 2008

Task: First Steps Into Test Driven Development

From here on we be using TDD (Test Driven Development) methodology.

While writing test driven code, we first write a unit test for the code we are about to write, and then we write the actual code. The code is refactored till the test passes. This process continues until we have a working solution. Writing code thus, also means we write code piecemeal in an iterative manner (which is another good coding practice).

We will use JUnit 3.8 as the testing framework. You may need to download it if your IDE does not already have it.

For this task you will write a simple program which takes a text file as an argument along with another argument which specifies whether the user seeks a word count or a line count. based on what the user asked for, print either the word count or a line count of the text file.

Remember you have to do Test Driven Development, which means first write an empty (solution) class, then write a test to test one of the public methods of your class, then implement the method and refactor it till the test passes. Then write another test for another public method, and implement that method in the actual class... so on and so forth.

As a practice of the solution class is called FileStats, the test class will be called FileStatsTest. Also if we are writing a test method for a method called methodA(), then the nam of the test method will typically be testMethodA(). See documentation of JUnit 3.8 for more details.

All the test classes will reside in the test directory and will have the same package as the solution class.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Resources:
  1. http://agilesoftwaredevelopment.com/videos/test-driven-development-basic-tutorial
  2. http://www.ic.sunysb.edu/stu/yosong/cse219/junit.html
  3. http://www.scribd.com/doc/524491/JUnit-Tutorial

Task: Refactor HelloWorld to use JSAP

In the HelloWorld example you wrote for Task 3, you wrote custom logic to parse the command line arguments.

JSAP is a very good open source library that does command line argument parsing. Download JSAP and use it to parse command line arguments in the HelloWorld exercise.

While refactoring code, try and use refactoring support in your IDE.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Sunday, November 09, 2008

Check-in code into a source control system

Register an open source project on http://code.google.com and check in your workspace project into the SVN repository.

If you are using the Eclipse IDE, you may have to download a plugin for SVN.

Describe what you did, including any problems you may have faced, and how you overcame them, in a blog post.

leave a comment here after completing this task.

Task: Hello World

Everything starts with a HelloWorld, and so shall we :-)

Write a HelloWorld program that takes in command line parameters to determine what should be printed. The program usage is as follows:

HelloWorld -g -n
-g A compulsory parameter which denotes a greeting such as Hello, or Hi
-n
A compulsory parameter which denotes the name that will follow the greeting in the output

Running
HelloWorld -g Hello -n Parag

will print

"Hello Parag"

HelloWorld -g Hello
Should print the usage string

If any of the arguments are not provided, the program should abort with a usage string.

Describe what you did, including any problems you may have faced, and how you overcame them, in a blog post.

Leave a comment here after completing the task.

Task: Create a working environment for Java

Ensure that you have installed JDK 1.6 (latest update), and an IDE such as Eclipse or Netbeans.

In your IDE, create a new project called JavaInsights101_. Create an empty readme.txt file in the project. Create a 'src' directory, and a 'test' directory in the project.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.

Task: Create a blog

To start with, all participants must create a blog which they can use as a regular learning journal, and a means for reflection, sharing, and collaboration.

If you need help with blogging, check out Freeman Murray's track on blogging for more information:

Also register and introduce yourself on this mailing list. We will use this list for asking questions and other discussions related to this track.