Where is java command located in Android? - android

I got my android phone rooted and I'm aware that the / doesn't contain the familiar linux /.
Is there a java command? Where is it located? I don't find one in /system/bin.

Is there a java command?
No. Such a command isn't shipped with stock Android images.
Where is it located?
It shouldn't exist on filesystem. What makes you think it should be there?
I don't find one in /system/bin.
You might consider installing any Java programming app for Android to have JDK/JRE installed. In this case the command will be located in the app's sandbox, not /system/bin.

Android does not use Java at all, at runtime.
Android runs programs that have been written in the Java language. Those programs are not compiled to Java bytecodes and will not run on a JVM.
Android executes Dalvik bytecodes. Until somewhere around Android 4, it used a virtual machine called Dalvik, to execute these bytecodes. Now it uses fantastically more complex virtual machine called ART.
Sorry. No Java.

Related

Can you run the same application and code on Android and Linux?

I'm looking to build a new app written in Java, can I write one code that can be executed both on an OS running Linux and OS running android? Or do I need to write two different codes one for each system?
Theoretically yes.
Android apps run in a Dalvik Virtual Machine, that comes with a Java language implementation that compiles down to Dalvik bytecode, but not to JVM bytecode. So, the code has to be written in Java or some language that compiles to Dalvik VM bytecode that uses the Android API.
However, the virtual machine runs on top of the underlying Linux OS, and there are ways to call native code. See NDK documentation.
So, it is technically possible to run native Linux programs on Android, as there is a Linux kernel running beneath everything.

accessing android os root files

i have the following doubt:
i have read that android os is based on linux, and i imagine it may have the same structure that ubuntu (in terms of file configurations: /root, /dev, etc).
so, is it possible to run an application written in C in android? just as it is possible to do in ubuntu? if so, how can i do that?
also, how can i get access to the root files through an android application (written in java)? and how to get access to the behavior of the os (in terms of interruptions for example)?
thanks in advance for your answers.
gus
Basic answer: Running a C app on Android isn't supported, except through the Native Development Kit (NDK).
You can't get access to the root files except by rooting a phone.
You can get access to some OS behavior through the API. Basically, if it's not part of the API, you can't access it.
The Android OS is based on Linux, but it's an OS, not a windowing server like X or a desktop environment like Gnome or KDE.
You may run C and C++ code on android using NDK. You may use also QT framework. But code is runing in virtual machine named Davlik. Android have root acount , but it is default not available for user. Therefore, access to directory is dependend for chmod.
If you would like read about access to low level in android:
http://www.phrack.org/issues.html?issue=68&id=6
And about architecture this system:
https://developer.android.com/guide/basics/what-is-android.html
You can run programs using Runtime.exec. As an example, you can see Terminal IDE which runs many different programs including ssh, vim and bash. It's also open source so you can learn from the code. You will probably have to include the executable as a resource or asset and then copy to a local directory, grant execute permissions, then run with Runtime.exec. You still have limited user permissions as your app runs under a restricted account unless the device is rooted and you request root access.
an android smartphone/tablet works with an Arm cpu, not a x85. the architecture is different.
but you CAN run a C application in android if you cross compile it for arm linux. or you can use a c compiler inside android device. people ported c compiler to android. you can try C4DROID and in android market. but you can only run compiled program in system memory because of android permissions about sd card.

Why does Android need a Virtual Machine(DVM)?

Virtual Machines are used for running apps on different OS(Java compiles code into OS independent .class files which is interpreted into bytecode). Since android apps run on the same OS (i.e Android), it doesn't require a VM (I could be wrong here). Then why does it need a Dalvik VM?
Android Platform can run on different architectures - ARM, MIPs and x86. To abstract out the need to compile binaries for each architecture VM comes into play. It also does memory management for the developer.
We need someone to compile and convert the java classes into bytecode which can be executed by the interpreter.
It is similar to JVM ... you have .java files which will be compiled by java compiler into .class files. the .class files are nothing but bytecode which will be run by the JVM. JVM can reside on any platform(windows,linux or unix).
In android too the files are compiled into .dex files and run by DVM. just to give an idea, when is application is installed, the Android OS assigns unique linux user id, a DVM is assigned for each app. So in short each app has own linux process, DVM and linux user id.
The java files are compiled into .dex files which consume less memory compared to .class files.
Now assume 10 applications are having 10 individual DVM's and the OS has 10 process to handle.
The dispatcher or scheduler in the android OS is responsible for handling these 10 processes....which is why we have android activity life cycle.
You need DVM to maintain the running state of each process(each app).
Why android needs a virtual machine is on the basis that Google engineered Android API to vastly use a Java interface. Java itself is usually run on a virtual machine.
The JVM itself is a stack machine based VM while Android's VM (called Dalvik) is a register based VM (this is for the sake of less code generated and faster speed to get better performance out of whatever device is using Android)
The purpose of a virtual machine is to be able to abstract hardware by simulating it. If you make a virtual machine and compile it to work on every possible hardware, you get what originally made Java rise to popularity: write once run anywhere portability.
You could write code, without having to change it and run it on any hardware that your virtual machine can run on.
Digressing, Android is mostly built in C (and C++?) but the API that manipulates the OS is interfaced through Java, thus you require a virtual machine.

Android NDk and CLI

Is it possible to use CLI - Command Line Interface in Android NDK?? Is there such a function: exec (query)?
Ie is it possible to make queries from the command line C program?
officiallyi have never seen commandline programs on android, whether written in java or android ndk.unofficiallyi have seen commandline c/c++ programs targeting arm processors and the authors claimed they run on android eg follow this link to whet your appetite
My thoughts?Should you write such 'unofficial' applications, i doubt that you will be able to distribute them to your customers eg through the android market since android applications are dalvik executables(kind of java applications compiled and optimised for the dalvik virtual machine)

.JAR + Android?

I just purchased an Archos 5 and I'm wondering if it is possible to put a .JAR file on it and use it as an application. I read somewhere that it is possible but saw somewhere else that it wasn't. If it is possible, is there anything I have to do differently? Or do I just run it like I would on my computer?
Android devices run Android applications, not ordinary Java applications, and the ARCHOS 5 is no exception. While Android applications are written in Java, an ordinary Java desktop application uses a different GUI framework than Android offers.
As said by CommonsWare, although Android apps are written in Java you can't actually run Java code(s) on Android devices sinces Android actually has the Dalvick Virtual Machine as compared to the Java Virtual Machine (which runs the Java Bytecode)
If you still plan to use the logic of your jar file and run it on your device, you may reference it in an android app and use the feature(s) from it.
But be awared, that this mostly depends on what your jar file actually does and how it is packed. You may need to, otherwise, repack it to suit if for using in it Android apps.
Bottom line is, however, you can't run the jar files directly on the device!

Categories

Resources