Skip to main content

Posts

Showing posts from February, 2007

Understanding the Java Exception heirarchy

In the previous section, we learned how to use custom exceptions. We also created a custom exception by subclassing java.lang.Exception. Let us now understand the Java exception hierarchy in greater detail. Play the audio to listen to an explanation of the java Exception class hierarchy. Understanding java.lang.error The video below shows how the JVM can throw an Error for an irrecoverable problem. Click on the 'Start' button to start playing the movie. Understanding RuntimeException The video below explains runtime exceptions. Click on the 'Start' button to start playing the movie.

Google group for Adaptive Learning Online

I have just created a Google group for this blog. We can use it to discuss individual posts, or other things related to software design, programming best practices and models of continuous learning for software professionals.  I look forward to having interesting and invigorating conversations that lead to learning and benefit one and all. Note: This text was originally posted on my previous blog at http://www.adaptivelearningonline.net

Coding dojo - Dictionary

I conducted an Open registration coding dojo in Pune, last Saturday. This was a short four hour dojo. The topic for the dojo was Dave Thomas' Kata Eight . As always we started with a discussion and design session and started coding. As we worked on the solution, several interesting learning opportunities came up: Designing for readability Using the decorators in Java's IO library Using various collection classes and understanding their performance characteristics Iterating through collections using an Iterator (we will also touch upon the Iterator design pattern) Design tradeoffs to make code faster Various coding conventions Some programming best practices Refactoring support in Eclipse Many thanks to ITVidya.com for organizing the dojo and to Pune IT Labs for hosting it.  Participants feedback showed that everyone though coding dojos offer a much better learning mechanism than traditional lectures. Everyone enjoyed the practice oriented approach. Some pe

Custom Exceptions

Till now we have seen why we need Exceptions and how to manage code that could throw Exceptions. We still have not learned how to throw our own Exceptions. Let us first understand the code below. 01 public class DocToPdfConverter { 02    public void convert ( String src, String des ) { 03      Document doc = readDoc ( src ) ; 04      writePdf ( doc, des ) ; 05    } 06 07    private Document readDoc ( String srcPath ) { 08    //read the source file and verify format 09    //if format is incorrect then throw an Exception 10    } 11 12    private void writePdf ( Document doc, String des ) { 13      //convert the document into pdf 14    } 15 } Java2html 01 public class DocToPdfConverter { 02    public void convert ( String src, String des ) { 03      Document doc = null ; 04      try { 05        Document doc = readDoc ( src ) ; 06        writePdf ( doc, des ) ; 07

Sharpen your programming skills

Dave Thomas the author of “The Pragmatic Programmer” says : How do you get to be a great musician? It helps to know the theory, and to understand the mechanics of your instrument. It helps to have talent. But ultimately, greatness comes practicing; applying the theory over and over again, using feedback to get better every time. How do you get to be an All-Star sports person? Obviously fitness and talent help. But the great athletes spend hours and hours every day, practicing. But in the software industry we take developers trained in the theory and throw them straight in to the deep-end, working on a project. It’s like taking a group of fit kids and telling them that they have four quarters to beat the Redskins (hey, we manage by objectives, right?). In software we do our practicing on the job, and that’s why we make mistakes on the job. We need to find ways of splitting the practice from the profession. We need practice sessions. Laurent Bossavit says : If I want to lear

Managing exceptions

When we call a method that can throw an Exception, handling the Exception is not the only option we have. We can also propogate the exception. The audio and code shown below explains this concept. import java.io.*; public class AnExceptionalDilemna {    public static void main ( String args []) {      AnExceptionalDilemna aed = new AnExceptionalDilemna () ;      System.out.println ( "Hello, this is a test program to      understand Exceptions" ) ;      try {        System.out.print ( "Please enter your name: " ) ;        String name = aed.getNameThroughMiddleMan () ;        System.out.println ( "Hey " +name+ " how are you doing?" ) ;      } catch ( IOException ioe ) {        System.out.println ( "Looks like the standard input        stream does not like you!" ) ;      }    }    /*Do I handle or propogate IOException?    I do not know what

Refactoring To Patterns

I learned design patterns when I was in grad school . Later when I started work, I used some patterns, but some were never used, and their knowledge became rusty over the years. I thought it was time to refresh my knowledge of software design patterns, sometime last year. Back then I was enamoured with the concept of web based learning (and I still am). I was also contemplating to take my Java workshops over the Internet. So instead of just re-reading the GOF book, I thought of taking a web based course on design patterns. This way I would learn what I needed to, and also get a hands on feel of how elearning works. When I Googled elearning and design patterns, I stumbled upon Industrial Logic's online course "Refactoring to patterns" . Now the concept of refactoring to patterns is'nt just about learning design patterns. It involves understanding design patterns, but also involves identifying code smells (bad code), that should be refactored to use a design pattern. I