YouTube Icon

Interview Questions.

Top 100+ Jaxb Interview Questions And Answers - May 31, 2020

fluid

Top 100+ Jaxb Interview Questions And Answers

Question 1. What Is Xml Binding?

Answer :

Maps XML to in-memory objects according to a schema

Generates instructions to represent XML factors:

so builders don’t need to write them
the “binding compiler” does this
the lessons observe JavaBeans assets access conventions
Supports three primary operations:

marshalling a tree of objects into an XML report
unmarshalling an XML file right into a tree of gadgets
consists of validation of the XML against the schema:

used to generate the classes of the objects validation of item trees against the schema used to generate their training

a few constraints are enforced while operating with the items
others are only enforced while validation is asked
Question 2. What Is Xml Binding Relationships?

Answer :

The relationships among the additives worried in XML binding (statistics binding) are shown underneath schema -> classes XML -> schema Schema generates training.

Objects are instanceof training.
Marshal from gadgets to XML
Unmarshall from XML to objects
XML validates and conforms to Schema
Java Script Interview Questions
Question 3. Why Use Xml Binding?

Answer :

It’s no longer vital

everything that need to be performed with XML may be completed with SAX and DOM
It’s less difficult

don’t have to write as an awful lot code
don’t have to analyze SAX and/or DOM
It’ s much less blunders-prone

all of the features of the schema are utilized
don’ t have to do not forget to manually implement them
It can allow customization of the XML shape

not like XMLEncoder and XMLDecoder within the java.Beans bundle
Question four. Explain Jaxb Use Cases?

Answer :

Create/Read/Modify XML using Java

however with out using SAX or DOM
Validate user enter:

using regulations defined in XML Schemas
Use XML-based totally configuration files

get entry to their values
write gear that creates and modifies those documents
Java Script Tutorial
Question 5. What Are The Goals Of Jaxb?

Answer :

Easy to use:

require minimal XML expertise
don’ t require SAX/DOM understanding
Customizable:

can customise mapping of XML to Java
Portable:

can change JAXB implementation with out changing supply code
Deliver soon:

supply core functionality ASAP
Natural:

 observe wellknown design and naming conventions in generated Java
Match schema:

clean to perceive generated Java additives that correspond to schema features
Hide plumbing:

encapsulate implementation of unmarshalling, marshalling and validation
Validation on call for:

validate objects with out requiring marshalling
Preserve object equivalence:

(spherical tripping)

marshalling items to XML and unmarshalling lower back to objects outcomes in equal gadgets
J2EE Interview Questions
Question 6. What Are The Disadvantages/non-desires Of Jaxb?

Answer :

Standardize generated Java:

classes generated by way of one of a kind JAXB implementations won't be like minded with every different
Preserve XML equivalence:

unmarshalling XML to items and marshalling lower back to XML won't result in equivalent XML
Bind current JavaBeans to schemas:

 can simplest marshal and unmarshal instructions generated by using JAXB
can be added later
Schema evolution help:

can’ t alter formerly generated code to guide schema modifications
ought to generated new code
Allow generated Java to get entry to:

XML factors/attributes now not described in initial schema

Partial binding:

unmarshalling simplest a subset of an XML document breaks round tripping
Implement each function of the schema language:

it’ s difficult to put into effect all of XML Schema!
Support DTDs:

 that specialize in XML Schema
DTDs have been supported in an earlier model, but received’ t be anymore
equipment for converting DTDs to XML Schemas exist
Question 7. Give Me An Example Of Xsd?

Answer :

<?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>

J2EE Tutorial Core Java Interview Questions
Question 8. Give Me An Example Of Xml Document?

Answer :

<?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>pink</color>

</car>

</cars>

Question nine. How To Generate Java From Xml Schema. Please Show The Example?

Answer :

From command-line:

Windows: %JAXB_HOME%binxjc vehicles.Xsd

UNIX: %JAXB_HOME%/bin/xjc.Sh vehicles.Xsd

these write generated documents to contemporary 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 listing

Car.Java:

interface representing the “automobile” complicated type
best describes get and set techniques for vehicle properties
Cars.Java:

interface representing “vehicles” international element
extends CarsType and javax.Xml.Bind.Element (just a marker interface)
describes no extra techniques
CarsType.Java:

interface representing nameless complex kind described within the “automobiles” global element
affords method to get collection of Car objects (as a java.Util.List)
ObjectFactory.Java:

class used to create gadgets of the above interface sorts
extends DefaultJAXBContextImpl which extends JAXBContext
bgm.Ser:

a serialized object of kind com.Solar.Msv.Grammar.Trex.TREXGrammar
can’t find any documentation in this - don’t recognise its reason
jaxb.Houses:

sets a belongings that defines the elegance used to create JAXBContext objects
com/withoutbook/motors/impl directory
CarImpl.Java:

class that implements Car
corresponds to the “vehicle” XML Schema complexType
CarsTypeImpl.Java:

magnificence that implements CarType
corresponds to the XML Schema anonymous type in the “automobiles” element
CarsImpl.Java:

class that extends CarsTypeImpl and implements Cars
corresponds to the “automobiles” XML Schema element 
AJAX Interview Questions
Question 10. How To Unmarshall Xml Into Java Objects? Convert From Xml To Java Objects?

Answer :

Example:

ObjectFactory manufacturing unit = new ObjectFactory();

Unmarshaller u = factory.CreateUnmarshaller();

Cars automobiles = (Cars) u.Unmarshal(new FileInputStream(“automobiles.Xml”));

unmarshal technique accepts:

java.Io.File
java.Io.InputStream
java.Internet.URL
javax.Xml.Remodel.Source
related to XSLT:

org.W3c.Dom.Node

related to DOM:

org.Xml.Sax.InputSource

related to SAX:

• Other Unmarshaller strategies
 void setValidating(boolean validating)
• actual to permit validation all through unmarshalling; false to disable (the default)
  boolean setEventHandler(ValidationEventHandler handler)
• handleEvent technique of ValidationEventHandler is called
  if validation errors are encountered at some point of unmarshalling
• default handler terminates marshalling after first blunders
• go back authentic to retain unmarshalling
• go back fake to terminate with UnmarshalExceptio
• see discussion of ValidationEventCollector later

Core Java Tutorial
Question eleven. Java Example/java Program To Set Object For Generating Xml?

Answer :

Cars cars = manufacturing facility.CreateCars();

Car automobile = factory.CreateCar();

car.SetColor("blue");

vehicle.SetMake("Mazda");

automobile.SetModel("Miata");

vehicle.SetYear(BigInteger.ValueOf(2012));

motors.GetCar().Add(vehicle);

vehicle = manufacturing unit.CreateCar();

vehicle.SetColor("crimson");

vehicle.SetMake("Ford");

automobile.SetModel("Mustang II");

car.SetYear(BigInteger.ValueOf(2011));

motors.GetCar().Upload(automobile);

Java-Springs Interview Questions
Question 12. How To Validate Java Objects?

Answer :

The graph of Java objects can contain invalid records:

should occur whilst gadgets created by using unmarshalling are changed
should arise whilst gadgets are constituted of scratch
Use a Validator to validate the objects

Example:

Validator v = manufacturing facility.CreateValidator();

try 

v.ValidateRoot(motors);

v.Validate(vehicle);

 catch (ValidationException e) 

// Handle the validation blunders described by way of e.GetMessage().

Other Validator methods:

boolean setEventHandler(ValidationEventHandler handler)

• handleEvent technique of ValidationEventHandler is referred to as

if validation errors are encountered

default handler terminates marshalling after first error
return authentic to keep validating
go back fake to terminate with ValidationException
Pass an example of javax.Xml.Bind.Util.ValidationEventCollector (in jaxb-api.Jar) to setEventHandler to gather validation mistakes and query them later as opposed to coping with them at some point of validation.

ValidationEventCollector vec =

new ValidationEventCollector();

v.SetEventHandler(vec);

v.Validate(automobiles);

ValidationEvent[] activities = vec.GetEvents();

Java Script Interview Questions
Question thirteen. Explain Customizing Type Bindings?

Answer :

Default bindings may be overridden:

at international scope
on case-by-case foundation
Customizations consist of

names of generated package, classes and strategies
technique go back kinds
elegance assets (subject) types
which elements are sure to instructions, rather than being disregarded
class assets to which each attribute and element assertion is certain
AJAX Tutorial
Question 14. Explain The Syntax Of Customization?

Answer :

Customizations can be specified in

the XML Schema (our awareness)
a binding declarations XML file (now not nicely supported with the aid of RI but)
The XML Schema have to declare

the JAXB namespace and version

xmlns:jxb="http://java.Solar.Com/xml/ns/jaxb"

jxb:model="1.Zero">

Customization elements are placed in annotation elements

 <xsd:annotation>

<xsd:appinfo>

 binding declarations

</xsd:appinfo>

</xsd:annotation>

Question 15. Discuss Customization Levels?

Answer :

Customizations can be made at four tiers

global:

defined at “top level” in a detail
applies to all schema factors within the source schema and in all protected/imported schemas (recursively)
schema:

described at “pinnacle degree” in a element
applies to all schema factors inside the target namespace of the source schema
definition:

described in a kind or international declaration
applies to all schema factors that reference the kind or worldwide assertion
component:

described in a selected schema element or characteristic declaration
applies most effective to it
JMS(Java Message Service) Interview Questions
Question 16. Discuss Global Bindings Attributes?

Answer :

collectionType:

“listed” (uses array and presents methods to get/set elements) or absolutely-qualified-java-class-name(have to enforce java.Util.List)
default is “java.Util.ArrayList”
enableFailFastCheck:

"true” or “fake” (default)
if proper, invalid assets values are pronounced as soon as they're set, as opposed to ready until validation is asked
no longer applied but in RI
generateIsSetMethod:

“genuine” or “fake” (default)
if real, generates isSet and unSet strategies for the belongings
underscoreBinding

“asCharInWord” or “asWordSeparator” (default)
if “asWordSeparator” , underscores in XML names are eliminated and phrases are camel-cased to form Java name
as an example, “gear_shift_knob” goes to “gearShiftKnob”
bindingStyle (became modelGroupAsClass):

“modelGroupBinding” or “elementBinding” (default)
choiceContentProperty:

“real” or “false” (default)
lets in gadgets to maintain one among some of assets choices which may additionally each have a extraordinary statistics type
enableJavaNamingConventions:

“proper” (default) or “false”
fixedAttributeAsConstantProperty:

“proper” or “fake” (default)
if true, “constant” attributes can be represented as constants
typesafeEnumBase:

“xsd:string” , “xsd:decimal” , “xsd:glide” , “xsd:double” or “xsd:NCName” (default)
defines discipline kind used to symbolize enumerated values in generated typesafe enum elegance
typesafeEnumMemberName:

“generateName” or “generateError” (default)
specifies what to do if an enumerated value can not be mapped to a valid Java identifier
“generateName” generates names inside the form VALUE_#
“generateError” reports an blunders
Java-Springs Tutorial
Question 17. What Is The Syntax Of Schemabindings?

Answer :

The syntax for the schemaBindings detail is

<jxb:schemaBindings>

<jxb:package [name="package-name"]>

<jxb:javadoc> ... Javadoc ... </jxb:javadoc>

</package>

<jxb:nameXmlTransform>

<jxb:typeName prefix="prefix" suffix="suffix"/>

<jxb:elementName prefix="prefix" suffix="suffix"/>

<jxb:modelGroupName prefix="prefix" suffix="suffix"/>

<jxb:anonymousTypeName prefix="prefix" suffix="suffix"/>

</jxb:nameXmlTransform>

</jxb:schemaBindings>

– each detail and attribute inside schemaBindings is optionally available

Hibernate Interview Questions
Question 18. Java Code For Marshalling Java Objects Into Xml?

Answer :

Example:

Marshaller m = factory.CreateMarshaller();

m.SetProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

Writer fw = new FileWriter(“newCars.Xml”);

m.Marshal(automobiles, fw);

marshal method accepts:

java.Io.OutputStream
java.Io.Writer
javax.Xml.Remodel.Result
associated with XSLT

org.W3c.Dom.Node

related to DOM

 org.Xml.Sax.ContentHandler

related to SAX

• Other Marshaller methods

boolean setEventHandler(ValidationEventHandler handler)

equal as use with Unmarshaller, however validation events

are introduced at some point of marshalling

void setProperty(String call, Object fee)

supported residences are

jaxb.Encoding – fee is a String
the encoding to apply whilst marshalling; defaults to “UTF-eight”
jaxb.Formatted.Output – price is a Boolean
actual to output line breaks and indentation; false to leave out (the default)
jaxb.SchemaLocation – price is a String
to specify xsi:schemaLocation characteristic in generated XML
jaxb.NoNamespaceSchemaLocation – price is a String
to specify xsi:noNamespaceSchemaLocation characteristic in generated XML
J2EE Interview Questions




CFG