File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What happens if my java code uses features not available on JVM program runs on? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What happens if my java code uses features not available on JVM program runs on?" Watch "What happens if my java code uses features not available on JVM program runs on?" New topic
Author

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

Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jul 26, 2007
Posts: 10372
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14146
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What happens if my java code uses features not available on JVM program runs on?