Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

The smartphone you carry with you is not just a small gadget that you can use to snaps to your friends or throw birds to pigs. In fact, it is a powerful piece of technology that can be used to do almost anything you would normally use a full-fledged PC – albeit a bit smaller and with a few caveats.

You can even write, run and compile code on your small computer and you do not have to install an IDE or even add your phone to it. Because Android is based on the Linux kernel, it also has a shell like you would find on Linux – although there is no way to approach it out-of-the-box.

Fortunately, you can install a Linux terminal emulator and access tons of Linux packages that you can use to do much more with your phone than you normally would have access to. Here is a list of things you can do once you are, with the terminal of Linux in your pocket,

Here is a brief example of how you can write, compile and run C, Java and Python programs on Android,

1. Downloading Termux

Termux is a powerful terminal emulator that comes with an extensive list of more than one hundred Linux packages. The first thing you have to do is go to Google Play and download Termux.

2. Set up storage

You must give Termux access to setting up storage. Just open Termux and write the following piece of code – It creates a folder for Termux on your Android device.

 termux setup storage 

The default path for Termux is "/ data / data / com.termux / files / home" . A warning when using this emulator is that Android does not allow access to the document outside of the home folder – the only way to bypass this is to row your phone.

However, you have read access, so you can easily copy any file you want to work with to your home folder and then do the rest from there.

3. Writing a code using a terminal text editor

There are a number of ways you can write code on Android.

1. Write code using a normal editor or move code from your PC to your phone and then transfer it to the base directory of Termux using the following command,

 cp old-path / filename new-path /

// EXAMPLE
cp /data/data/com.termux/files/home/storage/downloads/code.c /data/data/com.termux/files/home

This command copies a file named "code.c" from the downloads folder and places it in the base directory of Termux. You can change the path depending on where the file is located.

2. You can also write within the Termux terminal using an in-terminal text editor. You can install Micro, which is a lightweight easy-to-use code editor. You can install it using the following command,

 pkg install micro 

Once installed, you can open it by simply typing "micro" into the terminal. You can also use it to open and edit an existing file by typing "micro file name" (eg Micro hello.c).

Once in the editor the navigation is done with CTRL + keyboard keys (the volume down button of your phone acts as CTRL in the terminal). Here are a few handy shortcuts for Micro,

  • CTRL + Q – Exit Micro
  • CTRL + O – Open a file
  • CTRL + G – Help menu
  • CTRL + S – Save file

4. Install the compilers for C, Python and Java

For C language, enter the following code,

 pkg install clang 

Enter the following code for Python,

 pkg install python 

Execute the following code for Java,

 pkg install ecj dx 

5. Compile and execute code

For C language, enter the following code,

 gcc -o 
./

// EXAMPLE
gcc -o code code.c
./code

Enter the following code for Python,

 python 

// EXAMPLE
python code.py 

Execute the following code for Java,

 ecj 
dx - dex - output = 
dalvikvm-cp 

// EXAMPLE
ecj Hello.java
dx --dex --output = Hello.dex Hello.class
dalvikvm -cp Hello.dex Hello 

Now you are ready to get started. Happy coding!

The post Here is How You Can Write and Run C, Java and Python Programs on Your Android Devices appeared first on News Doses.



This post first appeared on News Doses, please read the originial post: here

Share the post

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

×

Subscribe to News Doses

Get updates delivered right to your inbox!

Thank you for your subscription

×