From the course: Learning Groovy

What is Groovy? - Groovy Tutorial

From the course: Learning Groovy

Start my 1-month free trial

What is Groovy?

- [Instructor] Let's get started. What is Groovy? Groovy is an object-oriented programming language which means that you write the code based on classes, methods, and fields. This approach leads to a much more structured program than procedural source code with the benefit of enabling non functional aspects like modularity, reusability, and encapsulation. Groovy stands on the shoulders of giants. The Java platform. The source code can be compiled to byte code and run on the Java virtual machine. If you have Java installed on your system you're already set up to execute a compiled Groovy program. Here's one of the main differences between Groovy and Java. Java only allows static typing. Groovy on the other hand uses optional typing meaning you don't necessarily have to spell out the type of a field for example. It will be derived at run time based on the assigned value. Nevertheless you can still opt into static typing as needed. The language comes with advanced programming concepts like metaprogramming, functional programming, and closures, some of which are not available in Java programming, making it a powerful and flexible tool to solve problems. If you're a Java programmer it should be relatively easy to read and write Groovy source code. The syntax aligns with Java constructs and extends it with new concepts. While the syntax looks familiar you will notice that you can express logic in a more concise and less verbose fashion. Groovy is not a competitor to Java. They rather compliment each other. Existing Java programs can be enhanced with Groovy code. You can even mix Java and Groovy source code based on your needs. And here's the kicker. The libraries you already used in Java programs, for example Google Guava or the Spring framework, can be used from Groovy code as well. Groovy's features make it easy to build domain specific languages to model higher level abstracted and understandable MIDI languages designed to solve a particular problem. I would like to mention a couple of examples here. The language elements in a Jenkinsfile to create a built pipeline with Jenkins or the language used in the Gradle build script. There are many more examples of what Groovy can bring to the table. You will find that the language comes with many capabilities out of the box that don't necessarily require the use of an external library. For example functionality to write tests and create mock objects are just some of them.

Contents