Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Creating funny objects
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="hopkins, post: 592668"] 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! [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Creating funny objects
Top