Slashdot Mirror


Summary of JDK1.5 Language Changes

An anonymous reader writes "Over at java.sun.com, there's an informative article about the new features in JDK1.5. Some of the changes like generics are nice and should make some things easier. Some of the enhancements to me are purely sugar, like enumerators. When it comes down to it, once the code is compiled, it's the same. The thing I hope is, some of this new syntactic sugar doesn't result in more obfuscated code. Unlike some people, I feel using programming shorthand leads to increased maintenance. This is especially true when you have to debug a complex application."

146 of 829 comments (clear)

  1. enumerators by billnapier · · Score: 4, Insightful

    enumerators are much better than just plain ints. Even though they may compile to the same thing, the compiler can do a little more checking on the enumerators, since it know the valid ranges for the enumerator so you don't have to explicitly check the range. You do check to make sure you get passed a valid value for all your int-as-enumerators? Don't you?

    1. Re:enumerators by Anonymous Coward · · Score: 2, Insightful

      It's preference right. Forcing some one to explicitly check isn't necessarily a bad thing. Iterators get too much flack, but it does change the programmers mindset. I would prefer programmers think carefully about what they are doing and not rely mainly on convienance, because when a bug does appear, it is harder to debug. But it all goes back to good programmers. bad programmers will make any language a nightmare.

    2. Re:enumerators by MilesParker · · Score: 2, Insightful

      Ya, its funny, enumerators were always one of the first things to gome up when people were griping, and has been the source of a lot of discussion re: workarounds. IIRC, Gosling wanted this in from the beginning, but they ran out of time..

    3. Re:enumerators by customiser · · Score: 4, Informative

      It's good to see enumerators formally supported, but you were not really _forced_ to use plain ints up to now. It is just some sort of an anti-pattern, which everybody seems to be using happily.

      The type-safe enum pattern shows the correct way of handling enumerations. And you can the Jakarta Commons Lang library to make it a bit easier.

    4. Re:enumerators by iabervon · · Score: 4, Interesting

      They're actually objects (you can put them in collections, for instance), they can have fields, methods, and constructors, etc. It's just that the compiler takes care of creating the instances and all, plus you can use them in swtch statements because the compiler knows they're enumerated.

      Evil thought: you could get relatively nice-looking static instances with methods if you combined enums with anonymous inner classes...

    5. Re:enumerators by ProfKyne · · Score: 5, Interesting

      I don't use ints for my enumerations anymore after reading Josh Bloch's Effective Java. The type-safe enum pattern he recommends is fantastic.

      For those not sure exactly how it works, you simply create a class to represent an instance of the enum, and you make the constructor private so that no one can create their own instances. Then you just provide a public static instance of the class for each enum.

      I used this pattern simply to achieve its intended effect of providing an enumeration, and then later found that by adding methods to the class, I could even give behaviors to the enumeration instances! Try doing that with an int. This was far more elegant than creating a giant "if" statement and performing conditional logic to test the value of the enumeration, because I simply used a polymorphic method call.

      An example:

      public class SenseEnumeration {
      // the action associated with this enumeration
      private java.lang.reflect.Method sense;

      private SenseEnumeration(Method m) {
      this.sense= m;
      }

      // assuming we've already created some
      // Method instances to use here
      public static SenseEnumeration TASTE
      = new SenseEnumeration(myTasteMethod);
      public static SenseEnumeration HEAR
      = new SenseEnumeration(myHearMethod);
      public static SenseEnumeration SMELL
      = new SenseEnumeration(mySmellMethod);

      ...etc...

      public Method getSenseMethod() { return this.sense; }
      public void invokeSenseMethod(Object target) {
      sense.invoke(target, null);
      }
      }

      You get the main idea. No, not as fast as an int, but far more powerful.

      --
      "First you gotta do the truffle shuffle."
    6. Re:enumerators by slagdogg · · Score: 4, Interesting

      This is a fine alternative ... but cumbersome, and indeed once you add the toString() methods and other such niceties, it's approaching messy. The fact that a single statement now can offer all of these features is outstanding.

      It's nice to see Java stealing something from C# for once ;)

      --
      (Score:-1, Wrong)
    7. Re:enumerators by etedronai · · Score: 2

      It seems a little bit evil that the compiler is creating object instances under the covers for you. One of the great things about c++ enums is that they are still primitives. By making them objects you have to worry about the compiler creating a lot of extra objects behind your back especially in tight highly used loops. Java is already a bit of "magic" language anyway but adding in "magical" object creation where you don't expect it doesn't seem like a good thing in all situations.

    8. Re:enumerators by revscat · · Score: 4, Insightful

      The article makes no claim about the typesafe enum pattern being broken, it just points out that you have to be careful if you use it and implement Serialzable. This is something that Bloch specifically addresses in Effective Java, and does not mean that the entire pattern should be scrapped. You just have to be aware of potential problems.

    9. Re:enumerators by billnapier · · Score: 3, Funny

      That's what we've been using but my fingers get tired from typing all that extra crap in...

    10. Re:enumerators by bnenning · · Score: 3, Insightful
      By making them objects you have to worry about the compiler creating a lot of extra objects behind your back especially in tight highly used loops.


      I would think they'd have to be like singletons, with the compiler creating exactly one instance of each enum value.

      --
      How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
    11. Re:enumerators by Mindbridge · · Score: 4, Interesting

      Metadata has been supported by the Java VM since the beginning, and JSR 40 (the metadata stuff in the language) has been around since 1999. It is _very_ doubtful that Java got this from C#. I will grant you that it probably forced issues a bit, though :)

    12. Re:enumerators by Mindbridge · · Score: 3, Interesting

      Using the switch statement automatically means the programmer has slept through the OO class.
      You simply do not need to use switch when you have polymorphism, which is a much more powerful mechanism and allows for much nicer scalable, maintainable, and readable code. Of course, this assumes that one has an understanding of OO.

      If there is a problem with safe enums, it is with serialization and deserialization. There are a number of solutions available for that, however. Personally, I feel that those should have gotten in the Java libraries, not enums in the language, but oh well.
      available such as , something that the safe enum provides, unlike the enumerations.

    13. Re:enumerators by iabervon · · Score: 3, Informative

      The instances are created when the class is loaded, and there's only one copy of each value. It's essentially like you're using int constants, except they're pointer constants instead, so you can dereference them to get more information than just equality. It's essentially the same as

      public class Season {
      static public final Season spring = new Season();
      static public final Season summer = new Season();
      static public final Season fall = new Season();
      static public final Season winter = new Season();

      private Season() { }
      };

      Except it's only one line, there are useful additional methods (like a toString), and you can use it in a switch statement.

    14. Re:enumerators by spells · · Score: 3, Insightful

      Polymorphism is a single tool in the belt and doesn't replace switch statements.
      Although I agree every instance of a switch statement can probably be implemented with polymorphismc some times you will end up with a worse design using polymorphic solutions that haven't placed enough emphasis on encapsulation and connascence. Options are good.

    15. Re:enumerators by j7953 · · Score: 2

      Apache's org.apache.jakarta.commons.lang package contains an abstract base class for typesafe enumerations (Enum), which contains a toString method and a readResolve method (to allow safe serialization of enumeration constants). The only disadvantage is that it also implements the Comparable interface, which sucks if you have an enumeration that doesn't really have a natural order.

      --
      Sig (appended to the end of comments I post, 54 chars)
  2. Generics by boxhead609 · · Score: 3, Interesting

    I think Generics is going to be a really nice long awaited feature. I am wondering if this type of change is going to require a modification to the bytecode specification. If that is the case, then new code bytecodes will not work with older bytecodes. Does anyone think that Sun can pull this feature off without a change to the bytecode spec? Would this be major compiler change?

    1. Re:Generics by gray+peter · · Score: 5, Interesting

      Agreed that it's a great feature. I use collections all the time and not only is it time consuming to keep casting (especially when you write out long class names like I do...) I'd say a huge % of my runtime errors are from bad casting. I'm definitely looking forward to this. As far as the bytecode specs go, I don't see that this will cause much change at all. The compiler should do the same thing it's always done.

      --
      May no camel spit in your yogurt soup.
    2. Re:Generics by gray+peter · · Score: 3, Insightful
      Read the article :-)

      --
      May no camel spit in your yogurt soup.
    3. Re:Generics by blamanj · · Score: 4, Informative

      No bytecode changes are required. There have been "test" implementations out since Java 1.2. You can get the current 1.3 release at
      http://developer.java.sun.com/developer/earlyAcc es s/adding_generics/

    4. Re:Generics by forgoil · · Score: 2, Insightful

      It looks like Java's generics are much like C++'s templates. This means that it is a compiler feature, and not a runtime feature. This is not a step forward, but a way to keep the VMs still working. A trade off.

      For some interesting words on generics, and implementation for both Java and M$ CLR take a peak at this link:

      http://msdn.microsoft.com/library/default.asp?ur l= /library/en-us/dv_vstechart/html/vbconCProgramming LanguageFutureFeatures.asp

      All you "I hate M$" people out there will more than likely scream about how horrible they are and how we must use Java. If you hate M$ I would suggest you go take a look at mono instead. The CLR together with C# completly owns Java, and when generics are added it will be even sweeter. I program both Java, C#, and C/C++ daily, and it gives a very good view on what language is the easiest to work with and use.

    5. Re:Generics by justins98 · · Score: 3, Interesting

      I don't think it will require a bytecode change. I don't know the details of how it works, but my guess is that the compiler will simply insert the casts for you. For example, when you say:

      List<Foo> list = new ArrayList<Foo>();
      list.add( myFoo );
      Foo otherFoo = list.get( 0 );

      The compiler will interpret the second and third lines as if they said:

      list.add( (Foo)myFoo );
      Foo otherFoo = (Foo)list.get( 0 );

      It's a pretty elegant way to incorporate type-safe generics without imposing any changes on the VM. I think the compiler changes would be relatively easy to implement -- nothing more than inserting casts at the appropriate places.

    6. Re:Generics by CognitivelyDistorted · · Score: 3, Informative
      Pretty close. For "list.add(myFoo)", it won't add a cast, because the type checker verifies that myFoo is-a Foo. The compiler will also add "bridge methods" for classes that implement a parameterized interface:

      class Byte implements Comparable<Byte> {
      ...
      public int compareTo(Byte obj) {
      return this.value - obj.value);
      }
      }

      The method compareTo is supposed to override the method in Comparable, which takes an object. So they create a bridge method that overrides it normally:

      class Byte implements Comparable<Byte> {
      ...
      public int compareTo(Byte obj) {
      return this.value - obj.value);
      }
      public int compareTo(Object obj) {
      return this.compareTo((Byte) obj);
      }
      }
    7. Re:Generics by Mindbridge · · Score: 2, Insightful
      It looks like Java's generics are much like C++'s templates

      No, they are not. In fact, they are very different. C++ templates are heterogenious (every parameter set means a new class, hence you get lots of additional classes); Java generics are homogenious (one class serves all parameters). C++ templates' requirements for the parameters are "as they come" -- the code is simply recompiled with the new parameter classes; Java generics' parameters need to implement interfaces/extend classes if a particular method of the parameter is to be used (which is much neater from a design perspective, if you appreciate this kind of thing). The only thing in common is the first glance appearance.

      The CLR together with C# completly owns Java

      Yes, it is a better solution in some respects and much worse in others. Given that it was designed 5 years after Java, the first was to be expected, the second was not. It merits a look, until you realize that any advantages are only marginal, and that there is only one company that provides major products for it (like application servers) and defines its interfaces. Given the fact that the company has a long notorious history and it has standardized less than 10% of the API does not make things better. And then there is Mono that now has to rely on Wine... Ah well.

    8. Re:Generics by MillionthMonkey · · Score: 2, Interesting

      Actually I believe all objects are type-checked at run-time, even if the casts were determined to be safe at compile time, but maybe there's a way to optimize that out.

      The JVM executes a checkcast bytecode instruction wherever there is a cast. It either does nothing or it throws a ClassCastException at you. (The instanceof instruction works the same way, except it puts a boolean on the stack instead.) But with generics, a runtime cast is never required IIRC. The compiler generates a one-shot collection class based on the generic that ONLY handles members of the type you've specified (e.g. String) and returns objects of that type, so the type checking is done statically. The entire purpose was to eliminate the runtime cast.

    9. Re:Generics by Caoch93 · · Score: 2, Insightful
      It's not possible to engage in the level of typechecking you're talking about with generics. All objects go through a typesafe container having the type of java/lang/Object. Java, right now, cannot check at compile time whether or not a call to get(), returning java/lang/Object, will yield an object of java/lang/String in the typecast. This is preceisely why ClassCastExceptions at runtime is such a big deal.

      By comparison, by telling the compiler that you want all of the objects in some container to be of type java/lang/String, the compiler can provide checks against it because the expected type is now a facet of the method signature. To engage in the kind of typechecking at compile time that I'm talking about without programmer clarification (via generics) would require the compiler to have a guaranteed knowledge of a lot more than it does. For example...

      If, in one piece of code you insert a java/lang/String into an ArrayList, then in another piece later, it is clobbered and replaced with a java/math/BigDecimal, and then in another piece, get() is called and the retrieved java/lang/Object is cast to java/lang/String, the compiler, to provide type-checking and catch this class cast failure, would have to be able to prove that, every time that specific get() was called, something other than a java/lang/String came out of it. To do that would requrie a lot of information about the dynamic state of the program at that time.

      In fact, depending heavily on the method in question, it may be impossible to guarantee the permitted type of the object available when you cast/miscast it. Consider a multithreaded environment. You're fast reaching a place where the only way to know what the type of the object is is to actually wait and see each time, which is what runtime casting is.

      You are correct that certain forms of type safety can be found at compile-time. For example, type safety in passing parameters, assigning values from a return, etc, can be tested. Likewise, a type saftey check of this nature is trivial:

      ArrayList l = null;
      String s = new String();
      l = s;

      However, there reaches a point where runtime type safety has to take over, and most of the cases of improved type safety thanks to generics is a matter of moving more type checks away from runtime and into compile time.

      And generics does not have to be "a hell of type casts". It can be a preprocessor hack where, at compile time, the types are provided in a special syntax and the generics (or template) code is then used to generate a unique piece of source code from those types. This would clearly make your compiled code size bigger, but avoids excessive use of the runtime type system.

  3. Give billg his due... by PHAEDRU5 · · Score: 2, Insightful

    ...he's forcing improvements in Java.

    --
    668: Neighbour of the Beast
    1. Re:Give billg his due... by rpk · · Score: 2, Informative

      Not knowing much about C#, is Java 1.5 "borrowing" features ?

      I see two trends: being a better C++ (typesafe enums and parameterized types), and borrowing features from Lisp (code metadata, auto boxing/unboxing). I don't like to tie developments like this to particular people, but I wonder how much Guy Steele has do to with the Lisp-like features, if in fact he is still working at Sun.

    2. Re:Give billg his due... by Hobbex · · Score: 4, Insightful

      One may say so. You see, C# had all features mentioned in article excluding generics since Beta 2. I think this is more than a year.

      It's more that C# includes a bunch of features that some java programmers had been asking for, and so does java 1.5. It's not like any of these features were out the blue in C#, they are mostly things people have been missing from other languages.

    3. Re:Give billg his due... by Grievance · · Score: 2, Interesting

      I see all six of the enhancements described in the article as coming directly from C#, and I think they're all Good Things. (i don't remember enough from my Lisp days to know if some ultimately derive from that most elegant language.)

      i've been a Java programmer (primarily) for 8 years, and just recently did a project in C# -- which i was dreading, but the language turned out to be OK, like Java with sops thrown to C++ diehards.

      now, if Sun adds operator overloading (*shudder*), i'm jumping ship.

    4. Re:Give billg his due... by slagdogg · · Score: 2, Insightful

      I couldn't agree more with your view of the Oracle tools ... but I really do use Java's platform independence all the time, and for non-GUI applications I think it works beautifully. The key here is the 'non-GUI' ...

      Actual example, I recently developed a servlet-based application, and given the hardware and time constraints I was under I developed on Linux, performed functional testing while deployed on Windows, and finally deployed on Irix. There was no change in behavior with the application other than performance, and it was a complex, multi-threaded application.

      --
      (Score:-1, Wrong)
  4. Re:Looking to Get Back into Java by stevenknight · · Score: 5, Informative

    check out eclipse -- a very sweet java IDE.
    http://www.eclipse.org/

  5. Programming shortcuts by GGardner · · Score: 5, Funny
    I feel using programming shorthand leads to increased maintenance

    I agree. This is why I never create my own functions or methods. Evey program should be just one big function.

    1. Re:Programming shortcuts by NReitzel · · Score: 5, Insightful

      During my time at telco, development costs were always a fraction of maintenance costs. Producing write-only code may be cute, and may cut back on other people using it, but it also cuts back on your own people being able to maintain it.

      Oh, do I agree, in boldface.

      --

      Don't take life too seriously; it isn't permanent.

    2. Re:Programming shortcuts by eGabriel · · Score: 3, Interesting

      It's true that wading through 20 different ways of doing the same thing in one program can really be maddening, but within reason some of these shortcuts should exist, and should have from the beginning.

      Every language has idioms, and a programmer should use those idioms in preference to other allowable ways to do things unless they have a good reason. It's all just part of good style.

    3. Re:Programming shortcuts by Angry+White+Guy · · Score: 2, Funny

      Makes for great job security!

      You wanna fire me? Have fun sorting out my code! It's commented in yiddish, if at all!

      --
      You think that I'm crazy, you should see this guy!
    4. Re:Programming shortcuts by radish · · Score: 4, Insightful

      Of course maintenance costs more than development, that's a given. But the thing which reduces maintenance costs is easy to read and understand code, coupled with good documentation.

      The ultimate removal of "syntatic sugar" would take you down to raw machine code. I do not believe that would be easier to maintain than Java, or pretty much any higher level language. The aim of syntatic constructs is (or should be) to make it easier for the developer to express the algorithm clearly. It's not about saving typing (unless we're talking perl) and not about being smart for the sake of it, it's about making it easier to read and understand.

      --

      ---- Den ene knappen er powerknapp, den andre er Bender voice knapp "Bite My Shiny Metal Ass"

    5. Re:Programming shortcuts by DunbarTheInept · · Score: 3, Insightful

      The problem is that some syntatic sugar doesn't actually increase readability. Consider operator overloading. If your language has that, you can never again know what on earth is going on when you see x = y + z, unless you are aware of every operator overload which was used. Let's say y is a char* and z is an integer. Normally then the expression (y+z) would mean in C++ "a char pointer which points at the character at index 'z' of the string stored in y." But with operator overloading in the language, you can never be too sure. Maybe somewhere in the code the programmer thought it would be a good idea to say that char* plus int really means "convert the string to integer with atoi(), then add the integer second argument to it, then convert back to string form and return that."

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    6. Re:Programming shortcuts by slagdogg · · Score: 2, Funny

      The problem is that some syntatic sugar doesn't actually increase readability. Consider operator overloading.

      Maybe it's just me, but I think operator overloading is closer to syntactic poison than syntactic sugar ...

      --
      (Score:-1, Wrong)
    7. Re:Programming shortcuts by dasmegabyte · · Score: 3, Interesting

      "Shortcuts" are not the problem. Stupidity is the problem. A good programmer, or at least a kind programmer, uses "shortcuts" so that somebody else can figure out what's going on without having to everything about an object.

      Enumerated types will save your ass the first time you change databases or some project manager adds a new "status level" in between DONE and FINISHED. They are much faster than using internalized strings, which is how I had been testing for this crap. Remember, once they hit the object code they're just constants anyway...

      Foreach was easily the coolest thing about C# when I started using it, indexers were the second, and the code they create is FAR more maintainable than for(Object o = someList.FirstItem(); o != someList.LastItem(); o = someList.NextItem()){ ...}.

      Automagic "boxing" is a beautiful thing for newbie coders...I have had to teach so many the difference between a Byte and a byte that it isn't funny. I intend to use it, too...we pass in and out of the classes for char, int, byte, bool etc so often it makes sense to have the compiler/VM do our dirty work for us.

      And generics...well, they look real queer in Java, where we've never used the syntax before. But they will save our behinds on reuse! Besides no doubt being faster, it will make more sense when typing collections of inherited objects. We have a BaseRecord class. We have an optimized BaseRecordColl class, usually full of different types of ChildRecord classes. If we can write the one collection class, and not have to explicitly cast each child op, it will save time, space, and hassle...and avoid calling the superclass methods of uncast subclasses!

      Metadata is the only ingredient here that seems like it could cause trouble, and if it does it will be because people are using it wrong. Java is not a language that inlines...that's the whole idea of the JIT...and with today's cut and paste GUI IDEs, there's no need for programmers to use the lazy C declarations of the past. If people start doing so because it's neat, just nip it in the bud. Find/Replace when the code hits your desk. Eventually they'll get the hint.

      --
      Hey freaks: now you're ju
    8. Re:Programming shortcuts by Ed+Avis · · Score: 2, Insightful

      No - distinguish between syntactic sugar, which gives you a new syntax to express what you could have said anyway, and real language features.

      For example array access with [] in C is syntactic sugar, since you could do the same with pointer arithmetic - a[b] is exactly equivalent to *(a+b). However a declaration of an array variable:

      int a[1000];

      is _not_ syntactic sugar, since there is no other way to reserve space for a thousand contiguous integers on the stack. You could use malloc() from the standard library, but as you know that allocates on the heap and you have to free the memory afterwards.

      (OK you could have a thousand 'int' declarations but I don't think it's guaranteed they will be a contiguous block in memory.)

      As an example of a language with no syntactic sugar, look at Unlambda (although you wouldn't want to program in it). The language syntax is minimal but semantically it is a long way off from raw machine code.

      --
      -- Ed Avis ed@membled.com
    9. Re:Programming shortcuts by willtsmith · · Score: 2, Insightful

      Any language feature can be abused and used in inappropriate ways. I once knew a programmer who included comments like the following. // I'm really tired now. ... // Gosh gotta go to the bar ... // I'll never do this again // Source control is my enemy, they'll know who writes all these stupid comments ....

      Obviously he wasn't using comments correctly. And sometimes would even obfuscate by not modifying comments to reflect code changes.

      However, this is not a reasonable arugment for why comments should NOT be part of a higher level language. Some people actually write usable comments that add something to code.

      Same thing is true with operators. The fact that some yahoos assign weird functionality to operators doesn't diminish the uses for operators AND the ability to write large volumes of code shorthand through operators.

      As far as syntactic sugar goes, as long as the compiler processes it correctly, it's good. Writing the same pieces of code OVER, and OVER, and OVER, and OVER, and OVER, and OVER, and OVER is a waste of time (AND MONEY!!!!). It's a job better left to a compiler. If a programmer can't grasp or understand newer constructs (beyond cut and paste :-), they should question whether they're in the right field.

      --
      -------- -------- Support Wesley Clark for president!!!
    10. Re:Programming shortcuts by dasmegabyte · · Score: 2, Informative
      Let's say you have a really complex, but SMALL, algorithm that you do all the time. Going into a new function takes resources even when compiled (basically, the CPU pops your current work onto the stack, flushes the current command queue and any fancy branch prediction going on, and moves to the memory location of the function EACH TIME it's called)...so C programmers invented this method called inlining.

      (this next bit is a very simple and very halfassed explanation in pseudo C. flames from C programmers about the bad syntax will be ignored. i got a D in C so F it)

      Inlining works like this. You write a function and assign it a variable name. Then, any place you want that function, you use the variable name. The "precompiler" converts any instance of the variable name into the original function. EX:
      #DEFINE PISETUP
      int pi;
      pi = 22/7;
      #ENDDEF
      Later, if you use the term PISETUP it will be replaced with that code by the precompiler.

      This was a good way to facilitate rewriting the same thing over and over, while maintaining speed, and a single location to change/fix the function. Unfortunately, it was also a good way for lazy programmers to obfuscate code by creating precompiler directives and variables for common language patterns. EX:
      #DEFINE STARTIF
      if (
      #ENDDEF
      #DEFINE CLOSEIF
      )
      {
      #ENDDEF
      Used to make:
      if ( true )
      {
      beep;
      }
      into:
      STARTIF true CLOSEIF beep; }
      Shorter, yes. But harder to read, much harder to understand, and absolutely confusing for the poor newbies. Kind of like learning how to read from logs of an AOL chatroom.

      One of the big "innovations" of Java was the elimination of the precompiler, which made sense. Java runs object code, not directly runnable byte code, so it is in essence already performing the tasks of the precompiler. The virtual machine "compiles" the code while it is running, to optimize for the individial physical machine, no matter what it may be.

      The idea worked IMO because, now that you can cut, paste, and find and replace (with regular and replace expressions), you don't really need these replacements. Might as well just be verbose as you want to be. Might as well use tiny little functions since inlining doesn't work anyway.

      Besides, since Java is interpretted and recompiled while it's running, you don't gain anything from inlining. Any "contextual" function (the function as written in the code) might become "inlined" when run by a good virtual machine program that performs "Just In Time" (JIT) compilation. Call void incrememtI(){ i++; ) a lot? The compiler will notice this, and replace calls in the stack to incrememtI() with the actual code this function contains. .NET does this with simple Properties...which results in a sincere benefit to using Properties for ALL inter-class data assignment and for some intra-class assignments as well.

      This is why Metadata is a bad idea, or could be. No real benefit to the code, not much of a benefit for the "thorough" developer, and yet there's a real chance for lazy folks to create disgusting, hard to maintain code. This is never a good idea...a lot of coders think that obfuscated code makes them more valuable to employers. Not half...they'll axe you first if they think you're playing the obscurity game and will not give great references if you leave first.

      Of course, if all Metadata does is replace:
      // @Property:int ID
      with:
      private int id;
      void setID(int value){ id = value; }
      int getID(){ return id; }
      Then it may be worthwhile. Time, and the Java Community, will tell.

      (PS: Used to work for/with a Pat Doyle, but he's not you)
      --
      Hey freaks: now you're ju
  6. Agreed.. by MilesParker · · Score: 5, Insightful

    ..Thought C# has some nice innovations, one of my big problems with it is that so many of its new 'features' are so much syntactic sugar. One of the big things I appreciate about Java is that there is typically onyl one right way to do something; a big change from C++ for example. Plus, modern IDEs like IntelliJ make it very easy to construct iterators and such [Ctrl-j itar..] That said, I don't think that the majority of the Java improvements are really sytactic sugar; things like generics will be very positve improvements. And its very important that Sun keeps up these improvements -- as long as they continue to be well thought out. Ideally we will continue to have a fairly state-of-the art language without any fluff.

    1. Re:Agreed.. by DunbarTheInept · · Score: 4, Interesting

      I'd say that "++x" is actually the "best" way because it puts things in verb-noun order, which I'm used to as an English speaker. "x++" is noun-verb, which feels strange to me. "++x" reads as "increment X", while "x++" reads as "x. increment it".

      (Just goes to show there will be differences of opinion and no such thing as "the" right way. Here's another example:

      if( x == 5 ) { do something }
      versus
      if( 5 == x ) { do something }

      Some prefer the second way because it puts the term which cannot be a valid lvalue on the left side, thus if you make the common typo of "=" instead of "==", you will get a compile error from it, which wold not happen for x = 5. But, it looks very odd to write it 'backward' like that, so some say the readability of doing it the 'dangerous' way makes it worth doing it that way.

      There is no such thing as "the" best way, not even in Java.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    2. Re:Agreed.. by dhovis · · Score: 4, Insightful

      Actually, i believe that in Java

      if(x = 5)

      will throw a compiler error because (x = 5) does not resolve to boolean.

      That is something I like about Java, it doesn't allow you to do stupid things like that. There is no reason to do an asignment in an if() statement.

      --

      --
      The internet is the greatest source of biased information in the history of mankind.

  7. So basically C# minus generics by earache · · Score: 3, Insightful

    The metadata, auto-boxing, enhanced iteration looks like catch up with C#'s attributes, foreach, etc.

    Where are true properties though?

    1. Re:So basically C# minus generics by devinoni · · Score: 2, Informative

      Generics
      No such thing in C#.

      Enhanced for loop

      foreach (type identifier in expression) statement

      expression needs to implement IEnumerable, or declare a GetEnumerator that returns an IEnumerator

      Autoboxing/unboxing

      int i = 1;
      object o = i; //boxing
      int j = (int) o; //unboxing

      Typesafe enums

      enum Rating {Poor, Average, Okay, Good, Excellent}

      Rating IncrementRating(r)
      {
      if (r == Rating.Excellent) return r;
      else return r + 1;
      }

      Metadata

      // Metadata saying this is a webmethod

      [ WebMethod ]
      public int PerSessionServiceUsage()
    2. Re:So basically C# minus generics by Mindbridge · · Score: 2, Insightful

      As pointed out in other posts, Metadata is JSR 40, which has been around since 1999 (before .NET). It is not a C# invention.

      In addition, C# properties are pretty badly implemented. Quite often one needs to have a private (protected) 'set' and a public 'get'. This is not something one can do as a property in C#. Also, who had the great idea of making public members and properties look the same? It is okay to allow one or the other in the language, but both?

  8. Re:Looking to Get Back into Java by pygeek · · Score: 2, Troll

    Emacs, of course. Syntax highlighting, integrated compiling, etc.

    *puts on flamesuit*

  9. Re:Looking to Get Back into Java by gray+peter · · Score: 4, Informative
    The language I could pop right back into, but could use some advice on good/affordable IDE.

    http://www.xemacs.org
    what more do you need? ;-)

    If you want a *real* IDE, I'd check out IntelliJ's Idea product. It's a few hundred $$$. Lots of folks like Netbeans and IBM's Eclipse as well (sorry, no url to eclipse, but I'm sure you can find it). The latter 2 are opensource.

    --
    May no camel spit in your yogurt soup.
  10. Re:Looking to Get Back into Java by Schezar · · Score: 4, Informative

    Eclipse is "the awesome." It's feature-filled and relatively easy to use. Being free is a nice plus, too.

    My roommate told me about it, and once I started using it I never looked back.

    --
    GeekNights!
    Late Night Radio for Geeks!
  11. programming shorthand by nother_nix_hacker · · Score: 4, Funny

    I feel using programming shorthand leads to increased maintenance

    My code was hard to write to it should be hard to read. :)

    1. Re:programming shorthand by Usquebaugh · · Score: 2, Insightful

      Code should be written so it can easily be read by a human and incidentally by a machine.

  12. Much, much more than syntactic sugar by jameson · · Score: 5, Insightful

    Hi,

    FYI: Generics are _much_ more than mere syntactic sugar (as are enumerators, a weak form of algebraic datatypes, if handled type-correctly).
    These are actually the kinds of things that make program maintenance considerably easier, since they allow more concise specifications of intended semantics to be done. No longer having to typecast (and thus expect run-time exceptions) when using a "vector of FooObjects" gives more power to the type checker, and thus allows a much richer class of programming errors to be detected at compile-time. This is the one major improvement in Java that's been missing since its very inception.

    But note that "generics" or "parametric types" have been present in languages such as Eiffel or Sather for well over a decade, and for much longer in ML. In a way, it's embarrassing that such an essential feature was added this late during development.

  13. Uglification? by oblom · · Score: 4, Insightful

    Is anybody else irked by generics? One of the arguments in C++/Java discussion that I've read was: "Java removes complexity of C++, while remaining OOP". Well, generics remind me of C++ templates, which where a bit hard for me to swallow. Not to mention that attached to variable name doesn't make code any more attractive to look at.

    It appears that Java's way to solve run time errors is to screw the bolts as tight a possible during compile time. Will generics become THE way, or just remain one of the options?

    1. Re:Uglification? by ptomblin · · Score: 2, Insightful

      I'm really looking forward to generics. I've got tons of code that casts the results from iterators or collections or maps. I've either got to test like hell and hope that I don't see any ClassCastExceptions and hope the testing was exhaustive, or I've got to do a lot of "instanceof" tests. Since 90% of the time when I use collections/maps I'm putting all of the same type in them, this just irks me.

      But for that other 10% of the time, remember that all classes are children of Object, so I'm betting you can still declare
      List = new ArrayList();

      --
      The next Cmdr Taco duplicate will be ready soon, but subscribers can beat the rush and see it early!
    2. Re:Uglification? by Anonymous Coward · · Score: 5, Insightful

      No, I'm not irked. Not even a little bit.

      If your only experience of generics is C++, then all you've seen is the *worst* implementation of generics ever done in a language. Template code is almost unreadable. (Have you ever tried debugging one of the STL implementations?)

      Besides, the lack of generic types cripples Java's ability to do static type checking, since your code ends up being full of things like this:

      Foo f = (Foo) vector.elementAt(i);

      where type errors can only be detected at runtime. That not only makes it impossible to detect errors at compile-time, it hurts performance at runtime.

      Check out how generics are handled in Modula-3 for to see a much better way to handle them than C++ templates, or look at ML for something even more groovy (ML uses polymorphic type inference instead of generics, so you don't even have to mention types - the compiler just does the Right Thing).

      Once you've worked with a good generic implementation, you'll never want to stop using them.

      Harry

    3. Re:Uglification? by jameson · · Score: 5, Informative

      Hi,

      Well, generics remind me of C++ templates

      They're not quite the same; C++ templates are essentially glorified preprocessor macros with
      some relatively small checking and a rather baroque
      underlying functional language. Generics are more
      concrete than that.

      Not to mention that attached to variable name doesn't make code any more attractive to look at.

      It would be really neat to have type inference there ;-)

      It appears that Java's way to solve run time errors is to screw the bolts as tight a possible during compile time.

      That's the idea, and that's also what I try to do when writing programs. Why should I have to write half a dozen test suites for some simple program property if the type checker can tell me whether it'll work right?

      Remember: Compilers don't do type checking just to optimise, but also to catch programming errors. And Generics allow you to catch a much more interesting class of these.

      -- Christoph

  14. Re:Write once, Rewrite forever? by customiser · · Score: 5, Informative

    AFAIK they will not be breaking existing code... If anything, they had to go out of their way (e.g. the ugly foreach statement) to ensure backward compatibility. In 1.4, the assert keyword might have caused problems, but now I don't think that's the case.

  15. Retro... by dance2die · · Score: 3, Interesting

    These new java features or shortcuts whatever reminds of C++... Is Java going to come with "Pointer" manipulation features later on? Will java become the next C++ and will be extremely tidious to program with? Overall, change is good... :)

    --
    buffering...
    1. Re:Retro... by jeremyp · · Score: 2, Interesting

      I agree with that. Following the backward compatibility rule blindly can lead to some serious abortions. In this case, they are sacrificing a nice elegant construct for the person who has a variable named "foreach" (unlikely) and the person who has a variable named "in" (their fault for choosing a stupid non descriptive variable name). A "java 1.4" switch would sort that out plus any reasonable search and replace facility.

      If they'd said "i" is now a keyword, that would have been more of a problem.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  16. One line summary by Anonymous Coward · · Score: 5, Funny

    Java adds four new syntaxes, Python's for loop, Perl type checking at compile time, something called 'metadata', and C enumerations, all of which impove compile time type checking at the expense of making the source code look and feel like perl.

  17. Re:Write once, Rewrite forever? by Knight2K · · Score: 2, Insightful

    I sure you have a valid point in general, but I'm not sure if this is a concern with the changes described. The description of the features in the article indicate to me that your concerns were taken into consideration. For instance, they explicitly mention that foreach and in weren't added as keywords to avoid killing programs that may have used these as variable names (kinda lousy variable names if you ask me, but I'm sure it happens).

    Looking at the examples in the article, I didn't see anything that would break the semantics of already existing code... assuming the generics feature uses Object if no other class is used.

    Do you have an example of the proposed semantics breaking some existing code? I would be interested in any examples and I'm sure the JCP would be too. I'm certainly not willing to go along with the JCP blindly if there is a practical, concrete example of where they are going wrong.

    --
    ======
    In X-Windows the client serves YOU!
  18. compilers never make mistakes? by cheezfreek · · Score: 5, Insightful
    As a compiler writer, I found this sentence to be particularly hilarious:

    Because the compiler, unlike the programmer, never makes mistakes, the resulting code is also more likely to be free of bugs.

    That's right, none of us has ever seen bad code generation or an internal compiler error. But, he does have a point. The compiler is less likely to make a mistake than a programmer.

  19. Re:Write once, Rewrite forever? by Ageless · · Score: 2, Insightful

    I might have missed something in the article, but as far as I could tell nothing existing breaks. They even mentioned that they worked very hard to make sure that was the case.

    What part of the new syntax would cause old code to break?

  20. not just sugar by Anonymous Coward · · Score: 4, Interesting

    I think the new additions are great (except, perhaps, the autoboxing stuff). But I'm missing a fix for that extremely common javabean convention: get/set methods.

    To add a property, say a String called name you have to write:

    /**
    * The name of this object.
    */
    private String name;

    /**
    * The name of this object.
    */
    public String getName() {
    return name;
    }

    /**
    * The name of this object.
    */
    public void setName(String name) {
    this.name = name;
    }

    That's 16 lines of code for one property! This is tedious to write, and more importantly, very hard to read when you have many properties.

    This could easily be reduced to something like:

    /**
    * The name of this object.
    */
    property String name;

    expanded to exactly the same code as above by the compiler. Incredibly useful if you're, say, writing a lot of value objects in a j2ee scenario.

    1. Re:not just sugar by Jack+Greenbaum · · Score: 3, Informative
      That's 16 lines of code for one property! This is tedious to write, and more importantly, very hard to read when you have many properties.
      You really need to try a generating/refactoring IDE like Eclipse. I once held to the orthodoxy that if I needed more than emacs then something was broken in the language. I grew up on object systems like CLOS where if you wanted a getter or setter you just asked for it in the definition of a field. So at first C++'s lack of public read-only/private read-write vars annoyed me, and Java's odd package visibility rules made me wince. But now I just declare private and generate my getters/setters, I navigate the file with the outline view, and I get more done per unit time then in any other language/ide pair, including VB.

      -- Jack

  21. Shorthand programming by Shamashmuddamiq · · Score: 5, Funny
    Yes, I'd agree with that remark about shorthand programming. I thought it was funny when I was teaching classes at UIUC to see stuff like this from the students:

    #define FOREVER for(;;)
    #define BEGIN {
    #define END }
    #define ONE 1
    #define PUSHORT unsigned short *
    #define DONE goto end

    The first thing an amateur programmer does when assigned a new project in C/C++ is to go redefine the language and all the types. I scolded them for these kinds of things, knowing that once they were forced to read other people's code often that they would realize how stupid these kinds of things are. Unfortunately, once I started my career in embedded development, I quickly learned how stupid I must have been to think that people left these behaviors behind in college... (all the above examples are taken from "professional" code that I've seen in the last few weeks)

    --
    ...just my 2 gil.
    1. Re:Shorthand programming by Anonymous Coward · · Score: 2, Funny

      a while back i did some obfuscation of my code to make it hard to read. i never really shared any of the code so it served no purpose whatsoever. i did things like:

      #define begin }
      #define end {

      but by far my favorite was:

      #define ONION UNION
      #define RINGS REGS

      so I could declare a structure:
      struct ONION RINGS o;

      for doing VESA interrupts.

    2. Re:Shorthand programming by KrisW · · Score: 2, Insightful

      I guess it doesn't matter if you're the only one reading the code, but I can't see how macros can do anything other than make code harder to read...

      --


      "Think you can take me? Go ahead on. It's your move." --Joe Don Baker in Final Justice
    3. Re:Shorthand programming by ratboy666 · · Score: 2, Insightful

      Redefining the language to better meet the problem is one of the hallmarks of good (artistic) programming. And it has other purposes. To give you one:

      #define NOTHING ;

      ...
      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;
      else
      ...

      I know I can change this to eliminate the empty
      ';', but I choose not to, because I feel that the conditional reads better as a positive statement.

      [I also prefer to have the '<' or '>' in a compound conditional always point the same way:

      (5 <= x) && (x <= 10)

      so the conditional can be read "x between 5 and 10". I am a hacker -- thinking about code is a compulsion for me].

      Now, LINT (splint which I use), complains about the empty ';' as a probable coding mistake... I redefine NOTHING as /*@i@*/; and splint no longer complains ("indent" doesn't do the right thing, so I REALLY use /*=i=*/ which indent can handle, and splint can be trained to). Plus, when I am reading the code I can tell instantly that I meant it that way. FOREVER can be for(;;) or while(1), but it is clear from the read that I mean to iterate, well, forever. Typically, I would use that as the main loop of a thread.

      As to BEGIN and END -- I have coded with C (pre-ansi) on machines whose keyboards didn't have '{' and '}'. I had to construct an include file to define BEGIN and END with a binary editor. But it worked.

      There may be reasons that hackers do this -- don't be immediately dismissive. [#define ONE 1 I have used as well -- in defining manifest constants for numeric types in an object oriented number stack for C++. Ok, it was a constructor: myint one = 1; but I did it to keep only one copy of the number around -- improved efficiency]. The PUSHORT style I agree is USUALLY nonsense. I can see USHORT, but the '*' notation is supported. Of course there may be an attempt to impose an object system underneath, and it may be nice to define PUSHORT as "void*" to quickly highlight all uses of the underlying implementation. So even that has a purpose.

      Ratboy.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    4. Re:Shorthand programming by divec · · Score: 2, Interesting
      As to BEGIN and END -- I have coded with C (pre-ansi) on machines whose keyboards didn't have '{' and '}'. I had to construct an include file to define BEGIN and END with a binary editor. But it worked.


      Interestingly, ISO C defines shorthands for people with crap keyboards. You can type <% instead of { and %> instead of }. Also:


      <: means [
      :> means ]

      %: means #
      %:%: means ##


      You get even more if you include iso646.h. Of course, the old compiler you were using may not have had these :-)
      --

      perl -e 'fork||print for split//,"hahahaha"'

    5. Re:Shorthand programming by spakka · · Score: 2, Insightful

      I know I can change this to eliminate the empty ';', but I choose not to, because I feel that the conditional reads better as a positive statement.

      At the cost of failing to compile

    6. Re:Shorthand programming by blahedo · · Score: 3, Insightful

      Your answer highlights the very reason that C macros are a bad idea. You say:

      #define NOTHING ;
      ...
      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;

      Correct me if I'm wrong, but that's going to put two semicolons after the if---not itself an error, but it's going to block the else from working properly, since the second semicolon is a(n empty) statement after the end of the if clause!

      In general, using macros in this fashion is dangerous and difficult to maintain, because it's not known what exactly is in the content of the macro. If a shortcut is at least part of a language, then a maintainer has some reasonable chance of understanding a piece of code as written without going hunting through header files. (Though of course one of the major complaints against perl is that there are so many shortcuts that are part of the language that nobody knows them all, pretty much reducing us to the previous problem.)

      --
      ``This, too, shall pass.'' ---Eastern proverb
  22. Why I don't like Java by pygeek · · Score: 2, Insightful

    Java is an OK language for teaching programming basics, but it's just too much bondage and discipline for my taste.

    You're forced to do object oriented programming. OK, I can respect that - but Java is not consistent. Everything is not an object, and it's just so damned ugly when you have to wrap an int in an Integer.

    Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!

    Furthermore, Java's text processing abilites suck so bad, I don't even know where to begin.

    Give me Python any day. It can do any job Java can do, and probably better.

    1. Re:Why I don't like Java by forsetti · · Score: 4, Interesting

      Also, it's statically typed. It's so .. annoying to have to typecast everything

      Typecasting is a tool -- do you really trust the compiler to recognize exactly what you mean in every scenario, throughout your hundereds of thousands of lines of code? I don't want to have the compiler (or run-time environment, or interpreter, whatever) to "guess" at what I mean -- I want to tell it exactly what I mean.

      <flame> Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty.</flame> :)

      --
      10b||~10b -- aah, what a question!
    2. Re:Why I don't like Java by MilesParker · · Score: 2, Insightful
      "Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!"
      Yea, you "know" you have a String...until you don't. Maybe you're superman, but I'm mortal -- and by the way, good practices demand a little humility, and assuming that you are _not_ perfect.

      Java's strong typing has been a huge productivity enhancement for everyone I've worked with. Just knowing that typically when you compile something, its actually going to run without a single error has been a revelation for me.
    3. Re:Why I don't like Java by Troll_Kamikaze · · Score: 2, Insightful

      I don't want to have the compiler (or run-time environment, or interpreter, whatever) to "guess" at what I mean -- I want to tell it exactly what I mean.

      Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty.

      Dynamically yet strongly typed languages such as Python and Lisp allow you to tell the compiler or interpreter "exactly what you mean" with regard to types, they just don't require you to do so. Where's the beef?

      Bruce Eckel, a C++ and Java expert and the author of the "Thinking In ..." series of books, wrote recently:

      After I had worked with Python for awhile -- a language which can build large, complex systems -- I began noticing that despite an apparent carelessness about type checking, Python programs seemed to work quite well without much effort, and without the kinds of problems you would expect from a language that doesn't have the strong, static type checking that we've all come to "know" is the only correct way of solving the programming problem.

      This became a puzzle to me: if strong static type checking is so important, why are people able to build big, complex Python programs (with much shorter time and effort than the strong static counterparts) without the disaster that I was so sure would ensue?

      This shook my unquestioning acceptance of strong type checking...

    4. Re:Why I don't like Java by __past__ · · Score: 2, Insightful
      Try Lisp. Common Lisp compilers usually generate faster code than Java (mostly because they compile to native code), yet you don't have to declare types unless you choose to do so. If you do, the compiler can use the declarations either to check type correctness or to generate optimize code, just as you wish.

      Once you've experienced the freedom and flexibility of Lisp, there's no way back. Unfortunatly, you'll soon realize that this fact sucks hard when you try to program by library-shopping, scince there basically are no third-party libs for CL.

  23. So C# is basically Ada without strong typing? by coyote-san · · Score: 2, Interesting

    It sounds like C# uses a lot of stuff from Ada (and I'm sure countless other languages), but forgot to honor prior work. :-)

    Seriously, the "C# copied from Java/Java copied from C#" argument misses the point. There's a lot of prior work, and finding the right balance between usability and clutter is difficult. As much as I loved writing stuff like "for (value'range) do..." I would rather see a conservative approach to features since it's always easier to add stuff than remove it.

    --
    For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
  24. Some quality stuff - competition is good! by Fnkmaster · · Score: 4, Insightful
    I gotta say, I'm positively impressed. C# and Java are feeding features off of each other. Iterators, enumerators and autoboxing/unboxing - hmm, I think I've seen those before. Java 1.5 starts to look more and more like C#.


    Some of this other stuff has been going on for ages - I'm curious about the metadata/declarative programming features. I've developed complete code generation systems for Java - the number of situations that require reams of very repetitive code in your average large-scale Java app is huge, and much of that can be automated. It would be great to see a consistent, standard system for doing this built in as a language feature rather than having hundreds of home-rolled systems everywhere, but the nature of many problems lends themselves to home-rolling. I can't tell you how many times I've written simple SAX parsers that spew out Java code, and rolled up an ant target to run it on some schema and package up the result. It's not clear from this brief example whether this is only for XML/RPC or whether there's an extensible metadata system that you can build on top of.


    Then again, we should be careful not to roll too much into the language itself. I think generics, autoboxing, and enumerators are fabulous. Iterators I could give less of a shit over. Other stuff is great, but I question whether extending the language is the right mechanism. Much of the power and flexibility of Java comes from its simplicity. And most importantly, the ease of reading other people's code - there's far less stylistic variation because there are only N ways to do a task, rather than N! ways to do it, like in C++ (don't get me wrong, for a lot of tasks, I'd never dream of doing them in Java, like 3D programming). But it takes me about 1/4 to 1/3 the time to assimilate and learn a new Java API or library as it does to learn your average C++ API or library, and that's the appeal of Java.


    Of course, I'll be thanking the gods that I never have to deal with the fugliness of casting and wrapping to move stuff between typed arrays and untyped Lists again.

  25. Re:Everything must change... by Grievance · · Score: 3, Insightful

    As others have pointed out, moving move type information into the declaration allows the compiler to help eliminate several kinds of type errors generated by programmers.

    Now, if you want a weakly/dynamically/non-typed language, you should use one, and deal with the inevitable tradeoffs. It's not like there's a shortage of non-strongly-typed languages out there.

  26. Netbeans by truthsearch · · Score: 2, Informative

    While eclipse is great, Netbeans has more features. I prefer eclipse because it uses a native interface and has refactoring. The most feature-rich IDE I've used for Java, however, is netbeans. If you don't mind a slow user interface it's a great tool to look at.

  27. A better solution than Generics by MarkSwanson · · Score: 2, Informative
    Generics is an auto-casting mechanism that is useful to catch programming errors at compile time instead of run time. Please note 2 things:
    1. the 'cast' still happens at runtime as the compiled bytecode is still the same.
    2. there is a much faster alternative that uses native data types instead of objects (below) and catches errors at compile time.


    As a pro Java developer, I want to use the native 'int' type in order to save memory, have less garbage collection, and perform better. Catching errors at compile time is helpful too. I think it is unreasonable for Sun not to include specializations for native data types. If I want to have an ArrayList of 10,000 ints I should be able to use 'int'.

    The link on this page states up to 10x performance but I've seen it work up to 30x performance - and you can run the code below to see this for yourself.
    NOTE:
    30 = 7272727/236966 where:
    1. 7272727 = 2nd iteration of Int2IntHashMap!
    2. 236966 = 15th iteration of HashMap (Hot spot had 12 more iterations to optimize)

    http://fastutil.dsi.unimi.it/

    package com.wss.utils.test;
    import java.util.*;
    import it.unimi.dsi.fastUtil.*;
    public class TestFastUtil {
    public static void main(String[] args) throws Exception {
    int count = 400000;
    int timerCount = 20;
    long start, end;
    Integer tmp; // Normal HashMap
    HashMap hashMap = new HashMap(count);
    for (int timer=0; timer timerCount; ++timer) {
    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    hashMap.put(new Integer(i), new Integer(i));
    }
    end = System.currentTimeMillis();
    System.out.println("HashMap put(Integer, Integer) count:" + count +
    ", put/s:" + (count / ((float)(end-start) / (float)1000)));

    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    Integer in = new Integer(i);
    tmp = (Integer)hashMap.get(in);
    if (!tmp.equals(in))
    throw new Exception("failed equals()");
    }
    end = System.currentTimeMillis();
    System.out.println("HashMap get(Integer) count:" + count +
    ", get/s:" + (count / ((float)(end-start) / (float)1000)));
    } // FastUtil HashMap Int2Int
    timerCount = 100;
    Int2IntHashMap int2IntHM = new Int2IntHashMap(count);
    int j;
    for (int timer=0; timer timerCount; ++timer) {
    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    int2IntHM.put(i, i);
    }
    end = System.currentTimeMillis();
    System.out.println("Int2Int put(Integer, Integer) count:" + count +
    ", put/s:" + (count / ((float)(end-start) / (float)1000)));

    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    j = int2IntHM.get(i);
    if (i != j)
    throw new Exception("Int2Int failed equals()");
    }
    end = System.currentTimeMillis();
    System.out.println("Int2Int get(Integer) count:" + count +
    ", get/s:" + (count / ((float)(end-start) / (float)1000)));
    }
    }
    }
    --
    Schedule your world with ScheduleWorld.com http://www.ScheduleWorld.com/ (Java Web Startable)
  28. Re:Write once, Rewrite forever? by Caoch93 · · Score: 2, Informative

    ...especially since the assert keywork is, on Sun's JDK, only compiled to a bytecode construct if you request it be at compile-time.

  29. Re:FreeBSD Support by chefbimbo · · Score: 2, Funny

    It'd be about time Sun ported it to FreeBSD (the ONE thing lacking from it) but as you know, FreeBSD is dying so why bother.

  30. Enumeration classes by coyote-san · · Score: 2, Informative

    This isn't the forum for a detailed discussion, but I actually prefer enumeration classes now over simple enumerations. The basic idea is to write a class something like:

    final class Color {
    String c;

    private Color (String color) { c = color; }
    String toString() { return c; }

    static final Color RED = new Color("red");
    static final Color BLUE = new Color("blue");
    static final Color GREEN = new Color("green");
    }

    You can then treat this class like a type-safe enumeration. It doesn't have all of the nifty features that you'll see in languages like Ada, but it has the nice property of allowing you to attach whatever information you want to the enumeration class.

    You can also use this approach to create self-initializing classes, e.g., a list of states (including full name, postal abbreviations, shipping zone, etc.) from a database. You can access the enumerated values through a collection class, a "lookup" method, or even reflection.

    --
    For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
  31. Article didn't mention new concurrency stuff by dood · · Score: 5, Interesting

    One of the coolest new features of JDK 1.5 is the completely reworked concurrency stuff (JSR 166). I just listened to Doug Lea (spec lead) give a talk on this very subject and I'm pretty convince this will rocket Java performance way up for a lot of the collections stuff, concurrent programming, etc.

    Bascially, the goal of JSR 166 is to do for concurrency programming what JDK 1.2 did for data structurs (Collections stuff). The gist is, you'll never need to use "new Thread()" or "synchronized" anymore, but rather you'll execute Runnables, use Locks and Semaphores, etc. Also, queues are *completely* reworked to be ultra scalable.

    JSR 166 is based on Doug's concurrency package:
    http://gee.cs.oswego.edu/dl/classes/EDU/ oswego/cs/ dl/util/concurrent/intro.html

    OH, and there will be classes like AtomicLong which guarantee atomic 'compare and set' options for primitives. :)

    Cheers!

    1. Re:Article didn't mention new concurrency stuff by bricriu · · Score: 2, Funny

      AtomicLong? Born in the heart of a nuclear furnace, endowed with the power of the atom, it's a bird, it's a plane, it's AtomicLong!

      Sounds like a "super" class to me. ;)

      --

      AHHHHHHH! I'm burning with goodness again!
      - Reakk, Sluggy Freelance

    2. Re:Article didn't mention new concurrency stuff by slagdogg · · Score: 2, Funny

      AtomicLong? Born in the heart of a nuclear furnace, endowed with the power of the atom, it's a bird, it's a plane, it's AtomicLong!

      Sounds like a "super" class to me. ;)


      Sounds like a porn star's name to me.

      --
      (Score:-1, Wrong)
    3. Re:Article didn't mention new concurrency stuff by etedronai · · Score: 4, Informative

      I am actually using the initial implementation of this on our current project and it is very nice. Actually have fine grained synchronization control makes it much easier to deal with a lot of thread synchronization problems. It has also helped us greatly reduce deadlock and detect deadlock because locks and waits can time out and report to you that they have timed out rather than just happily returning like Object.wait() does today. All in all this, along with generics, is probably the best new feature that is being added in jdk 1.5

  32. Generic Java by henni16 · · Score: 2, Informative

    Interested in Generics?
    A Compiler for generic Java has been available for years:
    You can check out Pizza/GJ here or here

  33. How this compares to C++ by lkaos · · Score: 4, Informative

    Generics
    The new Java generics are really weak compared to C++ template support. This is probably partially due to difficult in compiler support and also complexity (templates are without a doubt the most complex feature of C++). I was disappointed though in Java generics mainly due to lack of any kind of specialization support and also about the strange paradigm used for Iterators (instead of an iterator being class defined with a consistant interface, it's an external class that just behaves that must wrap a behavior around the class).

    Enhanced for loop
    This is for_each() in C++. Now, with for_each, you have to use function objects which is arguable as to whether it's more readable. Fortunately, Boost has developed a boost::lambda class that allows for code to be used as the third parameter. This is _really_ neat.

    Autoboxing/unboxing
    I presume this means that primatives can't be used in generics.. That's kind of sad. This isn't a problem in C++.

    Typesafe enums
    This would be a nice linguistic pattern to have in C++. As it stands, the equivalent would be:

    struct Coin { enum { penny, nickel, dime, quarter }; };

    Static import
    This can be achieved via using in C++. Of course, Java doesn't even really have a namespace paradigm so it's not really a fair comparision.

    Metadata
    This is.. well.. strange. I didn't see the syntax for doing something like this. If it is just keyword/code replacing, then an #include directive would work just as well.

    --
    int func(int a);
    func((b += 3, b));
    1. Re:How this compares to C++ by TummyX · · Score: 5, Informative

      Metadata
      This is.. well.. strange. I didn't see the syntax for doing something like this. If it is just keyword/code replacing, then an #include directive would work just as well.


      IMO, metadata is the coolest thing. It's a feature of C# which has had little recognition despite its coolness.

      In both Java and C# you can use reflection to find out information about a class (class name, method names, etc). Attributes/metadata allow you to attach information to just about every element of a class/struct so that it can be queried dynamically using the reflection apis.

      Imagine them as JavaDoc tags that aren't discarded at compile time but are instead compiled into a class's meta data. They'll do for source code what XML did for HTML -- give more meaning to the code.

      Here's an example of using attributes/metadata to simplify XML serialization:
      [XmlRoot("cat")]
      public class Cat
      {
      [XmlAttribute("id")]
      public string Name;

      [XmlElement("color")]
      public string Color;

      public Cat()
      {
      }

      public Cat(string name, string color)
      {
      this.Name = name;
      this.Color = color;
      }

      public static void Main()
      {
      Cat cat = new Cat("felix", "yellow");

      XmlSerializer serializer = new XmlSerialzer(typeof(Cat));

      serializer.Serialize(cat, Console.Out);
      }
      }

      The code yields the following output:

      <cat id="felix">
      <color>yellow</color>
      </cat>
      The C# XmlSerializer class dynamically generates the IL that will do the serialization so it is *very fast*. It knows how to map the field names to element/attribute names by inspecting the attributes.

      Some other obvious uses include object/relational mapping (no need for external XML mapping files) and XMLRPC (just mark a method as Remotable!) etc. You can imagine infinite other uses for attributes/metadata.

      I'm not sure how it works in Java but in C#, attributes are simply classes (usually with a name ending in 'Attribute'). You can define your own custom attributes and your own classes that work with them. It's very cool.
    2. Re:How this compares to C++ by slagdogg · · Score: 2, Informative

      This would be a nice linguistic pattern to have in C++. As it stands, the equivalent would be:

      struct Coin { enum { penny, nickel, dime, quarter }; };


      Not equivalent, the Java version also supports writing as a String ... so the below statement produces the string "coin: PENNY" which is very, very handy.

      System.out.println("coin: " + Coin.PENNY);

      --
      (Score:-1, Wrong)
  34. Problems with less verbose accessors by MilesParker · · Score: 4, Insightful

    AC, I agree that the current approach is a PITA. I would also be very happy to see a more terse way to express properties. But what you are doing in your example, is throwing the baby out w/ the bathwater.

    Note that you now don't have anyway to specify access and protection! I had given a little thought to better ways to handle this, and even had an interesting brief email exchange w/ a C# engineer about it. For the protection aspects you could do something like [this is just a quick idea I cam up with:]

    property access String name;

    where access is one of {read, write, readwrite}

    But note taht right away you have a problem -- no way to assign protection levels to the various access, which is really a cross-product. What happens for example if you want the getter to be public, but the setter to be private?

    Also, note that you would also need semantics to handle overriding the property accessors. You could just say that the property access defines an equivalent to the getter and setter methods, but that can get weird and confusing very quickly. Think about the situation where you have an interface defining getters and setters and then you implement it by just providing the one-line property definition. That would not be very transperent TSTL.

    All this is just to say that it is a noble goal, but not as trivial as it sounds at first glance. IMO, the C# "solution" is particularly ugly, and qualifies strongly for the "syntactic sugar" label.

    FInally, as in my other note, good IDEs like IntelliJ provide very convenient ways to auto-generate these things. I care much less about this issue now that I am not having to type all this stuff out by hand!

  35. Re:Write once, Rewrite forever? by MillionthMonkey · · Score: 2, Interesting

    This looks to me like they are changing a language so that existing apps no longer compile which is a bad idea.

    Huh? Where did you see that?

    It looks like they're making changes so that new apps won't compile on older compilers, not that old apps won't compile on newer compilers.

    They risked a backwards compatibility problem when they introduced that "assert" keyword in 1.4 but there is a compiler switch to turn it off if you have variables with that name. Before that, they haven't messed with the syntax since 1.1, when they added class literals (syntactic sugar) and inner classes (a major change). The new syntax was so bizarre that no older programs were affected. I don't see how the 1.5 changes are any different. Some of them look like a cat walked across someone's keyboard.

    My company is stuck with having to support Java 1.1 because of Mac OS 9. (In fact, according to our demo download stats, the number and percentage of Mac OS 9 users is only going up.) So we use modern compilers when developing (no decent IDE works well with 1.1) but the nightly build script uses 1.1.8.

    Inner classes were an immense change compared to most of this sugary 1.5 stuff (except generics). Work here a few months and you learn about all the bugs in the 1.1.8 compiler with respect to inner classes. There are a number of perfectly legal constructs that get flagged as errors. But I bet the same kind of thing will happen with generics.

  36. Re:conditional selection by MilesParker · · Score: 2, Insightful

    In my mind, this is _exactly_ the kind of thing that should be avoided in Java and that has sown so much confusions and monkey-business in the C++ community. Yea, you _should_ be defining those interfaces and abstract classes. That's why they call it OO. :D

  37. Re:Everything must change... by Malc · · Score: 2, Insightful

    Personally I like strong typing. The current approach of casting to (implicitly) and from (explicitly) Object violates this. IMHO, static typing saves far more pain in the long run than dynamic casting. If you like the general language, use JavaScript if you want to throw all that away.

  38. compiled java? by dipierro · · Score: 2, Interesting

    When it comes down to it, once the code is compiled, it's the same.

    If you're compiling, shouldn't you use a language which wasn't designed to be interpreted?

  39. What Bjarne Stroustrup has to say about Java by Q+Who · · Score: 5, Informative

    This is what he said about Java and the likes.

    Also here.

  40. Re:Write once, Rewrite forever? by YetAnotherName · · Score: 2, Insightful

    From the article: "... you'll have to get used to providing additional information in declarations. Instead of merely saying:

    List words = new ArrayList();

    You'll have to say:

    List<String> words = new ArrayList<String>();"

    The way he says "you'll have to" suggests that old collection class construction might break. Let's hope that something like new ArrayList<Object> becomes the implicit default if you don't otherwise specify a type.

  41. I disagree - x++ vs ++x by Pentagram · · Score: 3, Insightful

    x++ is the standard way of writing the statement, used by most coders in preference to ++x (in my experience anyway.) The fact that there is such a convention is reason enough to use it IMHO; if I see ++x in a piece of code, it's a warning that something unusual is going on.

    As for your equality test examples, putting assignments in if statements in Java gives you a compile error. Also, it's quite rare to ever put a specific number in an if statement, and if you do it's likeley to be 0.

  42. When will Java be 'frozen'? by MarkWatson · · Score: 3, Interesting
    I have complained here before on this issue:

    One of things that makes older more mature languages like Common Lisp (and perhaps Smalltalk) nice to work with is a feeling of both having really solid implementations and not breaking legacy code.

    I like the idea of boxing and generics, but, these changes will affect old code (probably?) and the platform in general.

    My vote would be to freeze the Java language (perhaps after 1.5) and concentrate on the following:

    • memory footprint
    • runtime efficiency

    I would not like to see Java become a language designer's playground.

    Because of great infrastructure software like servelt/JSP containers, (perhaps EJBs :-), XML utilities, solid web services support, etc. Java is a great platform.

    Leave it alone (the sooner the better) except for improvements in the implementation.

    -Mark

    1. Re:When will Java be 'frozen'? by _fuzz_ · · Score: 5, Insightful

      My vote would be to freeze the Java language (perhaps after 1.5) and concentrate on the following:

      * memory footprint
      * runtime efficiency ...

      Leave it alone (the sooner the better) except for improvements in the implementation.


      This is a good idea. However, my vote is to concentrate on Java3. Screw backwards compatibility going forward and fix the standard library. Throw out the crap that has come along from JDK 1.0-1.1 and make the platform consistent. Why do we have both Enumerations and Iterators? Why are constants mostly UPPERCASE but sometimes lowercase (see java.awt.Color)? What about Thread.stop()?

      This cruft is never going to go away until Sun releases a version of Java that isn't backwards compatible. Perl and Python do it. Java should too. It makes for a much cleaner language for new projects. Old projects may get stuck on a Java2 platform until the owners invest the time to convert them, but that's the way things go. It's time to clean out the cobwebs in Java and make better use of the new features.

      Once all the old crap is gone, then it will be time to freeze the language and standard library.

      --
      47% of all statistics are made up on the spot.
    2. Re:When will Java be 'frozen'? by cant_get_a_good_nick · · Score: 2, Insightful

      When will C be frozen?

      C99 changed a lot of things, and added things that may cause some breakage for old projects. Just like you can tell your compiler to compile pre-C99, you use a different jsdk. C is > 30 years old and still has to evolve. Java is much younger and has more places where it needs to mature.

  43. This is a sad day for me. by Henry+Stern · · Score: 2, Interesting

    I've been using Java for most of my projects for years because it didn't let you get away with many of the confusing things that you can do with a preprocessor. I may sound like a big geek for this, but I was actually weeping while I read the article. JDK 1.4 broke the ice with the assert keyword and now everything bad about C++ is going to pollute Java.

    To the many cooks who spoiled the broth: "Thanks a lot, assholes."

    1. Re:This is a sad day for me. by CharlesEGrant · · Score: 2, Interesting

      Hmm. I could understand your reaction if they were adding operator overloading, but assert seems pretty benign. Can you give an example of a confusing use of assert?

  44. I think these are all great... by axlrosen · · Score: 3, Insightful

    ... but man do I hate the enhanced for-loop syntax. At some point you have to give up perfect backwards-compatibility for readability. One or two new keywords would do a world of good.

    for (TimerTask task : c)
    task.cancel();

    becomes

    foreach (TimerTask task in c)
    task.cancel();

    1. Re:I think these are all great... by sohp · · Score: 3, Informative

      Sun has been burned once when they introduced the assert keyword and broke thousands of programs that use the JUnit testing framework. The bustage occured because JUnit already used the keyword as an identifier, for the assert() methods. A token can't be an identifier, so everyone's tests broke with 1.4 I applaud Sun from learning from that fiasco and avoiding a repeat.

    2. Re:I think these are all great... by Doppler00 · · Score: 2, Funny

      They can't make the syntax easy to read. If they did, then it would be called Python.

  45. JCP strikes again by Wesley+Felter · · Score: 4, Informative

    Thanks a lot Sun for posting absolutely no information about the progress of this JSR. At least Doug Lea has posted a little information.

  46. Re:what if... by pmz · · Score: 3, Insightful

    what if microsoft buys sun?

    What happens when matter meets anti-matter?

    1) Microsoft wouldn't have a clue how to manage Sun. Sun is a hardware-engineering firm with a different corporate culture than Microsoft.

    2) Most of Sun's employees would either quit or sight tight until they can quit.

    3) Sun's customers would leave for IBM or HP; they would not eat MS' dog food.

    4) The Justice Dept. would actually do something for once, because J2EE is the only big competitor to .NET, and Solaris is the biggest commercial competitor to Windows Server.

    what if ibm buys sun?

    Bye bye, UltraSPARC. This would probably alientate lots of Sun customers.

    Java would cease being as open as it is. The JCP would close down.

  47. Re:Where is operator overloading? by avalys · · Score: 2, Interesting

    Aside from the opportunities for abuse of operator overloading, I don't think it's really that important in Java since it was never intended as a language for anything heavy on calculation (being interpreted and all).

    --
    This space intentionally left blank.
  48. Re:Where is operator overloading? by Glock27 · · Score: 2, Informative
    I would *love* to see operator overloading. It would actually make Java much more useful for scientific tasks which involve things like vectors, matricies, or complex numbers. I'm also sure it would also be helpful in other areas.

    There was a preprocessor named jpp floating around a few years ago that supported operator overloading for Java. It seems to have vanished off the net in the meantime, though I'm sure I have a copy somewhere. True operator overloading is supposed to be added to Java at some point, IIRC.

    In the meantime, perhaps we should write a new preprocessor, the "Operator Overloading Preprocessor System" or OOPS. jpp seemed like a good idea (it offered several features beyond operator overloading). Java coupled with a good preprocessor is a fine idea. ;-)

    --
    Galileo: "The Earth revolves around the Sun!"
    Score: -1 100% Flamebait
  49. Re:Hope it fixes issues with 1.4.x by DogIsMyCoprocessor · · Score: 3, Insightful
    -1, troll

    memory leaks (StringBuffer ToString anyone?).

    Sorry, not a bug. What happened is the JDOM folks (gambling) relied on the internal implementation of StringBuffer and not its public API. That also broke JDOM for 1.2 jvms, which implemented StringBuffer differently. The internal implementation changed in 1.4.1, hosing the JDOM folks. Sun's only mistake was making this change in a minor version instead of a major one.

    --

    "And this is my boy, Sherman. Speak, Sherman." "Hello." "Good boy."

  50. Maintenance by ruriruri · · Score: 2, Interesting
    Unlike some people, I feel using programming shorthand leads to increased maintenance.

    Do you like seeing "public void setX()...public int getX().." a hundred thousand times to implicitly declare a bound property? Or would you rather see "published int x;" (to steal a line from C#) and be able to refer to x by field name rather than accessor method? I think simplifying code like this is a good idea. However, there is a dilemma created herein, as the example below will illustrate!

    Thought Experiment #1
    Assumption: Maintenance cost is directly correlated with program size.
    Therefore: The more terse the language grammar, the easier programs written in the language are to maintain.
    Thus: Perl.

    At that moment, the programmer was enlightened.

  51. Re:Looking to Get Back into Java by richieb · · Score: 3, Informative
    If you are willing to spend some money check out IDEA from IntelliJ. It's great!

    http://www.intellij.com/idea/

    --
    ...richie - It is a good day to code.
  52. "synchronized" vs. locks & semaphores by jlusk4 · · Score: 2, Interesting

    The gist is, you'll never need to use ... "synchronized" anymore, but rather you'll execute Runnables, use Locks and Semaphores, etc.


    I'm not sure how locks and semaphores are a step forward from monitors, which is what "synchronized" represents.

    Are you claiming "synchronized" is inefficient? Did you see the developerWorks article?

    Are you claiming that such a high-level structure as a monitor is unnecesary for real programmers, who know what they're doing and will never screw up using synchronization primitives?

    John.
  53. Programming Myth by mrpotato · · Score: 2

    " I feel using programming shorthand leads to increased maintenance."

    False.

    Shorter code and more powerful idioms makes a program *easier* to debug.

    Too much code makes the purpose lost in the noise. Consider:

    foreach (@array) {foo $_};

    and

    my $i;
    for ($i = 0; $i < $#array; $i++)
    {
    foo $array[$i];
    }

    (I use Perl here since it is well known and I can show the 2 idioms, but really Perl isn't the clearest language of all). One form is much clearer and reveal much more eloquently what is the intent of the code.

    Of course, this doesn't mean that shorter code "at all cost" is easier to debug, it means that "less code" is better.

    Oh, and also it pisses me off when management tells me I need to use only certains idioms in case someone comes over my code and don't understand it. I hate to have to program like the next maintainer will be clueless and ignorant.

    --

    cheers
  54. Automatic boxing/unboxing by autopr0n · · Score: 2, Interesting

    It's interesting the problem they were having with unboxing. Right now a null pointer would return a int value of zero, rather then throwing an error.

    Actually, I think that's a bad idea, since you wouldn't be able to tell a zero you put in a collection with one that you didn't. Personally I'd like to see this as an option, somewhere. perhaps as a parameter to Integer, so you could do Integer<0> or Integer<null> to chose the behavior of the class. The problem there is that it's not obvious what a parameter to integer would do. Although I suppose you could use an if statement.

    Personally, I wished they would have thought up a more interesting way to do generics then the C++ model. I wonder if this is going to give us the full range and power of C++ templates in java.

    --
    autopr0n is like, down and stuff.
  55. Re:ooooh baby by slagdogg · · Score: 4, Funny

    Typesafe enums. That alone makes me quiver with happiness.

    You don't get out much, do you?

    --
    (Score:-1, Wrong)
  56. Re:foreach by sohp · · Score: 2, Insightful

    I guess you didn't RTFA. Introducing a new keyword breaks programs that happen to use that as an identifier. They broke JUnit when they introduced the assert keyword, and having been burned once, learned something.

  57. The Six-Million-Dollar Sweetener by SEWilco · · Score: 2, Funny
    Some of the enhancements to me are purely sugar

    I often also enhance myself with sugar.

  58. Just from pesonal experience.. by LogicHoleFlaw · · Score: 5, Insightful

    You know, I've just got to say this.

    Each and every point on this list of additions to the languages addresses problems that I have personally run into in my use of Java at work. These things will make the writing and maintenance of java projects small and large much, much easier.

    Generics: Thank you God, yes! Having to explicitly cast objects out of Containers is tedious and error-prone.

    Iterators/Enhanced 'for': Make iteration much easier to read and understand.

    Autoboxing/Unboxing: This helps alleviate the enormous kludge that is the Object/primitive dichotomy. Casting to and from wrapper types just to pass ints, etc. around really sucks.

    static import: Not having to fully specify tedious class names to access static members is a big boon for making stuff digestible and easy to read.

    Metadata: Writing boilerplate sucks the big one. How many hours have I lost writing boilerplate? Way too many. Having language support for generating code from the metadata cuts my implementation times way down.

    I could sit here and argue with folks about the 'new Java' versus C++ or C# or Smalltalk or whatever endlessly. But man, these things sure make Java a whole lot more pleasant to use.

    --
    -- Flaw
  59. Re:Looking to Get Back into Java by doublem · · Score: 2, Funny

    I consider it to be on par with FrontPage.

    Harsh.

    Very cruel man.

    --
    "Live Free or Die." Don't like it? Then keep out of the USA
  60. This is sad... by pchown · · Score: 2

    It makes me really sad to read this. Java is a long way behind the state of the art for expressive power. These changes are welcome but Sun are presenting them as though they are innovative. Three lines to remove the four character strings from a collection? Look at it in Python:

    filter (lambda x: len(x) != 4, list)

    If you object that Java is doing type checking, and Python isn't, look at it in Haskell:

    filter (\x -> (length x) /= 4) list

    Time to move on I think...

  61. Bjarne Stroustrup should be lynched by melted · · Score: 2, Insightful

    For the gaping holes and pitfalls he has created in C++. Everyone who has read books from Effective C++ and Exceptional C++ series knows this. In Java or C# you've got to try to shoot yourself in the foot, in C++ this comes by default, you don't even have to do anything. Some insanely simple situations shoot you in the foot so bad, it's not even funny. Not that C++ doesn't have its uses, but its usage should be limited and punished for. Thanks to Bjarne's "excellent" design, devs punish themselves every time they use the language for something non-trivial.

  62. pizzacompiler by cyco/mico · · Score: 2, Informative
    I found java always underachieving, the rt environment ("virtual machine") and especially the language. the compiler was, well, ok.

    my favorite language (extension) for the vm has always been pizza. It gives you said generics, but also

    • first-class functions and
    • algebraic types (think functional pattern matching)
    all three compatible with the original jvm 1.0 specification.

    But to be honest: this seems to be a real great step for java. programmer with a certain need for aesthetics (and self regard) can now really use this language...

  63. Yeah, but... by Burpmaster · · Score: 5, Funny
    I'd say that "++x" is actually the "best" way because it puts things in verb-noun order, which I'm used to as an English speaker.
    In Soviet Russia, x++!
  64. Needed feature by quantaman · · Score: 2, Interesting

    They need to include an option to not include bounds checking in arrays. Right now Java is becoming very popular in physics because it's easy to use and portable across systems. I know a lot of people in physics who program in Java and I've worked the past two summers as a summer student writing code for physicists. The biggest complaint both they and I have in the bounds checking it does. It's a great option for debugging, testing, and for running most applications. But when you are running a large program the overhead of bounds checks in arrays can be prohibative. Ideally I would like either a runtime or compiler option where you can specify to run it without bounds checks. Obviously this wouldn't be a good idea for a great many apps but it would be extremely useful when running an array heavy application that takes hours or days to complete.

    --
    I stole this Sig
    1. Re:Needed feature by Thorgal · · Score: 2, Insightful

      Hotspot optimizes bound checks away. What would be more useful for scientists are:

      a) true arrays,
      b) FPU-using trigonometrical ops

      --
      "Man in the Moon and other weird things" - wfmh.org.pl/thorgal/Moon/
  65. Uh, read the article by autopr0n · · Score: 3, Informative

    This is exactly what the new Java enums do. You just get to type a lot less and you can use them in case statements.

    --
    autopr0n is like, down and stuff.
  66. Sig by Anonymous Coward · · Score: 2, Funny

    Arguably the most terrifying sig I've ever seen.

  67. What about making the language useful by samwhite_y · · Score: 5, Insightful

    In the old days when people talked about Linux, there was an expression "What about the big pink elephant in the middle of room" and it was referencing the fact that Linux did not support truetype fonts and font aliasing. Now some of that has been fixed, but Java still has its big pink elephant. Here are some of the things that people don't talk about.

    The memory foot print for loading Java is 20meg + and growing. I am part of a team that has been developing a complex Java application for the last few years and we have created about a 3meg library (and it probably does at least as much as the more popularily used Java classes). I have looked at some of the source code for the core Java libraries and it is clear that a good rewrite could reduce this footprint by a factor of 2 to 4. Currently, C# loads with a footprint of 2 meg to 4 meg. Most other scripting languages usually have engines that are about the same size. To put it simply, the base core Java libaries are unjustifiably large. Maybe if Java were truly open source this could be addressed, but of course Sun doesn't even believe in submitting Java to a standards board.

    You cannot load the Java VM once and run multiple processes (note "processes", not "threads") from the same Java VM memory footprint. I hear that such a thing is becoming possible for C# on Linux. You would have to build all the core Java classes into a "DLL" or ("so" on Linux), but that shouldn't be so difficult.

    You still cannot do basic OS operations in Java without writing your own JNI library. The one that stands out is the inability to get the ID for the current running process. The "nio" package has corrected some of these issues, but the "nio" package should be the "io" package instead of having two separate packages (similar to AWT vs. Swing).

    Window focus handling is still terrible. Ever have two frame windows up, have a modal dialog pop up on one frame while you were looking at the other? The frame window without the popop modal dialog becomes unresponsive and the other frame cannot be reached by tabbing through the windows. Only if you are lucky and that window is still visible on your desktop can you successfully reach it. Also, if a user clicks on a button that generates a modal dialog, the frame is only locked out from user input once the dialog manifests. This creates the infamous "double" clicking problem.

    Java's package management is still primitive. If you want to do anything more subtle then using the classpath to load in custom libraries, you have to write your own class loader. Having an auxillary file specifying parameterizable rules for class loading would be nice. It would also be nice if you could ask a running Java process what packages it had loaded (and metadata about them such as location and version). Compare this to C# (or the way some of the web server oriented scripting languages work).

    Some of the basic core library functions have some major weaknesses. For example, the Hashtable should be written as a native object when using String lookup keys and also allow you to dictate the algorithm for creating hashes (ex: use first 8 characters, last 8, or middle 8). There should also be a non thread safe version as well as a thread safe version. The lack of such a natively implemented primitive object is one of the big reasons why some less cleverly implemented scripting languages (such as python) can beat Java in performance on many web applications. In general, the core collection classes should be implemented in pure optimized (down to the actual chosen assembly code) native code.

    Many of the utility libraries are broken in fundamental ways. Send back a badly formed response to the HTTP library and you go into an infinite loop when it falls into its keep-alive/retry logic. Date parsing is still behind what is available in the C standard library. Locale specifications do not allow you to independently specify date formats, language, floating point format, currency format, and time zone. You get o

  68. Where are shared jar files/JVMs? by Anonymous Coward · · Score: 3, Interesting

    When will Java support shared jar files that work like shared objects or DLLs in operation systems?
    IMHO this is one the main shortcommings of Java. Every jar file is loaded into every process causing a huge memory footprint and long startup times.

    When playing around with some java shells, that only load classes once and simulate processes as threads, I saw simple swing applications load in 0.1 secs and other significant speed ups.

    I was hoping for it in 1.4.x and now it seems it won't even make it into 1.5. I realize that it will be hard to implement this in a platform transparent way.

  69. we can thank Microsoft for this by g4dget · · Score: 2, Interesting
    Sun is finally rolling this out because of competition from Microsoft and C#. Until C# looked real, Java had mostly stagnated.

    Unfortunately, this doesn't quite make Java competitive with C# yet. Major missing features are:

    • JVM support for generics. Lack of JVM support makes generics not type-safe across compilation units, and it also makes them less efficient. The result is that the current generics implementation for Java is a stop-gap measure that isn't a good long-term solution. C#/CLR doesn't have generics yet, but Microsoft is planning on CLR changes to support them.
    • Lack of value classes. Value classes are essential for scientific programming, and automatic optimization cannot infer them reliably.
    • Lack of operator overloading. Again, that's essential for scientific programming. Some people worry that they lead to unmaintainable code. Of course, andy feature can be abused, but that's really a problem with overloading, not operator overloading.

    Also, Sun's patents on core Java technologies and the lack of a well-defined, open Java standard are still serious problems. The fact that Swing is de-facto part of the Java standard but that Swing is as ill-defined as the Windows API is another problem because it makes it hard to create open source implementations of Java.

  70. More overloading evil... by Gorimek · · Score: 2, Insightful
    The same goes for preprocessing. Consider things like '#define + -'...

    An other awful consequence of operator overloading is that code like this
    if (x != null && x.foo()) ...
    is unsafe, since the && may be overloaded.

    (The above may not be valid C++ syntax. I left C++ for Java many years ago and I'm never going back!)
    1. Re:More overloading evil... by Gorimek · · Score: 2, Interesting

      My example in the general form is the fairly common "pattern"

      if (fooIsSafeToDo() && foo())...

      This is guaranteed to work in C and Java, and to 99.9% in C++. So as a C++ developer you're forced to either always write

      if (fooIsSafeToDo()) {
      if (foo())...


      or to keep writing code that will almost always work. That is, if you're even aware of the issue, which I'm sure most programmers are not.

      If I understand your point, this can't happen in the common case where 'fooIsSafeToDo' is a null check, which is good, but doesn't really change the principle. And no, I haven't seen this one bite anyone, but I've seen plenty of other really obscure C++ traps wreak havoc.

      Here's an other pet peeve, while I'm whining. Why is this unsafe C++ code?

      getResource(); // memory, file, whatever
      foo();
      releaseResource();


      because foo() may throw an exception, so this is a resource leak.

  71. Re:Looking to Get Back into Java by mobiGeek · · Score: 2, Informative

    Don't forget about the JDEE!

    --

    ...Beware the IDEs of Microsoft...

  72. if( xxx ) versus if( xxx ) by Baki · · Score: 3, Insightful

    I always get the creeps when I see if( xxx ).
    It is as if "if" is a function putting the parentheses like that.

    foo( xxx ) is a function call
    if ( xxx ) is a statement which gets a block in parentheses.

    I couldn't resist. I have to fight this good fight every day against some of my colleages.

  73. Re:Everything must change... by __past__ · · Score: 2, Insightful
    Java isn't strongly typed. It has static, or manifest, typing. Those two qualities are orthagonal.

    In a strongly typed language, there are no cast operators, and hence no ClassCastExceptions. You don't have these even in dynamically-but-strongly typed languages, like Lisp or Python.

    Java doesn't give you type safety, just type errors when you try to be smarter than the compiler, which isn't that hard. That is no surprise - it has been shown that proper type inference runs into the halting problem, by research on languages that at least try to be helpful rather than just annoying while maintaining static typing (like ML or Haskell). In this regard, Java combines the worst of both worlds, just like C and C++, even if it is otherwise better than them in almost everything.

  74. Redefining the language is essential. by rjh · · Score: 2, Insightful

    Any language which cannot be redefined is, much like any programmer who says languages must not be redefined, fundamentally wrong. If you can't rewrite your language on the fly, then what good is it? :)

    Signed,

    A Very Happy LISP Programmer.
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    No, really. Redefining the language is one of those things which sounds like a bad idea, up until the time you learn functional languages. Once you grok functional languages, redefining the language becomes second nature to you: for any given serious programming task, you modify the language into a special-purpose language meant specifically for solving your problem. For instance, I wrote a crypto library in LISP recently, and I needed to do a lot of addition modulo 2**32. In any other language, I'd have to write a function to do the additions... in LISP, I just wrote a macro.

    Redefining the language is an astonishingly powerful technique, and once you grok it, the idea of a language forbidding you the ability to redefine itself seems like an Apocalyptically Bad Idea.

  75. C# steals these ideas from Java by SuperKendall · · Score: 2, Informative

    All of these proposials have been around forever, I was attending talks on pretty much the same Generics syntax at JavaOne two or three years ago... and I've been using the same kind of enum classes since Java 1.1.

    C# didn't add generics at the start as they were waiting for Java to solidify how to do them.

    Also, Java has a bit more of a wait for new features since Java goes through a real standards body instead of just being defined by what Microsoft wants. And of course lots of real production code that can break if you get things wrong.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  76. I pity the software engineer... by gafter · · Score: 2, Funny

    who has to implement the new javac.

    Uh, ... wait, that would be me.