It's said in the title. which Java Classes can I use when developing Android apps. Are there any exceptions, can I use the lot of the Java Library, like the whole of the standard Edition?
You can use all classes listed in the Android API for your desired API level (which corresponds to Android releases).
The Android API is roughly based on the Java SE API, but it is missing a few parts and has added significant parts of its own API.
Knowing the Java SE API can certainly help, but you shouldn't assume that everything in there is available on Android.
You can almost use all the Java Classes. The only thing you need to be aware of is that you can't use any Graphical and UI classes as Swing and AWT. Else it's pretty much the same.
Related
I am new to android and I would like to know if there is any diffrence in the Java used in android programmming and standard java. This is because i have never heard about Intents ,etc in Java.
NO difference, but some packages of java excluded from android
framework. Core java is used as language for Android development,
Android SDK provides API that uses JAVA to interact with ANDROID OS.
You can find list of java packages that is supported by android here Java vs. Android APIs
Android uses Core Java as the language for programming. Its like a framework like Spring, Hibernate etc. . There are few basic components like Activity, Service, Broadcast receiver.
Intent is a simple message object which is used to communicate between components.
In both logical programming style is same
but you need to know few additional things in android. like basic components of Android. you can get everything in https://developer.android.com/training/index.html
happy android coding
This question already exists:
Closed 10 years ago.
Ok so this time I will make it more specific.
I want to learn Java only. So I have bought myself a book on Java programming and would like to follow the examples in the book. For doing this on the go (because I don't always have access to my PC) I've downloaded AIDE, which is basically an IDE for Android phones.
But this app seems to be for android development only. Can I use this to practice Java? Because now when I write anything in Java and compile it, it only outputs what's in the layout XML.
If you want to learn Java, then use a PC, not a mobile device.
While Android apps are written in Java, Android does not support the full set of Java APIs. For example, any program using awt classes will not run on Android, as Android's UI framework is completely different.
I would strongly suggest you use a PC and an IDE like Eclipse or IntelliJ to learn at least core Java before coming to Android app development. It will make your life much much easier if you know Java syntax and the basic core of the language well before you attempt Android development.
Here is a list of the Java packages that are included in the standard Java on your PC, but not part of the Android APIs (it may be a little outdated, but it should give you an idea of the differences):
java.applet
java.awt (except for the font classes)
java.beans
java.lang.management
java.rmi
javax.accessibility
javax.activity
javax.imageio
javax.management
javax.naming
javax.print
javax.rmi
javax.security.auth.kerberos
javax.security.auth.spi
javax.security.sasl
javax.swing
javax.transaction
javax.xml (except javax.xml.parsers)
org.ietf.*
org.omg.*
org.w3c.dom.* (sub-packages)
What you are asking for may be possible, but is not recommended.
Android programming requires a lot of specialized knowledge specifically about how to program for Android, and this requirement will get in your way when trying to learn basic Java.
Learn Java first, then, if desired, learn how to apply that knowledge to Android programming.
From what I understand, Blackberry Java Runtime runs micro-java runtime.
Which is based on Java 1.3. (thanks Andreas_D)
Blackberry supplies a few alternatives, or the micro-java supplies some alternatives.
But its such a pain. We have an App that uses android java, of which supports full Java 1.6. We were hoping for a conversion of the UI components, but now have to rewrite code?
Is there an easy way to over come this problem?
I cant get a java.io.File for example. And its not the only one..
Are there alternatives for :
java.io.RandomAccessFile
java.io.File
java.io.FileOutputStream
Missing a bit? Yes if you're comparing it to a full Java SE / EE implementation. No if you're comparing it against the Java ME reference implementation.
Java ME (J2ME) doesn't contain all the API classes you may expect in a full Java SE platform - it was never intended to. Also, mobile devices need to be able to grant and revoke specific permissions to applications etc.
Remember it's a deliberate subset for devices with limited resources and the omissions are pretty well documented. For example, file access in Java ME is done via file connection api:
File Connection API
Also see these sites (for other/general differences):
Differences between Java SE, EE and ME
Difference between Android and Java ME development
Differences between programming for a J2ME JVM, and programming for a J2SE JVM
Java ME Wikipedia Page
Java ME CLDC - Noteworthy limitations list at Wikipedia
Blackberry supports Java 1.3, not 1.4.
The cleanest way to get around those missing File-related classes would be to write some wrapper classes which just expose the functionality you need, then you can write implementations for BlackBerry using whatever's available via the J2ME and BlackBerry APIs.
Alternatively, you could just write your own versions of java.io.File etc for BlackBerry, and include those in your project. If you take this approach you'll need to be very careful to mimic the behaviour exactly or you could be opening yourself up to a whole new world of painful bugs.
There may well be libraries out there for BlackBerry which do what you want, I'll leave it up to you to do some googling on that...
I have a Java application that runs on BlackBerry (JDE 4.5). I want to port this application to Android, and be able to maintain the 2 applications simultaneously. I may also want to port this application to other Java platforms (J2ME ?).
I understand that a good part of the code will have to be specific to each platform (UI and other stuff). But I also feel that a lot of the code could (should) be shared (domain related classes).
What is the best way to achieve this, and what are the pitfalls to avoid?
I have been able so far to create a JAR with all my shared classes, that I have been able to integrate into my BlackBerry application (using preverify and rapc). But:
The JAR is a J2SE library. How can I make sure that it will run (or even compile) on BlackBerry, Android or J2ME?
I am also using a JSON library targeting J2ME (https://github.com/upictec/org.json.me/). This library seems to make use of some kind of preprocessing directives (CLDC, see https://github.com/upictec/org.json.me/blob/master/src/main/java/org/json/me/JSONObject.java#L392). How can I use (or convert) this library using the right preprocessing definitions?
This is likely to be difficult:
As you have already identified, the UI code will have to be different for each platform.
There are major differences between Java SE / Android and Java ME-based platforms. For example, ME doesn't have the Collections framework, or the java.io or java.nio stacks.
It is hard to predict from the information you've provided, but there's a fair chance that you'll spend more time fighting the platform dependencies than you are saving by sharing the code-base.
These days, the biggest stumbling block to sharing code this way is that the BlackBerry VM and Android VM both support different versions of the Java language. BlackBerry uses a subset of Java 1.3, Android uses a subset of Java 1.5. (As an aside, neither platform implements a Java VM, both use their own VMs. Java is used as the programming language. Java bytecodes must be transformed to the appropriate native VM format before they can run on the platform.)
The biggest difference you will find as a library implementor is that the BlackBerry lacks the things that were introduced in 1.5, very important things like generics and enums. Even worse, the Collections classes are missing from the BlackBerry. It is unfortunate, but that is the way it has been for a long time now.
This means that to be truly portable you have to write to the lowest-common denominator, which means using (very) old-style classes like Hashtable and Vector, not having generics, rolling your own enums (as in the 1st edition of Effective Java) and so on.
Or you build two libraries, a modern version for Android and a stripped-down version (with just the bare stuff you need) for the BlackBerry.
Hard to say what`s right for you.
Rather than prepackage your shared library, I would consider sharing the library project and having it as a dependency in your mobile applications' build process. That would allow you to share the code base, but have it built by the appropriate builders for your target devices. With a bit of IDE magic and some attention to detail, you should be able to pick up errors before anything is shipped out.
Alternatively, set up your library project to use two separate builders to pick up errors. That would allow cleaner distribution, but you may run into problems trying to convince your IDE to treat the project as being device specific in order to identify problem areas.
It would be likely that you would end up supporting the lowest common denominator device (cough Blackberry), and forgoing the additional facilities of the more extensive Java implementation on Android.
Unfortunately the answer will be one of experimentation. Try it and see what happens.
The article Porting Android code to BlackBerry has some good detail on how to work with code shared between the two platforms.
it will be very difficult to create shared library for blackberry and android.
if you want simple method, create your application as web app.
using
phonegap with jQtouch
I am relatively new to Java, and am developing a Java implementation of a class library I have already written in .NET and Objective-C. The library in Java is primarily being aimed at Android devices (or any device which supports Java) - would a standard Java SE library be compatible with Java ME? The only data types being used are the standard base types, including String, and possibly StringBuffer from the java.text package.
You'll have to look exactly at the class library present on each specific target device. There are different Java ME profiles, and Android is something else entirely (has nothing to do with Java ME). But the classes of java.lang (and that's where StringBuffer lives, not java.text) are of course present on all of them.
Android is mostly Java SE with a few Android extensions. But it sounds like your use case will work fine.
The compatibility of the library would depend on what does it actually use from Java API. Bear in mind that some classes that exist in both SE and ME don't have the same set of methods (i.e. ME has less).
As a general case, I'd say the answer is no, however the best way to find out is to actually try.
Also, as a sidenote:
If you need the library for some heavy lifting operations, it might not be wise to do that on the mobile device. If your app is supposed to communicate with a server, you'll probably want to put more resource-heavy operations there. Another benefit of that design is that the server side application is using Java SE and may use any Java library whatsoever.