Java for young developers

Are you teaching someone Java? Do you know anyone who is taking an introductory training in Java? Do you want your 5 year old kid to start on Java? If yes, then you can help them further by introducing to free interactive IDEs made just for this purpose 🙂

This Oracle page has a list of cool IDEs, available for free and targeted at Java aspirants of various age-groups. Scratch for example is targeted at age-group 5-15 and helps learn java using animations and games. Alice provides a similar drag-and-drop 3D development environment. Bluej provides visual tools to write Java programs. Greenfoot, which calls its Projects as “Scenarios” has a scenario like the one shown below where you can create “Leaf” instances to feed to a wandering Wombat. Another such IDE called Judo is available at sourceforge.

This page at Dzone has links for other cool stuff to teach Programming to kids.


Code Analyzers

During my search for Profilers I stumbled upon some good Java code checkers or Code Analyzers and though most of you may be already aware about them would like to share my thoughts on the same. Please feel free to correct me or add your inputs to this.

Talking of Code Review or Analysis I wonder if somebody would even think about going for the wearisome task of manually locating lapses in use of Proper Syntax, code indentation, unused variables/imports, naming convention and Javadoc comments without using any automated tool to do the task. Apart from the task of deciding about what code optimizations need be done or detecting any logical blunder rest can perhaps be safely left to these tools. Moreover more ambitious programmers can even look for these tools to operate in tight integration with their favorite IDEs. Fortunately my favorite Netbeans has many modules already available of which three are my personal favorites : PMD, Jalopy and Checkstyle, perhaps in that order.

All the three have various plugins available for various IDEs. Jalopy is a code formatter and beautifier and is highly configurable using code snippets though it does not comprehend well line spacing and tabs for files edited by other IDEs say Kawa or Textpad. Checkstyle is more about code formatting and nit-pickingly looks for white spaces, tabs, position of braces and javadocs and configuration is difficult (as far as I know certainly not configurable through Netbeans GUI). Out of these PMD deserves my high regard, here is a synopsis of what it can detect:

  • Unused local variables, parameters and private methods (very useful)
  • Empty catch blocks
  • Empty ‘if’ statements
  • Duplicate import statements
  • Classes which could be Singletons
  • Short/long variable and method names

A lesser known but very powerful code checking tool is FindBugs. Too bad it has no plugin available for Netbeans though. While the conclusions of the tool about unread fields is not very accurate, it detects what many others don’t such as:

  • Null pointer de-reference detector
  • Ignored returns from method
  • Unclosed I/O streams
  • Objecting usage of == or != for String comparison

Here are some other tools:

  • SourceMonitor: Provides size and complexity metrics for your source code.
  • JLint: A Code verifier
  • QStudio also seems pretty good to me. As per their site it is available for download with a year license at no cost.

P.S.: This post finds mention here, here, here and here.


"this" is no good!

Eric Burke has a very sound advice against using “this” in your Java code, an advice against the conventions. Prefixing object field references with “this”, says Eric, clutters up code and may indicate too much complexity. “If you really need to differentiate local variables from object fields, consider prefixing your object fields with “_” or some other character (instead of using this)”, he opines. I couldn’t  agree with him more on the following:

Don’t blindly follow conventions for the sake of following conventions. Follow conventions because they improve your code. If the coding convention encourages repetition, increases clutter, and relies upon human consistency to be effective, maybe the convention is flawed.