Listing a directory on the class path when it’s in a Jar archive

January 27, 2013 Leave a comment

Today I was revisiting an old memory game that I wrote almost seven years ago and I must admit that I was partly horrified by the code I have written back in the days. So I started to change small parts of it. For example I was loading a set of images from a directory on the class path, by generating the name of the image, like “card1.jpg”, “card2.jpg” and getting these via getClass().getResource(name). Now, as I was changing some images, and files happened to be “.jpg” and others “.png”, my old name-generator code failed. Not a good solution, I thought, and planned to load all files from a directory that would just contain card images – didn’t work as expected though, but I found a solution on the net, which I had to change a bit to make it work for me. Here’s the result that I’d like to share. Read more…

Categories: File handling Tags: , , ,

Dynamic proxies for classes

December 22, 2012 3 comments

If you have made your hobby a job, like I did, you have possibly seen your hobby die just like me. Because when you come home from work, you are likely to have seen enough code for a day. In such a situation a “be your own boss day” can be a delightful experience. Twice a year my company pays me a whole day to do whatever I like to do, given that I will report what I did. In the course of the past years, they say, the company has seen some interesting projects. I chose to devote some time to enhance my knowledge about the Java technology; more precisely I finally found the time to crack a nut that has been bugging me ever since I wrote the blog “Reflection without Strings”, more than two years ago: Dynamic Proxies for classes. Read more…

Into the Void: Refining Java beans with rare weapons

July 17, 2011 2 comments

Lately I’ve been experimenting with the Void class, because I asked myself what I could do with it that I haven’t yet thought about. I came across a use case that I’d like to share with you, because I think it is possible to beautify one’s code with it. In the process of slightly refactoring a Java bean in order to get a nicer, more refactoring-proof way of dealing with beans and reflection, I’m also using an inline-assignment in a way that you might already have come across, still I have hardly seen it anywhere in the wild, even though I find this particular use case for inline-assignments one of the best there is.
Read more…

Java actor framework “Kilim”: A solution without a problem?

November 26, 2010 3 comments

Some time ago I read a posting from a workmate, that was linking to an IBM developerworks article about the actor-framework “Kilim” and he seemed to be quite fond of it. Since I know this guy’s a very skilled technician and since actors are one of the bigger hypes in software technology nowadays, with languages like Scala openly supporting that concurrency model, and since the IBM developerworks articles are usually quite good, I instantly dived into it, only to be left perplexed. Read more…

Paint faster!

August 29, 2010 1 comment

It’s been a while since I came across this stuff and I already wrote about it on a company blog in the German language, but I thought this could be interesting enough for more people out there, so I’m sitting here translating what I wrote almost 2 years ago, keen on validating it with today’s Java Runtime. So what’s this fuzz about? Simply put: I noticed that you might have wasted a lot of time in swing, if you relied on the Graphics-object you get passed by Swing and the difference was dramatic!
Read more…

Categories: Swing Tags: , , ,

Reflection without Strings

August 9, 2010 4 comments

Sometimes reflection is very handy, but using reflection often involves referencing methods by Strings, which can get you into major trouble when you are refactoring your code. If a method belongs to an interface though, there is salvation. But let me first tell you how it started and what I did about it. Read more…

Hack of the day: Unchecking checked exceptions.

April 29, 2010 9 comments

In my last blog I announced to write something about some nice reflection magic, but it turned out that I got a little short on time, so that blog isn’t ready yet. But to keep you entertained I’d like to write something about a little hack I’ve found and instead of Reflection magic, you can read about some wild Generics magic. Not bad either, isn’t it? This hack is also really helpful! Read more…