Here i’m going to write down about how to deal with XML by using Java, especially with JAXB as you can see from the subject title.
Why JAXB ?
Of course, there are many ways to handle XML in Java. You could use JAXP API (Java API for XML Processing) which comprises DOMParser and SAXParser (old fashion style and complicated in my opinion ^_^), or XMLBeans which convert and transform your XML file to POJO class or vice versa. I thought the last one (i.e. XMLBeans) is much better compared to JAXP (this is my opinion, maybe you have different opinion). But…, nowadays, i think i would like to choose JAXB rather than XMLBeans. Why ? because (in my private opinion again ^_^), configure JAXB is much simpler than XMLBeans. Because its already become standard of Java EE. Starting from Java 6, its already bundled inside the JDK. So, you don’t need to include external libraries/APIs to use this API. That’s the reason why i choose JAXB instead of XMLBeans.
However, in some IDE (e.g. Oracle Weblogic Workshop), you can see there, that the IDE has already bundled XMLBeans as its standard API to dealing with XML. That’s why, i’m still using XMLBeans for some of my projects that using Oracle Weblogic Workshop as the IDE. However, i’m not talking about XMLBeans here. I will talk about JAXB here. Yes, sure you could find anywhere from the internet (just need to ask uncle google ^_^) about this JAXB. But, I will show you here by example (a simple example), about how easily configure and play with JAXB in order to handling your XML stuffs.
I am writing this just to share a little bit about my findings while playing with Grails. Hopefully, this could be a good note for me too.
By the way, I’m using Grails 2.0.4 at the time of this writing. You could download it from Grails official site.
Ok, lets start then.
There are 3 errors/exceptions that I’ve just found while playing with the Grails as you can see from the following:
1. java.lang.SecurityException occured while running grails command
I was trying to create new Grails app with
grails create-app command, and i’ve got such an error. See the image below:
Click the image to enlarge
Java is getting bigger and popular now. I think the OpenSource is one of the reason that influence it. People always look for something that are free and powerful. One of my friends who’s currently working as PHP developer told me that he’s trying to switch to Java. He came to me yesterday and has asked me about Generic.
In order to answer his question, i’m gonna write some explanation here about Generic. Hopefully this could help him and the others (including me :-)).
What is Generic ?
Generic is one of the java’s feature/extension that starting from Java 5 (Tiger). In my opinion, Generic helps your code more stable by trying to reduce as many as possible any exception that could be raised in runtime. This could be done by trusting the compiler to check our code in the compile time. Generic helps you to detect your program bugs at compile time as many as possible. So, it’s guarantee that our running code is less of any error.
Generic allows you to abstract over types. The most common examples are container types, such as those in the Collection hierarchy. Overall, Generics are heavily uses by these classes (i.e. Collection classes).
I’ve remembered that several weeks ago my laptop couldn’t boot the OS while I was using Ubuntu 10.04 for about 1 year. I was trying to boot with my Ubuntu 10.04′s bootable CD. But it always gave me the same result, I saw blank screen with blinking cursor :-(.
I have a thought that the problem could be one of the:
- memory card,
- harddisk, or even worse
- the motherboard (I was hoping not the motherboard X_X).
First, I checked the harddisk by removed it from my laptop, then restart again with the same bootable CD. Yupi, It was working (ye…ye..ye..ye..ye..:-D). I was glad, because at least i knew that the motherboard is still working :-).
So, the problem was on the harddisk. I thought that maybe the harddisk had some bad sector in it. So, without thinking too much, I’ve decided to backup all of the data to my PC’s harddisk, then performed low level format from my PC.
After finished, I had an idea to gave that harddisk new OS. So, I was choosing Ubuntu 11.04 (Natty Narwhal) instead of Ubuntu 10.04 (Lucid Lynx).
It’s all working now :-). But, I have to install again all of my development tools from the beginning. One of them is PostgreSQL 9.
Since 2 months ago, I’ve got my second remote job as Java EE Developer for Telco Company in Singapore named Hub9. So, currently now I’m working for two Telco’s Company in Singapore (i.e. CoreSDP and Hub9) as Java EE Developer. Both of them are remote jobs (which means working from home :-D), and I’ve got monthly payment for these jobs. This is what i’ve been dreaming for a long time :-).
Start from here I’ll write some notes about anything what i’ve been doing for over the last 2 months with Hub9.
As my first assignment, they’ve asked me to develop facebook chat (IM/Instant Messaging) application via SMS (known as Facebook SMS Chat). As you’ve already known, there are many chat (IM) application now, such as Yahoo Messenger, GoogleTalk, eBuddy, Jabber, etc. Even Facebook has provided it’s application with IM service, so every user on facebook could have a conversation via this chat (IM) service.
Every IM service need communication protocol in order to be working correctly. There are many protocols around can be used for this purpose. Some of them are under commercial (propietary) license, and some of them are not (means ‘free’, and this is what i’m going to use :-D).
One of the protocol that is free to be used is XMPP.
XMPP (stands for eXtensible Messaging and Presence Protocol) is an open-standard communication protocol for message oriented middleware based on XML (eXtensible Markup Language). This protocol was originally named Jabber, and was developed by the Jabber open source community in 1999 for near real-time, extensible instant messaging (IM), presence information, and contact list maintenance. The software implementation and client application based on this protocol are distributed as free and open source software (looks nice to me ^_^).
I think, you should read by your self later about XMPP, so I won’t give you the detail explanation about XMPP here (b’cause I’m not the kind of person who’s enjoy to talking to much about the ‘philosophy’ behind the ‘theory’ #:-s). So please googling or read the “RTFM” :-).
One thing that I think is important for us to know before we jump into the XMPP implementation is: basically, there are 2 implementations of XMPP. i.e. XMPP Server and XMPP Client.
In order to work, we should have those 2 implementation in our software.
I thought we’ve already heard about Dependency Injection (DI). I knew it when I learned Spring framework in Java. So far as I know, Spring framework has come with it’s 2 popular concepts which known as IoC (Inversion of Control) and AOP (Aspect Oriented Programming). When you learned about IoC concept in Spring, you often refers to DI as the other name of IoC. And there are many of Java developers equate IoC to DI. But, actually DI is not exactly the same as IoC. IoC is more wide than DI. On simplistic term, we can say that DI is a part of IoC, or one of the implementation of IoC.
IoC/DI has become popular with Spring. But, did you know that the main idea behind IoC/DI concept started from around 1994 ? In the year of 1994, Robert C.Martin wrote in his paper about “The Dependency Inversion Principle”, which also known as DIP for short. This is eventually known as IoC/DI’s principle, just like now.
On his paper, Robert states the three defining factors of bad code, shown as below:
- Rigidity, that it’s hard to change part of the code, because every change to the code often affects too many other parts of the system.
- Fragility, that when we make a change to our code, there is an unexpected parts of the system broken.
- Immobility, that it’s hard to reuse our application or application’s code, because it cannot be disentangled from current application
Usually, I use MS Paint on Windows for simple image editing such as cropping, giving some label, etc.
On this section I’ll try to explain to you step by step about how to use MS Paint on Linux.
Currently, I use Linux UBuntu 10.4 (Lucid Lynx). But it doesn’t matter what variant/distro you are using now, I think it will be quite similiar (not much different with mine, except on the first step).
The first step (this step will be different, depends on your linux’s variant/distro) is to get wine running on your linux.
on UBuntu (or other debian variant such as Linux Mint, KBuntu, etc.) just use apt-get to install thiswine like the following:
yauritux@yaurilab:~$ sudo apt-get install wine
You will be prompted for your user’s password. Input your password, then press enter to continue.
The system will automatically install the packages needed on your machine. You don’t have to do anything special, just make a cup of coffee while waiting the process to be done :-).
Here is the output sample of mine:
[sudo] password for yauritux:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
Neet to get ……. of archives.
After this operation, ….. of additional disk space will be used.
Get: 1 http://id.archive.ubuntu.com/ubuntu/ lucid-updates/universe wine 1.2.2-0ubuntu2~lucid1 [....]
Fetched …….. in 4 s (9,948B/s)
Selecting previously deselected package wine.
(Reading database … 164177 files and directories currently installed.)
unpacking wine (from …/wine_1.2.2-0ubuntu2~lucid1_all.deb) …
Setting up wine (1.2.2-0ubuntu2~lucid1) …
for the next step ahead, you’ll need to copy files needed from Windows XP system.