Monday Aug 24, 2009

Debugging basics and some link - Java

Some simple debugging tools related to Java. These are for those who are new to Java.

1. Application is crashing : Most miserable one. Get your log file, try to analysis log. How to write log file, use Java Logger API.  Java Logger had been introduced in JDK 1.4.2. The most awesome feature of  Logger API is that you can use it in production without much overhead. The overhead is controlled by something called level in API. Level goes from FINEST to SEVERE. You can refer to O'Relly Book "Java, In a NutShell". I guess. ...........
[Read More]

Sunday Jul 01, 2007

xjc.exe

Today I was looking some options in jdk/bin and suddenly I came across
a file name xjc.exe in JDK6. Quickly I checked the existence of this file in JDK 5.0 and JDK
1.4.2. File was not present. Goggling didn't provided too much of help
and I tried with myself :)

I just copied an XSD file from somewhere:

FileName: unknowntest.xsd

<xs:schema
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country">
 <xs:complexType>
   <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="pop" type="xs:decimal"/>
   </xs:sequence>
 </xs:complexType>
</xs:element>
</xs:schema>

 and passed this XSD file into xjc option:
Usage: xjc [-options ...] ... [-b ] ...

> xjc unknowntest.xsd

parsing a schema...
compiling a schema...
generated\\Country.java
generated\\ObjectFactory.java

Ah I got 2 Java files - Country.java and ObjectFactory.java
Look at these 2 files ( I am removing the documentation part of it, to make it small)

package generated;

import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"pop"
})
@XmlRootElement(name = "country")
public class Country {

@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected BigDecimal pop;

/\*\*
\* Gets the value of the name property.
\*
\* @return
\* possible object is
\* {@link String }
\*
\*/
public String getName() {
return name;
}

/\*\*
\* Sets the value of the name property.
\*
\* @param value
\* allowed object is
\* {@link String }
\*
\*/
public void setName(String value) {
this.name = value;
}

/\*\*
\* Gets the value of the pop property.
\*
\* @return
\* possible object is
\* {@link BigDecimal }
\*
\*/
public BigDecimal getPop() {
return pop;
}

/\*\*
\* Sets the value of the pop property.
\*
\* @param value
\* allowed object is
\* {@link BigDecimal }
\*
\*/
public void setPop(BigDecimal value) {
this.pop = value;
}

}

and
objectFactory don't have too much in it. Just creating a Country class
instance. Oh so it is something cool, its making all the getter and
setter method for me, what else I need :).

Remember, such type
of methods are too much in demand when you are writing any jsp page.
So, if you are clear with the data type, just make an xsd file and xjc
will convert in into java code.

I still doubt what xjc refers for ... may be xml to java converter :)

 

About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today