For example, I'm using URLConnection and the Thread class in my java program. Can the Android device use URLConnection to connect via a mobile network, and do I have to make any changes to threading to make it usable on the device? Is there anything that doesn't translate well?
-
1The structure of an app is inherently different from a normal Java program, but aside from that you can use `URLConnection` or `Thread` as much as you want, although there are possibly better alternatives on Android like `AsyncTask`. Also Java is not 100% supported on Android, technically it isn't Java what you are programming when writing an app, just something that is very Java-like. – Xaver Kapeller Jul 21 '14 at 13:29
-
Most of the Java API is translated to Android, so *in theory* you don't need to change your code. You can check any differences in the Android SDK documentation. Network connection is automatically handled by Android, so you don't need to worry about what kind of network connection is available, Android will use the one available if any or return an error. Anyway your question cannot be answered correctly if you don't show us your exact code. – m0skit0 Jul 21 '14 at 13:31
3 Answers
Android Java includes most of the Java standard libraries.
It does not contain AWT, Corba, or any of the media libraries.

- 6,615
- 3
- 24
- 40
Yes just like java you can do although the way of doing is different,
java.lang.Object
↳ java.net.URLConnection
For example to retrieve - ftp://mirror.csclub.uwaterloo.ca/index.html
URL url = new URL("ftp://mirror.csclub.uwaterloo.ca/index.html");
URLConnection urlConnection = url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
try {
readStream(in);
finally {
in.close();
}
}
URLConnection
must be configured before it has connected to the remote resource. Instances of URLConnection
are not reusable: you must use a different instance for each connection to a resource.
Refer - http://developer.android.com/reference/java/net/URLConnection.html

- 23,126
- 28
- 107
- 185
You won't have problem to run your code that uses URLConnection and Threads. But, the answer to your main question is no, Standard Java do not translate directly to the Android. Read this wikipedia article.
When using threads you must take some care about acessing the ui thread. This artilcle explains that.

- 15,044
- 7
- 62
- 88