Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motivations and Demotivation for migrating applications to Java 7

Java 7 has been around for a while now. Now if an application is to be migrated to Java 7 without any changes (code/configuration), are there any inherent advantages or drawbacks? I was curious to know what the problems are faced during such migration.

EDIT: By Migration I mean the code will remain the same but the runtime will change to Java 7 As I mentioned no code/configuration changes, so thing which I think should impact the application is new compiler/VM level default optimizations. So I was looking for anything which would impact the overall application behavior.

like image 982
Santosh Avatar asked Nov 22 '11 12:11

Santosh


4 Answers

The obvious disadvantage at the moment that I'm finding with my app (which was written in Java 7 to start with) is that most people don't have 7, and it takes a bit of effort to get it. The default Java download page at the time of writing still points to Java 6, not 7, and most of the current Linux distributions just seem to have 6 installed by default as well. Ubuntu 11.10 is the first to even have Java in its repository.

Also on the Ubuntu side of things, one thing I've noted is that even if Java 7 is installed, I haven't found a clean way to check if it's the default yet (and again, chances are it's not.) I'm just using a shell script that parses the output from update-alternatives --query java and launches it appropriately.

It was a conscious decision on my part to go with 7 because there were a number of new features in it that I could take advantage of, and by the time said app actually hits the point where I'd consider it out of alpha / beta I hope Java 7 will have gained more of a foothold then anyway!

The advantages pretty much all centre around using the added features - I've found the try with resources construct has made a lot of my code using IO stuff easier to read (no more nested try / finally's inside try / catches) and I'm using some of the extra APIs like the filewatcher API too. I also rather like the fact JComboBox and the underlying models are now generic which saves a fair bit of casting in Swing apps.

In short though, if you're not actually going to take advantage of any of the Java 7 features and you're just upgrading for the heck of it, there's little motivation to do so until Java 7 at least becomes a bit more established. It's made my code somewhat cleaner and been helpful with some of the additional libraries, but it's also caused a fair few headaches as well.

like image 121
Michael Berry Avatar answered Nov 18 '22 13:11

Michael Berry


I would also consider the probability/requirement change of running your new code(java 7) in java 6 or less since some features will not compile like the following:

  • Strings in switch statements
  • try-with-resources statements
  • improved type inference for generic instance creation ("diamond operator")
  • improved exception handling (multi-catch)

Make sure the version of java used on your considered projects is not likely to be enforced before switching.

like image 3
Liviu T. Avatar answered Nov 18 '22 12:11

Liviu T.


The question is really "when", not "if". If you have a pressing need for some of the new Java 7 features (doubtful) then it's obvious.

Otherwise I'd personally wait about year or so to weed out any other possible showstoppers & headaches, before seriously considering a migration production and UAT environments.

Still, you should already have an environment with Java 7 running just to get an idea of what you'll be in for. Java 6 will be retired at some point and you should be well prepared to make the transition.

like image 2
hythlodayr Avatar answered Nov 18 '22 14:11

hythlodayr


I think mostly you will be fine with the migration, although you should check with link provided by Oracle about the incompatibilities between Java 1.6 and Java 7 http://www.oracle.com/technetwork/java/javase/compatibility-417013.html

There are few source level incompatibilities like "Improved Exception Handling" in Java 7 which could cause some problems

like image 1
Edge Avatar answered Nov 18 '22 14:11

Edge