Pratham AI Systems
Mobile Programming

In previous article I discussed how to make your Android phone a Hacking and Programming Machine. Before reading this article you should read previous article first to make your Android phone as Programming learning machine. In this article, I will discuss how to configure Kali Linux or Termux as a programming machine. It will also discuss how to configure Android phone to use MySQL (MariaDB) RDBMS. For developing program we need editor, compiler or interpreter, debugger and for accessing RDBMS MySQL we need MySQL database. In this article we will use micro or nano editor to create a program and compiler/ interpreter to compile and execute program. Nano editor is already installed on Kali Linux.

Programming improves=> Logical thinking, Creativity, and Problem Solving.

Installation of Micro editor

To install micro editor use command
pkg install micro

Fig. 1 micro editor installation

Commands to use micro editor

ctrl+o: Open file
ctrl+s: Save file
ctrl+q: Exit micro
ctrl+g: Help

Nano Editor

Nano editor is already installed on Termux and Linux. We can also use nano editor for developing C/C++/Java and Python programs.

To open nano editor use command

nano filename

where filename is name of the file to create or open.

Nano editor Commands

ctrl+o : To save file

ctrl+x: Exit nano editor

Installation of C/C++ compiler

To install C/C++ compiler on Mobile use pkg command.

Below command installs the C/C++ compiler in Android mobile.

pkg install clang

Fig. 2 C/C++ Installer

Note: If you get installation related error then use following command to update and upgrade pkg.

pkg update && pkg upgrade

Creating, compiling and running C program

Compilation of C program

To compile a C program gcc compiler can be used. The syntax of how to use gcc is given below.
gcc -o (ExecutableFileName) (CurrentFileName.c)

-o option represents (ExecutableFileName) as output file which is executable and (CurrentFileName.c) as C program.
To execute C program ./ExecutableFileName is used.
./(ExecutableFileName)

Example
Open micro editor and type following C program.

To open micro editor use at command prompt.

micro programname.c

Example

micro first.c

Above command will open the micro editor. Type the following program in micro editor and save the file using Cnrl + s.

#include<stdio.h>

int main()
{
        printf(“Welcome to C Programming”);
        return 0;
}

Fig. 3 C Program

Save the C program using ctrl+s
Compile the C program using
gcc -o first first.c

Fig. 4 Compiling C Program

where -o represents output file as first and firsr.c as C program.
To execute the C program command is
./first

Fig. 5 Execution of C Program

Creating, compiling and running C++ program

Compilation of C++ program

To compile C++ program c++ command can be used.
c++ (CurrentFileName.cpp) -o (ExecutableFileName)
To execute C/C++ program
./(ExecutableFileName)

Example
Open micro editor and type following C++ program

micro example.cpp

#include<iostream.h>

using namespace std;

int main()
{
        cout<<“Welcome to C++ Programming”;
return 0;
}

Fig. 6 C++ program

Save the C++ program using ctrl+s
Compile the C++ program using
c++ example.cpp -o example

Fig. 7 Compiling C++ program


where -o represents output file as example and example.cpp as C++ program.
To execute the C++ program command is
./example

Fig. 8 Executing C++ program

Installation of Java compiler and runtime environment

To install Java compiler and runtime environment type the following command at Termux terminal.

pkg install ecj dx

Creating, compiling and running Java program

Compilation of Java program
ecj <filename.java>
Execution of Java program
dx –dex –output=<filename.dex> <filename.class>
dalvikvm -cp <filename.dex> <filename>

Example
Open micro editor and type following Java program

micro First.java
class First
{
        public static void main(String args[])
{
                System.out.println(“Welcome to Java Programming”);
         }
}

Fig. 9 Java Program

Save the Java program using ctrl+s
Compile the Java program using
ecj First.java

Fig. 10 Compiling Java Program

To execute the Java program give the following commands
dx –dex –output=First.dex First.class
dalvikvm -cp First.dex First

Fig. 11 Execution of Java Program

Installation of Python Interpreter

pkg install python

The above command is used to install Python Interpreter on Phone.

Creating, executing Python program

To execute python program command is
python <FileName.py>
where FileName.py is name of the Python program
Example
Open micro editor and type following Python program

micro Test.py

print(‘Welcome to Python Programming”);

Fig. 12 Python Program

Save the Python program using ctrl+s
FileName: Test.py
To execute the Python program command is
python Test.py

Fig. 13 Execution of Python Program

Installation of MySQL (MariaDB) on phone

pkg install mariadb

The above command will install MariaDB (MySQL) on phone.

Fig. 14MariaDB Installation

To start MySQL server give the command mysql at command prompt.

mysql

Fig. 15 Starting MySQL server

After successfully execution of mysql command MariaDB server instance will be started as shown in Fig. above.

We can use SQL (Structure Query Language) to interact with MySQL database. SQL is used to create, modify, and retrieve data from database.

Testing MariaDB (MySQL) database

Next we have to create a database using create database command.

create database testdb;

The above command will create a database named testdb;

Fig. 16 Database creation

Using database

use database command is used to use/ activate database for processing.

use testdb;

Fig. 17 Using database

Testing basic SQL commands

Create command is used to create a table in SQL. In order to create a table we require table name, column name and data type for column.

create table testtbl(rno int, name varchar(20));

It will create a table named testtbl and stored in database.

Fig. 18 Create command

Desc command is used to see the structure of a table.

desc testtbl;

It will display the structure of a table.

Fig. 19 Desc command

Inserting values into table

Insert command is used to insert values into table.

insert into testtbl values(1,’Ashish’);

Fig. 20 Inserting values

Displaying records from table.

Select command is used to display recodes/ row from table.

Fig. 21 Select command

Conclusions

This article provides details of how to compile and run C/C++/Java program in Termux/ Kali Linux on Android phone. It also provides details of how to install and configure MySQL (MariaDB) on phone and how to execute SQL commands.

Amar Nayak

22 years of experience in Training, Programming, and Research.
Certifications: IBM DB2, IBM WebSphere, IBM Tivoli, OCA, OCP, SCJP (OCJP), CCNA, RHCE,

https://prathamai.com

Leave a Reply

Your email address will not be published. Required fields are marked *