Play framework and Java – How to create web applications?

Play framework and Java

Let’s play with Play framework and Java

Overview:

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 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 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 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 Java development platform, can use it without switching to other IDE or languages or libraries. Play just helps developers to switch to more productive Java development environment. Let us check how Play is different from Java environment.

  • Stateless and RESTful architecture: It follows 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 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.

Environment setup:

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

http://www.oracle.com/technetwork/java/javase/downloads/index.html

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).

https://www.playframework.com/download









After this add the path (here c:\Play) to the system class path. It will help to use Play commands from any location on the command prompt. Following screen shot will show the installation once ‘Play’ is typed on the command prompt.

Play is installed successfully

Play is installed successfully

Image 1: Play is installed successfully

This will also create a directory structure on the local file system as shown below.

Directory structure created

Directory structure created

Image 2: Directory structure created

Now, the environment is ready to test our first Play application.

Sample application:

In this section we will create a project by using Play framework. Following are the steps to be followed.

First, open a command prompt and type the following command

[code]Play new playdemoapp [/code]

Now, it will ask for the application name as shown below.

Creating application

Creating application

Image 3: Creating application

Type the application name as shown below and select template type as Java (option 2).

Select template type

Select template type

Image 4: Select template type

After this the application will be created successfully as shown below.

Application created successfully

Application created successfully

Image 5: Application created successfully

Following directory structure will be created after successful creation of the application.

Project directory structure

Project directory structure

Image 6: Project directory structure

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.

Starting the server and loading the application

Starting the server and loading the application

Image 7: Starting the server and loading the application

This screen shot is showing that the server is running successfully.

Server started

Server started

Image 8: Server started

In Play framework, new applications have a standard welcome page as shown below. It shows that the application is running successfully.








Standard welcome page

Standard welcome page

Image 9: Standard welcome page 

Conclusion:
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 hand on coding. Developers can follow the instructions and implement it easily.


Read more about Play framework here https://www.playframework.com/

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share