Scripting in Java: Languages, Frameworks, and Patterns [NOOK Book]

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

See more details below
Scripting in Java: Languages, Frameworks, and Patterns

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac

Want a NOOK? Explore Now

NOOK Book (eBook)
$27.49
BN.com price
(Save 42%)$47.99 List Price

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.

Read More Show Less

Product Details

  • ISBN-13: 9780132702294
  • Publisher: Pearson Education
  • Publication date: 8/23/2007
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 1
  • Pages: 552
  • File size: 17 MB
  • Note: This product may take a few minutes to download.

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.

Read More Show Less

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.

Read More Show Less

Table of Contents

PREFACE XVII

PART I 1

CHAPTER 1 INTRODUCTION TO SCRIPTING 3

BACKGROUND 4

DEFINITION OF A SCRIPTING LANGUAGE 8

COMPILERS VERSUS INTERPRETERS 8

SOURCE CODE IN PRODUCTION 12

TYPING STRATEGIES 13

DATA STRUCTURES 17

CODE AS DATA 19

SUMMARY 23

SCRIPTING LANGUAGES AND VIRTUAL MACHINES 24

A COMPARISON OF SCRIPTING AND SYSTEM PROGRAMMING 26

RUNTIME PERFORMANCE 26

DEVELOPMENT SPEED 28

ROBUSTNESS 29

MAINTENANCE 32

EXTREME PROGRAMMING 33

THE HYBRID APPROACH 35

A CASE FOR SCRIPTING 37

CONCLUSION 38

CHAPTER 2 APPROPRIATE APPLICATIONS FOR SCRIPTING LANGUAGES 39

WIRING 40

UNIX SHELL LANGUAGES 41

PERL 43

TCL 43

PROTOTYPING 44

PYTHON 47

CUSTOMIZATION 49

VISUAL BASIC FOR APPLICATIONS (VBA) 50

SOFTWARE DEVELOPMENT SUPPORT 51

PROJECT BUILDING 51

TESTING 53

ADMINISTRATION AND MANAGEMENT 55

USER INTERFACE PROGRAMMING 58

TK 58

USE CASES 59

WEB APPLICATIONS 59

SCRIPTING AND UNIX 68

SCRIPTING IN GAMES 68

ADDITIONAL CHARACTERISTICS 69

EMBEDDABLE 70

EXTENSIBLE 70

EASY TO LEARN AND USE 71

CONCLUSION 72

PART II 75

CHAPTER 3 SCRIPTING LANGUAGES INSIDE THE JVM 77

UNDER THE HOOD 80

SCRIPTING LANGUAGE CONCEPTS 82

BEANSHELL 83

GETTING STARTED 83

BASIC SYNTAX 86

LOOSELY TYPED SYNTAX 87

SYNTAX FLAVORS 88

COMMANDS 91

METHODS 91

OBJECTS 92

IMPLEMENTING INTERFACES 93

EMBEDDING WITH JAVA 94

JYTHON 98

GETTING STARTED 98

BASIC SYNTAX 101

WORKING WITH JAVA 103

IMPLEMENTING INTERFACES 105

EXCEPTION HANDLING 107

EMBEDDING WITH JAVA 108

CONCLUSION 109

RHINO 110

GETTING STARTED 110

WORKING WITH JAVA 111

IMPLEMENTING INTERFACES 112

JAVAADAPTER 114

EMBEDDING WITH JAVA 114

HOST OBJECTS 117

CONCLUSION 120

GROOVY 120

OTHER SCRIPTING LANGUAGES 122

JRUBY 122

TCL/JAVA 122

JUDOSCRIPT 122

OBJECTSCRIPT 123

CONCLUSION 123

CHAPTER 4 GROOVY 125

WHY GROOVY? 126

INSTALLATION 127

RUNNING GROOVY SCRIPTS 127

USING THE INTERACTIVE SHELL 127

USING THE INTERACTIVE CONSOLE 128

EVALUATING THE SCRIPT FILE 129

COMPILING GROOVY SCRIPTS 130

DEPENDENCIES 131

CLASSPATH 131

ANT TASK 132

SCRIPT STRUCTURE 133

COMMAND-LINE ARGUMENTS 136

LANGUAGE SYNTAX 137

JAVA COMPATIBILITY 137

STATEMENTS 138

LOOSE TYPING 138

TYPE JUGGLING 140

STRINGS 143

GSTRINGS 145

REGULAR EXPRESSIONS 146

COLLECTIONS 148

LOGICAL BRANCHING 154

LOOPING 156

CLASSES 159

OPERATOR OVERLOADING 162

GROOVYBEANS 165

CLOSURES 168

SYSTEM OPERATIONS 178

FILES 178

PROCESSES 182

EMBEDDING WITH JAVA 184

SECURITY 190

CONCLUSION 194

CHAPTER 5 ADVANCED GROOVY PROGRAMMING 195

GROOVYSQL 196

groovy.sql.Sql 198

groovy.sql.DataSet 209

GROOVLETS 212

GROOVY TEMPLATES 220

GROOVYMARKUP 223

groovy.xml.MarkupBuilder 224

groovy.util.NodeBuilder 227

groovy.xml.SaxBuilder 230

groovy.xml.DomBuilder 232

groovy.xml.Namespace 234

groovy.util.BuilderSupport 235

GROOVY AND SWING 236

TableLayout 239

TableModel 241

CONCLUSION 243

CHAPTER 6 BEAN SCRIPTING FRAMEWORK 245

INTRODUCTION TO THE BEAN SCRIPTING FRAMEWORK 246

GETTING STARTED 247

BASIC CONCEPTS 248

ARCHITECTURE 248

REGISTRATION OF SCRIPTING LANGUAGES 249

MANAGER AND ENGINE INITIALIZATION 252

WORKING WITH SCRIPTS 253

WORKING WITH SCRIPT FILES 257

METHODS AND FUNCTIONS 259

call() 259

apply() 263

DATA BINDING 264

R EGISTERING BEANS 265

D ECLARING BEANS 268

COMPILATION 270

APPLICATIONS 275

JSP 275

X ALAN-J (XSLT) 280

CONCLUSION 288

PART III 289

CHAPTER 7 PRACTICAL SCRIPTING IN JAVA 291

UNIT TESTING 292 JUNIT BASICS 293

THE GroovyTestCase CLASS 296

ASSERTION METHODS 297

TEST SUITES 300

SCRIPTS AS UNIT TEST CASES 303

SUMMARY 304

INTERACTIVE DEBUGGING 304

BUILD TOOLS (ANT SCRIPTING) 309

BSF S UPPORT 313

G ROOVYMARKUP (ANTBUILDER ) 316

S UMMARY 322

SHELL SCRIPTING 323

C LASSPATH 324

E XAMPLE 325

ADMINISTRATION AND MANAGEMENT 328

CONCLUSION 334

CHAPTER 8 SCRIPTING PATTERNS 335

SCRIPTED COMPONENTS PATTERN 337

P ROBLEM 337

S OLUTION 338

C ONSEQUENCES 339

S AMPLE CODE 340

R ELATED PATTERNS 341

MEDIATOR PATTERN (GLUE CODE PATTERN) 341

P ROBLEM 341

S OLUTION 342

C ONSEQUENCES 345

S AMPLE CODE 345

R ELATED PATTERNS 354

SCRIPT OBJECT FACTORY PATTERN 354

P ROBLEM 355

S OLUTION 355

C ONSEQUENCES 356

S AMPLE CODE 356

R ELATED PATTERNS 359

OBSERVER (BROADCASTERS) PATTERN 359

P ROBLEM 359

S OLUTION 360

C ONSEQUENCES 362

S AMPLE CODE 362

R ELATED PATTERNS 369

EXTENSION POINT PATTERN 369

P ROBLEM 369

S OLUTION 370

C ONSEQUENCES 370

S AMPLE CODE 371

R ELATED PATTERNS 374

ACTIVE FILE PATTERN 375

PROBLEM 375

SOLUTION 375

CONSEQUENCES 375

SAMPLE CODE 376

CONCLUSION 380

PART IV 383

CHAPTER 9 SCRIPTING API 385

MOTIVATION AND HISTORY 386

INTRODUCTION 388

GETTING STARTED 390

ARCHITECTURE 391

DISCOVERY MECHANISM 391

ENGINE METADATA 393

CREATING AND REGISTERING SCRIPTING ENGINES 395

CREATION METHODS 396

REGISTRATION METHODS 399

EVALUATION 400

ScriptException 403

BINDING 404

ENGINE SCOPE 405

GLOBAL SCOPE 411

SCRIPT CONTEXT 416

CODE GENERATION 428

OUTPUT STATEMENT 429

METHOD CALL SYNTAX 429

PROGRAM 431

ADDITIONAL ENGINE INTERFACES 432

INVOCABLE 432

COMPILABLE 437

THREADING 440

DYNAMIC BINDINGS 442

CONCLUSION 445

CHAPTER 10 WEB SCRIPTING FRAMEWORK 447

ARCHITECTURE 448

CONTEXT 448

SERVLET 449

INTERACTION 451

GETTING STARTED 453

CONFIGURATION 456

DISABLE SCRIPTING 456

SCRIPT DIRECTORY 457

SCRIPT METHODS 458

ALLOW LANGUAGES 459

DISPLAY RESULT 460

BINDINGS 462

APPLICATION 462

REQUEST 464

RESPONSE 468

SERVLET 468

INCLUDE METHOD 469

FORWARD METHOD 471

SESSION SHARING 473

LANGUAGE TAGS 478

THREADING ISSUES 481

ARCHITECTURAL CHALLENGES 482

INTEGRATION OF JAVA AND PHP APPLICATIONS 482

JAVA BUSINESS LOGIC IN PHP WEB APPLICATIONS 484

PHP VIEWS IN JAVA WEB APPLICATIONS 487

CONCLUSION 488

PART V 489

APPENDIX A GROOVY INSTALLATION 491

DOWNLOAD INSTRUCTIONS 491

INSTALLING GROOVY 492

CONFIGURING GROOVY 492

TESTING GROOVY 492

APPENDIX B GROOVY IDE SUPPORT 495

INSTALLATION 495

USAGE 497

APPENDIX C INSTALLING JSR 223 499

REQUIREMENTS 500

INSTALLATION 500

INDEX 503

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)