Java Application Examples Blog

Ok, so I went to uni, and in uni they are big about plagiarism.  Not big in the sense they promote it, but big in that if you do it, you may as well consider yourself chemically castrated with no hope for a career in <chosen field> or especially academia ever again.

Uni made me wary of copying work.  It frustrated me to see other students copy assignments the night before something was due.  If you weren’t working something out yourself, you were missing out on the richness of the experience of, well, learning what the assignment was supposed to teach you. 

All this, work it out yourself, got turned on its head when I entered the professional programmer world.  Mentors advised to read as many code samples as possible, it will help you learn.  And whilst code samples aren’t necessarily cheating, and using this code in your own work provided you cite it and the license permits, should also be ok, it took a long time to get away from the stigma obtained during my time at uni…. which really when you think about people who further their academic careers by way of research papers that require you to reference other peoples work, is a really dumb stigma to get across.  I put it down to the plagiarism fear engulfing what should be best practice in normal circumstances.

So with that guilt trip swept away, there was a great blog: Top 5 Websites for Java Application Examples which referenced Java2s, Java DB, and Java Galaxy.  All sites that have come up in my Google searches before when I’ve lapsed my memory and forgotten the trivial convert something to a byte array or whatever other simplistic, seldom used, grassroots technique.

Whilst you cant be taught on these alone, the fact that they support you when you are the most stressed and your memory works its least efficient means I have no problem in recommending these sites 🙂

Building Java Applications with Windows Azure

Looking for a place to host my own home grown apps, I came across an interesting presentation about using Windows Azure cloud to run Tomcat and a JVM in the Microsoft cloud solution. See Building Java Applications with Windows Azure

The presentation basically says Azure can run any native code, which means java.exe and tomcat.  Native programs that runs off a batch file with no specific registry key or lowlevel system dependencies or installers are more likely to run in Azure.

Azure has worker roles and web roles.  Web roles are used for hosted apps with .net/php and IIS and not used here, however the worker role is used to run native code.  It can be bound to a network port (ie port 80)

The Microsoft support comes in with an Eclipse plugin to access your resources in the cloud from within Eclipse.  There is a jar that wraps up the RESTful interface to Azure that your app would normally use to access the clouds resources with Java helper classes and provides some other .NET helper classes.

It also comes with some helper stuff to setup Tomcat – ‘Tomcat Solution Accelerator’ – to configure Tomcat to make it very light in terms of OS dependencies.  It also has monitoring of Tomcat to let Azure know to restart the app if it fails and also help indicate to MS there is a problem with the particular server that instance in their cloud is perhaps not working as it should.

I do like that you get to choose the versions of Tomcat and Java you want, and there doesn’t seem to be much of a reason you couldn’t apply this to other languages and appserver environments.  (Grails/Jetty? – and hopefully Glassfish, but that may need a bit more config work to pack it up and install on the cloud).  That last point sounds a bit negative, you could probably get a service on a VM linux host that means you dont have to fudge around so much, but still the novelty polyglot value of having JVM and .NET in the same cloud environment may actually outweigh the negative of the DIY setup.  The presentation explains how the Tomcat is packaged and shows the contents of the packaging scripts to give you an understanding of how to do the same for another appserver.

One nice thing about the Azure platform itself is that you have production and staging slots – you can have a production app in the cloud, and also a staging version too – and swap them over when you are happy with Staging.

The other aspect is the queues/worker facility to allow for concurrency when running your app across multiple nodes, asynchronous architectures and scalability.

To try it out, you’ll get free access to Azure while its in CTP status (till Jan 09), and then MS will start asking for money. Apparently, Dominoes pizza is testing out their next version of their ordering webapp on the platform, if you wanted a vote of confidence too

Azure Java SDK available here: windowsazure4j.org

Key Promoter for IDEA

This is one of the best plugins that I’ve come across in IDEA.  It simply pops up an unobtrusive window every time you do something with the mouse, that has an equivalent keyboard shortcut to remind you how you can get to that action quicker.  This means you can become more productive.

An even better feature though is that if you use an action that doesn’t have a keyboard binding, after about 3 times of using an action it will ask you if you’d like to set one and take you to the preferences dialog (I’ve configured mine down to 2)

Speaking of plugins, Thoughtworks Neal Ford has a neat presentation online about some of the most useful plugins in Idea and Eclipse.  There were a couple in particular I wasnt aware of

CTRL+E – Open recent files list – This makes using tabs redundant.  A small popup list of files you’ve recently looked at for you to choose using, regardless of if they are appear on the tab bar, you closed or IntelliJ took the liberty of closing for you because you’ve exceeded the default 7 tab limit (super annoying coming from Eclipse, BTW)

ALT+SHIFT+CTRL+N – Symbol lookup (aka CTRL+N on roids) – Find a symbol (variable, method name, whatever) in any file.  Obviously slower than CTRL+N since it has more to look through, but a zillion times efficient than opening the Find dialog and navigating its controls.  BTW, Eclipse has CTRL+O, but from memory, that only looked in the currently edited file only.

Some Groovy Little Tips

My favourite Groovy/Java/IntelliJ web presenter, Vaclav Pech, has a short 20min Parleys talk on using Groovy with IntelliJ.

What I found neat was IntelliJ’s ability to take a Java class, rename it as a Groovy one, then refactor all the annonymous inner classes.  I also learnt about the capabilities of Groovy, the part where a class gets defined as a Map.  Wonderful stuff.

Also neat, was showing how refactorings apply not only to Groovy and Java, but also to Scala code in the same project.

http://beta.parleys.com/#state=state_player&slide=7&id=354

JVM garbage collection behaviour on virtual machines

Interesting blog about how multiple virtual machines running on the same metal, each with their own JVM instances performing garbage collection can degrade app performance when the hypervisor has to swap out memory

http://www.devwebsphere.com/devwebsphere/2009/08/why-you-shouldnt-overcommit-memory-on-virtualized-servers-running-java.html

Given at work, we will be switching platforms so everything is moving to the supposedly common good of redundancy that virtualisation provides, its worth noting.  I wonder if the new G1 garbage collector is any different, or if staying on Solaris with its Sun/Java roots and using zones instead manage this any differently?

Because I don’t use a social bookmarking service…

Nothing against them, but my blog is the most useful thing at present to record interesting sites that I may or may not read later.

To have hope that Scala can work in the enterprise: The Book Of JOSH – but more so to feel the state of where Java is.  Also the comments form a point of very interesting discussion.

To increase learnings in Spring through the use of a purpose built (Eclipse based) IDE: SpringSource Tool Suite

To learn Maven through all lessons learnt by others: Five tips for successfully deploying Maven

Want AJAX, why not try GWT?

GWT or Google Web Toolkit, is a platform that lets Java developers write Java apps and have them compiled in native javascript to run in the browser.  There are a lot of neat optimisations and support for RPC.  Although I’ve heard about GWT many times before, this article made things crystal clear.