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
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
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;
}
Save the C program using ctrl+s
Compile the C program using
gcc -o first first.c
where -o represents output file as first and firsr.c as C program.
To execute the C program command is
./first
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;
}
Save the C++ program using ctrl+s
Compile the C++ program using
c++ example.cpp -o example
where -o represents output file as example and example.cpp as C++ program.
To execute the C++ program command is
./example
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”);
}
}
Save the Java program using ctrl+s
Compile the Java program using
ecj First.java
To execute the Java program give the following commands
dx –dex –output=First.dex First.class
dalvikvm -cp First.dex First
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”);
Save the Python program using ctrl+s
FileName: Test.py
To execute the Python program command is
python Test.py
Installation of MySQL (MariaDB) on phone
pkg install mariadb
The above command will install MariaDB (MySQL) on phone.
To start MySQL server give the command mysql at command prompt.
mysql
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;
Using database
use database command is used to use/ activate database for processing.
use testdb;
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.
Desc command is used to see the structure of a table.
desc testtbl;
It will display the structure of a table.
Inserting values into table
Insert command is used to insert values into table.
insert into testtbl values(1,’Ashish’);
Displaying records from table.
Select command is used to display recodes/ row from table.
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.