Java -making sure you have the right versions
Archive - Originally posted on "The Horse's Mouth" - 2015-02-02 22:34:22 - Graham Ellis"Java is a portable language" ... "The binary .class files will work across platform". And indeed they will - within limits. I was teaching Java earlier today, using a Linux operating system on one of our delegate machines, and this evening I'm writing up examples on my backroom laptop - a system that has lots of interesting stuff (!) loaded onto it, some of which is older versions. Alas, when I compile an updated example from today, this is what I got:
WomanWithCat:dvla_4 grahamellis$ javac Cornet.java
warning: ./WellHouseInput.class: major version 51 is newer than 50,
the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
1 warning
WomanWithCat:dvla_4 grahamellis$
What happened?
• If you compile a class with a particular compile version, you cannot use the .class file on another system with an earlier java compiler.
• Classes should only be run on systems witha JVM at least of the level of the compiler you have used.
In my case, I had tripped over the first of these - copying our training class WellHouseReader as a .class file as well as a .java file from my up-to-date delegate machine to my more mature backroom system. And the compiler grabbed that .class file to check my compile against, and grumbled.
Since I have all the source of the examples and my classes with me, the solution was simple - delete the .class files from the more recent compile and let my local java compile regererate them.
WomanWithCat:dvla_4 grahamellis$ rm *.class
WomanWithCat:dvla_4 grahamellis$ javac Cornet.java
WomanWithCat:dvla_4 grahamellis$
Whilst I need to update my Java on my own machine, it's not wise for me to do so via a mobile phone link tonight!
On all of our courses, we set exercises for delegates to try out to cement what we've taught. Sample answers are available on our web site for them to look back to after the course. From time to time, we'll update the examples and that's what I'm doing this evening - with some very early examples of array handling.
Sources updated:
Flute.java - [here]
Cornet.java - [here]