{"id":108156,"date":"2020-12-31T07:00:00","date_gmt":"2020-12-31T05:00:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=108156"},"modified":"2020-12-22T12:12:28","modified_gmt":"2020-12-22T10:12:28","slug":"groovy-script-101-commonly-used-syntax-reference-guide","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html","title":{"rendered":"Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide"},"content":{"rendered":"<p>Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible object oriented programming language that compiles into JVM bytecode.<\/p>\n<p>In a way, <strong><a href=\"https:\/\/groovy-lang.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Groovy<\/a> can be viewed as a <em>flavor<\/em> of Java without being actual Java<\/strong>. This is because it works on the Java platform in a native capacity. Because of the way it works, it interoperates nicely with Java code and its associated libraries. <strong>Most valid Java code also translates to valid Groovy code<\/strong>.<\/p>\n<p><strong>Groovy is designed to be both a programming and scripting language<\/strong>. This means that unlike Java, which needs to be compiled, Groovy can be used in conjunction to provide on the spot programmatic processes that doesn\u2019t require a lot of server side heavy-lifting.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/540\/1*w4eu1Ue0lUflzU1Agt5nIw.jpeg\" alt=\"\"\/><\/figure>\n<\/div>\n<p>The biggest difference between Groovy and Java code is that <strong>Groovy is more compact, with less syntax requirements and therefore making it appealing to many developers<\/strong>. It also means that many Java developers going into Groovy will find the process of picking it up super simple. Why? Because fundamentally, most object-oriented based programming languages tend to follow the same ideas. This shared ideology makes it easy for developers to jump between Java and Groovy.<\/p>\n<p>This piece will go over <strong>how to do 7 most common things that we encounter when writing code<\/strong>. They are the foundation and general building blocks of any program and often crop up in some form within an object-oriented based thinking.<\/p>\n<h2 class=\"wp-block-heading\">1. Installing Groovy<\/h2>\n<p>You can install Groovy via your package manager. Alternatively, you can install groovy from their website.<\/p>\n<p>Groovy files are saved with <code>.groovy<\/code> extension.<\/p>\n<p>To execute files in the command line, you can do so using <code>groovy<\/code>. For example:<\/p>\n<p><code>&nbsp;groovy index.groovy<\/code><\/p>\n<p>To run Groovy Shell, you <code>groovysh <\/code>in the command line.<\/p>\n<h2 class=\"wp-block-heading\">2. List and maps<\/h2>\n<p>A list is also commonly known as an array. It stores objects sequentially and can be accessed via integer indices. In Groovy, a list looks something like this:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def shoppingList = [\"flour\", \"eggs\", \"banana\", \"bread\"]\n \u200b\n println shopingList[2]\n \/\/will give \"banana\"\n \u200b\n shoppingList.remove(\"flour\")\n shoppingList.add(\"milk\")\n \u200b\n println shoppingList[2]\n \/\/will give bread<\/pre>\n<p>A map holds a key-pair value based list where you can attach data to a custom named key. Rather than calling values based on integer based keys, this lets you use the custom named key instead.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def productDetails = [\n  \"name\": \"banana\",\n  \"type\": \"fruit\",\n  \"price\": 2.99,\n  \"unit\": \"kg\",\n  \"color\": \"yellow\"\n ]\n \u200b\n println productDetails[\"name\"];\n \u200b\n productDetails[\"price\"] = 5.99<\/pre>\n<p>We can also add lists into maps like this:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"wp-block-preformatted brush:java\">def toDoList = [\n  \"monday\": [\"water plants\", \"laundry\"],\n  \"tuesday\": [\"assignment due\", \"feed cat\"]\n ]\n \u200b\n toDoList['wednesday'] = [\"clean kitchen\", \"get groceries\"]\n \u200b\n println toDoList['wenesday'][1]<\/pre>\n<h2 class=\"wp-block-heading\">3. Conditionals<\/h2>\n<p>The most basic conditionals are if else statements. The result is a boolean that determines which block of code to execute next. An if else statement in Groovy looks like this:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def myString = \"I am allergic to cats.\"\n \u200b\n if(myString.contains(\"allergic\")){\n    println myString\n } else {\n    println \"all clear!\"\n }<\/pre>\n<p>You can also do the expressions that evaluates to a boolean within the if statement. For example:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def myString = \"I am allergic to cats.\"\n \u200b\n if(myString.contains(\"allergic\") &amp;&amp; myString.contains(\"cats\")){\n    println myString\n } else {\n    println \"all clear!\"\n }<\/pre>\n<p>&amp;&amp; and || operators are conditionals known as \u2018and\u2019 and \u2018or\u2019. The statement needs to evaluate to <code>true <\/code>in order to proceed, or it goes down to the else block.<\/p>\n<p>Another condition you can use to give your <code>if else<\/code> statement options beyond just the two is to use the <code>else if<\/code> option.<\/p>\n<p>For example:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def myString = \"I am allergic to cats.\"\n \u200b\n if(myString.contains(\"allergic\") &amp;&amp; myString.contains(\"cats\")){\n    println \"ahchooo! blasted cats!\"\n } else if(myString.contains(\"allergic\") &amp;&amp; myString.contains(\"dogs\")){\n    println \"oh no! not dogs!\"\n } else{\n    println \"all clear!\"\n }<\/pre>\n<h2 class=\"wp-block-heading\">4. Loops<\/h2>\n<p>A loop is a set of code that we want to repeat under certain circumstances. Three common types of loops are: <code>while<\/code>, <code>collection iteration<\/code>, and <code>recursion<\/code>.<\/p>\n<p>Let\u2019s begin with the first of the three: the <code>while <\/code>loop.<\/p>\n<p>A <code>while <\/code>loop runs through a set of execution statements until the condition is satisfied. It accepts an argument to determine the validity of the boolean evaluation.<\/p>\n<p>Writing a <code>while <\/code>loop in Groovy looks something like this:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def counter = 0;\n \u200b\n while(counter &lt; 10){\n  counter = counter +1\n  println \"just counting...\" + counter\n }\n \u200b\n println \"all done!\"<\/pre>\n<p>A <code>collection iteration<\/code> is when you work through a list, iterating it until the list is exhausted. To do this, you use the <code>each <\/code>method like this:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def children = [\"James\", \"Albus\", \"Lily\"];\n \u200b\n println \"The children's names are:\"\n children.each { child -&gt;\n    println child\n }<\/pre>\n<p>You can also iterate through maps like this:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def families = [\n  \"Potter\": [\"James\", \"Albus\", \"Lily\"],\n  \"Weasley\": [\"Rose\", \"Hugo\"],\n  \"Lupin\": [\"Edward\"]\n ]\n \u200b\n families.each{ family, child -&gt;\n  println \"The children of the \" + family + \" family are \" + children.join(', ')\n }<\/pre>\n<p>And finally, we have <code>recursions<\/code>. A recursion is a function that calls itself when the conditions are met. For example, here is a function that calls itself.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">def fibonnaci(n) {\n  if(n &lt;= 2) {\n    return 1\n  } else {\n    return fibonnaci(n - 1) + fibonnaci(n - 2)\n  }\n }\n \u200b\n println fibonnaci(4)\n println fibonnaci(5)<\/pre>\n<h2 class=\"wp-block-heading\">5. Writing JSON<\/h2>\n<p>You can write lists and do things to it. But what we really want is to turn this data into something more universally accessible \u2013 that is, make it into valid JSON.<\/p>\n<p>Groovy includes simple classes for writing to JSON. All you have to do is import <code>JsonBuilder <\/code>and use on the list map you want to transform.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">import groovy.json.JsonBuilder\n \u200b\n def families = [\n  \"Potter\": [\"James\", \"Albus\", \"Lily\"],\n  \"Weasley\": [\"Rose\", \"Hugo\"],\n  \"Lupin\": [\"Edward\"]\n ]\n \u200b\n new File('familyMembers.json') &lt;&lt; new JsonBuilder(families).toPrettyString()<\/pre>\n<p>The new <code>File()<\/code> will create a new file object that we assign our transformed <code>families <\/code>JSON to.<\/p>\n<h2 class=\"wp-block-heading\">6. Reading JSON<\/h2>\n<p>JSON is the most popular method of moving structured data between different applications and networks. Let\u2019s pretend we get given a JSON file containing all a giant list of inventory information.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">import groovy.json.\\*\n \u200b\n def inventoryListFile = new File('products.json')\n def inventory = new JsonSlurper().parseText(inventoryListFile.text)\n \u200b\n println inventory['banana']<\/pre>\n<p>The <code>JsonSlurper <\/code>lets you create a new instance and <code>parseText <\/code>method allows you to pass texts into your file, allowing you to modify and do what you want with the data set.<\/p>\n<h2 class=\"wp-block-heading\">7. HTTP requests<\/h2>\n<p>An isolated application that doesn\u2019t communicate with anything isn\u2019t much use in this day and age. there\u2019s a lot of data that gets transferred over the Internet and to do this, we need the ability to create HTTP requests.<\/p>\n<p>Here\u2019s a scaffold of how you\u2019d write it.<\/p>\n<pre class=\"wp-block-preformatted brush:java\">@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )\n \u200b\n import groovyx.net.http.HTTPBuilder\n import groovy.json.JsonBuilder\n \u200b\n new HTTPBuilder('https:\/\/en.wikipedia.org\/w\/api.php').get(\n   'query': [\n     'action': 'opensearch',\n     'search': 'Harry Potter'\n  ]\n ) { resp, json -&gt;\n   if(resp.status == 200) {\n     def responseFile = new File('potter.json')\n     responseFile.text =  new JsonBuilder(json).toPrettyString()\n  } else {\n     println 'Uh oh. Something went wrong:('\n  }\n }<\/pre>\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n<p>I hope you found this reference helpful. It\u2019s<strong> a quick cheat sheet style list of commonly used things you\u2019d find in programming, but in a Groovy flavor<\/strong>.<\/p>\n<p>If you\u2019re coming from a Java background, everything should feel almost at home. If you\u2019re coming from a JavaScript environment, the elements of Groovy are generally identifiable.<\/p>\n<p>The fundamentals of programming are still the same, no matter where you go. Most of the time, once you learn one language, the ideas are transferable and all you have to do is learn the syntax.<\/p>\n<p>From what you can see above, the ideas are mostly the same. So in theory, you can potentially close your eyes and pretend it\u2019s Java or JavaScript but with a few differences in syntax and how certain things are run.<\/p>\n<p>But for the scope of this piece, the content presented here should be enough to get you started on your next Groovy based project.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Aphinya Dechalert, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/blog.codota.com\/groovy-script-101\/\" target=\"_blank\" rel=\"noopener\">Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible object oriented programming language that compiles into JVM bytecode. In a way, Groovy can be viewed as a flavor of Java without being actual Java. This is because it &hellip;<\/p>\n","protected":false},"author":120107,"featured_media":132,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-108156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-groovy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-31T05:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aphinya Dechalert\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aphinya Dechalert\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html\"},\"author\":{\"name\":\"Aphinya Dechalert\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ef9b079d87457183f61b2fda533be909\"},\"headline\":\"Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide\",\"datePublished\":\"2020-12-31T05:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html\"},\"wordCount\":995,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/groovy-logo.jpg\",\"articleSection\":[\"Groovy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html\",\"name\":\"Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/groovy-logo.jpg\",\"datePublished\":\"2020-12-31T05:00:00+00:00\",\"description\":\"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/groovy-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/groovy-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/12\\\/groovy-script-101-commonly-used-syntax-reference-guide.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\\\/groovy\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ef9b079d87457183f61b2fda533be909\",\"name\":\"Aphinya Dechalert\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g\",\"caption\":\"Aphinya Dechalert\"},\"description\":\"I code. I write. I hustle. Living the #devLife remotely. Full-stack MVP developer. Coding and writing about code.\",\"sameAs\":[\"https:\\\/\\\/www.codota.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/aphinya-dechalert\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks","description":"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html","og_locale":"en_US","og_type":"article","og_title":"Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks","og_description":"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible","og_url":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-12-31T05:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg","type":"image\/jpeg"}],"author":"Aphinya Dechalert","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Aphinya Dechalert","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html"},"author":{"name":"Aphinya Dechalert","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ef9b079d87457183f61b2fda533be909"},"headline":"Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide","datePublished":"2020-12-31T05:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html"},"wordCount":995,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg","articleSection":["Groovy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html","url":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html","name":"Groovy Script 101 - Commonly Used Syntax Reference Guide - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg","datePublished":"2020-12-31T05:00:00+00:00","description":"Groovy has been around on the Java scene since 2003. With over a decade\u2019s worth of history, development and experience, it is a Java syntax compatible","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/groovy-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2020\/12\/groovy-script-101-commonly-used-syntax-reference-guide.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages"},{"@type":"ListItem","position":3,"name":"Groovy","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages\/groovy"},{"@type":"ListItem","position":4,"name":"Groovy Script 101 &#8211; Commonly Used Syntax Reference Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ef9b079d87457183f61b2fda533be909","name":"Aphinya Dechalert","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5b8c532eb7b65cb09ada1a7b663a366436f97baa96f412ebf1263711ba0b2131?s=96&d=mm&r=g","caption":"Aphinya Dechalert"},"description":"I code. I write. I hustle. Living the #devLife remotely. Full-stack MVP developer. Coding and writing about code.","sameAs":["https:\/\/www.codota.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/aphinya-dechalert"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/108156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/120107"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=108156"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/108156\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/132"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=108156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=108156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=108156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}