Compiling Java Source File From Running Java Application

Did you know that you can compile Java source code from your running Java Application? It’s not even so hard and the JavaCompiler javadoc is quite verbose. Try it for yourself: package com.piotrnowicki.javacompiler; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; public class Executor { public static void main(String[] args) { JavaCompiler jcp = ToolProvider.getSystemJavaCompiler(); // Compile pointed *.java file jcp.run(null, null, null, "/home/piotr/MyClass.java"); } } Now imagine that you can compile your Java code from a Java application that compiles your Java code....

May 27, 2012 · 1 min

Playing movies and music over SSH

If you want to remotely access your SSH account (e.g. NAS in home) and listen to the music or watch some movies without downloading them in the first place, you can use the following command: ssh [email protected] cat mediaFile.avi | mplayer - It will connect to your.host.com, log into the user account, invoke the cat command on the given mediaFile.avi and transfer the output (stream of bytes) to your local mplayer....

May 27, 2012 · 1 min

After the GeeCON 2012

Whoa, those few days of GeeCON – Polish Java conference – just passed way too quick. A lot of great speakers, pretty good organisation and the overwhelming Java climate. Yep, it’s geeky or even nerdy but – what the hell – me like it! ;-) But for all of you who was not able to attend this conference – it consisted of 3 parts: University Day (1 day), Conference (2 days), Open Spaces with Bruce Eckel (1 day)....

May 23, 2012 · 12 min

After the Spring 3 Core Training

At the end of march 2012 I was attending a Spring 3 Core Training in Cracow which was organised by the SpringSource. Because I am more of a pure Java EE world type and mainly develop in this area, I wanted to improve my knowledge about Spring. Sure, I’ve used Spring, worked with it but never felt really comfortable with it. I was missing the big picture and so that’s why I decided to go to this training....

May 19, 2012 · 3 min

DWR -- Access Your Java Objects Directly From JavaScript

I must admit – I’m neither very experienced in the field of user interfaces nor really familiarised with all that JavaScript, jQuery stuff. I was always thinking of myself more as a service layer guy. Nevertheless, I wanted to improve my knowledge, so I decided to learn more about something called DWR (Direct Web Remoting). I’ve heard about it few years ago but never actually passed the “yeah, I’ve heard about it” stage....

May 11, 2012 · 7 min

BTrace -- a Simple Way to Instrument Running Java Applications

Sometimes you need to audit or profile your Java application. The easiest but most intrusive way to do this is to do a bunch of System.out.printlns (which is obviously bad) or to use loggers. After adding a lot of logging statements, your application becomes cluttered with unnecessary boilerplate code. Profiling, instrumentation or method measuring are great examples of cross-cutting concerns that might be nicely solved using AOP (Aspect Oriented Programming.) Basically, it allows you to invoke a certain action upon some defined conditions without the need for changing the instrumented code....

May 5, 2012 · 16 min

One Servlet Instance to Rule Them All...

I see a lot of people saying that: “there is only one instance of servlet per application”. Surely it gives you some information and knowing this will save you from a lot of strange, unexpected errors. However, the above statement is not very accurate and precise. It’s useful to know what is the actual contract between the web container and developer. Moreover, a lot of questions arise because of the multi-threading issues, so let me sum this up backing my words with Servlet 3....

April 30, 2012 · 2 min

Odd Colors in Ubuntu's Flash Player

After one of the Ubuntu 11.10 updates I was affected by some really weird colors in the embedded flash player. Basically, every movie looked similar to the one below (notice the dominance of the bluish color): The solution is to disable hardware acceleration in Flash Player settings (RMB -> Settings) just as shown here: After un-checking this option and refreshing the page all videos were back to normal: I’m not sure if I even want to know why one update could mess up so bad with the Flash Player....

April 28, 2012 · 1 min

To FEST or not to FEST?

When you write your unit tests you must use some kind of assertions. I think that most of you will agree with me on that the asserts that comes with the JUnit aren’t the easiest and most readable ones. So, some time ago I started to use a Hamcrest matcher library. It was a great progress, as I was able to move away from JUnit’s unintuitive: assertEquals(11.0, actual). I mean, if you try to read it out loud it doesn’t seem very logical:...

April 27, 2012 · 3 min

Content Assist With Static Imports in Eclipse

If you’re using Eclipse and working with a class with a lot of static members, you might be affected by the problem of lack of content assist and automatic import for such members. Let’s say you’re using a Hamcrest matchers; you need a is(), notNullValue(), hasEntry() and so on (there are plenty of those). You don’t want to type Matchers.hasEntry() every time you use it in your code. Hey, that’s not why the fluent API was invented in the first place!...

April 26, 2012 · 2 min