Programming Groovy 2: Dynamic Productivity for the Java Developer (Pragmatic Programmers)

By Venkat Subramaniam

Groovy brings you the simplest of either worlds: a versatile, hugely efficient, agile, dynamic language that runs at the wealthy framework of the Java Platform. Groovy preserves the Java semantics and extends the JDK to provide you actual dynamic language features. Programming Groovy 2 may help you, the skilled Java developer, study and make the most of the most recent model of this wealthy dynamic language. you will cross from the fundamentals of Groovy to the newest advances within the language, together with ideas for kind checking, tail-call and memoization optimizations, bring together time metaprogramming, and fluent interfaces to create DSLs.

You should not have to depart the wealthy Java Platform to use Groovy. Groovy preserves Java's semantics and extends the JDK, so programming in Groovy sounds like the Java language has been augmented; it is like operating with a lighter, extra dependent Java. in case you are an skilled Java developer who desires to learn the way Groovy works, you can find precisely what you wish during this book.

You'll commence with the basics of programming in Groovy and the way it really works with Java, after which you will discover complex suggestions equivalent to unit trying out with mock items, utilizing developers, operating with databases and XML, and developing DSLs. you are going to grasp Groovy's strong but advanced run-time and compile-time metaprogramming features.

Much has advanced within the Groovy language because the booklet of the 1st variation of Programming Groovy. Programming Groovy 2 can help you research and observe Groovy's new good points. growing DSLs is simpler now, and Groovy's already-powerful metaprogramming amenities have superior much more. you will see the best way to paintings with closures, together with tail name optimization and memoization. The e-book additionally covers Groovy's new static compilation feature.

Whether you are studying the fundamentals of the language or attracted to getting informed with the recent gains, Programming Groovy 2 has you covered.

What You Need

To paintings at the examples within the publication you wish Groovy 2.0.5 and Java JDK five or higher.

Show description

Quick preview of Programming Groovy 2: Dynamic Productivity for the Java Developer (Pragmatic Programmers) PDF

Best Java books

Mastering Lambdas: Java Programming in a Multicore World (Oracle Press)

The Definitive consultant to Lambda Expressions learning Lambdas: Java Programming in a Multicore global describes how the lambda-related positive factors of Java SE eight will permit Java to satisfy the demanding situations of next-generation parallel architectures. The e-book explains the best way to write lambdas, and the way to exploit them in streams and in assortment processing, offering code examples all through.

Mastering JavaFX 8 Controls (Oracle Press)

Layout and installation High-Performance JavaFX Controls bring state of the art functions with visually attractive UIs. gaining knowledge of JavaFX eight Controls offers transparent directions, specific examples, and ready-to-use code samples. tips on how to paintings with the most recent JavaFX APIs, configure UI elements, instantly generate FXML, construct state of the art controls, and successfully practice CSS styling.

Data Abstraction and Problem Solving with Java: Walls and Mirrors (3rd Edition)

The 3rd variation of info Abstraction and challenge fixing with Java: partitions and Mirrors employs the analogies of partitions (data abstraction) and Mirrors (recursion) to coach Java programming layout strategies, in a manner that starting scholars locate available. The ebook has a student-friendly pedagogical procedure that rigorously debts for the strengths and weaknesses of the Java language.

Java Software Solutions: Foundations of Program Design (7th Edition)

Java software program recommendations teaches a origin of programming strategies to foster well-designed object-oriented software program. Heralded for its integration of small and big sensible examples, this around the world best-selling textual content emphasizes development sturdy problem-solving and layout abilities to jot down top quality courses.

Additional info for Programming Groovy 2: Dynamic Productivity for the Java Developer (Pragmatic Programmers)

Show sample text content

Com> document erratum • speak about Chapter five. operating with Strings • 102 sooner than we repair the matter, let’s take a second to appreciate how GString expressions are evaluated. while comparing a GString, if we have now a variable, its price is just published to a author, as a rule a StringWriter. although, if we've a closure rather than a variable, the closure is invoked. If our closure takes a parameter, then GString sends the author item as a controversy to the closure. If our closure takes no parameters in any respect, then GString easily calls our closure and prints the end result we go back to the author. If our closure takes multiple parameter, then the decision fails with an exception; let’s now not pass there. Let’s positioned that wisdom to exploit to resolve our expression-evaluation challenge. Here’s the 1st try: WorkingWithStrings/LazyEval. groovy companyClosure = { it. write(company) } priceClosure = { it. write("$price") } quote = "Today ${companyClosure} inventory closed at ${priceClosure}" shares. each one { key, worth -> corporation = key expense = worth println quote } Let’s run the code to work out the output: this present day Apple inventory closed at 663. 01 this day Microsoft inventory closed at 30. ninety five We obtained the output we wish, however the code doesn't glance very groovy. although we don’t are looking to enforce our ultimate code this fashion, seeing this instance might help in methods. First, we will be able to see what’s particularly going on—the GString is looking our closure on the time whilst the expression should be evaluated/printed. moment, if we have to do a little computations which are greater than only exhibiting a property’s price, we all know tips to do this. Let’s eliminate that it parameter. Like we mentioned previous, if our closure has no parameters, then GString makes use of what we go back. we all know the way to create a closure without parameters—define it with the syntax {-> . So, let’s refactor the former code: WorkingWithStrings/LazyEval. groovy companyClosure = {-> corporation } priceClosure = {-> expense } quote = "Today ${companyClosure} inventory closed at ${priceClosure}" shares. every one { key, price -> corporation = key expense = worth println quote } obtain from Wow! booklet record erratum • talk about Multiline Strings • 103 Here’s the output of the refactored model: this present day Apple inventory closed at 663. 01 this day Microsoft inventory closed at 30. ninety five That’s a notch higher, yet we don’t are looking to outline the closures individually. as an alternative, we'd like our code to be self-contained for easy instances, and we’re keen to write down a separate closure if now we have extra code to compute the values. Here’s the self-contained code that solves the matter (we’ll name it the “Google and Apple attempting to take over the area” problem): WorkingWithStrings/LazyEval. groovy quote = "Today ${-> corporation } inventory closed at ${-> rate }" shares. every one { key, worth -> corporation = key rate = price println quote } This concise model produces a similar output because the past model: this present day Apple inventory closed at 663. 01 at the present time Microsoft inventory closed at 30. ninety five GString’s lazy review is crucial idea.

Download PDF sample

Rated 4.33 of 5 – based on 26 votes