Setting up your Ubuntu 16.04 LTS for Java Development

It is always good to idea to automate setup to speed up your development. In case you need to setup your computer from scratch it can be very painful and a long process taking days if not weeks. Your laptop might get broken, stolen or you might just want a fresh installation.

The script I have is optimised for myself but can easily be modified for yourself as well.

It first downloads the setup files for below applications:

  • IntelliJ Idea Community Edition IDE
  • Android Studio IDE
  • Studio-3t (formerly called robomongo)
  • xmind
  • zoom
  • exodus crypto coin wallet

Below is the script to download files off internet;

#!/usr/bin/env bash

function downloadIfNotExists {
    if [ -f "$1" ]
    #0 = true
        echo "Already Exists : $1"
        return 0
    # 1 = false
        echo "Downloading : $1"
        wget -P /opt/setup/ -U 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' "$2"
        return 1
#!/usr/bin/env bash

#include for utils
. --source-only

#idea intellij
downloadIfNotExists /opt/setup/ideaIC-2018.1.1.tar.gz
#android studio
downloadIfNotExists /opt/setup/
#3t studio - robomongo
downloadIfNotExists /opt/setup/studio-3t-linux-x64.tar.gz
downloadIfNotExists /opt/setup/
downloadIfNotExists /opt/setup/zoom_amd64.deb
downloadIfNotExists /opt/setup/


Then it will install below programs from ubuntu repos:

  • VirtualBox
  • docker
  • docker-compose
  • chrome browser
  • dropbox
  • open-jdk-8
  • ubuntu-restricted-extras
  • htop
  • thunderbird
  • git
  • pinta
  • gparted
  • terminator
  • yakuake
  • sl
  • vlc
  • code2html
  • maven
  • openssh-server
  • xclip
  • toilet
  • figlet
  • cowsay
  • libav-tools
#!/usr/bin/env bash

#check if the running has root privileges
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"


#download program setup files first

chown -R $USER:$USER /opt

#add java_home
echo "JAVA_HOME=\"/usr/lib/jvm/java-8-openjdk-amd64/\"" >> /etc/environment
source /etc/environment

#virtualbox installation
apt-get install -y virtualbox virtualbox-ext-pack 

apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
apt-get update
apt-get -y install docker-ce
curl -L$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

#systemctl status docker
usermod -aG docker $USER
docker info

#install zoom
dpkg -i /opt/setup/zoom_amd64.deb
sudo apt-get -f install

#install chrome
wget -q -O - | apt-key add -
sh -c 'echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google-chrome.list'
apt-get update
apt-get -y install google-chrome-stable

sudo -H -u $USER bash -c 'cd ~ && wget -O - "" | tar xzf -'
sudo -H -u $USER bash -c '~/.dropbox-dist/dropboxd &'

#install new programs
sudo apt-get install openjdk-8-jdk
apt-get -y install ubuntu-restricted-extras
apt-get -y install htop
apt-get -y install thunderbird
apt-get -y install git
apt-get -y install pinta
apt-get -y install gparted
apt-get -y install terminator
apt-get -y install yakuake
apt-get -y install sl
apt-get -y install vlc
apt-get -y install code2html
apt-get -y install maven
apt-get -y install openssh-server
apt-get -y install xclip
apt-get -y install toilet
apt-get -y install figlet
apt-get -y install cowsay
apt-get -y install libav-tools

#idea extract
tar -xzvf /opt/setup/ideaIC-2018.1.1.tar.gz -C /opt/

#mongodb entry for /etc/hosts for docker mongodb
echo '       mongodb' >> /etc/hosts

#android studio
apt-get -y install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
unzip /opt/setup/ -d /opt/

#xminf - mind mapping software
mkdir -p /opt/xmind
unzip /opt/setup/ -d /opt/xmind/

#exodus wallet
mkdir -p /opt/exodus
unzip /opt/setup/ -d /opt/exodus/

mkdir -p /opt/studio-3t
tar -xzvf /opt/setup/studio-3t-linux-x64.tar.gz -C /opt/studio-3t
chmod +x /opt/studio-3t/
/opt/studio-3t/ &

#change ownership to user for those programs
chown -R $USER:$USER /opt

#update existing programs first
apt-get update
apt-get -y upgrade - for android signing apk release files
mkdir -p /home/$USER/.gradle
cat > /home/$USER/.gradle/ << 'EOF'
RELEASE_STORE_PASSWORD=[put tore password here]
RELEASE_KEY_ALIAS=[put key alias here]
RELEASE_KEY_PASSWORD=[ut key password here]

chown -R $USER:$USER /home/$USER/.gradle

#create .m2 & github token files
sudo -H -u $USER bash -c 'mkdir -p /home/$USER/.m2/'
sudo -H -u $USER bash -c 'touch /home/$USER/.m2/github-token'
sudo -H -u $USER bash -c 'touch /home/$USER/.m2/settings.xml'
sudo -H -u $USER bash -c 'mkdir -p /home/$USER/.m2/'

cat > /home/$USER/.m2/github-token << 'EOF'
[place your github token here]

cat > /home/$USER/.m2/settings.xml << 'EOF'
[place your settings.xml content here]

#Setup SSH keys
sudo -H -u $USER bash -c 'mkdir -p /home/$USER/.ssh'

cat > /home/$USER/.ssh/id_rsa << 'EOF'
[place your private key here]

# Setup SSH public key
cat > /home/$USER/.ssh/ << 'EOF'
[place your public key here]

#Update access rights for SSH keys
chown -R $USER:$USER /home/$USER/.ssh
chmod 0700 /home/$USER/.ssh
chmod 0644 /home/$USER/.ssh/
chmod 0600 /home/$USER/.ssh/id_rsa

chown -R $USER:$USER /home/$USER
chown -R $USER:$USER /opt/

#setup workspace and clone repos

apt-get update
apt-get upgrade
apt-get -y autoremove


lsb_release -a

And finally, update the following file to clone your own repos

#!/usr/bin/env bash

#Workspace setup
git config --global "[place your email here]"
git config --global "[place your name here]"
git config --global push.default simple

#Cooldatasoft github - [Replace with your own repositories]
#you should have setup your ssh keys to get access to the repos
sudo -H -u $USER bash -c 'mkdir -p /home/$USER/workspace/cooldatasoft-github'
cd /home/$USER/workspace/cooldatasoft-github
sudo -H -u $USER bash -c 'git clone'
sudo -H -u $USER bash -c 'git clone'
sudo -H -u $USER bash -c 'git clone'
sudo -H -u $USER bash -c 'git clone'
sudo -H -u $USER bash -c 'git clone'

chown -R $USER:$USER /home/$USER/


Github Repo for scripts


HttpUrl Parameter Encoding in Java

Some already know that there is URLEncoder class in java but not many know that this class is actually not for URL encoding but for form encoding if you have look at the javadocs. There are several other utility libraries as well doing this correctly like apache-commons but if you just need url encoding, it might be easier to use one utility class instead of loading a whole library.


public class URLParamEncoder {

    public static String encode(String input) {
        StringBuilder resultStr = new StringBuilder();
        for (char ch : input.toCharArray()) {
            if (isUnsafe(ch)) {
                resultStr.append(toHex(ch / 16));
                resultStr.append(toHex(ch % 16));
            } else {
        return resultStr.toString();

    private static char toHex(int ch) {
        return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);

    private static boolean isUnsafe(char ch) {
        if (ch > 128 || ch < 0)
            return true;
        return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;


click here for source