Web Frameworks

Java is a great language, but if you have ever tested any scripting language like PHP, Ruby, node.js, you know Java is… Over Engineered.

You have to write lots of code for anything. Big configuration files, use of application servers, too many classes to perform simple tasks, no support for Collections literals, etc…

Because of that, and before I knew the world beyond java, I started Blaapps (Bery Lol AAplication Server). A very lightweight application server minded for speed up development of web apps.

After I presented it as my final year project I stopped developing new features, but recently I had to do some web stuff on java and I remembered how painful it is.

If you start doing a web project with java, you feel naked. Standard tools are bare minimum. That’s why there’s a lot of web frameworks for JavaEE.

But most of them follow the java over engineering philosophy. Let’s see some examples…

Installation

Let’s see what is needed to develop with some of the main web technologies:

Technology Base Testing server Dependency Management
Java EE Java Runtime + IDE Application Server maven, not included
Play Framework Java Runtime + Play Embedded server included commands
PHP PHP Embedded server pear – Included
Ruby On Rails Ruby + Rails Embedded server Ruby Gems, not included
Node.js Node.js Embedded server npm – Included

So, if you want to develop a Java EE web app, you will have to download the JRE, an application server, and the Java framework you want to use. Also, you will need an IDE, as the Java language requires you to write lots of code, and compiling processes aren’t simple.

So, if you want to develop a Java EE web app, you will have to download about 500MB. ¡WTF!

Node.js download is 7,7MB.

Hello world

Let’s see how to write a Hello World app in different platforms:

Java EE

You need the following files:

  • index.jsp
  • WEB-INF/web.xml

The WEB-INF/web.xml would be like this:

<?xml version="1.0" encoding="UTF-8"?>
 
<web-app
        version="3.0"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name>Hello World</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</web-app>

And the index.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
  <head><title>Hello World</title></head>
  <body><h1>Hello World</h1></body>
</html>

Zip them on a file named helloworld.war and copy them to the application server… ¡Super easy!

Play Framework

First, create the play project:

 $ play new helloworld

This creates lots of files.

Then, edit the main route helloworld/app/controllers/Application.java (configurable):

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {
  
  public static Result index() {
    return ok("Hello World!");
  }
  
}

Run:

 $ play
 [helloworld] $ run

And you will see the app on localhost:9000

PHP

Write an index.php:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
  <head><title>Hello World</title></head>
  <body><h1>Hello World</h1></body>
</html>

and run:

 $ php -S localhost:8000

Your app is on localhost:8000

Ruby on rails

Like play, we have to create a project first:

 $ rails new helloworld
 $ cd helloworld
 $ rails server

That will start the new project and a server on localhost:3000

To edit the index, remove the default index and create a route:

 $ rm public/index.html
 $ rails generate controller home index

Edit config/routes.rb to add:

root :to => "home#index"

Edit app/views/home/index.html.erb to be:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
  <head><title>Hello World</title></head>
  <body><h1>Hello World</h1></body>
</html>

And that's all! Almost easier than Java!

Node.js

write a new file named app.js:

var http = require('http');
var requestListener = function (req, res) {
  res.writeHead(200);
  res.end('Hello, World!\n');
};

var server = http.createServer(requestListener);
server.listen(8080, "127.0.0.1");

run:

 $ node app.js

And you are ready! Your app will be on localhost:8080.

Conclusion

There are lots of Web frameworks out there, and Java is not the only way of doing things.

Choose your framework thinking in what's important for you. For me it's:

  1. Fast Development
  2. Fast Deployment
  3. Huge community

I want to start developing fast. One way of reading it is the lack of need for an IDE. If you need an IDE to help you, it's not simple enough.

Also the lack of a framework is important. With Java EE you will need to add a framework, it's another layer of complexity. The more layers, the more things that can go wrong.

Ruby on rails is a framework by itself, but hey! You need commands to create correctly new files. There's too much dark magic in ruby on rails…

Make it simpler!

Same could be applied to deployment. If I can't just copy the files to the server, it's not simple enough.

Also, a huge community ensures you that you'll have lots of plugins and libraries ready.

Of course, my option right now is Node.js.

2012-11-04 My brother’s birthday / The Assault

20121104-181619.jpg

Tomorrow is my brother’s birthday, we celebrated it today with my brothers, parent’s and grandma at “Mery Limón”.

Uff, I cannot move. I’m drunk, and full. Good food, some dishes were strange, but that’s the deal with experimental cooking. Good wine!

20121104-181630.jpg

This photo corresponds to a wall near to the restaurant.

Once a year there’s a competition in Zaragoza, the “Asalto” (assault). Wall painters from around the world come to Zaragoza and leave their art on the walls of the city.

It’s awesome to take a walk through the oldest streets of the city and discover this pieces of art in hidden corners.

20121104-182139.jpg

My favourite one is this one with a squirrel mixed with a billboard. The billboard is like an x-ray machine showing the squirrel’s skeleton.

2012-11-02 Welcome iPad mini

So, finally I bought an iPad (mini).

I should stop spending my money.

20121103-120434.jpg

I’m quite surprised, as I’m using the iPad more than I thought. Painting, writing, reading, web browsing. Now I’m just searching for the right apps.

20121103-120443.jpg

Right now I’m testing Paper. Great interface, great results. I just have to practice a lot.

After trying digital tablets (wacom bamboo), it’s refreshing to draw on the ipad. It could seem a tiny detail, but seeing your hand at the same time than the drawing is a HUGE improvement.

What I miss on Paper (maybe it’s an iPad limitation) is the lack of pressure sensitivity, and the bad precision of the touches while drawing. I hope it can be solvable with practice.

About the iPad mini… It’s the perfect size (at least for me). Interface doesn’t seem small at all, it’s really light (it could be better), and I’m not missing the retina display (as much as in the iPad 2).

New Stage

After all the changes in my life in the late months, I wanted to keep track of what’s going on on my life. Since twitter killed my blog (I’m too lazy), and I’m unable to write on a diary / moleskine / notebook, I’m gonna try using Day One.

20121103-120454.jpg

The implementation of Day One is quite cool, as you already have photos os each day, just write a little comment about one of them. Cool way to remember.

20121103-123855.jpg

If I have many pics from one day, I always can use Diptic to create a composition.

Well, let’s see in a few days if I succeed!