Skip to main content

Dynamic Magic

Posted by daniel on December 5, 2003 at 5:41 AM PST

Imagine adding methods and variables to objects at runtime. Seems odd - how do other objects know what methods they can call. Seems scary. Seems kind of cool.

We link to part two of Bill Venners interview with Matz, Ruby creator Yukihiro Matsumoto, in Also in Java Today. Matz provides an example of the use of dynamic features.

One example is a proxy. Instead of designing individual proxy classes for each particular class, in Ruby you can create an all purpose proxy that can wrap any object. The proxy can probe the object inside of it and just morph into the proxy for that object. The proxy can add methods to itself so it has the same interface as the wrapped object, and each of those methods can delegate to the corresponding method in the wrapped object. So an all-purpose proxy, which can be used to wrap any object, is an example of how a library class can adapt to the environment.

Venners asks Matz about whether Ruby is lest robust because it lacks the static compile-time type checking found in Java and other languages. Matz answers that his goal is to "try to make the interpreter robust, but the language itself in its design does not care about robustness for two reasons. First, you need to test the system anyway to be robust. So we encourage unit testing using a testing framework to help achieve robust systems. The second reason is that programs written in dynamic languages are very easy to run and check."

Our other linked article today is Hetal Shah's ONJava introduction to Regular Expressions in J2SE. Perl programmers have learned to make RegEx dance and do amazing things. With J2SE 1.4, Java programmers can add these powerful devices to their own applications. Shah provides a nice introduction for those new to Reg Ex.


In his java.net feature article Three Rules for Effective Exception Handling , Jim Cushing provides concrete helpful advice when throwing and catching exceptions. He writes that you should "be specific, throw early, and catch late." You probably understand that you should throw an exception close to the source of the exception. Cushing writes, "By throwing an exception early (also known as "failing fast"), the exception becomes both more specific and more accurate."

It's the last piece of advice that people often miss. He explains "A common mistake of many Java developers, both new and experienced, is to catch an exception before the program can handle it in an appropriate manner. The Java compiler reinforces this behavior by insisting that checked exceptions either be caught or declared. The natural tendency is to immediately wrap the code in a try block and catch the exception to stop the compile from reporting errors." He also provides an example where "Catching an exception too early, before it can properly be handled, often leads to further errors and exceptions."


In Weblogs , Vincent Brabant writes I saw the new Java Studio Creator in action (codename: Rave) at BEJUG . He reports from a talk by Robert Brewin on project Rave. The current plan is for Rave 1.0 to support visual development of JSP/JSF applications and Rave 2.0 to permit visual development of Swing applications. Vincent reports that the demo of building a little web application with two JSP pages "was amazing: You drop a JSF Table element in the JSP page. Then you drop the table of your database in that JSF Table element and it customize automatically the rows with data format of your database table."

Vincent points out that Rave is built on top of NetBeans. In fact, when the question came up at the presentation, people thought the speaker was lying. "Nobody trusted him. That application, that seems so nice, so beautiful, so well-responding can't be based upon the ugly, and slowly application that is NetBeans. That is impossible." The enhancements to the NetBeans code will be given back to the community but not the new features.

John Mitchell writes that Sun bails on NetBeans merger with Eclipse. Vincent's post about the dependence of Sun tools on NetBeans seems to imply why Sun is not prepared to fold or merge NetBeans into Eclipse.


Today in Projects and Communities, the JXTA community is asking you to look at their proposed list of features for their March 15 release. Bernard Traversat encourages you "to review this list, and help us prioritize the work to be done on Churrasco, and future releases."

The Java Communications home page features a story on the MeRMI (Micro Edition RMI) project. The article reporst that MeRMI helps "a developer to quickly and easily create network MIDP applications. [...] You point the MeRMI Compiler at this remote interface and it generates a suitable server side skeleton and matching client side object for use in your MIDP app."


In today's java.net News Headlines :

Registered users can submit news items for the href="http://today.java.net/today/news/">java.net News Page using our
news submission form.
All submissions go through an editorial review by news director Steve
Mallet before being posted to the site. You can also subscribe to the href="http://today.java.net/pub/q/news_rss?x-ver=1.0">java.net News RSS
feed.


Current and upcoming Java Events:

Registered users can submit event listings for the href="http://www.java.net/events">java.net Events Page using our href="http://today.java.net/cs/user/create/e"> events submission form.
All submissions go through an editorial review before being posted to the
site.


This blog is delivered weekdays as the href="http://today.java.net/pub/q/java_today_rss?x-ver=1.0">Java Today RSS
feed. Once this page is no longer featured as the front page of href="http://www.java.net"> java.net it will be archived at href="http://today.java.net/today/archive/index_12052003.html">
http://today.java.net/today/archive/index_12052003.html. You can
access other past issues in the href="http://today.java.net/today/archive/">java.net Archive.