Skip to content

JAXB 2.0 Hello World

For people who have played with JAXB 1.x, JAXB 2.0 has the same beahavior: it can marshall/unmarshall object from/to XML. But the syntax is completly different. It uses all kind of annotations. This blog is just about writing and executing a good old Hello World with JAXB 2.0. First you need to download and install the binary. For the following example you will just need to put jaxb-api.jar and jaxb-impl.jar in your classpath. The following code represents a HelloWorld class with two attributes. The main method creates a HelloWorld object, sets some values, marshalles it to the hello.xml file, displays the xml representation, unmarshalles the xml file into a HelloWord and displays the toString method : import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlRootElement; import java.io.File; import java.io.FileOutputStream; @XmlRootElement public class HelloWorld { private String hello; private Integer world; public String getHello() { return hello; } public void setHello(String hello) { this.hello = hello; } public Integer getWorld() { return world; } public void setWorld(Integer world) { this.world = world; } public String toString() { return hello "-" world; } public static void main(String[] args) throws Exception { // Set up file and JAXB context final File file = new File("hello.xml"); JAXBContext context = JAXBContext.newInstance(HelloWorld.class); // Creates a HelloWorld object HelloWorld hw = new HelloWorld(); hw.setHello("Hello !!!"); hw.setWorld(1234); // From a HelloWorld object creates a hello.xml file Marshaller m = context.createMarshaller(); m.marshal(hw, new FileOutputStream(file)); m.marshal(hw, System.out); // From the hello.xml […]

Read More →

Java Day 2006 in Paris

Well, in fact Java Day 2006 wasn’t held in Paris itself but in Versailles, just in front of the castle So, yes, things also happen outside the US. I know, it was just a one day java conferences with only 5 sessions, nothing compare to the four days of Java One and its 188 sessions. But still, we had James Goslings on stage. If you look at the agenda, this is what happened. Welcome Eric Mahé ? Technology Advisor ? Sun Microsystems France Eric, who has been working for 17 years at Sun, introduced the java day and the agenda. After few marketing slides (you always have to thank the sponsors) he joked about Extreme Pixel Programming. The idea is that Eric is not a java programmer, the tool he uses the most is Photoshop and he would like to use it to code some java classes. So he opened Photoshop, dragged & dropped some images, saved it as a raw file, opened the raw file, copied the content and pasted it into a java file in Netbeans. He then executed it, and the image was displayed with animation. He said that the one who finds the trick will win one of its own art work… bets opened. The Next Wave of Java Tools James Gosling ? Chief Technology Officer of Sun’s Developer Products group James arrived on stage and threw some left over t-shirt of Java One at the […]

Read More →

What would be your ideal job?

I‘ve been working in the IT industry for quite a long time now. Mainly in big companies, on big projects where you spend half your time in meetings and the other half writing meeting reports. Through this experience I‘ve met a lot of people who have had different experiences, different projects but I‘ve never met anyone who has had their ideal job during his/her career. There are always management, political, personnel or budget problems which cause the project to turn into a nightmare. When you talk to people, everybody seems to converge towards an ideal situation where innovation, dynamism, professionalism, intelligent management and beauty flow 10 hours a day… but that never happens. As a Java developer, architect or project leader, what would be your ideal job? Working in a big company, an editor, a start-up, self-employed, working in open-source, in a training company? At the office or at home? Part-time or full-time? What kind of industry would fulfil your dreams? Bank, insurance, telecommunications, industry, leisure? What would be the perfect allocation between development, management, training, publishing articles, working for open source, technology watch, learning new things? Or would you quit Java to move to .Net or a deserted island under the sun? While waiting for the magical wand to create the job of our dreams, let’s blog about it.

Read More →

Weblogic cluster life cycle

When you run a weblogic cluster you have to deal with several messages BEA-0001xx . It is then difficult to figure out what is the normal behavior of a cluster and the normal messages to get. Imagine two managed servers ClusterServer1 (listening on port 4001) and ClusterServer2 (port 4002) running on a cluster and sharing heartbeats through the multicast address […]

Read More →

Connection time out. Careful with your threads

Last week we had a bottle neck on our application and it took us several days to find it. So, here is what you should not do. The architecture is as followed : 2 Alteons to spread the load 2 reverse proxy a layer of Firewalls 2 HTTP compressors 4 web server iPlanet (Sun Java Web Server 6.0) a cluster of 40 Weblogic server running on 4 different boxes a database server. Everything running on HP-Ux11. iPlanet only dispatch static pages and images and Weblogic has the presentation (JSP/Servlet) and EJB layers (it does 99% of the work). The problem was that a lot of connections were falling on time out. We kept on focusing on weblogic and controlling the thread and memory activity to see if we had any dead lock of memory leek (there are some JNI calls somewhere). Weblogic wasn‘t doing anything, not under stressed at all. The application was configured to run 2000 concurent users that‘s why each instance of weblogic was running 60 threads (60 threads * 40 instance = 2400). After some days of analysing and twisting weblogic, we remembered that we had a layer of iPlanets on the front. The admin guys were sure that there was no problem with iPlanet because each server was supposed to run 512 threads. It wasn‘t the case. Each instance was configured with 128 thread (128*4 instance = 512). That was why weblogic was doing nothing and […]

Read More →

God is a .Net Programmer

Part of my company‘s job is to create tailored software for clients. They manage to deliver 5–6 a year and producing each one takes between 200–500 days. For the last 2 years they have developed around 80% using the .Net platform and the remaining 20% using Java. Last year I worked for 1 month with a .Net team trying to re-architect their software, but I gave up. Those guys didn‘t know what a Singleton was, nor a framework, nor even a package ! And because I didn‘t know anything about .Net (and still don‘t) I moved to do other things. The other day I was talking to one of the commercial guys and I asked him why my company wasn‘t putting any effort in trying to do more Java. The answer was quick and precise: “We realized that .Net software is 40% cheaper than Java“ (understand faster to develop for the same price). I was about to argue, bring the technical side, the big mistakes that I spotted during my little experience with .Net, talk about the Java community, the open source framework, the well designed architecture I‘ve worked with and so on. When I realized that he was a commercial guy, wearing a suit and a tie, I had the divine inspiration that made me reply: “God created the universe, the planet and Man in just 7 days. And you can see the mess. Imagine if he had 40% […]

Read More →