concept Java in category groovy

This is an excerpt from Manning's book Groovy in Action, Second Edition.
new MyGroovyClass(); // create from Java
Being Java friendly means two things: seamless integration with the Java Runtime Environment and having a syntax that’s aligned with Java.
In Groovy, everything is an object. It is, after all, an object-oriented language. Groovy doesn’t have the slight “fudge factor” of Java, which is object-oriented apart from some built-in types. To explain the choices made by Groovy’s designers, we’ll first go over basics of Java’s type system. We’ll then explain how Groovy addresses the difficulties presented, and finally examine how Groovy and Java can still interoperate with ease due to automatic boxing and unboxing where necessary.
Converting a primitive value into an instance of a wrapper type is called boxing in Java and other languages that support the same notion. The reverse action—taking an instance of a wrapper and retrieving the primitive value—is called unboxing. Groovy performs these operations automatically for you where necessary. This is primarily the case when you call a Java method from Groovy. This automatic boxing and unboxing is known as autoboxing.
You’ve seen that Groovy is designed to work well with Java, so what happens when a Java method takes primitive parameters or returns a primitive return type? How can you call that method from Groovy? Consider the existing method in the java.lang.String class: int indexOf (int ch). You can call this method from Groovy like this:

This is an excerpt from Manning's book Making Java Groovy: Foreword by Guillaume Laforge.
For all of its flaws (and we’ll be reviewing them shortly), Java is still the dominant object-oriented programming language in the industry today. It’s everywhere, especially on the server side, where it’s used to implement everything from web applications to messaging systems to the basic infrastructure of servers. It’s therefore not surprising that there are more Java developers and more Java development jobs available than for any other programming language. As a language, Java is an unmitigated success story.
If Java is so ubiquitous and so helpful, why switch to anything else? Why not continue using Java everywhere a Java Virtual Machine (JVM) is available?
In this book, the answer to that question is, go right ahead. Where Java works for you and gets the job done, by all means continue to use it. I expect that you already have a Java background and don’t want to lose all that hard-earned experience. Still, there are problems that Java solves easily, and problems that Java makes difficult. For those difficult issues, consider an alternative.
That alternative is Groovy. In this chapter I’ll review some of the issues with Java that lead to problems for developers and discuss how Groovy can help alleviate them. I’ll also show a range of tools, provided as part of the Groovy ecosystem, that can make pure Java development easier. In the long run, I suggest a blended approach: let Java do what it does well, and let Groovy help where Java has difficulties.
Figure 3.1. Guide to integration features. Groovy can be accessed with Java classes alone using the JSR 223 script engine. If you are willing to add some Groovy library classes to Java, the Eval, GroovyShell, and Binding classes make working with scripts easy. The best way to combine Groovy and Java is using classes for both languages.
![]()