Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What happens if my java code uses features not available on JVM program runs on?

 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ie if I have used Java 1.6 features but user of application only has say JVM v1.1? What will happen? How do I deal with this issue?

Another related question, if I write a Java applet should I only use features up to Java v1.1 to assure applet will run correctly if workstation has not installed a current JVM?

Angus
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Comber wrote:ie if I have used Java 1.6 features but user of application only has say JVM v1.1? What will happen? How do I deal with this issue?

There are two possibilities:
1) the code is not compiled to explicitly be able to run on an older JVM (using the -target compiler flag). You'll get an UnsupportedClassVersionError.
2) the code is compiled to explicitly be able to run on an older JVM, but a method, field or class is simply not there. You'll get an NoSuchMethodError, NoSuchFieldError or NoClassDefFoundError.

Another related question, if I write a Java applet should I only use features up to Java v1.1 to assure applet will run correctly if workstation has not installed a current JVM?

Well, you can either require your clients to use an up-to-date version, or use only features of an older version. I definitely would not go back to Java 1.1; the oldest version I'd even consider is Java 1.4. That one's over 9.5 years old, Java 5.0 is almost 7 years old and Java 6 is almost 5 years old. Both 1.4 and 5.0 have been end-of-life for a few years as well. I would probably require my users to use Java 6; if they still have an older version they really need to upgrade, if not for the features, then for performance and especially security.
 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reason for Java 1.1 comment was I thought applets running in a web browser could only use features up to Java 1.1 if Java JVM was not explicitly installed (because web browsers used their own java engine which only generally supported uo tp v1.1 features). But this might be really old information.

So really my question is if a workstation has just a web browser, eg IE 6 and Java JVM has not been installed, will the applet run? And if it will run, what version level of features can be used? My information from a long time ago was up to v1.1.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft's own JVM had support up to Java 1.1, but if I remember correctly they are no longer allowed to distribute it. That means that these days, if no JVM is explicitly installed, applets simply will not run. There are ways to prompt the user to install a JVM, but I can't really remember how to... For some browsers like Firefox there is built-in support for finding the required plugin.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Microsoft's own JVM had support up to Java 1.1, but if I remember correctly they are no longer allowed to distribute it.


If I'm not mistaken that court case was settled in 2004. It's possible that there are still computers which still have the Microsoft JVM installed in their browser (Internet Explorer 3?) because they haven't been upgraded for the last seven years, but if I were writing an applet (which I have done) I wouldn't bother trying to support them.
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One elegant way of handling this issue could be using Java Web Start Using JWS you can figure out the client JVM version and prompt an update if required.
Please not, we also have a JWS and JNLP forum which has all kinds of discussions on this topic. Browsing around that forum should provide you with much more insight.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To check in a browser what version of Java is installed (or if Java is installed at all) and to prompt a user to install Java, have a look at this: Java Deployment Toolkit

The Java Deployment Toolkit is something that was added in Java 6 update 10. Some more info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic