Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 303 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
303
Dung lượng
4,13 MB
Nội dung
[...]... 164 165 166 167 168 169 169 11 Working with Scripts and Classes 11.1 The Melting Pot of Java and Groovy 11.2 Running Groovy 11.3 Using Groovy Classes from Groovy 11.4 Using Groovy Classes from Java 11.5 Using Java Classes from Groovy 11.6 Using Groovy Scripts from Groovy 11.7 Using Groovy Scripts from Java 11.8 Ease of Integration ... organized as follows: The book has has three parts: “Beginning Groovy, ” “Using Groovy, ” and “MOPping Groovy. ” In the chapters in Part 1, “Beginning Groovy, ” I focus on the whys and whats of Groovy those fundamentals that’ll help you get comfortable with general programming in Groovy Since I assume you’re familiar with Java, I don’t spend any time with programming basics, like what an if statement is or how... example to show you that Groovy classes are Java classes: Download Introduction/UseGroovyClass .groovy println XmlParser.class println XmlParser.class.superclass If you run groovy UseGroovyClass, you’ll get the following output: class groovy. util.XmlParser class java.lang.Object Now let’s talk about the third reason to love GroovyGroovy is dynamic, and it is optionally typed If you’ve enjoyed the benefits... to the similarities of Groovy and Java and topics that are specific to Groovy In the chapters in Part 2, “Using Groovy, ” I focus on how to use Groovy for everyday coding—working with XML, accessing databases, and 23 W HAT ’ S IN T HIS B OOK ? working with multiple Java /Groovy classes and scripts—so you can put Groovy to use right away for your day-to-day tasks I also discuss the Groovy extensions and... the power of Groovy and the JDK at the same time In the chapters in Part 3, “MOPping Groovy, ” I focus on the metaprogramming capabilities of Groovy You’ll see Groovy really shine in these chapters and learn how to take advantage of its dynamic nature You’ll start with the fundamentals of MetaObject Protocol (MOP), learn how to do aspect-oriented programming (AOP) such as operations in Groovy, and learn... not only necessary in Groovy because of its dynamic nature, but it is also easier to do—you can use Groovy to unit test your Java and Groovy code, as you’ll see in this part of the book Here’s what’s in each chapter: Part 1: “Beginning Groovy In Chapter 2, Getting Started, on page 30, you’ll download and install Groovy and take it for a test-drive right away using groovysh and groovyConsole You’ll... documents One of the key strengths of Groovy is the integration with Java In Chapter 11, Working with Scripts and Classes, on page 172, you’ll learn ways to closely interact with multiple Groovy scripts, Groovy classes, and Java classes from within your Groovy and Java code Part 3: “MOPping Groovy Metaprogramming is one of the biggest benefits of dynamic languages and Groovy; it has the ability to inspect... choose from for coding Groovy See http:/ /groovy. codehaus.org/IDE+Support for some choices You can edit your Groovy code, run it from within your IDE, debug your code, and a lot more depending on which tool you pick IntelliJ IDEA and JetGroovy IntelliJ IDEA offers outstanding support for Groovy through the JetGroovy plug-in (http://www.jetbrains.com/idea) Using it, you can edit Groovy code, take advantage... addition, you can invoke the Groovy shell or Groovy console from within Eclipse to quickly experiment with Java and Groovy code TextMate Groovy Bundle As a Mac user, I use the Groovy bundle (http://docs.codehaus.org/display/ GROOVY/ TextMate) in TextMate (http://macromates.com, [Gra07]) exten- sively.6 It provides a number of time-saving snippets that allow code expansion for standard Groovy code such as closures... ? Second, when programming in Groovy, you can expect almost everything you expect in Java Groovy classes extend the same good old java.lang.Object Groovy classes are Java classes The OO paradigm and Java semantics are preserved, so when you write expressions and statements in Groovy, you already know what those mean to you as a Java programmer Here’s a little example to show you that Groovy classes . are saying about Programming Groovy More than a tutorial on the Groovy language, Programming Groovy is an excellent resource for learning the advanced concepts of metaob- ject programming, unit. Java and Groovy . . . . . . . . . . . 172 11.2 Running Groovy . . . . . . . . . . . . . . . . . . . . . . . 173 11.3 Using Groovy Classes from Groovy . . . . . . . . . . . . 174 11.4 Using Groovy. I was learning Groovy? ” After you’ve read thi s book, it’s difficult to l ook at programming on the Java platform the same way. Scott Davis Editor-in-Chief, aboutGroovy.com; author of Groovy Recipes Venkat