Category Archives: Java

Type safety

Consider the method findByDate that executes a query to find something by the year and month. One way of implementing this method in Java can be with two parameters year & month, both of type int. But this has some problems with passing valid arguments to methods and statically type checking.

public function findByDate(int year, int month) {
  // do stuff

Continue reading Type safety

Websockets in Java EE

With the JSR-356 spec websockets can be easily created and run within a Java EE container. I am using TomEE as a very lightweight and easy to install and deploy container but every Java EE 7 container should work, thanks to the EE specs.

I’m showing some easy to understand example of the Java POJO and some Javascript example code, together with some explanation about what is does and how it should work.
Continue reading Websockets in Java EE

OpenCL in Java

My first experiment with OpenCL was in XCode on Mac and I was wondering if there is also support for Java. My C/C++ skills are not what they used to be and I feel more comfortable with Java. Luckily there is a binding for Java which is called Javacl and I have tried to make the shortest working example to learn how OpenCL is working and how the library must be used. I’m sharing this example because I found that there are not many simple short examples.

At the end of the post you find the complete sourcecode I’ve used and I will describe the code in a few blocks to make clear what it does and why. You should be familiar with some of the OpenCL terminology, this helps in understanding the code.

Continue reading OpenCL in Java