How to run CONSOLE Java code on Android

Step 1: Termux

>Download and install Termux (best app)
>Open and run the command apt update && apt upgrade && pkg upgrade
This command is very important! You should run it whenever you want to use the Advanced Package Tool or pkg
>Now make sure you have ecj, dx, and dalvikvm by individually running ecj --version, dx --version, dalvikvm --version
>>If you don't have it, it should say 'The program '[tool]' is not installed. Install it by executing:
pkg install [tool]' or '...apt-get install [tool]'
pkg is a newer tool used; I had to use apt-get since I had this app for a long time.
Use whatever it tells you to use

Step 2: compile and run

>I recommend going to your home folder cd ~ and making a directory called Java mkdir Java and cd in there cd Java and make project folders inside /Java
>In there [project folder], make a Java code using nano or vim editor. I use vim.
>Compile your code with ecj File1.java File2.java or, if first compilation, use ecj *.java
Don't always use *.java unless necessary; slows down compilation time by compiling already good code again
>You should now get .class files. Check with ls *.class
>Compile them to Dalvik bytecode so that Android can read it using dx --dex --output=MainClass.dex *.class
The output must have the extension dex
>Finally, run it by dalvikvm -cp MainClass.dex MainClass
-cp means classpath so you must specify the class which has the main entry point. No extension

幸If you have any questions or suggestions for other tutorials, feel free to post in the comments!幸