3. Get Rid Of Main

Based on doctrine of JAVA, for every single program must have one class and one main method. The future of java in 21st century is groovy which is capable to make java better. One of unique thing that make groovy is a rapid programming language is non existence of main method. We don’t need to make a main method in every single groovy program, but not only that class is also unnecessary to be used in groovy program. This is the example from previous program (Employee.groovy)

public class Employee{
	String name
	String address
	String jobDescription
}
		def employees = [
			new Employee(name:"Achmad", address:"Jember", jobDescription:"Programmer"),
			new Employee(name:"Fauzi", address:"Bangkalan", jobDescription:"Artist"),
			new Employee(name:"Fauzi Achmad", address:"Jember", jobDescription:"Web Designer")
		]
		employees.each{
			println "${it.name} ${it.address} ${it.jobDescription}";
		}


From the script above, I compile and run the program using groovy console. Well, everything is more simple and easy. For most java developers don’t need to learn too much in this programming language because groovy is very familiar with java. This is another example :

Tagged: , ,

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: