Posts

Showing posts from 2014
DOMParser - XML Parsing 2 In DOMParser everything is a node. A node has childNodes which might have childNodes. DOM Structure I always find DOMParser a better choice when the whole xml files need to be loaded to a single object. When doing a lot of calculations on the xml use a SAXParser. I will post in an example soon. Use a SAXParser over a DOMParser. Reason: SAXParser gives better performance. SAX is faster! DOMParser reads the whole XML File in the memory, if the file is big.. we might get Memory issues!
XML Parsing - 1 Lets start with the structure of XML first. XML is a way of storing data.. sample xml file: <?xml version="1.0" encoding="UTF-8 " ?> <person> <name>Richa</name> <age>100</age> <lastname>Vaidya</lastname> <address>India</address> </person> the first line gives the version of the xml i.e 1.0 the next line person is the root all the contents of the xml are a part of the root i.e. person the later lines.. these are the elements of the root. So now we have the data, how do we use it in a java program. Read it line by line? No... We have been provided with two excellent parsers : DOMParser and  SAXParser . Difference between DOMParser and SAXParser., DOM reads the complete xml element, so you have the complete file in the memory and you can access the elements of the DOM root at you wish. SAX parser reads the file line by line. DOM parser has a greater memo

Polymorphism,Overloading v/s Overriding

Polymorphism! One name.. but many functions. Polymorphism can be dynamic or passive. Dynamic as in terms of... the object knows which method to actually call when the JVM is up Passive polymorphism is when which method to call is already know when the classes are compiled. Example: We have a class A. B extends A. A has a method : public int getA(){ return 1; } B also has this method, but the value returned is different: public int getA(){ return 2; } In our main class, we create objects of A and B, always keeping reference to the object as A. So, our main looks like: A a = new A(); A b = new B(); System.out.println("a.getA() : "+a.getA()); System.out.println("b.getA() : "+b.getA()); Output: a.getA() : 1 a.getB() : 2 This is dynamic polymorphism, or overriding. If we carefully see, the method signature is the same!!!! IMP: 1. access modifier should be the same OR default can become protected, protected can be public but not otherwi