Relationship between OS version, API Level, and Java version

In the case of your given example, that flag wasn’t added until API 24. In a lot of cases, even though support for a given language level (e.g. 7) was added earlier doesn’t mean everything is added instantly. Some things are waited with for whatever reason Google has for waiting with it.

I can’t tell you why because I don’t know.

And as Gabe mentioned, the versions of Java isn’t necessarily compatible with Android.

So because of your code where you use the flag on API 19 and up, you’ll get a crash on versions between and equal to 19 and 23 because the flag isn’t added yet.

And it’s also worth noting that version compatibility doesn’t limit versions of Java by versions of Android. Now you can for an instance run Java 8 on whatever version of Android you want. This is compatibility.

However. If you read Android Java 8 Language Features, it says (emphasis mine):

Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.

I’m using Java 8 as the example here, but this applies to mostly every version of Android and java.

Essentially:

  • The flag you’re using wasn’t added until API 24. AFAIK, usage wasn’t added even though the hard-coded variable is there
  • Android doesn’t necessarily have every single Java API, and these vary by versions of Android
  • Versions of Java isn’t limited by API, but the accessible features vary. Meaning you can run Java 8 on API (random number) 12 if you wanted to.

There’s no fixed relationship (Android [x] = Java[x]) between the two. Different fields/methods/classes may be added eventually, instantly (on release of support for a given version of java) or not at all.


The regular Java and the version of Java used in Android are two very different ones, because Android is platform-based while Java is version-based. You can’t compare versions between them, and they both have separate documentations.

It’s worth noting that for Android (Java) questions you should look at the Android docs which can be found in the API reference instead of using the Oracle documentation which doesn’t apply to Android because of the massive differences in the API.

Leave a Comment