H
hopkins
After reading some of the Java/XML tutorials on the Sun site I was
puzzled by the way in which they create objects:
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new Echo01();
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);
} catch (Throwable t) {
t.printStackTrace();
In particular, why are objects created like this
SAXParserFactory factory = SAXParserFactory.newInstance();
...and
SAXParser saxParser = factory.newSAXParser();
I have always been taught to creat object in the form
Person newPerson = new Person();
This way where you seem to call a different method other than the
constructor when the object is created confuses me and I cant really
understand why you'd want to do this. Secondly as the two lines in
question dont seem to have the "new" keyword does this mean they are
not created on the heap and are stack based like in C++?
Thanks in advance!
puzzled by the way in which they create objects:
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new Echo01();
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);
} catch (Throwable t) {
t.printStackTrace();
In particular, why are objects created like this
SAXParserFactory factory = SAXParserFactory.newInstance();
...and
SAXParser saxParser = factory.newSAXParser();
I have always been taught to creat object in the form
Person newPerson = new Person();
This way where you seem to call a different method other than the
constructor when the object is created confuses me and I cant really
understand why you'd want to do this. Secondly as the two lines in
question dont seem to have the "new" keyword does this mean they are
not created on the heap and are stack based like in C++?
Thanks in advance!