Wednesday, January 9, 2008

Things to watch out for in 2008 for Java Developer - Part 2

In the first part of this series " Things to watch out for in 2008 for Java Developer-Part 1", I did mention about Scala,Groovy and Gant.And in continuation of that series,in this part let me discuss about other technologies ,which I think will take huge strides in J2EE application development,if not already.I assume the readers of this article did read the Part 1 article,though its not a primer for this part.

To start with,let me start with defining what scripting language is (thanks to Guillaume Laforge,project manager for Groovy and the initiator of Grails).
"Usually, scripting languages refer to languages which are interpreted, but not compiled. They are mostly used and live on the command-line, in shell environments, like bash. Those languages are often used to script some live applications, objects or components, to manipulate them programmatically, and potentially interactively.And scripting languages come in handy for prototyping spikes, for small to mid-sized projects where the expressivity matters more, or for integrating some customized logic to be interpreted or changed at runtime for bigger enterprise applications"

And I would like to start with Jython
Though it has been available as open-source from Sourceforge since 2000,what perplexes me is the lack of interest and usage of this software.I agree it has evolved from Python and not many Java J2EE n-tier enterprise applications tend to use it(I might be wrong,but I personally never come across any requirements which need Jython),I dont see it losing in race with JRuby or Groovy,though they are also one to watch out for,but given how easy it is to learn and on its roadmap(next release v2.5) this year(hopefully) has extensive support for JDK5.0 features like annotations,generics the buzz words now and almost all enterprises turning towards Java 5 (excluding some old beasts who never dare treading on with evolving world) I would definitely like to add this to my skills repertoire . And for the following reasons,Jython is an implementation of Python that has been seamlessly integrated with the Java platform. Python is a powerful object-oriented scripting language used primarily in UNIX environments.
Jython is extremely useful because it provides the productivity features of a mature
scripting language while running on a JVM. Unlike a Python program, a Jython
program can run in any environment that supports a JVM.And you would agree if you see the below excerpts,and I thank Weiqi Gao for his article here.Since Python (the language implemented by Jython) has a richer set of features than JavaScript, Jython provides more convenience for the exploratory Java programmer. Let's try out some examples in Jython:

* Java classes and packages can be imported using the Python import statement (Note the extra work Jython does for you, compared to Java):
>>> import java # Import the java 'module' so that we can use names therein
>>> java # This works now

>>> java.awt # Surprise, this works too

>>> from java.awt import * # Import all names from the java.awt 'module' into he current 'module'
>>> Frame # We can now refer to java.awt.Frame as simply Frame
Instantiating a Java object is straightforward (you don't need the 'new' when instantiating an object in Python):
*
>>> f = Frame("A Java Frame in Jython")
>>> b = Button("Hello")
>>> f.add(b); f.pack() JavaBeans style properties (defined by getter and setter methods) can be accessed directly:
*
>>> f.visible = 1 # In Python, 1 is true, 0 is false Java interfaces can be implemented with Python code:
*
>>> class MyActionListener (java.awt.event.ActionListener):
... def actionPerformed(self, event): # Note the extra self argument
... print("World")
>>> listener = MyActionListener()
>>> b.addActionListener(listener) Java classes can be extended with Python code, (however Python's multiple inheritance does not apply when Java classes are extended):
*
>>> class MyWindowListener (java.awt.event.WindowAdapter):
... def windowClosing(self, event):
... from sys import exit; exit() # Calling Python's sys.exit() to rather than Java's System.exit()
>>> adapter = MyWindowListener()
>>> f.addWindowListener(adapter)

Jython makes creating Java arrays easier through the jarray module:

>>> from jarray import array, zeros
>>> array([1,2,3], 'i')
array([1, 2, 3], int)
>>> from java.util import HashMap
>>> a = array([HashMap(), HashMap()], HashMap)
array([{}, {}], java.util.HashMap)

Jython goes one step further than Rhino in JavaBeans scripting. All properties and event listener methods can be assigned at object construction time using keyword arguments:

>>> f = Frame("A Java Frame in Jython", visible=1, windowClosing=exit)

This is roughly equivalent to the following Java code

Frame f = new Frame("A java Frame in Jython");
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
exit();
}
});


B)Next in line is other scripting language in Java,JRuby, though I didnt mention about it in my part 1 article,I would like write something about it,that way we can compare it with Jython as well here.
For the popularity,Ruby on Rails has gained so far,it comes as no surprise as to so much interest in JRuby.Ruby is a full-featured object-oriented language. But there are many significant differences compared to Java. Ruby is dynamically typed and runs in a source-code interpreter, and it conveniently supports metaprogramming as well as the procedural and functional paradigms. Java has static typing. You declare the type of each variable, and then, during compilation, you get an error message if you use a variable of the wrong type. Ruby, on the other hand, has dynamic typing: You don't declare types for variables or functions, and no type-check occurs until runtime, when you get an error if you call a method that doesn't exist. Even then, Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call and JRuby is a Java implementation of the Ruby platform. Ruby
can run directly on mainstream operating systems with a C runtime, and is starting to run on .NET's CLR. When you program in JRuby you primarily use Ruby's libraries which are implemented in Java, and may also use Java's libraries at your discretion. If you stick to Ruby's libraries, or at least wrap any foreign elements, you can run Ruby
programs on the C, Java, or (in time) .NET runtimes. So you can use JRuby to both run Ruby programs on the JVM and as a language for scripting the JVM. The fact that JRuby is a Ruby platform on the JVM means that in JRuby you have two kinds of objects - JRuby objects and Java objects.There are times when you need to know whether you're dealing with a Java string or a JRuby string.
Some JRuby examples are , http://www.codecommit.com/blog/java/rapid-prototyping-with-jruby
Thanks to Martin Fowler

C)And I would like end Part 2 with Rake.
Rake is a software build tool similar to Ant.The tool is written in the Ruby programming language and the Rakefiles (equivalent of Makefiles in make) use Ruby syntax. It was originated by Jim Weirich.
Rake uses Ruby's anonymous function blocks to define various tasks, allowing the use of the Ruby syntax. There's a library of common tasks available, for example, functions to do common file-manipulation tasks and a library to remove compiled files (the "clean" task). Like Make, Rake can also synthesize tasks based on patterns (for example, automatically building a file compilation task based on filename patterns). Rake is now part of the standard library form Ruby version 1.9.
And go through this article by Martin Fowler for clear understanding about Rake.
http://martinfowler.com/articles/rake.html

Print this post

0 comments: