Preface - Client-Server Web Apps with JavaScript and Java (2014)

Client-Server Web Apps with JavaScript and Java (2014)

Preface

There are only two hard things in Computer Science: cache invalidation and naming things.

—Phil Karlton

While cache invalidation is not a difficulty encountered when writing a book, choosing a suitable title is. The title of this book is intended to represent a broad area of changes in web development that have resulted in a new approach to designing web applications.

Of course, many aspects of web development can be considered new. Developers scramble to keep up with enhancements to desktop browsers, new mobile device clients, evolving programming languages, the availability of faster processors, and an increasingly discerning audience of users with growing expectations about usability and interactivity. These changes require developers to continually innovate when coming up with solutions for their specific projects. But many of these solutions have broader implications and are not isolated to any particular project.

Therefore, I chose “client-server” as the term which in many ways captures the changes to web development that have occurred in response to these innovations. Other descriptions of modern development practices currently in vogue don’t adequately represent the problem domain. Web application development is associated with desktop browsers, but excludes the increasingly relevant area of mobile applications.

The terms Single Page Application and Single Page Interface have been used to distinguish modern web applications from earlier static websites. These terms correctly identify modern sites as far more dynamic and interactive than their predecessors.

However, many modern dynamic applications are made up of multiple pages rather than a single page. The focus in these terms is on the page, the client portion of an application. They make no specific statement about corresponding server-side development. There are JavaScript frameworks that are also associated with highly dynamic pages (such as Angular, Ember, and Backbone), but these are also concerned with the client tier. I wanted the title of this book to encompass more than front-end innovations and to recognize the corresponding server-side design and web service messaging.

The method of communication captured by the popular acronym REST (Representational State Transfer) does suggest the web service messaging style. But the definition of REST as specified by its author Roy Fielding is very limiting. On his blog, Fielding lists specific restrictions to REST that are commonly violated in so-called RESTful APIs. And some even question whether a JSON API can be truly RESTful due to the fact that it does not satisfy all of the constraints associated with the style of architecture. There is a continuum by which REST services can be described; so that an API can be described as RESTful only to the degree that it adheres to the constraints. REST does include client-server as one of its constraints, and the verb and URL naming conventions are certainly applicable.

So a JavaScript client consuming messages from a pragmatic “RESTful” API is a significant part of the method of development. What about the server component?

Java Enterprise Edition (JEE) includes the JAX-RS API, which uses Java’s flavor of REST (which is not inherently strict) and is demonstrable using the Jersey reference implementation. But limiting to JAX-RS web application development ignores frameworks and alternate JVM language solutions that are available and particularly appealing for quick prototypes.

And so crystallizing the intentions of a book in a simple, catchy title is not an easy task. Fortunately, James Ward did a presentation at OSCON 2012 in which he described the development of “Client-Server Web Applications with HTML5 and Java.” He listed the benefits of a method of web application development that is increasingly popular, a method that I have been involved with in recent years on various projects. And the phrase “client-server” is the key to understanding what this method is. It captures the fundamental architectural changes that include aspects of the terms listed above, but represents the distinct partitioning between the client and server and considers each of the roles significant.

A client-server architecture of web applications requires a shift (in some cases seismic) in the way programmers work. This book was written to enable developers to deal with this revolution. Specifically, it is intended to provide a proper perspective in building the latest incarnation of modern web applications.

Who Is This Book For?

This book is written for web application developers who are are familiar with the Java programming language, as well as HTML, JavaScript, and CSS. It is geared toward those who “learn by doing” and prefer to see and create specific examples of new technologies and techniques integrated with standard tools. If you want a better understanding of recent developments in JavaScript and how the language and its development process compare with those of Java, this book is for you.

A bit of a balancing act is evident as you read this book. On the one hand, the most important thing you can take away is a sense of the “big picture”—the influences and trends causing a shift in the technologies in use. On the other hand, technologies are often best understood by seeing specific examples. If you are interested in an overview of how these technologies actually fit together, you will benefit from this book.

My goal in writing this is to help you to make informed decisions. Good decisions result in the right technologies being used on new projects. They allow you to avoid pitfalls caused by mixing incompatible technologies or having the wrong expectations about the implications of a given decision. They help you to step into projects in process and better support existing code. In short, informed decisions will make you a more productive programmer. They help you make effective use of your time in researching areas of specific interest in your work now and in the future.

How This Book Is Organized

Chapter 1 provides a general overview of the client-server web application architecture. It discusses the history of web development and provides a justification for the paradigm shift in development. This leads into the next three chapters that will describe the tools used in the development process.

Chapter 2 describes JavaScript and the tools used in JavaScript development.

Chapter 3 introduces web API design, REST, and the tools used when developing RESTful applications over HTTP.

Chapter 4 pertains to Java and other software that’s used in the remainder of this book.

The next section of the book discusses higher-level constructs (such as client libraries and application servers) and how these provide separation and allow for rapid development.

Chapter 5 describes major client-side JavaScript frameworks.

Chapter 6 addresses Java API servers and services.

Chapter 7 discusses rapid development practices.

Chapter 8 delves into API design in greater depth.

With an understanding of libraries and a process for speedy development of prototypes, the next several chapters apply these to specific projects using various JVM languages and frameworks. The next two chapters use lightweight web servers and microframeworks instead of traditional Java web application packaging and servers.

Chapter 9 provides an overview of a project using jQuery and Jython.

Chapter 10 documents the development of a project using JRuby and Angular.

The final chapters detail projects using traditional Java web application servers and libraries.

Chapter 11 looks at the range of packaging and deployment options available in the Java ecosystem.

Chapter 12 explores virtualization and innovations emerging from the management of large server environments.

Chapter 13 draws attention to testing and documentation.

Chapter 14 wraps up with some final thoughts on responding to the tumultuous changes to Internet-related technologies and software development.

Appendix A describes how to explore and manipulate Java classes interactively.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to variables, method names, and other code elements, as well as the contents of files.

Constant width bold

Highlights new code in an example.

Constant width italic

Shows text that should be replaced with user-supplied values.

NOTE

This element signifies a tip, suggestion, or general note.

WARNING

This element indicates a warning or caution.

Code Examples

Projects and code examples in this book are hosted on https://github.com/java-javascript/client-server-web-apps. You can view them online or download a .zip file for local use. The assets are organized by chapter.

The code examples provided in this book are geared toward illustrating specific functionality rather than addressing all concerns of a fully functional application. Differences include:

§ Production systems include greater refinement of selected data types, validation rules, exception handing routines, and logging mechanisms.

§ Most production systems will include one or more backend datastores. To limit the scope of discussion, databases are not accessed in most of the examples.

§ The modern web application includes a large amount of infrastructure geared toward mobile device access and browser compatibility. Again, unless these are the specific topic of discussion, responsive design is eschewed for a more minimal design.

§ The practice of some degree of unobtrusive JavaScript to separate CSS and JavaScript from HTML is a generally accepted best practice. In the examples in this book, they are frequently commingled because all aspects of a given application can be immediately apprised by viewing a single file.

§ Unit tests and testing examples are only included when they are directly related to the topic under discussion. Production systems would include far greater test coverage and extensive testing in general.

That said, this book is intended to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you are reproducing a significant portion of the code. For example, writing a program that uses several sections of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Client-Server Web Apps with JavaScript and Java” by Casimir Saternos (O’Reilly). Copyright 2014 EzGraphs, LLC., 978-1-449-36933-0.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at permissions@oreilly.com.

Long Command Formats

Code displayed inline will be adjusted to be readable in this context. One convention used is that of backslashes to allow newlines in operating system commands. So for instance, the following commands are equivalent and would execute the same way in a bash session. (Bash is a standard operating system shell that you see when accessing a Linux server or Mac OS X at the command line.)

ls -l *someVeryLongName*

...

ls -l \

*someVeryLongName*

The same convention also appears in other settings where OS commands are used, such as Dockerfiles.

Similarly, JSON strings, being valid JavaScript, can be broken up to fit on multiple lines:

o={"name": "really long string here and includes many words"}

// The following, as expected, evaluates to true.

JSON.stringify(o)=='{"name":"really long string here and includes many words"}'

// The same string broken into multiple lines is equivalent.

// So the following statement also evaluates to true.

JSON.stringify(o)=='{"name":' +

'"some really long ' +

'JSON string is here' +

' and includes many, many words"}'

Safari® Books Online

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.