How to write Code in Java?

If you Google then you will find lots of code and solution of your coding issue. but
The most important point is How Code should be?
When you are writing code in Java, As per my knowledge - There are points which should be implemented into code

Key Pointes are :

1. Always generate logs for your application.You can use apache Log4j.jar for that.

2. Don't generate log file into root of your application. Try to create new Log directory into your application,
   and generate new log file for earch Run/Build into log folder

3. Naming convension of log file is important as well. it should be Ex. _DataandTimeStamp.log.
   In order to create new log file each time your applicaton runs, you can create inherit superclass FileAppender
   and overrid it's method and write logic to create new name with timestamp.


4. If your application require Global variable,which will be used throught your appplication(like Configuration) then you
   should make define it into Properties and access it using ResourceBundle from Java.util package.
 

5. Exception Handling is one of the important factor which should be implemented into your program.

6. Don't use static absolute path. Better to use relative path Ex. path config/Resource.properties is better than
   c:/myproject/src/config/Resource.properties


7. Write all your java files into packages rather than in Default package

Marshelling and Unmarshelling Document using JAXB

Marshelling is a process of transforming java objects into XML format. and Unmarshalling is the process of converting an XML document into a corresponding set of Java objects.

Concept 1 : Marshelling Document
Create JAXBContext object as per your project as
JAXBContext jaxbContext;
jaxbContext = JAXBContext.newInstance("com.anuj.jaxb");

Once your domain object is initialized, use the JAXB context to create a Marshaller object and a typed JAXBElement. Creating the marshaller is simple:
Marshaller marshaller = jaxbContext.createMarshaller();

You can Set a property so that the output will be formatted for human use and then write to standard output
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal( bookingElement, System.out );  Outout will be XML.

Generate .xsd Schema file from .xml file

When you are using JAXB(Java Architecture for XML Binding), you must require xml document to be converted into .xsd file. There is one Open Source called "trang" which does same thing. It takes .xml file as input and give .xsd as output. You can also use XMLSpy but It's not free. you will be provided 30 days trial.

1. Download "Trang"and Copy .jar files to local
2. Generate .xsd file using command as below using command prompt

java -jar trang.jar app-defaults.xml app-defaults.xsd

Note : app-defaults.xml is existing input .xml file and app-defaults.xsd is file which will generate after running this command.