Play is an open source Java based web application development framework. The framework has been written in Scala with a Java wrapper API. It follows the MVC (Model-View-Controller) architectural model and RESTful architecture. The main focus of Play framework is to increase productivity and support agile development methodology. The main differentiators of the Play framework are rapid application development, hot code reloading and browser based error display. Play framework based web applications can be written in both Scala and Java languages. Play applications can also be packaged as WAR file for distributed deployment in application servers. So, Play can also be considered as a clean alternative to Java EE development stack.
How Play framework is different from Java?
As Play is a Java framework, all Java development tools can be used as it is. So, anybody using the Java development platform, can use it without switching to other IDE or languages or libraries. Play just helps developers switch to more productive Java development environment. Let us check how Play is different from Java environment.
- Stateless and RESTful architecture: It follows the stateless MVC architecture, which is also known as ‘share nothing’ model. Play is RESTful and modular.
- Integrated testing environment: Selenium and JUnit comes as a part of the core Play framework. So, the testing environment can be used easily without any integration effort. It supports test driven development (TDD).
- API based: APIs are available as default for most of the built-in functions.
- Support for Asynchronous I/O: It supports asynchronous requests and I/O calls.
- Use of static methods: All controller entry points are static in nature.
- Scala support: Play 2 has in-built support for Scala. Although, it has API support for Java also.
Apart from the above points, Play also supports JPA, template engine, HTTP to code mapping, etc. for efficient web application development.
What you can do with Play framework?
Play framework is a full-stack web application development framework. It is inspired by Java technology platform and contains all the tools for complete web application development. Following are some of the functionalities covered in Play framework for full-stack development.
- Database support through JDBC
- Persistence support with Hibernate and JPA
- Caching support with memcached system
- Authentication support with OpenID
- Web service support with JSON and XML
- API support for image manipulation
The modular approach in Play framework supports integration with various external systems. The existing Java code, libraries, static resources can also be integrated seamlessly.
Following are the steps to be completed to set the stage ready for application development. Let us have a look at the configuration and installation details.
The first pre-requisite is to have Java (version 5 or higher) installed in your system. You can also install IDE or use any text editor.
- Download JDK from the following link and set the class path
- Set up any IDE like NetBeans or Eclipse and install
The second step is to download and install Play framework.
- Download the Play framework (.zip file) from the following link. Then unzip it to any local directory (for example c:\Play).
After this, add the path (here c:\Play) to the system class path. It will help us use the Play commands from any location on the command prompt. The following screen shot will show the installation once ‘Play’ is typed on the command prompt.
This will also create a directory structure on the local file system as shown below.
Now, the environment is ready to test our first Play application.
In this section, we will create a project using the Play framework. Following, are the steps to be followed.
First, open the command prompt and type the following command
Play new playdemoapp
Now, it will ask for the application name as shown below.
Type the application name as shown below and select template type as Java (option 2).
This will result in successfully creating the application as shown below.
The following directory structure will be created after successful creation of the application.
To run the application, go to the project directory and type the ‘play run’ command. It will start the server and the default application will start running on web server listening at port 9000.
This screen shot shows that the server is running successfully.
In Play framework, new applications have a standard welcome page as shown below. It shows that the application is running successfully.
Play framework is based on a light weight, MVC, stateless architectural model. It provides ease of development with minimum resource consumption. Play application can be developed by using Scala or Java technology. So, Java developers find it more useful while shifting to more productive development environment. And the best part is, without throwing away the existing Java resources. Play is going to get more popularity in near future. This article will give pointers to start development with hands on coding. Developers can follow the instructions and implement it easily.