• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

java 1.4 and 1.5 compatable ?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Suppose i compile a java file with java 1.5 ......
then try to run it in java 1.4 ..... Will there be version mismatch errors ?? is there some amount of Upward compatablity in Java ??
thank you
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by merwin pinto:
Hi ,
Suppose i compile a java file with java 1.5 ......
then try to run it in java 1.4 ..... Will there be version mismatch errors ?? is there some amount of Upward compatablity in Java ??
thank you



If you do not specify the -target option to your 1.5 compiler, then no, it will not run.

It works like this:
In order for your code to run on 1.4, it must be "1.4 source compatible". That means you must not use any 1.5 language features (you can use the 1.5 keyword enum as an identifier in this case) and specify the -source option to the compiler with a value of 1.4 (or lower). This also means you must specify a -target value of less than 1.5, which means your code will run on a non-1.5 VM.

However, if you are 1.5 source compatible (you use 1.5 features), you must also be "1.5 target compatible". This means you cannot run on any JVM less than version 1.5.

Now, the 1.5 compiler, by default, already sets the -source option to 1.5 and the -target option to 1.5. So, by default (no compiler options specified), code compiled by a 1.5 compiler will not run on a 1.4 VM for this very reason.

Also, the 1.4 compiler has a default -source and -target option of 1.2. The only addition to the language is the 'assert' keyword, which must be "switched on" explicitly.

Hope it all makes sense
 
merwin pinto
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Tony,
Thanks a lot for the information.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic