Skip to content

Tag Archives: java

Enforcing Fluent API adherence using Interfaces in Java

07-Jul-11

This some considerable noise on the internet about Fluent APIs and using them. There was a question on stackoverflow.com about how to enforce calling all the required methods to guarantee you fully materialize an object when using a Builder Pattern with a Fluent API approach. The appropriate way to achieve this is through Interfaces that [...]

A Generic Object Oriented replacement for large Switch / Case and If / Else statements in Java

22-Feb-11

I saw this post on StackOverflow and thought I would whip up a quick Object Oriented solution using Generics using the Chain of Responsibility Pattern. This was a quick exercise to see how it might look. There are many other ways that this could be implemented, like using Dependency Injection to supply the implementations of [...]

Reading data from a file on the classpath in Java

22-Feb-11

Sometimes you want to load data at runtime from inside a .jar file or .war file to populate at List or Map or something. Here is how to do that easily. Just make sure that your data file is in the same package along side the Class that is loading it, or refer to it [...]

Working Maven 3 Google App Engine Plugin with GWT support.

06-Feb-11

I spent a great deal of time getting this to work. I could not find a single source of information on what all the needed dependencies and repositories were, so there was a lot of trial and error involved. This first version is configured for GAE 1.4.0 and GWT 2.1.1, the latest versions at the [...]

How to install the Offical Oracle JDK on Centos 5.5 and add select it as the default JDK

02-Nov-10

Here’s the command to install an alternative installation of Java: I installed JDK 6u22 from the executable rpm.bin file from the Oracle site. Then I ran this command to add it to the alternatives program. alternatives –install /usr/bin/java java /usr/java/jdk1.6.0_22/bin/java 99 then you just run alternatives –config java There are 3 programs which provide ‘java’. [...]

Migrating Java Projects to Maven 2

13-Jul-10

Looks like Maven 2 is pretty much inline with the generic Ant based build system I have been using for the past 8 years. So I am going to take the plunge and start using Maven 2 so I don’t have to keep maintaining my system. Less time maintaining a build system means more time [...]

How to determine how many threads you can create from Java

19-May-10

I was getting Out of Memory Error: can’t create native thread errors on a server, and it was definately not running out of memory, so I hacked this little program together to tell me how many threads I should be able to create. 64K is the minimum stack size that Java will allow on an [...]

Send Messages to Glassfish JMS Queue from External Application

07-Jan-10

Here is a basic class to connect to a Glassfish 2.1.x JMS Queue from a command line client. You need the following .jar files in your CLASSPATH for the code below to work. …/glassfish/imq/lib/imq.jar …/glassfish/imq/lib/imqutil.jar …/glassfish/imq/lib/jms.jar …/glassfish/lib/appserv-admin.jar …/glassfish/lib/appserv-rt.jar …/glassfish/lib/j2ee.jar …/glassfish/lib/javaee.jar import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.Properties; public class Main {     public [...]

Ternary Like Operation in Erlang

02-Dec-09

I have to parse the TXT records from DNS responses for my inet_mdns project. The valid key values pairs look like one of the following three formats: “key=value” “key=” ( key with an empty/no value ) “key” means the same thing as “key=true” so in Java I would write something like. public String processKeyValue(final String [...]

Disable default Java DNS caching

30-Nov-09

By default Java 1.6 caches DNS queries, either forever if there is a security manager installed or for an implementation specific period if there is no security manager installed. There are two ways to disable this behavior which breaks things like load balancers that do DNS load balancing. first you can disable it by adding [...]