XML is used in platforms for defining deployment descriptors, metadata information, and so on. XML is also used as an integration technology that solves the problem of data independence and interoperability.  Associated with these XML documents, schemas are used to validate exchanged data.
In Java, there are several low-level APIs to process XML documents and XML Schemas , from common APIs (javax.xml.stream.XmlStreamWriter and java.beans.XMLEncoder) to more complex and low-level models such as Simple API for XML (SAX), Document Object Model (DOM), or Java API for XML Processing (JAXP). JAXB provides a higher level of abstraction than SAX or DOM and is based on annotations.

JAXB defines a standard to bind Java representations to XML and vice versa. It manages XML documents and XML Schema Definitions (XSD) in a transparent, object-oriented way that hides the complexity of the XSD language.
Except for the @XmlRootElement annotation, The following code shows the code of a normal Java class.

package test.jaxb;

import javax.xml.bind.annotation.XmlRootElement;


/**
*
* @author Saeed Zarinfam
*/
@XmlRootElement

public class CreditCard {

private String number;
private String expiryDate;
private Integer controlNumber;
private String type;

public CreditCard(String number, String expiryDate, Integer controlNumber, String type) {
this.number = number;
this.expiryDate = expiryDate;
this.controlNumber = controlNumber;
this.type = type;
}

public CreditCard() {
}

public Integer getControlNumber() {
return controlNumber;
}

public void setControlNumber(Integer controlNumber) {
this.controlNumber = controlNumber;
}

public String getExpiryDate() {
return expiryDate;
}

public void setExpiryDate(String expiryDate) {
this.expiryDate = expiryDate;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}

As shown in the following code ,With this annotation and a marshalling mechanism, JAXB is able to create an XML repreentation of a CreditCard instance :

package test.jaxb;

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

/**
*
* @author Saeed Zarinfam

*/
public class Main {

public static void main(String[] args) {
try {
CreditCard creditCard = new CreditCard("1234", "12/09", 6398, "Visa");
StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(CreditCard.class);
Marshaller m = context.createMarshaller();
m.marshal(creditCard, writer);
System.out.println(writer.toString());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
 
Reference : Beginning   Java™  EE 6 Platform  with GlassFish™  3 From Novice to Professional 

 
 
 
 
 
have a nice time.