Prev Next

Java / JAXB

Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. What is JAXB?

Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. JAXB provides methods for unmarshalling (reading) XML instance documents into Java content trees, and then marshalling (writing) Java content trees back into XML instance documents. JAXB also provides a way to generate XML schema from Java objects.

2. Explain the JAXB architecture.

JAXB architecture consists of 3 components.

Schema compiler binds a source schema to a set of schema-derived program elements. The binding is described by an XML-based binding language.

Schema generator maps a set of existing program elements to a derived schema. The mapping is described by program annotations.

Binding runtime framework provides unmarshalling (reading) and marshalling (writing) operations for accessing, manipulating, and validating XML content using either schema-derived or existing program elements.

3. What is Unmarshalling in JAXB?

Unmarshalling refers to the process of converting XML data into JAXB-derived Java objects.

4. What is marshalling in JAXB?

Marshalling provides a client application the ability to convert a JAXB-derived Java object tree into XML data.

5. What is the default encoding for generating XML in JAXB?

UTF-8.

6. What is XML binding in JAXB?

XML binding is the representation of XML document content as an object in computer memory. At compile time, a schema driver processes the XSD and generates an execution object model (XOM). At run time, an XML data driver creates an XML object from the XML document.

7. Difference between DTD and XML Schema.

DTD is not written using XML while XML schema are xml documents in itself.DTD stands for Document Type definition, a legacy way to define structure of XML documents.

XML schema offers more types to map different types of data in XML documents.

8. Difference between JAXB and DOM/SAX.

The Java DOM and SAX parsing are lower-level APIs to parse XML documents, while JAXB is a higher-level API for converting XML elements and attributes to a Java object hierarchy (and vice versa). Implementations of JAXB may use a DOM or SAX parser behind the scenes to do the actual parsing of the XML input data.

9. Difference between JAXP and JAXB.

JAXP (Java API for XML Processing) refers to the outdated low-level XML APIs in JavaSE, such as DOM, SAX and StAX.

JAXB (Java Architecture for XML Binding) uses annotations to bind XML documents to a java object model.

10. Steps involved in JAXB marshaling or Java object to XML conversion.
  • Create POJO class and add JAXB annotations. Annotate with @XmlRootElement @XmlAccessorType and annotate all fields with @XmlElement. This will bind Object properties to XML elements.
  • Create the JAXBContext object.
  • Create the Marshaller objects.
  • Create the content tree by using set method.
  • Invoke the marshal method.
«
»
Servlet Interview Questions

Comments & Discussions