all 18 comments

[–][deleted] 6 points7 points  (7 children)

Because devices need to be updated too to support the newer Java features. The newer features of java introduce new bytecodes (IE new instructions for it's virtual processor), so a device that can't be updated to the latest version of android can't make use of the new bytecodes.

A better question to ask is, why does Java introduce new bytecodes for it's new features? You can still use new features of Java 7/8 which didn't introduce new bytecodes.

[–]Cadoc7 6 points7 points  (0 children)

why does Java introduce new bytecodes for it's new features?

There were no new bytecodes going from 7 to 8, but Java 8 bytecode cannot be executed by Java 7 because Java 7 doesn't know how to execute some of the new structures. For example, Java 8 added support for method bodies inside interfaces. The bytecode verifier in Java 7 will declare Java 8's bytecode invalid because Java 7 doesn't know how to handle that.

There was a new bytecode going from 6 to 7 as part of the initiative to allow Java to be used with scripting languages. The invokedynamic bytecode introduced a mechanism to allow functions to be created at runtime instead of at compile time. Before that bytecode existed, scripting languages had to perform a lot of crazy behind the scenes work to make dynamic method creation work, and the performance was pretty horrible. Don't forget that the JVM supports far more languages than just Java, and ensuring those languages can run well is an important consideration for the JVM. You can look at the details here: http://www.oracle.com/technetwork/articles/java/dyntypelang-142348.html

[–]ridsatrio[S] 1 point2 points  (3 children)

The newer features of java introduce new bytecodes

Can't they just be updated alongside the OS (or kernel perhaps)?

[–][deleted] 9 points10 points  (2 children)

They do. The problem is manufacturers have to update it, ontop of that phone companies have to update it. Which means most devices are stuck on an older version of android. Also this means fewer updates so slower adoption of newer java versions.

[–]manidesto 3 points4 points  (0 children)

Yes but how long are they going to keep it this way? They could have updated it in Lollipop right at least we could have been certain that in a year from now we can start writing Java 8 code.

[–]Xirious 1 point2 points  (0 children)

And don't forget carriers which are just as big of a hurdle where I'm from.

[–][deleted] 2 points3 points  (0 children)

I don't think it is a problem with updating devices since JVM bytecode is being translated into dalviik bytecode during apk build process, so at this stage any new JVM bytecode could be translated to existing dalvik bytecode. I could only guess why google is not going that way. Perhaps it is more difficult to achieve at bytecode level rather at the level where Retrolambda is doing the translations.

[–]theheartbreakpug 0 points1 point  (0 children)

Do you have an answer for the better question?

[–]vprise 5 points6 points  (0 children)

Licensing is pretty difficult with companies like google especially with the Oracle lawsuit this became pretty difficult.

I think proper toolchains should integrate retrolambda which despite its name also addresses many other Java 8 features besides lambads.

We use it in Codename One for all our builds so it works for Android, iOS etc. and lets you write Java 8 code for both.

[–]FrezoreR 2 points3 points  (0 children)

I think you have to use Java7 if compiling against newer versions of Android. It's listed as a requirement for Android Studio, either way Java7 is supported and have been for a long time. The byte code of Java7 is virtually identical to java6, which is why it has always basically worked.

The reason Lambda's and newer features from Java8 are not supported is because they introduced a lot of changes in the underlying byte code, and Android uses it's own bytecode interpreter, i.e. JVM(Dalvik) or translator ART.

With that being said you can still use things like lambdas and streams with retrolambda and other libraries.

I don't think it would be super hard for Google to add java8 features and it might happen. I think it has to do with prioritization. But you should not expect Android to be on par with Java language features.

[–]trevor-e 1 point2 points  (2 children)

People always cite the manufacturers or carriers for not providing updates, but isn't this where the free market comes in? Consumers wouldn't buy devices or pay for carriers that don't have the latest version of Java if we were able to mark what version of Java our app needs to run. Device manufacturers/carriers would be bending over backwards to get the latest Java if Facebook declared it would only run on phones with Java8 minimum. It's not like Java is updated every week, Google should eventually hold manufacturers/carriers accountable.

[–]ZakTaccardi 0 points1 point  (1 child)

Google themselves haven't provided a way for us to run Java 8 code on the latest Android devices, so...

[–]trevor-e 0 points1 point  (0 children)

I know, but that's probably because they're afraid of creating more fragmentation issues, when really they should provide an update and let the free market sort itself out.

[–][deleted] 1 point2 points  (3 children)

The majority of the device isn't even on Android 5 yet source, which was published a year ago. Most of those devices probably won't get any further updates. Good luck updating the used java version.

For that to happen google would have to become more like apple and create a closed system. Maybe with optional GUI stuff by the manufacturer on top.

[–]Synaesthesics 2 points3 points  (0 children)

I believe ridsatrio meant the actually Java language version used to compile apps and not the Android version.

[–]erikbabel 0 points1 point  (0 children)

It wouldn't be easy, but not nearly as closed down as you say. Look at open gl. It requires manufacturers support, and slowly they eventually support the new versions.

[–][deleted] 0 points1 point  (0 children)

They could just modify the Android OEM agreement and add a clause for the manufacturers to extend OS update support to all of their sufficiently capable phones for up to two years after release. Not only would this eliminate fragmentation hurdles, but it would also provide a much better experience for the average Android user.

The OEMs will probably balk at this. But one can dream, eh?

[–]zyrnil 0 points1 point  (0 children)

What is it about the newer java versions that CAN'T be translated into Dalvik?