Best way to run java on Android | Using Termux

Computer Bits Daily
2 min readJun 16, 2021

Termux is an Android terminal emulator.

Answer of the question “ How to run java program in Android device ? “ is here.

To run java in android using Termux requires the installation of two termux packages.

  • ecj : — (Eclipse compiler for java) this compile your java program and create .class file.
  • dx : — it take .class file and redevelop .dex.
Java using Termux

Before we Learn How to run java on android, lets take a look at Some Important Termux command we must remember:

- To clear all screen content run the command.

$ clear

- To find current working directory.

$ pwd

- To change our current working directory to another directory. Here I’m moving in /java directory/folder.

$ cd /java

  • If you want one directory/folder to move

All in one free Computer Course Best Android app:

https://play.google.com/store/apps/details?id=com.computerdictionary.mcqtutorial.computerbitspradip

$ cd..

- If you want to back two directories use.

$ cd ../../

- To Create New File: To Create New Directory/Folder use mkdir commad Stands for make a new directory.

$ mkdir <new-directoy-name>

- To Delete Directory/Folder in Termux

$ rmdir <directory-name>

- To delete File

$ rm <file-name>

Here is How You Can Write and Run Java Programs on Your Android Devices

Step 1: Install Termux from Google Play

Step 2: Now Update and Upgrade Termux

- Open Termux

- To Update Termux type command

$ apt update

- To Upgrade Termux type command

$ apt upgrade

Step 3: To install ecj and dx run the following commands

$ apt install ecj

$ apt install dx

Step 4: To Create java file with .java extension.

- Type command

$ nano hello.java

- This will create hello.java file and open in nano text editor.

- Now write simple java program in nano text editor as given below

public class hello

{

public static void main(String args[])

{

System.out.println(“ Welcome to Java Learning Word With computer bits daily”);

}

}

- Note down that file_name and class name must be same to avoid error and confusion.

- Ctrl + s to save file and Ctrl + x to close nano text editor

Step 5: $ ecj hello.java

Step 6: $ dx — dex — output=hello.dex hello.class

Step 7: $ dalvikvm -cp hello.dex hello

For more reading : Best way to run java on Android | Using Termux (computerbitsdaily.blogspot.com)

Now you’re ready to Run Java program On Termux . Happy Coding | Keep Learning | |Keep Sharing | Stay Safe!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Computer Bits Daily
Computer Bits Daily

Written by Computer Bits Daily

Learning Computer skills and Computer technology by learning and sharing

Responses (2)

Write a response