java

Jakarta Commons DBCP Tutorial

A quick code preview showing working example of using one of the best-performing JDBC connection pools in Java.


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;

-- snippet --


        Connection conn = null; PreparedStatement p_stmt = null;

        try {
            conn = ConnectionManager.ds.getConnection();

            p_stmt =  conn.prepareStatement(
            	"INSERT INTO articles (text,url,content) VALUES (?,?,?)");
            p_stmt.setBytes(1, (new String("jsdhgkdjshgkjdshkg")).
            	getBytes("UTF8") );
            p_stmt.setString(2, "http://dsfsfsfdsfdsfda");
            p_stmt.setBytes(3, (new String("aadada")).getBytes("UTF8") );

            p_stmt.executeUpdate();
        }  catch(Exception e) {
                LOG.debug("Failed to execute a JDBC task: ", e );
            } finally {
                try {
                    p_stmt.close();
                    conn.close();
                }  catch ( Exception ex) {
                    LOG.error ( "Failed to finalize JDBC task: ", ex );
                }
            }

-- snippet --

Mobile Computing, The iPhone Way

The confusion is over - Apple revealed the secrets of creating slick iPhone applications.

When Apple announced iPhone in January, this year, the shocking news and the source of much speculation became the alleged lack of third-party application support. An intelligent cellphone without Java/J2ME was so unusual that for a long while it gave Apple-haters a thing to wave in front of everybody's face and left Apple-lovers confused and curious for what it really meant.

The first clarification came during the Steve Jobs's WWDC keynote on June 11th and once again proved how risky it is for mediocre minds to challenge the design decisions of the Cupertino-based centre of innovation excellence. The message was quite short and ambiguous, yet loud and telling: the future of the mobile applications, as Apple saw it, were Web applications.

SOA In Buzz-Word Laden Prose

SOA is probably the most overused/abused buzzword. I would say even more so than AJAX - which is scary, really. It's also funny how "SOA experts" can make the subject even blurrier.

That was the subject of the conversation between Doug and I, recently that I am quoting below. We were discussing a recent SOA article. Nothing too serious, just fun.

irakli: Got a minute?
dharris: sure
irakli: Trying to catch a blasphemy in this: http://www.theserverside.com/tt/articles/article.tss?l=ChurchandState

Breakthrough: Java Implementation of PHP5

According to Caucho, you can run Drupal in Java now.

Following is the excerpt from Quercus website:

"Quercus is Caucho Technology's 100% Java implementation of PHP 5 released under the Open Source GPL license. Quercus comes with many PHP modules and extensions like PDF, PDO, MySQL, and JSON. Quercus allows for tight integration of Java services with PHP scripts, so using PHP with JMS or Grails is a quick and painless endeavor.

With Quercus, PHP applications automatically take advantage of Java application server features just as connection pooling and clustered sessions.

Quercus implements PHP 5 and a growing list of PHP extensions including APC, iconv, GD, gettext, JSON, MySQL, Oracle, PDF, and Postgres. Many popular PHP application will run as well as, if not better, than the standard PHP interpreter straight out of the box. The growing list of PHP software certified running on Quercus includes DokuWiki, Drupal, Gallery2, Joomla, Mambo, Mantis, MediaWiki, Phorum, phpBB, phpMyAdmin, PHP-Nuke, Wordpress and XOOPS."

This is very impressive. I am going to try installing Drupal over Quercus soon and share the experience.

Incorrect Date Formatting in Sun JDK 1.5 Russian Locale Implementation

Even though Russian is one of the few languages i can speak and I have worked on both the internationalization of Web applications, as well as Java quite a lot, in the past, particular problem of Russian i18N has never come to my attention. That is - until now.

Unfortunately, I was unpleasantly surprised as soon as I touched it - Sun JDK 1.5.x does not format dates correctly with Russian Locale.

The deal with Russian language is that month names have different suffix when they are presented stand-alone (i.e. in a list or smth) and yet another one when they are part of a formatted date. So, even though March is "Март" in Russian, correctly formatted today's date would be: "7 Марта 2007 г."

Let's see how JDK fortmats today's date: 7 Март 2007 г. Clearly wrong.

It's very sad. No matter how you feel about it, Russian is one of the major languages and Sun could have put enough effort to get it right.

Below is the test JSP code:

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>

<HTML>
<head>
  

Marc Fleury Quits JBoss

The biggest news of the day, in the tech industry, is that Marc Fleury has quit JBoss/RedHat. Honestly, I do not think there is much to say about this fact. As soon as RedHat acquired JBoss many of us knew it would happen, because of how unfitting Fleury's personality is in a culture like RedHat.

I will just say that I hope Marc will prove himself for the entrepreneurial visionary he has been marketing himself as and will start something new with the money he collected. I would presume "new" would be something in more agile arena: Ruby On Rails, Drupal, Ajax are first things that come to mind.

I really hope he does. It would be interesting.

Exception Handling and the Chain of Responsibility Design Pattern

Developers often compain about explicit Exceptions, especially in a strongly typed language like Java, and how much real estate handling those takes up in source code.

I have seen approaches when people try to avoid java.lang.Exception and fall back to java.lang.RuntimeException for most cases. Is that a good thing to do? RuntimeException is a valid choice for certain cases but overusing it beats the whole idea of exception-handling, really.

As part of my responsibilites as a software architect, I get to review code of many developers. I think the problem, in most cases, is incorrect usage of exception-handling. More specificly, developers overdo with catching exceptions at the lowest level - at the same spot they expect exception to be fired. Passing it up the class hierarchy is often needed but not done. It is especially true in the case of more junior developers (however, you quickly find out that many "senior" developers are vulnarable, as well).

BEA Weblogic on OS X

Following are detailed instructions for installing Weblogic 9.1 on OS X Panther.

Download AIX version of Weblogic 9.1 (AIX as that's the generic version of WebLogic, in fact). You can download it from:http://commerce.bea.com/showproduct.jsp?family=WLS&major;=9.1&minor;=0

Run the installation with the following command:
java -Dos.name=unix -jar server910_generic.jar

it's crucial to indicate os.name parameter. Otherwise, installer will complain about insufficient disk space.

At the end of installation you will be asked whether to run QuickStart. I recommend not to, as it hung on me.

In any case, you need to create a new weblogic domain, first by running:
~/bea/weblogic91/common/bin/config.sh

Domain creator will ask about JDK. It actually manages to find Apple's one but in case that fails, indicate the following path:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

To run the server, go to the following directory from Terminal:
~/bea/user_projects/domains/<domain_name>
e.g. if your domain name is "base_domain" then go to:
~/bea/user_projects/domains/base_domain

and then run:

How Many Microseconds are there in a Nanosecond?

Do you know how many microseconds are there in a nanosecond? You thought it was 10-3, eh? Heh, think twice and no, I have not gone nuts. At least, not yet. Read on.

More seriously, what am I ranting about, here? Time precision in Java, is the topic.

Today, I needed to profile a process which takes less than a millisecond (10-3 seconds). Up to and including JDK 1.4 the precision of Java time used to be order of a millisecond and for anything more precise you were pointed to JNI, which is a nasty place to be pointed to, let me say. Fortunately enough JDK 5 has added System.nanoTime() method and Sun has honestly implemented it in its JDK. Thanks a lot to Sun, for that but - hold the excitement, for a second.

Does this method really give the precision of a nanosecond? Let's check it (using a tuned version of the code from Vladimir Roubtsov):

IntelliJ Rocks on iMac Core Duo

One of the major reasons I got iMac Core Duo was the Split Personality I was starting to develop having to chose between my most favorite "toys": PowerBook G4 and IntelliJ IDEA. While Mac is the only worthwhile computer, to me, and I really enjoy the mobility of a PowerBook, I have recently gotten addicted to IntelliJ\'s awesome Java IDE and can not imagine developing anything in Java without it.

The catch is - IntelliJ IDEA does not really work on a PowerBook G4. Let me be more specific: it is so slow, it is useless for any practical use. Now, whoever\'s fault it is - that\'s the fact and it was really poisoning my PowerBook experience.

Since I am a Java hacker, most of the time, you get an idea how serious my clinical condition was getting.

Long story told short - I have been using IntelliJ on my new iMac Core Duo, for a while now, and I am delighted. Works flawlessly and gives an absolute best experience for Java development. And, oh, yeah - I think I have less of Split Personality, now :)

P.S.

Syndicate content