Why Java?

I was recently asked, why Java? It’s a great question – exactly why do I choose to learn the Java language?

I gave it some thought and I’ll share what I considered. I’m certainly not saying that what follows is a justification of the Java language in any general context, nor am I any kind of expert. This is just my view, given my circumstances.

It’s Free!

If you want to learn a language you don’t want to be laying out pots of cash up front. It’s likely you’ve got a Java Virtual Machine on your computer right now, and obtaining a development kit to get you started writing software is free and straightforward. Win.

The Java Virtual Machine

You never know when you might need to run that little app you wrote on a Windows host, or a different flavour of UNIX, or even a big ol’ IBM mainframe system – it’s nice to have some confidence that it’s just going to work.

Now, the JVM runs on any platform I can think of. Perhaps in the early days, there was some divergence in different platform implementations of Java (having felt the pain of the slight non-standard nature of the Micro$oft JVM in IE some time ago!) which somewhat hampered the cross-platform claim, these days there’s a suite of compliance tests that a JVM implementation must pass to brand itself Java compatible. That means that I don’t have to worry too much about cross-platform compatibility.

The JVM supports more than just the Java language. Jython, JRuby, Scala, JavaFX, Groovy, Fortress, Clojure… the list is getting ever longer, and there’s even a JVM Languages Summit. So, if you’re using the Java language and find a problem that better solved in another language, it’s perhaps not such a huge leap to get your Java code and your new JRuby code working together. Tim Bray wrote up some nice notes on the language summit here if you’re looking for a little more.

The other trick about the JVM is that your code gets better without you changing it. As new JVMs are released, they include the latest, hottest optimizations that take the software you write and give it go-faster stripes.

Tools and Platforms

Tool support for the Java language is extensive enough that there is generally a choice – for example, there is a choice of many Integrated Development Environments (Eclipse, NetBeans, IntelliJ IDEA to name but three) in which to write your software.

If you’re building ‘Enterprise’ software (whatever that really means!) you have a choice of application servers (WebSphere, JBoss, Jetty, Tomcat, GlassFish…) that all implement the Java Enterprise Edition specification in whole or in part (for example, the open source Tomcat application server supports a stripped-down subset of the spec) you know that any of the application servers should run your software.

With all these things the choices mean that I can choose the implementation with the right strengths and at the right price point for the project in hand.

Learning

Java’s got a lot going for it as a learning language – it seems to be on the syllabus for most computer science degrees. There’s a wealth of online material available for free, including Sun’s own learning trails and Sang Shin’s excellent javapassion.com learning site.

I know that the question of value in professional certification seems to polarize opinion, but there certainly is a certification trail in the Java language that’s not trivial to achieve.

The cost of achieving these certifications is financially quite insignificant, but (certainly for me – I’m sure there’s folks that find this stuff easier) demands a significant amount of time and commitment. The objectives and exam questions are put together by teams of Sun engineers, Java developers and Java instructors, orchestrated by Sun. (Thanks to Bert Bates and javaranch.com for that info!)

Having done a couple of certs myself, I found them to be a very useful useful guided tour of the language and its extensions. I found plenty of useful features and techniques whilst studying that have since steered me clear of errors and wasted time.

The JCP and Standards

New APIs for the Java language happen through the JCP, or Java Community Process. Everyone from from individuals to the largest IT players (IBM, Cisco Systems, Nokia – the members are listed here) are involved, and new standards happen in a publicly visible process of proposal and review.

Don’t believe me? Here’s the latest Java Enterprise Edition spec. See those JSR numbers? They’re the specifications that have been developed, reviewed and approved as part of the JCP.

Libraries

There’s sometimes so much choice of open source Java libraries, it’s hard to know what to choose for a given problem. The Apache Software Foundation hosts loads of open source Java projects, as does Google Code and java.net.

Not that every library is a piece of awesome… but many are. Having lots of choice increases the chances there’ll be something out there that’s already been built and tested and fits the bill. The libraries and APIs I have to use with my language of choice to get things done make a big impact to my productivity.

What – No Discussion of Technical Stuff?

Nope. I reckon it’s rather pointless to try and discuss differences between the capabilities of one language versus another. Anything computable can be computed in any Turing-complete language, which I think covers any language you might seriously approach as a general purpose problem solving platform.

So it’s not about what can or can’t be done – it’s really about what language I can be most effective and productive in. The biggest productivity killer in Java seems to be the boilerplate code necessary to do simple things, but over the last couple of years, strides forward have been made with annotations, for example, to reduce the boilerplate problem.

That’s All Folks

That’s about it, really. There’s plenty of other languages that can lay claim to some of the points I’ve made, but few that can claim them all.

There are other languages I choose for specific jobs (JavaScript for client-side behaviour in web browsers, PERL for sysadmin-type scripts) but my day to day workhorse, and the focus of my learning attention, is Java. For now, at least.

If I’ve missed anything or you disagree, feel free to drop me a comment!

Machine Learning – After the Project

My project for machine learning got handed in on time. It took hours to strip it down from the 8 pages I had when I’d finished to the 6 pages the spec asked for. Careful stripping out of any unnecessary waffle and merging of plots and charts was the order of the day.

I ended up scaling back my plans to explore text mining or ensemble learning to a simple comparison of some of the learning algorithms we learnt about on the course, with some exploration of slightly more advanced statistical comparison methods than we covered. The thinking was that it’d be better to try and demonstrate sound understanding of the basic algorithms and the experimental method – time will tell whether that was the right call.

Unlike how I used to do this kind of work when I was an undergraduate (start with a couple of days to go to deadline), this time I used most of the three weeks allowed to explore the options, work on the software, gather results and produce the paper. Hopefully, the work will show in the result, but I suspect it’s more a case of getting the approach right to minimise the time taken figuring out what to do.

But I guess it’s another example of work expanding to fill the time allowed!

Machine Learning – Day 5

So that’s the end of the taught course in Machine Learning, finishing up learning about Markov Chains and Hidden Markov Models.

Yep, those are just links to the Wikipedia articles, and it’s quite possible that if you clicked on them and you’re anything like me, the crazy-looking maths stuff at the other end made the sensible part of your brain run off and sit in a corner, clutching its knees and rocking gently back and forth.

Probably muttering to itself.

To be honest, I can’t really explain what this stuff is about just yet – I’ve had a lot crammed into my head over the past few weeks, and I think I need a really good night’s sleep before I can comprehend the deeper aspects of this last bit. Suffice to say for now that it seems like some really interesting and powerful ideas are in play, and when I’ve got my head round it I’ll blog up my thoughts.

I’ve now got one more homework assignment on today’s material to complete by next Wednesday, and the project we’ve been assigned to do is then due on Friday 6th November – a nice surprise, as a typo on the schedule had us believe it was due on the previous Tuesday.

I’m sorry the taught part of the course is done, to be honest. Although I’m not sure I could have taken any more at the pace it was being taught, I’ve thoroughly enjoyed the material.

In fact, I’d say I feel a little inspired.

And, as James Brown might say – it feels good.

Machine Learning – Day 4

Day 4 covered methods of automatically identifying clusters in data – and some of the issues that arise using those techniques.

Doing this automatic identification is called unsupervised learning, because it doesn’t depend on having a set of labelled data examples to hand. The learning is done purely based on the statistical and probabilistic properties of the data itself.

I got to say, I’m struggling with the probablistic side of things – my intuition isn’t helping me much, so I’ve been doing the books thing to try and really get my head round it. So little time…

We also covered some techniques involving reducing the dimensionality of data – say a dataset has a thousand properties, and the computational overhead of processing increases with the number of properties. You’ll need some way of reducing the number of properties, whilst retaining the maximal information they encoded. We were looking at selecting features a couple of weeks ago, but today we looked at PCA – Principle Component Analysis, a technique to ‘project’ information into a smaller number of dimensions, or properties.

I quite like this paper on PCA, if you’re looking for somewhere to get an idea what it’s about.

And that, if you were reading this blog a few weeks ago, is where the eigenvalues and eigenvectors come in.

We also have a project to complete in the next couple of weeks, so time is very much of the essence right now. I suspect that as with the Semi-Structured Data and the Web course last year, the deeper concepts behind some of this material will only become clear to me when I’ve completed the set material and start to work on the revision of what we’ve covered.

Back in the day, revision was time off between lessons and exams – these days, not so much!

Machine Learning – Day 3

Getting through the coursework was a challenge – my computers have never worked so hard.

The last section involved performing a computation over a data set that took a few seconds per run to exhaustively search for the optimal settings for two parameters in the computation’s algorithm. Searching over 25 possible settings doesn’t sound like a lot, but two of ’em means 625 runs – times a few seconds is quite a wait.

Oh, wait – there was also a requirement to randomly shuffle the input data for the algorithm ten times and do some simple stats, to give some chance of reducing potential bias brought about by the order in which the data appears in the data set. So that’d be 10 runs per pair of parameter settings, which is 6250 runs. Or several hours with a CPU core maxed out and a nice, toasty computer.

But hey. I got some neat 3-d mesh plots out of it, showing the performance of the algorithm over the parameter search space. Proper science, this! Sure it has faults, but Matlab’s plotting functionality is pretty neat and easy to use. Plots like the following are a doddle:

Matlab 3D Plot

Figure 1. Gratuitous use of a 3D plot for fun and profit

The goal of the exercise was to identify the most relevant ‘features’ in the data set for assigning the data into an appropriate class. Imagine you had a big table of information about a set of people, where the first column (could call it ‘Feature 1’)  was their heights, the second was the time of day the height was measured, and you were trying to predict their sex. You and I would guess that height would be a good indicator of sex and the time of day would be irrelevant, but we’d be cheating by applying information about the meaning of the data that exists in our heads and wasn’t supplied with the problem.

By applying a variety methods to our table of data, a computer might be able to recognise relationships between the features and what we’re trying to predict, without knowing anything else about the information. In doing, it could remove the features that do not appear to have any relationship and save the computational effort and time that would otherwise be spent processing useless data. The approaches that can be applied are various, and some degree of tuning needs to be applied to to ensure that removing features doesn’t compromise the goal in subtle ways.

Today’s lectures moved on to machine learning techniques using the perplexing mathematics of probability (perplexing for my tiny brain, at any rate), in preparation for the last two weeks where unsupervised learning is the order of the day. The usual lab afternoon was focussed on kicking off a three week project involving applying the techniques we’re learning to do something with bunch of data in the style of a research paper.

Time to polish up the LaTeX from last year then…

Machine Learning – Day 2

Day 2 of the Machine Learning MSc module at Manchester saw us learning about Decision Trees and the role that entropy, linear correlation and mutual information can play.

It’s all about categorical data (like name, a set of fixed values), whereas last week was about the automated classification of continuous data (like temperature, a smooth range of values). The algorithms we were looking at to automatically build decision trees using the inherent statistical and probabilistic properties of a set of data to try and maximise the decision accuracy with the minimum overhead of computation and memory.

Today’s stuff didn’t seem too tricky, and last week’s lab assessment went pretty well.

This week, we need to use the mi() and h() fuctions from the a Matlab Mutual Information library here. Sounds great, but – I’m getting problems using it referring to undefined symbols that may be related to the 64-bit OS on this machine, so I’ll need to try a few options to work around that. Need to get that working!

Well, it’s been a long day so I’ll call a close here. Cheers!

Machine Learning – Day 1

So I made it in on time for the first day of my Machine Learning course. The train was fantastic, particularly in comparison to the tiny cattle carriage that I ended up last Wednesday. Tip of the day – even on the same routes, not all trains are equal!

After the usual stop at the butty shop for a sausage and egg sandwich plus a coffee, I was in room 2.15 and ready for action.

So what’s Machine Learning then? Sounds very Skynet and The Matrix, doesn’t it? Dr. Gavin Brown started out explaining how ML is a subset of the field of Artificial Intelligence, which focuses on software that can analyse and adapt to the underlying patterns in the information it sees.

Other areas under the AI banner include reasoning, robotics and vision, to name but a few. This breakdown of the big, amorphous ‘thinking machines’ field as it was in the 60s into these sub-areas is why we have made huge leaps forward in the field since the past couple of decades.

What progress? Today, Machine Learning technology finds use everywhere – some examples are the Amazon online store (selecting your recommended stuff), tuning computer games, filtering spam emails and fraud detection in banking. If you’d like to know more about the motivation behind studying this stuff, you can check out these introductory slides.

The format for this module is very different to the Semi-Structured Data and the Web module. It’s still every Tuesday for five weeks, but there are no full days of lectures. Instead , the mornings are lectures and the afternoons are lab sessions.

Assessment is also different – there’s still an exam, but the coursework consists of assessed verbal lab reports for 20% and a project for 30%. The exam counts 50%. Whereas in the last module, we were assigned to groups of two and much of the coursework was largely joint in nature, this time it’s all individual work.

The labs use a matrix-based programming language called Matlab. Takes a bit of getting used to, but usable enough when you start to get the hang of it.

Day 1 covered terminology, the ‘Perceptron’ algorithm (will find a dividing line between two classes of data, if one exists) and Support Vector Machines (tries to find the ‘best’ such line, using hairy maths). If you’re interested in knowing more, Googling for ‘Machine Learning’ and these terms will find papers, communities and video talks and lectures. It looks like a really active area of research.

I get the feeling the focus is to be on understanding what’s going on more than any implementation details. That’s a good and a bad thing for me – I know implementation, and you can largely tell if you’ve got an implementation functionally correct by whether it does what it’s supposed to do.

This time it might be a bit less clear cut whether I’m right or wrong before I get to the assessment phase!

Matlab from the Ubuntu Menu

Getting stuff to work from the Ubuntu Menu is pretty straightforward, but I ran into some little problems that confused me with Matlab. This post goes through the steps and difficulties I had, which might be useful in general, not just in relation to Matlab.

First up, I installed the Student Edition of Matlab (currently R2009a and a steal at the student price), taking into account the fact that I’m running a 64-bit OS and the student edition doesn’t come with the 64-bit architecture libraries. Pretty confusing on first install as the installer detects the architecture but then can’t find the libs, but corrected using this guidance on the Mathworks website.

Once you’ve done that, you need to pass the argument ‘-glnx86’ to Matlab every time you start it up.

That’s a pain, plus the other boilerplate to run it in the background – so I tried to set up a menu option using ‘Main Menu’, which is the relevant administrative tool that comes with Ubuntu. It’s in System – Preferences – Main Menu if you’ve not used it before. Here’s a screenshot of it, set up with a Matlab launcher.


Main Menu with Matlab

The obvious thing is to give Main Menu the command that works from the command prompt, but no. Doing this results is strange behaviour where the splash screen fires up, disappears, and nothing. Checking the .xsession-errors log file in my home directory shows what’s happening. The application is launching in command line mode, writing its prompt to stdout, and then being shut down.

Kinda weird, maybe, as launching the app from the command line launches the Matlab GUI. Anyway, you also need to also add a ‘-desktop’ argument to the launcher command. My Matlab is installed in /opt/matlab, remember to change the path as appropriate for you.


The Matlab Launcher

You can also add the icon if you want by clicking where the Matlab icon is shown above, browsing to wherever you installed Matlab then into the ‘X11/icons’ directory, where you’ll find a number of icons.

Now you can launch the program from Main Menu, or drag-dropping it onto a panel, onto your desktop – wherever you like.

Induction Week 2009

Before each academic year, there’s ‘Induction Week’, where alongside the orientation stuff going on for the new students, the academics running the courses sell their wares to the students who’ve signed up to do an MSc. There’s a choice of 25-odd courses which seem to cluster around formal methods, artificial intelligence, high performance computing and the semantic web.

This year, I’ve saved up a few days’ holiday to let me attend the Wednesday and Thursday, when the course talks are going on. It also lets me sort out library books, admin stuff and the like. The 05:45 starts to get to Manchester on time are painful, mind.

I’ve transferred most of the introductory talks I was interested in seeing to my Google Calendar, so that I had my agenda for the day on my phone. That saved me potentially missing anything I wanted to see without me having to sit in the same room all day. In theory anyone who’s interested in what’s going on should be able to view my MSc calendar here. I haven’t tried to give out links to a personal public Google calendar before though, so let me know if you want to look and it doesn’t work.

It certainly felt very different this year from last. Knowing where everything is and seeing a few friendly faces makes everything much easier and more comfortable.

As for the courses, I confirmed what I want to study this year, so it’s time to get stuck into maths and Matlab ready for Machine Learning, which starts on Tuesday.