Posted in Core Java, Groovy, Java EE

Groovy vs Java

  Java Groovy
Access modifier (by default) package public
getters and setters Need to provide for fields Are automatically generated for class members
Utility methods System.out.println println
Support substitution   Can print dynamic content without string concatation

Println(“Hello $name !”)

 

Specifying type definition   Instead use keyword def

Mandatory for methods, optional for method arguments

Using semicolons Every statements end with semicolon optional
main method To make a class executable Don’t need
Initializing String arrays, static arrays Curly braces { “abc”, “dfg”} Square brackets [“abc”, “dfg”]
autoboxing/unboxing/conversion of primitives yes No, everything is Object and uses only Objects
Inner static classes yes no
Anonymous classes yes no
     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s