Copy/Paste this bit of code and we will add some awesome functionality to your Java program.
Have you ever come across web sites making a similar claim ?
No. I don’t think so.
We, Java developers, don’t copy/paste bits of code.
Except for nudge4j, of course. But that’s the odd case.
Instead, web developers are quite used to this.
Web developers know that they can integrate functionality from third-parties by copying/pasting a tiny script into their HTML pages.
Some examples are:
It’s a great engineering work: by adding a few lines you end up with pages with conversations (disqus), with web analytics (google analytics) and with social buttons (addthis).
There is more to it: disabling/enabling the added functionality then becomes as easy as commenting/uncommenting their snippets of code.
In Java, we just don’t do it like that.
And, to be honest, there are clearly some good reasons.
Copy/Paste this bit of code and we will add some awesome functionality to your Java program.
Can we really try that ?
And how can we create the smallest snippet of Java code which adds whatever functionality to the JVM ?
Below is my attempt to write the tiniest, minimalest, claustrophobically spaceless snippet ever.
Copy/Paste this tiny bit of code (less-than-200-characters) and talk to your JVM from the browser on http://localhost:5050/
try{new javax.script.ScriptEngineManager().getEngineByName("js").eval("load('http://nudge4j.appspot.com/n/n4j.js')");}catch(Exception e){throw new RuntimeException(e);}
The less-than-200-characters-of-code is
Frankly, I don’t think you can get any shorter than that.
But I’d love to be proved wrong. Let me know if you can think of a shorter way.