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.

JavaInsights 101

Description:

This learning track is for developers who have completed at least one course in Core Java (or are familiar with basic principles of Java, like Syntax, compiling, and running Java programs) and would like to improve their understanding of the Java language and ecosystem.

Why Is This Track Needed?:

A typical Core Java course focuses on the Java syntax and simple exercises to understand Java. These are an important first step, however, usually due to lack of time such a course cannot equip the learner with deeper knowledge of how to develop good software in the Java ecosystem. The Java landscape is very huge and cannot be dealt with in a single course. When dealing with such magnitude, the best way to learn is self learn. This track's focus is to help developers by providing guidance as they get their feet wet, and give them the initial momentum for continuous self learning. The track will provide developers with:
  1. An understanding of coding and design best practices
  2. An exposure to the Java ecosystem of open source libraries and frameworks
  3. An understanding of how to unit test Java code
  4. An understanding of source control systems and how to use them
  5. An understanding of how to use development and code analysis tools
  6. A deeper understanding of some of the topics already learned in a regular Core Java course
Learning Methodology:

For this track we will use the concept of networked collaborative learning. Breifly, this means that everyone is a learner and a mentor. Learning happens by understanding, practicing, and participating. New media technologies (such as blogs, and podcasts) will be used for participation.

The JavaInsights101 track consists of 16 tasks. I recommend that you try and complete them in 16 weeks. Each task is explained in a separate blog post. After completing a task, please write a blog post (describing your solution, problems faced if any, and how you overcame them) on your own blog and leave a comment on the post describing the task (on this blog). Be sure that your comment contains the URL of your post describing your solution for the task.

Participants are encouraged to write blog posts regularly as well as read posts of other participants and leave (constructive) comments on their blogs.

There is a supporting Google Group for this track, which can be used for asking questions, and other discussions related to the track. Participants are also encouraged to go beyond this Google Group and ask questions on public Java forums, such as Java Ranch and Java.net . Participating on these forums will give you a wider perspective and will also help you connect with the Java developer community. For the benefit of other participants, whenever you ask a question on another forum, either write a blog post with the URL of the question, or write a quick mail on the mailing list, describing your question and it's URL. This will help other participants who have similar questions. Moreover if someone already knows the answer, they can post it on the question thread.

Registration:

To register for this track leave a comment on this post with your blog URL and go to Task 1. If you do not already have a blog, do Task1 first and then leave a comment on this post.

Fees:

This is a pay-it-forward course, which means you do not have to pay any fees monetarily. However, you are strongly urged to volunteer after completing this track by helping new participants, by either answering their questions on the forum, or by reviewing their code.

Frequently Asked Questions

Learning Tasks:
  1. Create a blog
  2. Create a working environment for Java
  3. Hello World
  4. Task: Check-in code into a source control system
  5. Refactor HelloWorld to use JSAP
  6. First Steps Into Test Driven Development
  7. An exercise with Collections
  8. An exercise with Threads
  9. An exercise with Swing
  10. Unit testing the Swing GUI
  11. Unit test code coverage
  12. Using Log4J for logging
  13. Code review
  14. Using ANT for compiling your project
  15. Ensuring code quality with FindBugs
  16. Your journey begins now

Thursday, January 04, 2007

Word Count Assignment

Today we will work on an assignment that reuires knowledge of all the things we have covered till now.

Assignment: Word Counting
Using any text file that has at least 500 words, count the number of words in the file, and count the number of times 'and' appears in the text file regardless of it's case. For the sake of simplicity any token delimted with whitespaces will be considered a word if it has at least 1 alphanumeric character.
Print the word count and the number of times 'and' appears on the system cosole.

Tasks:
1. Create a project in eclipse with a 'src' directory
2. All the code will be put in the src directory
3. Use the package name 'edu.scit.javalab.wordcount'

Grading: 10 marks
1. Coding conventions 2 marks
2. Code quality 3 marks
3. A working program 5 marks

Wednesday, January 03, 2007

Java I/O Basics

Today we will cover the basics of the Java I/O system. Even though this topic will be covered in detail after 2 weeks, you will need to know enough to be able to read text files and do console I/O.
References:

Monday, January 01, 2007

This blog has been moved to Adaptive Learning Online.

Saturday, June 17, 2006

Barcamp Pune - 17 June 2006 - Technology Enabled Learning

The crux of this talk is: how can we use technology to achieve self guided continuous learning.
Attribution: All the images in this presentation have been taken from Flickr and are licenced under the Creative Commons licence. They are copyright of their respective owners.

Happy learning :-)

Friday, June 16, 2006

The way ahead
  • Remember, the best learning occurs in a stimulating, active, challenging, interesting, engaging environment
  • Join a learning community
  • Create your own learning community
  • Participate in barcamps and openspaces
  • Be generous enough to share your experiences and knowledge with others
Does this thing really work?

My point? I’m getting tired of hearing people continue to ask for the evidence that technology helps students learn. It doesn’t matter. We know — that good teachers help students learn. We need technology in every classroom and in every student and teacher’s hand, because it is the pen and paper of our time, and it is the lens through which we experience much of our world. [src]

Learning institutions will be replaced with learning ecologies





Putting it all together

So how do we use all these technologies to be bicycle riding learners?

  • Identify learning goals
  • Make a plan
    • Manage the plan
      • Wiki
      • ePortfolio
  • Identify resources
    • Books
    • Journals
    • Online resources
      • Articles
      • Newsletters
      • Blogs/podcasts/screencasts
      • Wikis
      • Open course ware - offered by several institutions
  • Consume the resource
  • Record, (reflect, practice, and discuss)* on the knowledge
    • Writing a blog
    • Commenting on other people's blogs
    • On a discussion board
    • Answering quizzes
    • Assignments
    • Hands on development
    • Teach
  • Use micro mentoring
Till the process is internalized and propels you towards continuous learning.


Learning Tools

  • Blogs
    • Provides first hand news on various topics
    • Can be used as a learning journal
    • Provides a tool for a more interactive learning experience
      • Establishent -> Introspection -> Reflective Monologue -> Reflective Dialogue -> Knowledge Creation
  • Newsreaders
    • Allows us to effively track news, changes, and blogs
  • Wiki's
    • Shared whiteboard
    • Collaboration medium
  • Groups
    • Facilitate discussion
  • Online calendars
    • Facilitate scheduling and event announcements
  • Flickr
    • Facilitates sharing of photographs and images
    • Facilitates reuse of images distributed under a Creative Commons license
  • Conferencing
    • Allows real time interaction for distributed groups
  • Podcasting/screencasting/videocasting
    • Facilitates distribution of rich media
    • harnesses the power of RSS for rich media
  • ePortfolios
    • Facilitates users to track their learning goals and outcomes
    • Facilitates users to show case their learning
  • Delicious
    • Facilitates people to tag resources of interest
    • Facilitates community wide sharing of tags
  • coComment
    • Allows users to track their comments on other peoples blogs
  • online mind mapping and diagramming
    • Allows users to represent knowledge in a way that is native to their brains
  • Second life
    • Facilitates an extremely rich distributed collaboration environment
    • Uses
      • Socializing
      • Meetings/Conferences/Barcamps/...
      • Customer support
      • Virtual workplaces
      • Virtual universities


Learning Enablers
  • The internet
    • Makes information available on our fingertips



  • Multimedia
    • Allows a richer representation of information
    • Goes beyond text
      • Images
      • Audio
      • Video


  • Collaboration technologies
    • Allows real time collaboration accross geograhical boundaries

The New Learning Environment

The new way to progress and innovation (according to Kathy Sierra)






The learning landscape has changed. The new environment is:
  • Networked
  • Collaborative
  • Guided by micromentors
And more sources of information are available to learners
  • Teacher, guide, mentor, collegue
  • Print books
  • The digital universe
To top it all technology allows for a very good distributed collaboration experience
  • Wiki's
  • Blogs
  • Discussion boards
  • Chat
  • Audio and video conferencing
  • VOIP
  • Virtual wordls

Monday, June 12, 2006

Learning To Learn - with Web 2.0 technologies

Learning has changed significantly in the past few years as the knowledge needs of people and tools available to them have changed.

Learning Before:
  • Most learning happened in the classroom
  • The knowledge was sufficient for decades with very little upgrading (2)
  • Half life of knowledge was large
  • The pressure to continuously learn new things was less
  • Learning was formal
  • Learning was individual
  • Learning was generic
  • Lecturing was only related to factual information
  • Teacher and print media served as the primary means of communication and information
  • Learning was separated from the rest of the community
Learning Now:
  • Only 10-20% of learning happens in the classroom (1)
  • Only fundamentals last… the knowledge changes
  • Half life of knowledge is less (3)
  • The pressure to continuously learn new things is VERY high
  • Learning is informal (4)
  • Learning is networked & collaborative (5)
  • Learning is personalized (6)
  • Lecturing is about guiding, motivating, and facilitating (7)
  • Learning using a vast variety of media including the Internet (7)
  • Learning now occurs globally (7)



Now let's see what Kathy Sierra has to say about ideal learning (more...)