O'Reilly logo

Java Programming for Beginners by Mark Lassoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Printing Jane's car details

Now, leaving our main() method, we'll define our new PrintCars() method. I have divided the definition of the PrintCars() function into eight parts:

  1. Because we're in the entry class of our program and the PrintCars() method is being called by the static main() method, it should probably be a static function. All it's going to do is print to our console, so void is an appropriate return type. We already know it's going to take NodeList of cars as input:
        public static void PrintCars(NodeList cars) 
        { 
        } 
  1. Once we've entered this function, we know we have a list of car XML elements at our disposal. But in order to print each one out, we're going to have to loop through them. We've already looped through XML NodeList ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required