Category Archives: Java


Spark – A micro web framework in Java

Spark is a micro web framework in Java, inspired from Sinatra (a popular lightweight web framework in Ruby). Using spark, you can quickly build web applications in Java, with minimal effort (without going through the boring xml configurations steps). If you learning java, then you can learn a lot by reading the source (since, it’s a free and open source framework).



  • its simplicity
  • fast development
  • high productivity (get more done, in fewer lines of code)

Getting started with Spark

1. First setup spark

Download Spark (If you’re using Apache Maven, then it would be much easier for you)

2. Write some code

Code in image ? Ha Ha .. just to remind you that it’s not a good habit to copy/paste code! Type it.

3. Launch

Now, you can see your little app in action :


Recommended Link(s)
Read official – getting started guide for Spark


Getting Started with Play Framework : Ubuntu/Linux Mint

What is Play Framework ?

Play Framework is a simple and powerful web development framework for Java/Scala. It’s very inspired from Ruby On Rails framework, so it’s like Rails, but for Java/Scala (initially it supported only Java, but now it also supports Scala (a programming language, very similar to Java, with some functional features, designed to be as a better Java)). Unlike other complicated java web development frameworks, Play is very simple and highly productive.


Play is a lightweight, fast and highly scalable web development framework, with web friendly architecture and features (stateless, low resource consumption, reactive model based on Iteratee IO etc). So if you’re a Java/Scala developer, who want to develop cool web applications – then Play is a great choice for you.

Installing Play Framework

You must have Java installed (JDK 6 or later), read this tutorial on installing JDK in Ubuntu / Linux Mint if you haven’t already done that. When you’re done setting up java development kit, open a terminal and type javac to make sure everything is setup properly.

Download Play Framework

Download the latest version of Play (currently, it’s v2.1.0) and extract it to your Home Directory (it can be anywhere, but you should have write permission).

Set Path Variable for Play

Add the play to your path variable. Suppose, you have extracted the play framework to ~/packages/play-2.1.0 directory. Then open a terminal and type :

export PATH=$PATH:~/packages/play-2.1.0/

Now, if you type play at the terminal, you should have play command available.


Creating your first app

Now, you have successfully installed the play framework – Let’s create a simple application “TestApp” (it will simply say : “Hello Play”, not any useful, but you get an overview).

play new TestApp

Now, it will prompt for few questions (Application Name, Java/Scala etc), then move into the application directory and start the application.

cd TestApp

Now, you will have the play prompt, So you can run the application –

[TestApp]$ run

Open your browser and type the address http://localhost:9000, the default page should appear.


Now, open the file App/Controllers/ in your favorite text editor (Emacs, Vi, gedit etc) or IDE (geany, Eclipse etc) and replace the existing return line (in index method) with this :

return ok("Hello Play");

Now, visit the address http://localhost:9000 (or refresh if it’s slready loaded) and you should see the “Hello Play” greetings. Yeah! our first useless app is running :)


Recommended Resources For Further learning!


How To install Java / JRE on Ubuntu 12.04

Ubuntu 12.04 is a LTS (Long Term Support) release, for desktop as well as server edition. Just after a fresh install of Ubuntu 12.04, you need to install few things to get everything running, atleast for common tasks (you may find my previous post useful – things to do after a fresh install of Ubuntu 12.04).

Now, you want to execute Java programs then you must – so you just need to install a JRE (Java Runtime Environment, includes Java Virtual Machine, JIT (Just in Time compiler, IcedTea plugin)) and you’re ready to run Java Applications and Applets (not so popular anymore, JavaScript rocks!).

Installing Java - using Ubuntu Software Center


But, remember if you want to develop Java Applications then you need more (JDK, Docs etc) than just a JRE. So checkout this post – Install JDK on Ubuntu 12.04 if you want full development environment rather then just the run time environment.

Installing JRE/Java on Ubuntu 12.04

There are many implementation of Java Runtime environment but we will stick to the Open Source implementation of Java – OpenJDK (Open Java Development Kit). The latest stable version is openjdk-7 (although v 8 developer preview version is also available). a terminal (hit Ctrl+Alt+t, to open a bash shell or terminal or whatever shell (such as zsh) you prefer) and execute these command(s) –

sudo apt-get install openjdk-7-jre

(The package size is around ~30MB)


Sun JDK will be removed from Ubuntu Partner Archive

In a recent announcement, Canonical has specified that Ubuntu Partner Archive will no longer contain Sun JDK, the packages (sun-java6-jre, sun-java6-jdk, sun-java6-plugin, sun-java6-source etc) will be removed on 16th of the next month, due to some licensing problem, as the said in announcement –

we no longer have permission to redistribute new
Java packages as Oracle has retired the “Operating System Distributor License for Java”

Although, it will be remain installed on the systems but no security updates will be provided in future so the ubuntu users who are dependent on Sun JDK or any of this component are recommend to migrate to OpenJDK or Oracle JDK if you get any problem with open JDK in some applications.


Migrating from Sun JDK to Open JDk

Uninstall Sun JDK and its components

sudo apt-get purge sun-java*

Then install OpenJDK 7/6

sudo-apt-get install openjdk-6*

If you want to install only few selected package such as openjdk-6-jre then type

sudo apt-get install openjdk-6-jre

how to install jdk on Ubuntu 11.10

Java is one of the most popular programming language and its popularity has undergone an exponential growth (probably because it’s well suitable in distributed environment – you can use Java to develop cool web application with a lot of complex features as well as in developing sophisticated desktop applications, and it’s platform independent – ‘write once and run everywhere‘) in fast few years.

Similarly Ubuntu (latest version : Ubuntu 11.10 beta 1) has become the most popular Linux distro – for desktop environment. That’s why, Ubuntu is now considered as a great platform for developing Java applications.

Anyway, if you are an Ubuntu user and going to start learning Java or a java programmer/developer – want to start coding on Ubuntu, this post is about installing Java Development Kit (JDK) on Ubuntu 11.10 (although it is expected to work on other Debian based Linux distro too). On the other hand if you’re an Ubuntu user, interested only in running java applications then you don’t need to install jdk (it has lot of components which is not required for executing a java program/software) – instead you just need to install jre on Ubuntu 11.10 i.e java runtime environment (includes Java Virtual Machine, for executing java bytecode/class).

Java - jdk for Ubuntu 11.10

Installing Java Development Kit (JDK) on Ubuntu

There’re many JDK available thesedays. One of the most popular – open source jdk is openjdk. OpenJDK is well compatible with Ubuntu/Linux and it is available in official repository – so you can install it a click.

install openjdk on Ubuntu 11.10

Open a terminal (Ctrl+Alt+t) and execute the command(s) –

sudo apt-get install openjdk-7-jdk

OR you can install sunjdk

Update1 : The sun jdk isn’t included with the official repository, so you first need to add a PPA for that; Thanks to Casier :).

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin

That’s All..have fun in programming in Java, with Ubuntu!