For a project recently, I had the pleasure of working with both DBUtils and DBCP (Database Connection Pooling) from the Apache commons libraries. Both of these libraries together helped me to quickly create a simple, extensible DAO layer for my project. Both libraries include some great default features that I used right out of the box, without any configuration or fuss. In the post I’ll be talking about, and showing an example of using DBUtils. I will also show a quick and easy way to get a DataSource using DBCP.
Continue Reading »
Found this by accident and thought it was hilarious.
How to Pronounce “Subversion”
The 1.6 release of the JDK included a new java.io.Console class, which adds some new features to enhance and simplify command-line applications. Notably,
Console includes a method specifically for reading passwords that disables console echo and returns a
char array; both important for security.
Continue Reading »
I’m not sure why I haven’t ventured into the realm of web services before this week. It probably has a lot to do with time (or lack thereof) and the type of projects I’ve worked on. But, I finally got my feet wet this week. My employer asked me to create a web service that publishes a service that we currently offer via a JSP web application. As I found out, the back-end logic is unnecessarily complex. To complicate matters the app is written using old-style JSP that is inundated with scriptlets and scattered across many smaller pages which are included based on if-then logic within the scriptlets. Yeah, it’s a mess. So, I read up on XML Schema and WSDL formats and created a WSDL. I know a lot of frameworks create the WSDL for you based on your objects, but I’ve heard that the WSDL-first approach is better for interoperability across platforms. I used Apache Axis as the WS framework because that’s what our project already used to consume web services, I just found out we’re switching from Tomcat to WebLogic and using the WebLogic web service framework. Nice. Good thing I used the WSDL-first approach. Should be a snap to convert. We’ll see.
Here’s a quick and dirty way to do a shallow copy of an object by overriding the clone method of Object. If you want to do deep copying, you’ll have to fidget with this a little more…or maybe I’ll do another blog about doing recursive cloning for deep copying. We’ll see.
Continue Reading »
I can’t really think of a good reason why you’d want t send object data to std out (System.out), but I recently had a project requirement that a parent process read the output from a child process. The child process output was complex, so I wondered if I could send it as object data instead of text. I was told, “You can’t do that”, which is when I knew that I would find a way. Turns out, it was easier than expected. As you’ve probably guessed, sending text would be faster. I didn’t time it against sending text, so I don’t know by how much. If you time it, let me know your results.
Continue Reading »
Before adding Drag and Drop capabilities to my JTable, I read Java Tip 97 and Java Tip 114 from JavaWorld. They were fairly helpful, but I ended up doing things a little differently. In implementing my Drag and Drop JTree, however, I was plagued by a persistent exception: “InvalidDnDOperationException: Drag and drop in progress.” I debugged my code for hours before finally finding the source of the error. Somewhere along the line I had called
tree.setDragEnabled( true ), which is what caused the error. You will always get this error if you call
setDragEnabled ( true ) while also creating a DragSource using your JTree. My completed Drag and Drop enabled JTree can be found here if anyone is interested in using it. It contains a lot of other methods related to my specific project that you’ll have to wade through and remove. But if you focus on the Drag and Drop related methods, you’ll get the gist of how it’s done.
I started working on a news aggregator application as my semester project last month, but it has turned into much more than the simple RSS reader is started out as. It now reads all versions of RSS, RDF and Atom. I’ve also updated the GUI to have a nicer look and feel. Here’s are some screen captures.
There’s still some work to be done before ComputerFest contest in February, but it’s coming along nicely. I’ll be offering it for beta testing when I get all of the minimum features added. If you’re interested, check back in the next week or so and I should have something posted for download.
I’ve recently been extending my Java RSS/Atom feed reader to support more versions of RSS. In doing so I’ve discovered that the version history of RSS is a lot more complicated than I’d thought. One would assume that the version history was linear from 0.9 through 2.0, but one would be wrong. Versions 0.9, 0.91, 0.92, and 0.93 all follow the same branch, but version 1.0 forks from this branch to form it’s own specification that uses the
rdf namespace. And adding to the confusion, version 2.0 is a continuation of 0.93. (Here’s a good article with links to information about the history of RSS, the fork, and the Atom format.) As someone with no knowledge of this fork, I’ve looked through scores of RSS feeds, trying to reconcile the obvious differences in version formats. When I read about the fork, it finally made sense. Whew. But man, what a pain in the butt. I now have to write SAX parsers that read and validate all of these differeng standards. I guess it’s better than wriing an HTML parser!
Robert Eckstein writes:
The latest beta version of the Java 2 Platform Standard Edition 6.0 version (Mustang) now lets you access the system tray in Java with the help of two separate classes in the java.awt package: SystemTray and TrayIcon. These classes give you the ability to add graphics, popup menus, and floating tip functionality to the system tray. If approved by the JSR 270 Expert Group through the Java Community Process, you can expect to find this feature in the final version of Mustang.
Article here I’ve also recently tried the built-in splash screen API that Mustang will ship with. Pretty nifty.