Will java applications run on android

Can Java application run on Android?

You can do it quite easily as there are many ways to run Java apps on Android. Specific application called Java Emulators can do it quite easily. These are the popular Java emulators for Android: viz, JBED, PhoneME, Jblend and NetMite.

Why is Java Android preferred?

Java has platform independent feature so it is used for android development. Thus android developers to choose java as there is already a good base of java programmers are available that can help in creating, improving android applications plus with many libraries and tools of java make developers life easier.

Will Android stop supporting Java?

It’s unlikely that Android will stop supporting Java any time soon. The Android SDK is still mostly written in Java. The majority of Android apps still include Java. The Android OS is built upon a Java Virtual Machine.

Why does Android need Java during installation?

Android Studio is the official IDE for Android development. They perform a lot better than Windows when it comes to Android development. Since Android’s source code is in Kotlin (or Java), you’ll need to install the Java Development Kit (JDK) as well.

Is Java good for mobile apps?

JAVA gives the best option for development of mobile applications that are based on Android, as Android consist of its own APIs and JAVA libraries. You can also code in other language as well but you need a framework to convert into native app for that API.

Is there any way to run Java apps on Android?

There is no way to run them directly on Android and there are no (at least not known to me) apps or modifications that allow it. The apps (emulators) mentioned in other answers are for the J2ME (Java2 Micro Edition, also known as MIDP and applications as “midlets”) environment. They are the Java applications for mobile devices…

Why is my Android app not running on my Device?

Make sure instance run in android studio is disabled. Because if Instance run is enabled when you debug the app on real device through usb debugging it will work properly . but if u share the apk from your device to other device it will not work. It might show an error . App Name Unfortunately Stoped.

Can I run JAR files on Android without JVM?

No.. you can’t. Let me eloberate. Android does not use JVM which is needed to run the Java byte code. You can not run .jar files if you don’t have JVM. Android used to come with DVM (Dalvic Virtual Machine) which is a optimized and stripped down version of JVM.

Читайте также:  Python datetime timedelta examples

Do Java applets work in Android browsers?

Java Applets will not work within a browser in Android as they do not make a plug-in like the ones you’d find for a desktop computer. There are no plans for creating one since the resources required would not suffice on a mobile device and the technology is considered obsolete.

Источник

How to run Java programs directly on Android (without creating an APK)

A step by step instruction for compiling a Java program into an Android executable and using ADB to run it.

When you want to create a system / commandline tool for Android, you have to write it in C(++)… or do you? TLDR; here’s the final proof of concept. Sticking with Java would have the benefit of avoiding all of the native ABI hassle and also being able to call into the Android runtime. So how do we do that?

A (not so) simple Hello World program

Let’s start with the Java program we want to run. In order to make it a bit more interesting (and because any useful program has dependencies), it won’t just print the obligatory “Hello World” message, but also use the Apache Commons CLI library to parse its commandline arguments:

package com.example; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; public class HelloWorld  public static void main(String[] args) throws ParseException  Option version = new Option("v", "Print version"); Option help = new Option("h", "Print help"); Options options = new Options(); options.addOption(help); options.addOption(version); for (Option opt : new DefaultParser().parse(options, args).getOptions())  if (opt.equals(version))  String os = System.getProperty("os.arch"); System.out.println("Hello World (" + os + ") v0.1"); > if (opt.equals(help))  new HelpFormatter().printHelp("Hello World", options); > > > >

Setting up the working directory

We will have to manually run several commandline tools in the next step, assuming the following final directory structure:

. ├── android-sdk-linux │ └── build-tools │ └── 23.0.2 │ └── dx ├── bin │ └── com │ └── example │ └── HelloWorld.class ├── lib │ └── commons-cli-1.3.1.jar ├── src │ └── com │ └── example │ └── HelloWorld.java ├── helloworld.jar └── helloworld.sh
  • Android SDK (either via Android Studio or the SDK Manager). NOTE: If you are an Android developer, you’ll have the Android SDK already installed. In that case, you don’t actually need to copy it to the working directory as long as you know the path to the dx tool.
  • Apache Commons CLI library v1.3.1

Afterwards copy&paste the HelloWorld code from above into the source folder. You might also find my semantic version parser class useful later on (not required here, though).

Compiling and dexing the Java class

Next step is to compile the java class (keep in mind that Android is stuck with Java 7 — bytecode for later versions won’t work). In case you are not used to doing this outside of an IDE, here’s the command:

javac -source 1.7 -target 1.7 -d bin -cp lib/commons-cli-1.3.1.jar src/com/example/HelloWorld.java

Make sure the program compiled properly:

java -cp lib/commons-cli-1.3.1.jar:bin com.example.HelloWorld -h usage: Hello world -h Print help -v Print version

Android cannot run Java class files directly. They have to be converted to Dalvik’s DEX format first (yes, even if you are using ART):

./android-sdk-linux/build-tools/23.0.2/dx --output=helloworld.jar --dex ./bin lib/commons-cli-1.3.1.jar

NOTE: Android Build Tools v28.0.2 and later contain a dx upgrade, called d8 . The d8 tool can process Java 8 class files. I’ll stick with dx for backwards compatibility reasons here.

Creating the startup shellscript

Android does not have a (normal) JRE, so JAR files cannot be started the same way as on a PC. You need a shellscript wrapper to do this. Copy&paste the one below to the workspace.

base=/data/local/tmp/helloworld export CLASSPATH=$base/helloworld.jar export ANDROID_DATA=$base mkdir -p $base/dalvik-cache exec app_process $base com.example.HelloWorld "$@"

NOTE: DEX files can also be started directly using the dalvikvm command, but going through app_process gives us a pre-warmed VM from the Zygote process (it is also the method employed by framework commands like pm and am ).

Installing and running the (non-) app

Time to push everything to the device:

adb shell mkdir -p /data/local/tmp/helloworld adb push helloworld.jar /data/local/tmp/helloworld adb push helloworld.sh /data/local/tmp/helloworld adb shell chmod 777 /data/local/tmp/helloworld/helloworld.sh

Moment of truth (fingers crossed):

adb shell /data/local/tmp/helloworld/helloworld.sh -v Hello World (armv7l) v0.1

NOTE: Since nothing was installed into the system, getting rid of the program is simply done by deleting the directory again.

It works, but how do I get a Context?!

Contexts represent an environment that is associated with an app (which we explicitly did not build) and are also device dependant. They can only be created by the ActivityThread class (a hidden system class that you cannot instantiate). If you want to interact with the Android runtime, you have to talk to the system services directly through their Binder interfaces. But that’s a topic for another article.

Follow up articles

Источник

Can Java applications run on phones (at least android) AND Windows?

Hi all I love stackoverflow so helpful. Afaik IOS has some security measures that dont let other apps (such as jvm) execute code from your app. Not sure how much this is true. But anyway, I heard that there are some problems when you try to run java application targeted for Windows on android phone. Is that because some libraries (or most) are not cross platform? Or maybe even standard library is not cross platform (at least not completely)? So basically if I wanted to code app for both windows,linux,mac,etc AND android, would I have to create functions like:

 IF unix THEN unixfunction() IF android THEN androidfunction() 

or I wouldnt have to worry about it? What should I know if I want to target both android phones AND computers (windows,linux,etc)? Is the above approach okay or I need to know something else? Is this even possible? Sorry for a lot of questions, But portability was why I got interested in Java.

3 Answers 3

Java applications are run on a java virtual machine, which is what allows them to work on multiple platforms. However, android sdks have quite a few additional libraries and features pertaining exclusively to an android-compatible application that would make direct porting to windows impossible without adaptation.

That said, there are libraries which when used will allow an application for android to work on windows, with the exception to features of the android phone which obviously absent when run on windows. My guess is these libraries would provide a means to distinguish, but ideally you would want to distinguish as little as feasibly possible.

So in short no, not without some adaptations. If you’re considering creating a program which will work on both, I would recommend you first find one such library, as it will be far more difficult to change later.

Источник

How to run Java Program on Android? (Simple Method)

RUN JAVA PROGRAM on ANDROID

Java is a popular programming language and taught in schools and colleges to students. If you’re a student or working professional who wants to run Java Program on Android, you need to follow this tutorial.

In this tutorial, I will be explaining the methods to run Java Program on Android. So, stick with the tutorial and follow each and every step carefully.

RUN JAVA PROGRAM on ANDROID

How to Run Java Program on Android?

To run Java Program on Android, follow the steps mentioned below:

Step 1: Launch Play Store on your Android phone

To begin with, you need to launch the Play Store app on your Android phone. Open your Android app drawer and search for Play Store. Now, click on the Play Store app icon to launch the Play Store on your Android phone.

Step 2: Search for JvDroid app on Play Store

After launching the Play Store app, you need to click on the Search bar. In the search bar, enter JvDroid and search. From the search results open the first result.

Step 3: Install JvDroid app on Android Phone

After opening the first result from the search results on Play Store, you need to Install the JvDroid app.

Step 4: Launch the JvDroid app on Android Phone

Once you’re done installing the JvDroid app on Android Phone, you need to click the Open button to launch the JvDroid App.

Step 5: Write Java Program and Click Run to Run Java Program on Android

After you open the JvDroid app on your Android phone, you need to write the Java Program. You will get a decent code editor with a Run button at the top. You need to click the Run button to Run Java Program on Android with the JvDroid app.

Conclusion

JvDroid is a very useful Android app to run your Java programs on Android. You can use it to write and run simple Java programs. But, you cannot run advanced Java programs and add install additional libraries.

Related Articles:

Источник

Оцените статью