This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There are various ways to do this. In simple cases you might just write directly to a file, using the java.io classes.
For anything that's not trivial, construct an in-memory representation using DOM, and then serialize that to a file once it's complete. Here's an introduction on how to do that. All classes needed for that are part of the the JDK, so you don't need to download anything else.