Recently I was reading the new features of J2SE 5.0, that claim to be the most important upgrade of J2SE and the main point is to make the development easier.

Well, ok, reading that they are interested to make the Java development easier I was interested to see all this new things:

  • Enhanced for Loop:
  • Basically is our foreach() for collections (array of objects):

    new Java way:

    ArrayList ar = new ArrayList(); for(String item : ar) { ... }
    old Java way:
    ArrayList ar = new ArrayList(); for(Iterator i = ar.iterator(); ar.hasNtext(); ) { String item = (String); }
    my @ar ; foreach my $item (@ar) { ... }
  • Typesafe Enumerations:
  • Is just the old enum resource from C:

    new Java way:

    public enum int {MENU_FILE, MENU_EDIT, MENU_FORMAT, MENU_VIEW} ;
    old Java way:
    public int MENU_FILE = 0; public int MENU_EDIT = 1; public int MENU_FORMAT = 2; public int MENU_VIEW = 3;
    my ($MENU_FILE, $MENU_EDIT, $MENU_FORMAT, $MENU_VIEW) = (0..4) ;
    Well, Perl already have an easy way to declare a sequence of numbers, so, we don't need a enum word.

  • Static Imports
  • This is the most interesting part of the new features, since this goes directly in the oposit way of a pure OO language like Java, import from another class static declarations. With Perl we use this a lot, is just our Export module, were when we load a module we automatically can get static references in the main package to variables and subs in other packages.


    ------------------------------------------ package; interface XYZ { public static final double Constant1 = someValue; public static final double Constant2 = anotherValue; } ------------------------------------------ import static*; public class MyClass { ... double value = 2 * Constant1; ... }
    The problem that they haven't realised yet is that we can't import using groups or a specific static declaration like in Perl. With this new feature in Java we always have to import all the static declarations of the other class, what will create problems in the main class, since method overloading will exists. On Perl we can define groups to be exported or get a specific name:
    use XYZ qw(Constant1) ; use XYZ qw(:SOMEGROUP) ;

  • Final Notes
  • Well, for us this new features can be dum, but for a language that don't change it's syntax in the last 10 years is not so dum, specially for who always use Java.

    Maybe the biggest new features are the performance changes, and monitoring (since Thread monitors in Java doesn't work 100%, what make not viable to use them).

    Now as a Perl developer I realise that be able to change the language that we use and know that we have a language that care about an usual way to do things is very good. We don't need to wait Larry Wall to create new features or fix them. We are able to embed Perl in any application, etc... But the most important, we don't need to be misled by a release the claim that is giving to us incredible things, were actually they are just adding simple things that all the world saw years ago.

    Graciliano M. P.
    "Creativity is the expression of the liberty".

    In reply to J2SE 5.0 new features are just sugar from Perl (and other similar languages). by gmpassos

    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":