1

In an Interview, Interviewer asked me this question that how to restrict an application developed in java between a minor version and major version. I know about -target options as Cross-Compilation Options but not sure about the restricted application between minor and major.

Even i search for it, i didn't find any data related to same.

My Question:

Whether it is possible to restrict an application between minor and major?

Answer

As suggested by Subin, Compile the application with minor version and check major version by inspecting java.version as answered by SimonC in application which may fulfill the minor and major version restriction for an application.

Shashi
  • 12,487
  • 17
  • 65
  • 111
  • The interviewer question is not clear. What does "retricting an application" mean? – JB Nizet Jan 04 '13 at 09:59
  • e.g. Between 1.4 and 5.0 or Between 5.0 to 6.0 – Shashi Jan 04 '13 at 10:00
  • 1
    That's what a version is. It doesn't explain what restricting means: preventing it from compiling? From running? Showing an error message if it's run with an incorrect version? – JB Nizet Jan 04 '13 at 10:02

1 Answers1

6

You could inspect the java.version system property.

SimonC
  • 6,590
  • 1
  • 23
  • 40
  • 1
    and compile the app in minor version of java compiler. – Subin Sebastian Jan 04 '13 at 10:02
  • So what you mean is to check the java.version system prop upon startup of your application and exit if it does not meet your expectations. But Shashi asked about doing this at compile time. :( And there are no compile time asserts in Java, right? – wojciii Jan 04 '13 at 10:12
  • Yes.. I am asking at compile time. As suggested by Subin, Compile the application with minor version and check major version by inspecting java.version as answered by SimonC in application which may fulfill the minor and major version restriction. – Shashi Jan 04 '13 at 11:40