This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Java version compatibility

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well dang.  A program I use weekly, wrote maybe 6 years ago, and haven't touched it's jar file in 2, is now throwing an array out of bounds exception.  Not an issue except I had a hard drive crash last October and nothing on that machine was recoverable (good backups FTW).  I haven't written any Java since then and don't have a JDK installed on this machine.  Nor do I know which version I developed the program on.

2 Questions:

1)  If I download Java 12 what are the odds my program will build without issues?  No resources, just 3 .java files
2)  Is there a way I can find out which JDK my Program.jar was built with?
2.1   I developed this under Eclipse, but got pissed at Eclipse for something or other and switched to something else, only to ultimately use Android Studio.  No idea which was used for my current Program.java.

For 1 keep in mind this was maybe the third program I ever wrote in Java, and the first one over 100 lines (wc *.java shows 1417 lines).  It's pretty much C with a bunch of Regexp's in it, nothing object oriented about it.  I'm effectively parsing a log file.

For 2.1, does it matter?  And how do I figure out what I used?

/ look at my first posts on this forums, it was trying to figure out how to do OO log file processing I found/joined this site
// years later, yeah, I could have done better
/// but who amongst you haven't looked at a learning project that was useful and thought "oops"?
 
Saloon Keeper
Posts: 10675
228
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eddie Nguyen wrote:If I download Java 12 what are the odds my program will build without issues?  No resources, just 3 .java files


Pretty good. Java has maintained good backward compatibility, and with just 3 source files I wouldn't expect much problems. Even if the source is not compatible, it wouldn't be a lot of work to alter it slightly.

Is there a way I can find out which JDK my Program.jar was built with?


You can unpack the JAR using a ZIP tool, and open the file META-INF/MANIFEST.MF in a text editor. If you're lucky, your build tool with have notated the relevant build information there.

And how do I figure out what I used?


If it's not in the JAR manifest, then it's probably not a big deal to recompile and repackage the application by hand using the command line.
 
Saloon Keeper
Posts: 21137
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Eddie!

Java was especially designed to be write-once/run anywhere and that includes not only any OS and any hardware, but also in terms of language version compatibility. Obviously a program written using Java 11 constructs isn't going to compile or run on a Java 6 system, but Java 6 apps should almost invariably compile and run unchanged on a Java 11 system. And, incidentally, unlike, say Internet Explorer, you can have multiple versions of Java installed and running on a single machine, which can be very valuable on production servers where potentially many different apps may run untouched for years.

Probably only the COBOL language approaches this level of stability, and Java has extra constructs that even COBOL does not, such as the ability to select the version compatibility of the compiler output. Not to mention the deprecation mechanism that allows you to cause the compiler to issue warnings about obsolete features while still being able to use them in an emergency.

One of my worst nightmares was a Windows system that failed and needed a 1-line code change. It had been sitting around "as-is" for a long time, but now the show had stopped. To make this 1-line change, I had to install an obsolete copy of Visual Studio, which then had to be patched, and came very close to having to install an obsolete version of Windows and its patches to run Visual Studio.

In contrast, I can create a Java project, pack it up, ship it to Ulan Bator, let it sit on a shelf for 5 years and then chances are very good that someone there can build a fully functioning app without making a single change.
 
Greenhorn
Posts: 13
Android Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! How long have you been using eclipse?
 
Tim Holloway
Saloon Keeper
Posts: 21137
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Harold Kelly wrote:Hi! How long have you been using eclipse?



Since about the time IBM started giving it away.

Eclipse is my favorite IDE, but I've also worked with Borland Visual Café (now defunct, alas), IntelliJ (the standard for one shop I worked in), Forte (the original NetBeans). and the Java IDE plugins for the Emacs text editor.

I don't depend on an IDE to do my work, and in fact, all my production code gets built from the command line, no IDE.
 
Sheriff
Posts: 21805
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:but Java 6 apps should almost invariably compile and run unchanged on a Java 11 system.


Unfortunately, that can't be guaranteed anymore. Since Java 11, Oracle is throwing away some of the APIs. So far that's pretty limited, with the exception of the removal of all JEE modules in Java 11.

However, Eddie, unless you're using those (and you probably aren't), you should be safe.
 
Tim Holloway
Saloon Keeper
Posts: 21137
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:So far that's pretty limited, with the exception of the removal of all JEE modules in Java 11.



JEE modules have never been "in" Java. JEE - and its predecessor, J2EE - was a Sun, later Oracle spec for Enterprise Java. You could pull reference implementations and APIs (Interfaces) from Oracle, but anyone could provide their own implementation - and was required to, in fact. That's why Tomcat can't do the full JEE stack - they never felt obligated to implement much of anything beyond the servlet/jsp specs. And JBoss simply embedded Tomcat, so they didn't have to create their own implementation of that part of the spec.

The difference between then and now is that Oracle no longer claims ownership of the JEE spec as it's now owned by Jakarta.

We have had reports of Oracle breaking a few methods in the JDK lately, however. Historically, though, that was not the case.
 
Rancher
Posts: 3444
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2)  Is there a way I can find out which JDK my Program.jar was built with?


Are you asking about what jar command was used?
Or what version of the javac command was used to compile the programs?  The class file contains a value for each version at the 8th byte.
 
Tim Holloway
Saloon Keeper
Posts: 21137
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there a way I can find out which JDK my Program.jar was built with?



The version of Java that the code was generated for is a field in the class file. That's actually what's important. So by examining the class file itself you can tell.

There are come considerations. First, a complex application may have pulled in external dependencies compiled under other Java versions. So the classes you want to look at are the primary classes of your application.

Secondly, the version ID is not the same as the actual JDK version number. Instead of, say 1.8.0-u37, the version ID will be a value more like "57". That's the version used to determine code compatibility, though, and it is usually the same for each minor release of a JDK version.

Thirdly, note that I said "the version of Java that the code was generated for". The Java compiler has an option to generate classes for older JVM versions, so that you can compile using the Java 13 compiler and run under a production server that only has JVM version 9. When doing this, any attempt to use features newer than Java 9 features in the code being compiled will cause the compiler to emit error messages and refuse to compile.
 
Rob Spoor
Sheriff
Posts: 21805
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Rob Spoor wrote:So far that's pretty limited, with the exception of the removal of all JEE modules in Java 11.



JEE modules have never been "in" Java.


There were a few. https://docs.oracle.com/javase/10/docs/api/java.se.ee-summary.html lists the modules that were part of the java.se.ee (that's the correct name) module. It included JAXB, JAF and a subset of JTA and JAX-WS, as well as a module with package javax.annotation (with @PostConstruct and @PreDestroy). Those are all gone since Java 11, and can only be accessed by including a separate API and/or reference implementation.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!