Scripting in Java: Languages, Frameworks, and Patterns

Scripting in Java: Languages, Frameworks, and Patterns

by Dejan Bosanac
     
 

View All Available Formats & Editions

Groovy and Beyond: Leverage the Full Power of Scripting on the JavaTM Platform!

Using the JavaTM platform’s new scripting support, you can improve efficiency, streamline your development processes, and solve problems ranging from prototyping to Web application programming. In Scripting in Java,

Overview

Groovy and Beyond: Leverage the Full Power of Scripting on the JavaTM Platform!

Using the JavaTM platform’s new scripting support, you can improve efficiency, streamline your development processes, and solve problems ranging from prototyping to Web application programming. In Scripting in Java, Dejan Bosanac covers key aspects of scripting with Java, from the exciting new Groovy scripting language to Java’s new Scripting and Web Scripting APIs.

Bosanac begins by reviewing the role and value of scripting languages, and then systematically introduces today’s best scripting solutions for the Java platform. He introduces Java scripting frameworks, identifies proven patterns for integrating scripting into Java applications, and presents practical techniques for everything from unit testing to project builds. He supports key concepts with extensive code examples that demonstrate scripting at work in real-world Java projects. Coverage includes

· Why scripting languages offer surprising value to Java programmers

· Scripting languages that run inside the JVM: BeanShell, JavaScript, and Python

· Groovy in depth: installation, configuration, Java-like syntax, Java integration, security, and more

· Groovy extensions: accessing databases, working with XML, and building simple Web applications and Swing-based UIs

· Bean Scripting Framework: implementation, basic abstractions, and usage examples

· Traditional and new patterns for Java-based scripting

· JSR 223 Scripting API: language bindings, discovery mechanisms, threading, pluggable namespaces, and more

· JSR 223 Web Scripting Framework: scripting the generation of Web content within servlet containers

About the Web Site

All code examples are available for download at this book’s companion Web site.

Product Details

ISBN-13:
9780321321930
Publisher:
Addison-Wesley
Publication date:
08/23/2007
Pages:
552
Product dimensions:
6.90(w) x 9.10(h) x 1.30(d)

Read an Excerpt

PrefacePreface

Java is an excellent object-oriented programming language. It has provided many benefits to software developers, including a good object-oriented approach, implicit memory management, and dynamic linking, among others. These language characteristics are one of the main reasons for Java's popularity and wide acceptance.

But Java is much more than a programming language; it's a whole development platform. This means that it comes with a runtime environment (JRE), which provides the virtual machine, and the standardized application programming interfaces (APIs) that help developers accomplish most of their desired tasks. The main advantages of this integrated runtime environment are its true platform independence and simplification of software development.

On the other hand, scripting languages have played an important role in the information technology infrastructure for many years. They have been used for all kinds of tasks, ranging from job automation to prototyping and implementation of complex software projects.

Therefore, we can conclude that the Java development platform can also benefit from scripting concepts and languages. Java developers can use scripting languages in areas proven to be most suitable for this technology. This synergy of the Java platform and scripting languages, as we will see, adds an extra quality to the overall software development process.

In this book, I describe the concepts behind scripting languages, summarize solutions available to Java developers, and explore use cases and design patterns for applying scripting languages in Java applications.How This Book Is Organized

This book consists of fivelogical parts.Part I

The first part of the book comprises two chapters that describe scripting languages in general:

  • Chapter 1, "Introduction to Scripting"—Here I define the basic characteristics of scripting languages and compare them to system programming languages.

  • Chapter 2, "Appropriate Applications for Scripting Languages"—In this chapter, I explain the role of traditional (native) scripting languages in the overall information technology infrastructure. I also discuss tasks for which scripting languages have been used in various systems over time.

Part II

After discussing the basic concepts and uses of scripting languages, we are ready to focus on real technologies and solutions for the Java platform. This part of the book contains the following chapters:

  • Chapter 3, "Scripting Languages Inside the JVM"—I begin this chapter by covering the basic elements of the Java platform and explaining where scripting languages fit into it. After that, I describe the main features of three popular scripting languages available for the Java Virtual Machine (JVM)—BeanShell, JavaScript, and Python—and how they can be used to interact with Java applications. At the end of this chapter, I describe other solutions available for Java developers.

  • Chapter 4, "Groovy"—Here I discuss the Groovy scripting language in detail. I cover its Java-like syntax and all the scripting concepts built into this language, and I discuss Groovy's integration with Java, as well as some security-related issues.

  • Chapter 5, "Advanced Groovy Programming"—In this chapter, I cover some of the Groovy extensions that can aid in day-to-day programming tasks. I also explain how Java programmers can access databases, create and process

  • Chapter 6, "Bean Scripting Framework"—In this chapter, I describe the general Java scripting framework. In addition to explaining how to implement general support in your project for any compliant scripting language, I also discuss some basic abstractions implemented in the Bean Scripting Framework (BSF) and show some examples of successful uses.

Part III

This part of the book focuses primarily on the use of scripting languages in real Java projects:

  • Chapter 7, "Practical Scripting in Java"—Here I cover topics related to the use of scripting for everyday programming tasks, such as unit testing, interactive debugging, and project building, among others.

  • Chapter 8, "Scripting Patterns"—In this chapter, I discuss Java application design patterns that involve scripting languages. I show how you can use scripts to implement some parts of traditional design patterns and introduce some new design patterns specific only to the scripting environment. I also discuss the pros and cons of these design patterns, as well as their purpose.

Part IV

In the final part of this book, I cover the "Scripting for the Java Platform" specification, which was created according to the Java Specification Request (JSR) 223. Specifically, I cover two APIs defined by the specification:

  • Chapter 9, "Scripting API"—Here I cover the Scripting API, the standardized general scripting framework for the Java platform. The purpose of this framework is the same as that of the Bean Scripting Framework, but the Scripting API brings many new features that the modern scripting framework needs. The Scripting API is a standard part of the Java platform with the release of Mustang (Java SE 6).

  • Chapter 10, "Web Scripting Framework"—In this chapter, I discuss the Web Scripting Framework, a framework built on top of the Scripting API and created to enable scripting languages to generate Web content inside a servlet container. I explain how native scripting languages, such as PHP, can be synergized with the Java platform to bring more flexibility in Web application development.

Part V

At the end of the book, you can find a section comprising three appendixes. The main purpose of these appendixes is to provide the technical details about installation and use of certain technologies described in the book:

  • Appendix A, "Groovy Installation"—In this appendix, I describe how to install, build, and configure the Groovy scripting language. A working installation of the Groovy interpreter is needed to run the code samples from the text.

  • Appendix B, "Groovy IDE Support"—In this appendix, I provide instructions on how to install general Groovy support for Integrated Development Environments (IDEs).

  • Appendix C, "Installing JSR 223"—Here I describe how to install the reference implementation (RI) of the JSR 223, which is needed to run examples from Chapter 10.

I hope you'll enjoy reading the book.About the Web Site

This book is extended with a Web site at http://www.scriptinginjava.net where you can find the following:

  • Source codes of all examples shown in the book available for download

  • Book news, updates, and additions

  • News and information related to this field of software development


© Copyright Pearson Education. All rights reserved.

Meet the Author

Dejan Bosanac is a professional software developer and technology consultant. He specializes in the integration and interoperability of diverse technologies, especially those related to Java and the Web. He has spent several years developing complex software projects, ranging from highly trafficked Web sites to enterprise applications, and was a member of the JSR 223 Expert Group.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >