JSR 59: J2SE 1.5.0 Beta 1 Maintenance Review

Discussions

News: JSR 59: J2SE 1.5.0 Beta 1 Maintenance Review

  1. JSR 59: J2SE 1.5.0 Beta 1 Maintenance Review (18 messages)

    This maintenance review offers the nitty gritty changes that are happening in the various APIs of the JDK.

    For example, you will learn that the Collections API now has a method to tell you if an element is shared between two collections (boolean disjoint(Collection c1, Collection c2)).

    Check this out if you want to know all of the subtle changes that are going on.

    Read Java Community Process Maintenance Review for J2SE 1.5.0 Beta 1

    View the JSR 59: J2SETM Merlin Release Contents home page

    Threaded Messages (18)

  2. getEnv is back![ Go to top ]

    A noteworthy change is that System.getEnv() is back. It was deprecated and threw an error before, and is now un-deprecated and functional.
    See here for details.
  3. getEnv is back![ Go to top ]

    Just wanted to say WOO HOO! The getEnv bug report has attracted a lot of comments over the years on Sun's Java Bug Parade, and now Sun finally got around fixing it. Lots of people will rejoice as platform dependent workarounds are no longer needed.
  4. Another useful method[ Go to top ]

    Reading through briefly, another useful method is java.util.Arrays.deepEquals(Object[] one, Object[] two). I don't use arrays often myself, but when I run into them a deepEquals method was usually needed. This will help eliminate boxing in a collection, or iterating through the array, to find equality! See it here:
    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#java.util
  5. Disjoint[ Go to top ]

    Disjoint isn't described correctly. It actually returns true if there are no elements in common. So, rephrased:
    For example, you will learn that the Collections API now has a method to tell you if two collections do not share any elements (boolean disjoint(Collection c1, Collection c2)).
    Seems odd that they didn't also create methods for the other set operators: union, difference, and intersection.
  6. Not Odd[ Go to top ]

    Why create methods for any of the set operations - they all exist in Jakarta Commons Collections anyway.
  7. Disjoint[ Go to top ]

    Disjoint isn't described correctly. It actually returns true if there are no elements in common. So, rephrased:
    For example, you will learn that the Collections API now has a method to tell you if two collections do not share any elements (boolean disjoint(Collection c1, Collection c2)).
    Seems odd that they didn't also create methods for the other set operators: union, difference, and intersection.
    addAll, removeAll retainAll can simulate these operators:
    <br/>union of c1,c2: new HashSet(c1).addAll(c2)
    <br/>difference c1,c2: new HashSet(c1).removeAll(c2)
    <br/>intersection c1,c2: new HashSet(c1).retainAll(c2)
    <br/> though it isn't quick.
  8. Finally[ Go to top ]

    Finally an easy way to see if a host is available

    isReachable(int timeout)
  9. My favorite fixes and new stuff[ Go to top ]

    I'm a J2EE programmer by day, game programming hobbyist by night. Most of my favorite new stuff after reading the list are related to improved performance and reduced memory footprint:

    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#math - bit flipping galore! Should lead to more speed:

    "Many applications, such as cryptography, network programming, image manipulation, data structures, game programming, and multiprecision arithmetic, require common bit manipulation operations, such as rotate, reverse and population count. It is tricky to code these operations correctly, and even trickier to code them correctly and efficiently. Furthermore, they often appear in inner loops, so it is important that they run fast. Many machines have special instructions that speed up these operations, so they are a natural for VM "intrinsification." Providing library methods enables this intrinsification."

    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#swing - performance improvements and better spreadsheet support plus JTable printing:

    "Several invalidate and repaint methods have been added to Swing's default cell renderers. Overriding these methods improves performance."

    "Printing support has been added to javax.swing.JTable."

    "Improved Memory Consumption of Swing Applications - For this release, work was done to reduce the instance size of Swing components."

    "Previously, a computation-heavy method was called frequently when rendering HTML. Internal caching is now used to reduce the times this method is called."

    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#2D - mostly font-related improvements, but I liked this:

    "There are 2 different means for accessing hardware acceleration for imaging operations: explicit image acceleration via the VolatileImage object and implicit acceleration for other types of Image objects. This change adds the following new fields and methods to these APIs:

        * java.awt.GraphicsConfiguration.createCompatibleVolatileImage(int w, int h, int transparency)
        * java.awt.image.VolatileImage.getTransparency()
        * java.awt.image.VolatileImage.transparency
        * java.awt.Image.accelerationPriority
        * java.awt.Image.getCapabilities(GraphicsConfiguration gc)
        * java.awt.Image.setAccelerationPriority(float priority)
        * java.awt.Image.getAccelerationPriority()
        * java.awt.GraphicsConfiguration.createCompatibleVolatileImage(int w, int h, ImageCapabilities imageCaps, int transparency)
        * java.awt.image.BufferedImage.getTransparency() "

    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#sound - new and improved all over the place. The best:

    "Class AudioFormat in package javax.sound.sampled previously lacked extensibility and was not suitable for common audio formats like mp3. Adding a generic way of adding format qualifiers by way of properties solves this and related problems, such as how to expose capabilities of specific hardware in a uniform concept."

    http://java.sun.com/j2se/1.5.0/jcp/beta1/index.html#vm - increased class loading speed!:

    "Application class loading speed is limited in part by the need to copy the class file data into a Java byte array, so it can be passed to the java.lang.ClassLoader.defineClass(), where it is copied to a C buffer. In many cases there is no need to have the class file data in a Java array at all.

    Given an average class file size of 1K, and potentially of thousands of classes loaded by the application class loaded, there could be megabytes of unnecessary java array creation, and unnecessary copying data into and out of the java arrays.

    This change adds a set of new defineClass methods that accept a java.nio.ByteBuffer object instead of a byte array:

    Class loaders can now map in class files (using java.nio functionality or extensions to current jar file code), create a ByteBuffer encapsulating the class file data, and pass the ByteBuffer to one of the new defineClass() methods."

    Awesome! JDK 1.5 is going to be a VERY different beast, and is the kind of major transition unlike any we've seen since 1.0 to 1.1 and 1.1 to 1.2. Tools, libraries, IDEs, and tons of apps will need to be upgraded, which is huge.

    Quick poll: when do you think you'll do your first JDK 1.5.0 production deployments? Any type of app, applet, webapp, etc. I use WebLogic, so we'll obviously be 6-12mos off the JDK 1.5.0 final release. But for the game programming stuff I do, I think I'll switch right away. Too many benefits to not switch.
  10. I hate to have a un predicateble behavior of swing regarding when to call pack or repaint or anyother method to refresh a swing component. It was amazing to see it work differently on different machines - especially running low on memory. Looks like SUN has finally realized that SWING sucks and is trying to address the issues in 1.5.
      And i hope some of my critics who claimed that swing was the best etc will also understand that even SUN knows swing is far from best.
  11. Im quite interested to see what they do with SWING. WHat differences/changes are there going to be 1.5?

    Cheers,

    Smythe
  12. Im quite interested to see what they do with SWING. WHat differences/changes are there going to be 1.5?Cheers,Smythe
    Also has anyone tried swing out in 1.5 any faster?
  13. does it deal with some wierd effects of boxing/unboxing

    int a = 1;
    Integer A = a;
    int b = 1;
    Integer B = b;

    a==b true
    A==B false // oh no, why??
    a==B true
    A==b true
    A.equals(B) true
    A.equals(b) true
    B.equals(a) true

    and another one ("transivity failed", from Paul Tyma'a ?)

    Integer a = new Integer(7);
    int b = 7;
    Integer c = new Integer(7);

    if (a == b) System.out.println("a = b");
    else System.out.println("a != b");
    if (b == c) System.out.println("b = c");
    else System.out.println("b != c");
    if (c == a) System.out.println("c = a");
    else System.out.println("c != a");

    gives

    a = b
    b = c
    c != a
  14. good point. this is for backward compatibility + impossible to implement w/out operator overloading.

    reference comparison as opposed to content comparison of objects.

    i can see this as a source of confusion for new java developers who start out fresh with 1.5
    does it deal with some wierd effects of boxing/unboxingint a = 1;Integer A = a;int b = 1;Integer B = b;a==b trueA==B false // oh no, why??a==B trueA==b trueA.equals(B) trueA.equals(b) trueB.equals(a) trueand another one ("transivity failed", from Paul Tyma'a ?)Integer a = new Integer(7);int b = 7;Integer c = new Integer(7);if (a == b) System.out.println("a = b");else System.out.println("a != b");if (b == c) System.out.println("b = c");else System.out.println("b != c");if (c == a) System.out.println("c = a");else System.out.println("c != a");givesa = bb = cc != a
  15. cant find anything on transivity[ Go to top ]

    Please notice that A and B are two different objects, so A <> B;
    When you use Integer.equal(), it compare the int values in the two Object.
    So, your examples are not weird.

    William
  16. I see they added an easier way to get floats and doubles as hex strings.
    Is there a way to transfer floats/doubles in BINARY form with C/C++?
    I am aware of longBitsToDouble and friends, but I couldn't manage to get
    C/C++ on the other side neitherto read or write these values in a sensible way.
  17. NT
  18. Since you have direct access to memory in C, you can do it yourself. You just have to be aware of byte ordering and alignment issues.

    If buf is aligned, and the endian-ness matches, you can just cast:
     double d = *(double**)buf;

    An untested stab at something portable:

    /* buf points at a big-endian binary double */
    double readBinaryDouble(char* buf) {
      double d;
      char* dptr=(char*)&d;
      if (1==htons(1)) { /* big endian machine */
        memcpy(dptr,buf,sizeof(double));
      } else { /* little endian machine */
        int i;
        for (i=0; i<sizeof(double); i++) {
          dptr[i] = buf[sizeof(double)-i-1];
        }
      }
      return d;
    }

    -Yonik
  19. See http://java.sun.com/j2se/1.4.2/docs/api/java/nio/ByteBuffer.html ("Access to binary data").

    Combine with direct access to memory buffers (http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html#NewDirectByteBuffer or http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html#GetDirectBufferAddress) and you should be all set !?

    Matthias