I have code that is already compiled using Java 1.5. Is it possibly to run this code using Java 7 without any problems?
Asked
Active
Viewed 378 times
0
-
2http://stackoverflow.com/questions/10895969/can-newer-jre-version-run-java-programs-compiled-with-older-jdk-versions – Steve Townsend Mar 18 '13 at 18:48
1 Answers
1
Yes, it should usually run with no problems. Certainly the theory is that it should be fine - there's a small chance that you'll run into some area where the behaviour has changed in a backwardly-incompatible way, but if you're only relying on behaviour specified in the documentation, you'll normally be okay.
There's definitely no problem in terms of the JVM understanding the bytecode itself.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
1
-
One thing that isn't working for me is MouseWheelListener `java.lang.NoSuchMethodException: javax.swing.table.TableModel.addMouseWheelListener(java.awt.event.MouseWheelListener) at java.lang.Class.getMethod(Class.java:1624)` – htkhtk Mar 18 '13 at 18:54
-
@htkhtk `addMouseWheelListener` is defined for `JTabel` not for `TableModel` in all versions of `Java`. – Vishal K Mar 18 '13 at 19:05
-
@htkhtk: Yup, I can't see that in the docs for `TableModel` for 1.5: http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/table/TableModel.html Looks like you were compiling against an odd implementation... – Jon Skeet Mar 18 '13 at 19:13
-
the only thing that should cause it to not work is if there are methods called that have been deprecated i would think – Jeff Hawthorne Mar 18 '13 at 19:14
-
1@JeffHawthorne: Deprecation shouldn't be a problem. It would only be methods which had been *removed*. – Jon Skeet Mar 18 '13 at 19:15
-
@JonSkeet my mistake, i think i was mixing up those two terms ;) what you say is what i meant – Jeff Hawthorne Mar 18 '13 at 19:16
-
@JonSkeet: But how come this his code is in compiled form with the source code containing that method!!!?? It is and `Exception` not `compile time error` .. Isn't it? – Vishal K Mar 18 '13 at 19:22
-
1@VishalK: If it was compiled against some odd (non-standard) version of Java which *did* include that method, then when it was run against a standard version which *didn't*, there'd be exactly this issue. – Jon Skeet Mar 18 '13 at 19:37
-
It is java 1.5 version 22. The rt.jar has the MouseWheelListener in there under java.awt.event.MouseWheelListener. Is it possibly to have two versions of rt.jar or something to get this to work properly? – htkhtk Mar 18 '13 at 20:04
-
@htkhtk: It's not a matter of where MouseWheelListener is - it's the `addMouseWheelListener` method that's missing. – Jon Skeet Mar 18 '13 at 22:59