S
S
Semisonic2015-02-08 23:56:28
Java
Semisonic, 2015-02-08 23:56:28

Java as a Language: Are there any differences between Android development and Java SE/EE (February 2015)?

Hello!
As part of the task of learning how to create applications for Android, I asked myself to master the required tools, primarily the Java language itself.
After reading an introductory book on Java, focused primarily on the use of Java SE, I noticed that the language is actively developing, and various new constructs are constantly appearing in it. For example, Java 8 introduced lambdas.
In this regard, the question is: exactly as a language , that is, a set of syntax and grammar, as well as the programming structures that they describe, is the "canonical" Java from Oracle identical to the language in which Android programs are written? Relatively speaking, all these generics, lambdas and annotations, are they available to Android developers in the same form as "normal"
A separate issue is language versioning. As far as I understand, in "normal" Java everything depends on the JVM version, that is, when writing code, the available syntax is determined by the version of the virtual machine on which it will be executed.
What about Android? Does it all depend on the OS version? Then, for example, if I create an application that supports Android starting from version 2.1, then not only the API that existed at that time is available to me, but also the syntax of the language that was relevant at that time, that is, in my example, without lambdas ? Or do the restrictions apply only to the API, and the compiler automatically generates bytecode from the new source text, which even the old version of Dalvik can understand?
I would be grateful to anyone who can shed some light on this issue.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Semisonic, 2015-02-09
@Semisonic

Inspired by the previous answers and noticing some inconsistencies in the opinions of their authors, he went on his own search. And here's what I found.
Is it possible to use Java 8 for Android development? is a question on StackOverflow dated April 2014. The general idea of ​​the answers is as follows:

  • Java from Oracle and the development language for Android are de jure unrelated things. The reason is again legal, related to Java licensing issues for third-party use.
    As a result, the language and framework for Android development is based on the Apache Harmony project, an open source implementation of Java SE, and on the branch that implemented Java 6.
  • Oracle's canonical Java features appear in the Android development language sporadically and solely at the request of Google, that is, they have nothing to do with Oracle's Java versioning. De facto, when working with Android KitKat and higher, you can use most (although, as I understand it, not all - for example, try-with-resources in flight) Java 7 chips.
  • The existing ways to use the new features of canonical Java in Android development are based on various tricks of the build procedure. For example, to support lambdas, it is proposed to use something called gradle-retrolambda , which converts the bytecode resulting from compiling Java 8 code into Java 6/7 bytecode, after which this bytecode is converted into the JVM format used in Android. Apparently, this method does not support other Java 8 features other than lambdas.
    Another approach for using new Java features in Android development is alternative languages, in particular, Kotlin ( gadfi , thanks for the tip;)) - a product of JetBrains, on the basis of whose IDEA the official Android development toolkit is now being built.
    Also interesting considerations on this subject can be gleaned in another question on StackOverflow - “Why Apache Harmony” or “How to use Java 8 on Android”

O
Oleg Gamega, 2015-02-09
@gadfi

Android does not support java8, moreover, android itself runs its own version of jvm ─ dalvik, and in android l art (in some earlier it was possible to select a virtual machine on the device, in l they abandoned dalvik )
almost all sugar for android is not available, but if you really need it, you can look towards kotlin

P
Pavel, 2015-02-09
@ProgramCodePav

The last statement is correct.
All the same. The language version doesn't matter. The difference between android versions is the API. To support very old versions of android with modern features, the Support Library is used.
Let's say you were developing in Java 6. Then you upgraded to Java 8. You rewrite the code in Java 8 (optimizing only the features and operation of Java, not Android) and everything works fine.
That is, how the language is exactly "canonical" from Oracle. But Android seems to only work with Java 6. (correct in the comments if wrong).
In structure, it has a similarity to Java EE (you can immediately notice this), but this is the structure of an Android project.

I
Ivan, 2015-02-09
@sputnic

in fact, some buns of the seventh version are available, but if I'm not mistaken, only for the 4+ version of android

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question