Introducing Java Web Development
An intelligent machine is that which extends the very imagination with which it was built. An example of this is the instruction called invoke dynamic, 1 which was introduced with Java 7 to optimize the performance of dynamically typed languages on the Java Virtual Machine (JVM). The JVM, originally intended for Java, can now host a myriad of programming languages, including Groovy2 and Scala.3 This has led to a renaissance of Java web development. This new paradigm of cross-pollination and diverse, well-founded options carves out a number of niches in the Java ecosystem, resulting in a richer web landscape than ever before.
The JVM is the runtime environment that provides you with the ability to use different programming languages for building web applications. The JVM languages can be largely classified into two types: languages that are designed for the JVM and existing languages that are ported to JVM.
Languages Designed for the JVM
Groovy, Scala, and Clojure fall on the functional language continuum. Java 8 introduces lambdas, which makes it slightly functional, Groovy has had functional constructs since its inception and is even more functional with Groovy 2.0, and Scala is the most functional of the three object-oriented (OO) languages. Clojure, on the other hand, is a purely functional, non-OO language
Java began life as a programming language designed for building stand-alone applications and grew rapidly into other spheres. A large part of Java’s popularity can be attributed to its usage in creating web applications. A web application consists of static and dynamic (interactive) web pages. Static web pages contain various types of markup languages (HTML, XHTML, and so on) and are used, in general, to provide information; dynamic web pages, on the other hand, are capable of generating content with the aid of additional web components (covered in Chapter 2). Thus, a web application is a collection of web pages and is capable of generating dynamic content in response to requests. Unlike a web page used merely to provide information, a web application lets you perform some activity and save the result
The Java EE Platform
The Java EE platform is driven by the following two goals:
- Providing the API specifications that are the building blocks of the web application.
- Standardizing and reducing the complexity of enterprise application development.
It does this by providing an application model that defines an architecture for implementing services as multitiered applications.
The Client Tier
The client tier is the top tier in a multitiered Java EE architecture; it consists of application clients that make requests to the Java EE server, which is often located on a different machine. The server processes the requests and returns a response to the client. An example of a client is a web browser or a stand-alone application
The Web Tier
The web tier consists of components that handle the interaction between clients and the business tier. After receiving a request from the client, the web tier does the following:
1. Collects input from the client
2. Controls the flow of screens or pages on the client
3. Maintains the state of data for a user’s session
4. Obtains results from the components in the business tier
5. Generates dynamic content in various formats for the client
This chapter introduced the Java language and then took you on a whirlwind tour through the Java landscape. The diverse landscape of the Java world consists of several web frameworks (such as Struts 2, Spring Web MVC, JSF 2, Grails 2, and Play 2) that make development much easier; thus, as a Java web developer, you need to be familiar with these web frameworks. Modern Java is more than just a language; it is now a fully optimized platform for several other industry-strength languages such as Groovy, Clojure, and Scala. All these languages, especially Groovy, have a close association with Java, and you will come across web applications before long where Java and these alternative JVM languages will work in tandem.