I am working on a Java Project for my own learning, what i have made is a class which can both read and write to external process using Runtime.getRuntime().exec(cmd);
Runtime.getRuntime().exec(cmd);
In Ubuntu/Debian you can use :
dpkg -s packagname
to see if a package is installed. Then you can parse the output of the command in your app.