Most asked top Interview Questions and Answers & Online Test
Education platform for interview prep, online tests, tutorials, and live practice

Build skills with focused learning paths, mock tests, and interview-ready content.

WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.

Prepare Interview

JAXB Interview Questions and Answers

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

β€’ 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.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.withoutbook.com/cars"
targetNamespace="http://www.withoutbook.com/cars">
<xs:complexType name="car">
<xs:sequence>
<xs:element name="make" type="xs:string"/>
<xs:element name="model" type="xs:string"/>
<xs:element name="color" type="xs:string"/>
</xs:sequence>
<xs:attribute name="year" type="xs:positiveInteger" use="required"/>
</xs:complexType>
<xs:element name="cars">
<xs:complexType>
<xs:sequence>
<xs:element name="car" type="car" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Is it helpful? Add Comment View Comments
 

Ques 8. Give me an example of XML document.

<?xml version="1.0" encoding="UTF-8"?>
<cars xmlns="http://www.withoutbook.com/cars"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.withoutbook.com/cars cars.xsd">
<car year="2001">
<make>BMW</make>
<model>Z3</model>
<color>yellow</color>
</car>
<car year="2001">
<make>Honda</make>
<model>Odyssey</model>
<color>green</color>
</car>
<car year="1997">
<make>Saturn</make>
<model>SC2</model>
<color>purple</color>
</car>
</cars>

Is it helpful? Add Comment View Comments
 

Ques 9. How to generate Java from XML Schema. Please show the example.

β€’ From command-line
– Windows: %JAXB_HOME%binxjc cars.xsd
– UNIX: %JAXB_HOME%/bin/xjc.sh 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"/>
</java>

Generated Files:

β€’ com/withoutbook/cars directory
– Car.java
β€’ interface representing the β€œcar” complex type
β€’ only describes get and set methods for car properties
– Cars.java
β€’ interface representing β€œcars” global element
β€’ extends CarsType and javax.xml.bind.Element (just a marker interface)
β€’ describes no additional methods
– CarsType.java
β€’ interface representing anonymous complex type
defined inside the β€œcars” global element
β€’ provides method to get collection of Car objects (as a java.util.List)
– ObjectFactory.java
β€’ 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
– jaxb.properties
β€’ sets a property that defines the class used to create JAXBContext objects

β€’ com/withoutbook/cars/impl directory
– CarImpl.java
β€’ class that implements Car
β€’ corresponds to the β€œcar” XML Schema complexType
– CarsTypeImpl.java
β€’ class that implements CarType
β€’ corresponds to the XML Schema anonymous type inside the β€œcars” element
– CarsImpl.java
β€’ 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.

β€’ Example
ObjectFactory factory = new ObjectFactory();
Unmarshaller u = factory.createUnmarshaller();
Cars cars = (Cars) u.unmarshal(new FileInputStream("cars.xml"));
β€’ unmarshal method accepts
– java.io.File
– java.io.InputStream
– java.net.URL
– 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:

Copyright Β© 2026, WithoutBook.