Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

JAXB Interview Questions and Answers

Ques 6. What are the disadvantages/non-goals of JAXB?

Ans. • Standardize generated Java
– classes generated by different
JAXB implementations may not be
compatible with each other
• Preserve XML equivalence
– unmarshalling XML to objects and
marshalling back to XML may not
result in equivalent XML
• Bind existing JavaBeans
to schemas
– can only marshal and unmarshal
classes generated by JAXB
– may be added later
• Schema evolution support
– can’ t modify previously generated
code to support schema changes
– must generated new code
• Allow generated Java to access
XML elements/attributes not
described in initial schema
• Partial binding
– unmarshalling only a subset
of an XML document
breaks round tripping
• Implement every feature of the
schema language
– it’ s tough to implement
all of XML Schema!
• Support DTDs
– focusing on XML Schema
– DTDs were supported in an earlier
version, but won’ t be anymore
– tools for converting DTDs to
XML Schemas exist

Is it helpful? Add Comment View Comments
Ques 7. Give me an example of XSD.
Ans. <?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
<xs:complexType name="car">
<xs:element name="make" type="xs:string"/>
<xs:element name="model" type="xs:string"/>
<xs:element name="color" type="xs:string"/>
<xs:attribute name="year" type="xs:positiveInteger" use="required"/>
<xs:element name="cars">
<xs:element name="car" type="car" maxOccurs="unbounded"/>
Is it helpful? Add Comment View Comments
Ques 8. Give me an example of XML document.
Ans. <?xml version="1.0" encoding="UTF-8"?>
<cars xmlns=""
xsi:schemaLocation=" cars.xsd">
<car year="2001">
<car year="2001">
<car year="1997">
Is it helpful? Add Comment View Comments
Ques 9. How to generate Java from XML Schema. Please show the example.
Ans. • From command-line
– Windows: %JAXB_HOME%\bin\xjc cars.xsd
– UNIX: %JAXB_HOME%/bin/ cars.xsd
– these write generated files to current directory
• From Ant
<java jar="${env.JAXB_HOME}/lib/jaxb-xjc.jar" fork="yes">
<arg line="-d ${gen.src.dir} cars.xsd"/>

Generated Files:

• com/withoutbook/cars directory
• interface representing the “car” complex type
• only describes get and set methods for car properties
• interface representing “cars” global element
• extends CarsType and javax.xml.bind.Element (just a marker interface)
• describes no additional methods
• interface representing anonymous complex type
defined inside the “cars” global element
• provides method to get collection of Car objects (as a java.util.List)
• class used to create objects of the above interface types
• extends DefaultJAXBContextImpl which extends JAXBContext
– bgm.ser
• a serialized object of type com.sun.msv.grammar.trex.TREXGrammar
• can’t find any documentation on this - don’t know its purpose
• sets a property that defines the class used to create JAXBContext objects

• com/withoutbook/cars/impl directory
• class that implements Car
• corresponds to the “car” XML Schema complexType
• class that implements CarType
• corresponds to the XML Schema anonymous type inside the “cars” element
• class that extends CarsTypeImpl and implements Cars
• corresponds to the “cars” XML Schema element
Is it helpful? Add Comment View Comments
Ques 10. How to unmarshall XML into Java objects? Convert from XML to Java objects.
Ans. • Example
ObjectFactory factory = new ObjectFactory();
Unmarshaller u = factory.createUnmarshaller();
Cars cars = (Cars) u.unmarshal(new FileInputStream("cars.xml"));
• unmarshal method accepts
– javax.xml.transform.Source
• related to XSLT
– org.w3c.dom.Node
• related to DOM
– org.xml.sax.InputSource
• related to SAX

• Other Unmarshaller methods
– void setValidating(boolean validating)
• true to enable validation during unmarshalling; false to disable (the default)
– boolean setEventHandler(ValidationEventHandler handler)
• handleEvent method of ValidationEventHandler is called
if validation errors are encountered during unmarshalling
• default handler terminates marshalling after first error
• return true to continue unmarshalling
• return false to terminate with UnmarshalException
• see discussion of ValidationEventCollector later
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2020 WithoutBook