Monday, June 13, 2011

Groovy, A simple Hello world program.

In this post we will see a simple Groovy "Hello world" program. You can check my previous post here. Since Groovy is an Jvm language, and runs in JVM. I need to mention on one important point about Groovy. "Some Groovy code—but not all—appears exactly like it would in Java" (keep this in mind). So we can see the "Hello World" program. The code will be :



println("Hello World");


Thats it, when you run this Groovy Script you will get the output in console as "Hello World". Note that here the println method is made as a convenient method n Groovy. What i mean convenient method is that, we need some jobs that have to be done again and again in our programming life, and convenient method makes our life easier by providing a simple syntax and solution. This code is not only short and sweet. Its more readable. Fine, lets make it more readable even, so we can do something like:



println "Hello world"


Note that in above code i have left out parenthesis and also the semicolon. Groovy can run this well as we would expect. You can see this code is very short than a normal Java Code, which can take upto 8 lines, where as groovy provides the solution in a line. This can show that Groovy code is 3 times lesser than the Java code. The reason because, if we have done this in Java then we would have defined args and many other code like public static void main(blah blah...!), which is not needed in the Hello world program(Is't it?). Groovy provides what we need in a exact manner. So i can say this following quote holds true for all Groovy programmers:


Do what you think is interesting, do something
that you think is fun and worthwhile, because
otherwise you won’t do it well anyway.
—Brian Kernighan


And also note that All Groovy code is Java but not the vice versa. So that's all for this post. 
Hope this is short and sweet and comments are welcome.

Saturday, June 11, 2011

Groovy, Frequently Asked Questions.

I have tried to explain what is JVM and Groovy in my last two posts(here and here). However still there may be questions about Groovy and JVM, in this post we will see the frequently asked question in Groovy language.

1)What is Groovy?
   Well it is an powerful dynamic language that can run on JVM(For more details click here)

2)Is it useful to learn this new language?
  Yes exactly it will be very useful if your a Java programmer and Groovy provide so many advantages to the Java language and its platform. To see what Groovy can offer, click here.

3)Am a experienced Java developer, whether i should learn Groovy?
  Ya your the correct person to start and learn Groovy.

4)How does Groovy runs on JVM?
    Simple, Groovy is converted into java bytecodes internally

5)Is it is possible to integrate Groovy with Java?
   Yes you can and it is very easy too.

6)List some of the Groovy powers?
  You can check here

7) Any frameworks that are built on this language?
   Ya Grails and Griffon are the famous framework that are built on Groovy language. However there are many frameworks apart.

8)Since Groovy is a dynamic programming language, performance issue will be there?
 Not exactly, since the newer version of Groovy 1.8 have Runtime performance improvements.

9)So whats new in Groovy 1.8??

  •  Nicer DSL's with comment chain 
  •  Closure enhancements
  •  Runtime performance improvements
  •  Built-in JSON support and many
10) Well show me a simple "Hello World" program in Groovy!!
         print "Hello World" // is it simple enough?? :D

I have answered few questions and also Groovy supports Domain Specification language(DSL's)   in a very concise manner, which is becoming popular in the recent days. And there is continuous improvements in efficiency of Groovy 1.9, which will be the next version (If you love Groovy then cheers :D)


Hope I have answered few things about Groovy, well comments are welcome. If you have other question regarding Groovy that are not mentioned here, you can post it with a smile :D

Wednesday, June 8, 2011

What Groovy Can offer!

As stated in my previous blog(Jvm And Groovy), i have said what is groovy and mentioned that it is a JVM language for Java platform. Everyone likes Object-Oriented Programming due to its power of what is called as Objects. There are so many OOP languages available in this planet, for example Java, C#, C++ and so on. Using OOP we can take full control over logic and data.
      As said Groovy is the JVM language for Java, Groovy enhances the power of Java to the next level. The latest version of Groovy language is 1.8 which can offer many things, some of them mentioned here:
1) Is an agile and dynamic language for Java.
2) It supports what is called DSL's(Domain Specification Language)
3)Uses elegant syntax
4) Provides more readability, which indicates that Groovy shows what it does rather than how it does.
5)produces very less number of codes, it doesn't mean that it provides ugly syntax.
6) easy to integrate into Java code.
I have mentioned only few points, and my following posts shows Groovy codes in action. As we know Groovy runs on JVM-- it means that, it is been converted into JavaByte code behind the hoods, so Groovy can run anywhere Java runs. (Isn't cool? Yes?)

In the next post will see how Groovy makes Java a fully object oriented programming language! 
     

What is JVM languages and what is Groovy?(in plain simple english)

Edit: Typos have been corrected
Well I love Java very much as it is  platform independent and its free! As i guess you know Java runs on what is called as Java Virtual Machine(JVM). To be a bit deeper, when you compile the Java code it turns into what is called as .class files. Hmmm class files? Ya, class files are the ones that can be understood by the JVM. To be simple enough, consider your the JVM(just as a example) and assume you have trained well verse in French language. So any one who speaks in French language to you, you can easily interpret it, understand it, and even get details of it and so on.
          Ya what you guess is correct, here the French language is .class files and your the JVM! From this analogy we can say that Java is capable of producing .class files(i.e French language kinda syntax,in our example) . Hmmm well, till now so good. Lets take a breath and go in further.
        Since JVM understands .class files, any language that produce .class file can run in JVM!!(Shocked?). With our example, I can say that any person can speak French language to you, until you understand it(note that your considered as JVM in this case). The languages(apart from Java) that produces .class files and can run in JVM are called as JVM languages. For example, Groovy  is one of the JVM languages(other example are avilable at examples page). JVM languages are powerful and flexible even.
Hope you understand this post, comments are welcome.

About Me and the blog:)

Hi this is Anto, doing my final year engg belongs CSE department. Passionate about :
1)Java and .net
2) Jvm languages like Groovy :)
3) And about latest technologies!

And this blog will go through a series of Groovy language features in a simple code snipets! And will keep you updated in what this powerful language does :)