How does Android's Java version relate to a Java SE version? - java

I am constantly wondering how the Java version used for Android development relates to a Java SE version. For example, I was reading today about "Type Inference and Generic Methods" which is a feature added in Java SE 7. I wonder to myself, "Can I use this in Android code?"
Of course I could type the code into an Android project and see if it compiles, but I'd be happier to have some kind of mapping in my head.
I've tried Googling for this info, checking the Android docs, etc, but can't find an answer.
Edit: I'm more interested in language features, e.g. how does the Android Java syntax version relate to Java SE syntax.

Android's version doesn't directly relate to Java SE, although it uses a subset of Apache Harmony's SE 6 libraries and tools. It will be up to the Android team to decide if & when to support/require the SE 7 version of Harmony.
Edit It looks like as of KitKat Android supports Java SE 7 language features. See the comments below.

There is no direct mapping:
Some parts of the API (such as JAXB, which has been around since at least Java 6) have never been available on Android.
When features of a new Java version are introduced, this can happen gradually over multiple versions.
Some newer Java features are made available for older, already-released versions as backports.
In the past it has taken Google some 2–3 years to start adopting a new Java version. Java 7 features started appearing around API 19 (KitKat). Java 8 features started at API 26 (Nougat), but a mechanism called desugaring is available to make certain Java 8 features available on earlier Android versions, regardless of their API level.
So, generally speaking, if you want to know whether a particular Java API feature is available on Android, look it up on the Android developer reference and check the minimum API version.

Related

What is the current status of Java scripting? (i.e., JSR 223 or successors)

I would like to add scripting capability to events in an existing Java application. Looking about, I find JSR 223 for Java scripting. But it is withdrawn, and wikipedia tells me that
it was decided that this functionality would be included as an integral part of Java 9 and onward.
Yet looking at the wikipedia page on Java SE versions I see nothing from Java SE 9 onward to the present time (Java SE 16, under development) that sounds like "scripting" to me.
So what is the current recommended approach to integrate a scripting facility into an existing Java program? (And did I miss something in Java SE 9+ that speaks to this?) (Or does the fact that it does show up in Java SE 8 on that wikipedia page mean that it actually got in "early" - for some definition of "early" that includes being in a late release ...)
I think you can ignore the withdrawn status, especially because it's already working/embedded to Java
I'm looking at your wiki link and it states that JSR 223 in on Java SE 8
JSR 223, JEP 174: Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
and even Java 6:
Scripting Language Support (JSR 223): Generic API for tight integration with scripting languages, and built-in Mozilla JavaScript Rhino integration.
Actually there were enhancements since Java 7
Enhancements in Java SE 7
The JDK 7 release is co-bundled with the Mozilla Rhino JavaScript engine based on version 1.7R3 pre-release sources with Oracle modifications. You can download the Oracle modified Rhino sources at java.net.

Will my app run on android 4.0 if I use JDK 8

My android studio project uses the embedded JDK which is version 8 by default im wondering will my app still run on android 4.0 and 5.0 devices ?
The app will definitely run with JDK 8 run it.
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.
Android Studio provides built-in support for using certain Java 8 language features and third-party libraries that use them.
Note:
When developing apps for Android, using Java 8 language features is
optional. You can keep your project's source and target compatibility
values set to Java 7, but you still need to compile using JDK 8.
And about your minSDK comment "whats your preferred minSDK? if you start with API 19 you have a rate of 95%"->
minSdk is required to set the minimum api level run environment(android OS version) to the application. If you choose minSdk the minimum possible you can target max number of devices.
If you want to use JDK8 to compile your Android app there is no problem with it, you can easily set compatibility to Java 6/7 and there won't be any issues.
If you want to use Java 8 language features it all depends on the mindSdkVersion that you have set up. You can freely use:
- lambda expressions
- method references
- default and static methods in interfaces
- repeating annotations
Java 8 API is available from API level 24 unfortunately in your case you won't be able to use any Stream API and such.
For more information please check:
https://developer.android.com/studio/write/java8-support

TimeZone.observesDaylightTime() requires API level 24; is it possible to get it in older API versions?

TimeZone.observesDaylightTime() requires API level 24. How do I get it for older APIs? Even though this is included in JAVA 1.7 Android is still complaining.
The short answer is that you can't do things like that in the general case. If a call requires a minimum API level you can't use it if you're targeting older API levels.
Also as one more general remark, keep in mind that Android is not running the "standard" version of Java - it even has its own Virtual Machine that differs in some significant ways from the standard JVM - so the fact that something's allowed in "standard" Java doesn't automatically mean it's possible in Android. For example, it was only very recently that Android had support for Java 8 features, and even now it doesn't support all of the features.

Does ADT support Java 8 API?

Do Android Developers Tools support JAVA 8 API up to this date? I'm trying to build an Android app using JAVA 8 and I was wondering about this thing.
Java 8 APIs started becoming available in Android API 26 (which is Android 8, or Nougat). A mechanism called API desugaring is available to use certain Java 8 APIs on earlier Android versions, regardless of the Android API level.
However, there is no 1:1 connection between Android and Java API versions. In the past, it has taken Google some 2–3 years following the release of a new Java version to gradually start implementing its APIs. So, the question “is a certain Java API available on a certain Android version” can only be answered on a per-class/member base. You will have to look up every class, method, constant etc. on the Android API reference and see if it it supported, and what the minimum API version on Android is – or see if API desugaring provides it, which is not tied to a particular Android API level.

what is difference between JDK 1.4 and JDK1.6

I have created the project using the JDK 1.4. Now I want to use JDK 1.6 version in my project.
for this what steps are required.Means I want to know the what changes is require in code to get a JDK 1.6 feature.Basically I am talking about the features that is added in JDK 1.6. If any one list out that changes it is very helpful.
Thanks in advance..............................
Better to see differences between 1.4 and 1.5 and then between 1.5 and 1.6.
You can check new features in each version on official web site, but below is a little chronology ...
JDK 1.0 (january 23, 1996) oak
Initial release
JDK 1.1 (february 19, 1997)
Retooling of the AWT event model
Inner classes added to the language
JavaBeans
JDBC
RMI
J2SE 1.2 (December 8, 1998) playground
This and subsequent releases through J2SE 5.0 were rebranded retrospectively Java 2 & version name "J2SE"
(Java 2 platform, Standard edition) replaced JDK to distinguish the base platform from
J2EE (java 2 platform, enterprise edition) and J2ME (java 2 platform, micro edition).
Strictfp keyword
Reflection
Swing api integration into the core classes
JVM equipped with a jit compiler
Java plug-in
Java IDL
An IDL implementation for corba interoperability
Collections Framework
J2SE 1.3 (may 8, 2000) kestrel
Hotspot jvm included
JavaSound
JNDI included in core libraries
Java platform debugger architecture (jpda)
RMI was modified to support optional compatibility with corba
J2SE 1.4 (february 6, 2002) merlin
assert keyword
Regular expressions
Exception chaining (allows an exception to encapsulate original lower-level exception)
Internet protocol version 6 (IPV6) support
Non-blocking nio (new input/output)
Logging API
Image i/o api for reading and writing images in formats like jpeg and png
Integrated XML parser and XSLT processor (JAXP)
Integrated security and cryptography extensions (JCE, JSSE, JAAS)
Java web start
J2SE 5.0 (september 30, 2004) tiger [originally numbered 1.5]
Generics: provides compile-time
(static) type safety for collections
and eliminates the need for most
typecasts (type conversion).
Metadata: also called annotations; allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities.
Autoboxing/unboxing: automatic conversions between primitive types (such as int) and primitive wrapper classes (such as integer).
Enumerations: the enum keyword creates a typesafe, ordered list of values (such as day.monday, day.tuesday, etc.). Previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern).
Swing: new skinnable look and feel, called synth.
Var args: the last parameter of a method can now be declared using a type name followed by three dots (e.g. Void drawtext(string... Lines)). In the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type.
Enhanced for each loop: the for loop syntax is extended with special syntax for iterating over each member of either an array or any iterable, such as the standard collection classesfix the previously broken semantics of the java memory model, which defines how threads interact through memory.
Automatic stub generation for rmi objects.
Static imports concurrency utilities in package java.util.concurrent.
Scanner class for parsing data from various input streams and buffers.
Assertions
StringBuilder class (in java.lang package)
Annotations
Java SE 6 (december 11, 2006) mustang
sun replaced the name "J2SE" with java se and dropped the ".0" from the version number.
Beta versions were released in february and june 2006, leading up to a final release that occurred on december 11, 2006.
The current revision is update 20.
Support for older win9x versions dropped.
Scripting lang support: Generic API for integration with scripting languages, & built-in mozilla javascript rhino integration
Dramatic performance improvements for the core platform, and swing.
Improved web service support through JAX-WS JDBC 4.0 support
Java compiler API: an API allowing a java program to select and invoke a java compiler programmatically.
Upgrade of JAXB to version 2.0: including integration of a stax parser.
Support for pluggable annotations
Many GUI improvements, such as integration of swingworker in the API, table sorting and filtering, and true swing double-buffering (eliminating the gray-area effect).
Java se 6 update 10
A major enhancement in terms of end-user usability.
Java Deployment Toolkit, a set of
javascript functions to ease the
deployment of applets and java web
start applications.
Java Kernel, a small installer including only the most commonly used jre classes. Enhanced updater.
Enhanced versioning and pack200 support: server-side support is no longer required.
Java quick starter, to improve cold start-up time.
Improved performance of java2D graphics primitives on windows, using direct3D and hardware acceleration.
A new Swing look and feel called NIMBUS and based on synth.
Next-generation java plug-in: applets now run in a separate process and support many features of web start applications.
Java se 6 update 12
This release includes the highly anticipated 64-bit java plug-in (for 64-bit browsers only), windows server 2008 support,
and performance improvements of java and JAVAFX applications.
...........
You can check in wikipedia till latest update.
To my opinion, the four most prominent enhancements since Java 1.4.2 are
Generics
enums
enhanced for-loop and
Annotations
There are a lot of additional classes and API enhancements, but if you want to 'upgrade' your code, I'd suggest to start your refactoring with using generics and replacing standard for loops by enhanced for loops. Both can be done without major code changes, clean up the code (you can delete a lot of lines of code) and improve readability. And using generics might reveal some hidden bugs ;)
I have created the project using the JDK 1.4. Now I want to use JDK 1.6 version in my project. For this what steps are required.
Actually, there is (almost) nothing that you need to start to make a JDK 1.4 application run using JDK 1.6. In nearly all cases, you simply need to recompile the code with the JDK 1.6 compiler and run it in a JDK 1.6 JVM. The only problems you are likely to encounter are:
If your code uses "enum" as an identifier, you will need to change it to something else. enum is a keyword starting in Java 1.5.
If your code directly depends on Sun proprietary / internal classes, you may need to deal with unannounced API changes.
You might find the certain official API classes or methods have been marked as deprecated.
There are a small number of changes in API implementations / behaviors with each release that may impact your application. These are typically highlighted in the document on upgrading.
Once you have got your application working on Java 1.6, you can then think about whether and when to start using the Java 1.5 language extensions, and the new / enhanced APIs in the class libraries.
Means I want to know the what changes is require in code to get a JDK 1.6 feature.
Almost no changes are required. But obviously, if you want or need to use a new feature you will need to change your code to do that.
Wikipedia has an summary of the most significant changes made across various Java releases.
UPDATE
As of May 2014, Java 6 has been "end-of-lifed", and Java 8 has been released for a month or so (with no significant early release number dramas). You should now be thinking about moving to at least Java 7, and probably Java 8.
The same principles apply. Recompile and run your regression tests, and you will most likely to be good to go. Then start learning all about the Java 8 language extensions.
What's new in JDK 6?
There are so many changes added in 6.0.
However all your 1.4 code will run smoothly.
For further reference about the version please see the following link
http://en.wikipedia.org/wiki/Java_version_history#Java_SE_6_.28December_11.2C_2006.29
Hope it helps.
The important details on 1.5 extensions are covered in these slides which provides also code examples.
There is a big difference in behaviour for volatile keyword in 1.5 - more along the lines of C# away from C++ behaviour. But it only makes the code safer. So no code changes.

Categories