Slashdot Log In
Preview of Java 1.5
Posted by
michael
on Sat May 31, 2003 03:42 AM
from the skim-milk-and-two-sugars dept.
from the skim-milk-and-two-sugars dept.
gafter writes "An early access prototype implementation of
the proposed new J2SE 1.5 language features is
available. The prototype includes
generics (JSR 14),
typesafe enums, varargs,
autoboxing, foreach loops, and static import
(JSR 201). In other words, all the new language features
planned for 1.5 except
metadata (JSR 175). The
prototype includes full sources for the compiler,
written in the extended language. You can download the prototype from
java.sun.com.
It requires J2SE 1.4.1 and provides some examples of how to use the new language constructs. The prototype includes an experimental type
system (variant type parameters)
for Generic Java that is being considered
for Tiger (1.5) based on a paper by
Igarashi and
Viroli at ECOOP 2002 .
Comments and votes for the new type system are
being gathered at
bugParade."
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
good and bad ...? (Score:4, Interesting)
Re:good and bad ...? (Score:5, Funny)
Because no language is complete without printf.
Anyway, I'm glad to see Java finally getting generics. This will make it a little easier to manage very large projects in Java. The only problem I see is that generic java usually sucks compared to the brand-name stuff (e.g. Lavazza [lavazza.it]).
Parent
Re:good and bad ...? (Score:5, Informative)
isn't syntactic sugaring all about making code more readable? I think boxing , generics, typesafe enums, static imports make the java language more simple to use.
It's just looking over the fence to the "sibling" languages (c++, c#) and copy what they do better.
Parent
Re:good and bad ...? (Score:5, Insightful)
Parent
Re:good and bad ...? (Score:5, Insightful)
Type-safe enums were added to eliminate previously verbose and obfuscated code. It simplifies the code without complicating the language.
There are iterators for doing stuff like foreach-looping
What does polymorphism have to do with an enhanced the for-loop or variable arity functions? The enhanced for-loop ensures that collections are properly iterated across (no out of bounds exceptions). You honestly think that
for (int i = 0; i < C.length; ++i) {/*
is more complex than
for (int i : C) {/*
Also look at what you can do with variable arity functions. Say you have a constructor for a collection class and you want to be able to initialize a variable number of default values. Well, now you can. Apple's Cocoa (Foundation) library uses this to allow easy construction of NSDictionary objects.
id d = [NSDictionary dictionaryWithObjectsAndKeys:@"foo", @"bar", @"biz, @"baz"];
The other way to do it would have been
id d = [[NSMutableDictionary alloc] init];
[d setObject:@"foo" forKey:@"bar"];
[d setObject:@"biz" forKey:@"baz"];
Aside from Cocoa's long parameter naming scheme, the first method is a shorter and a lot easier. It also uses fewer messages.
Parent
Collections should be first-class entities (Score:4, Insightful)
You can already declare arrays in-line. So if they were to define an appropriate constructor, you could do List l = new ArrayList(new Object[] { "foo", "bar", "baz" }).
That is verbose of course. What they really should do is add collection manipulation stuff to the language, so you could go List l = ( "foo", "bar", "baz" ) and be done with it.
I believe that that scripting languages get most of their advantages (more functionality with less code, easy to develop in, etc) because they have collections as first-class entities. It's not as if it would be polluting the language... How often do you write code that doesn't use some kind of aggregate data type? For the language to not recognize that is just silly.
Parent
Re:good and bad ...? (Score:3, Interesting)
for(i = 0; i < count; i++) {
You can use iterators for this, but (depending on the implementation) it is likely to be slower, since the object in question must create an iterator instance.
Iterators should be used (in fact, are pretty much a necessity) on types that are not easily indexed, such as hash tables or linked lists. As long as the Java language doesn't have support for iterators, developers creating non-indexable container class
No subject. (Score:5, Funny)
Just had to get that trolling out of the way. Now let the educated and well-formulated arguments begin.
Re:No subject. (Score:3, Interesting)
Re:No subject. (Score:4, Insightful)
I'm tired of running into C programmers who are scared of lower level code (read: Assembly).
I'm tired of running into GUI users who are scared to use the command line.
I'm tired of running into calculator users who are scared of using a slide rule.
I'm tired of running into automatic transmission drivers who are scared of manual transmisions.
I'm tired of running into people who use drive automobiles and are afraid to use a horse and buggy.
In fact, I don't think scared is the issue here at all. The real issue is automation. Something that always makes people more productive, and requires greater machine resources. (See all above examples.) In fact, using your own argument against you, I would argue that anyone here, even a Basic programmer, can learn to program Assembly, use a command line, use a slide rule, etc. In fact many of us were Basic programmers. Many of us do or did these other skills. That fact that you can be "macho" and learn pointers is missing the real issue. Automation.
In Java, you are trading machine performance for human performance. You simply eliminate the possibility of even having the all of the most common C/C++ bugs that plague so much modern software.
CPU cost is going down. People cost is going up. This trend has been going on for a long time. (Have you noticed this trend in the past 20 years?)
Back in the early 60's and 70's there were huge debates about whether "high level" languages (like the C you advocate) would ever be useful because the compiled code was so much less efficient than hand written code. (And yes, I know that argument in the late 70's that compilers would eventually write better code than by hand.) But the point remains, that even if this is or is not true, high level languages won.
Think about why that is for a moment.
In any sufficiently complex C/C++ system, you either end up implementing garbage collection, or end up with some complex disciplined memory management strategy, and still end up with object lifecycle bugs. In C/C++ you sometimes end up implementing your own miniature Lisp, even if you've never seen Lisp. But your own implementation of Lisp ends up poorly specified, and not throughly debugged.
Parent
Sounds like what C# has that makes it better... (Score:4, Interesting)
Re:Sounds like what C# has that makes it better... (Score:5, Insightful)
To me, Java was a lanaguage with a minimum of "redundant" features. You can write a "for" loop without using "foreach". You can use a class instead of a struct. And so on... I'm actually a bit surprised that Sun are throwing in features the language doesn't really always seem to need. I thought that was C#'s area.
Parent
Simplicity lost (Score:5, Interesting)
Anonymous inner classes was first major ugliness which came into language - not very clear, hard to explain to a newcomer. But with all these new proposals, significant complexity is added to code in terms of visual overview. This is not critical for developers - perl hackers are faring very well, despite of having language 10 times as complicated as java as far as syntax is concerned - but pure-OO, java-is-new-pascal-for-algorithms academic society will probably start looking for a new language soon... (ok, maybe not really 'academic', I'm thinking more about secondary-level school programming basics).
Re:Simplicity lost (Score:5, Insightful)
Actually though I think for this kind of teaching you can just use the simple subset of Java that's been about since 1.1 - after all, you're teaching principles of programming and OO - you can teach actual Java *development* down the line and cover the complexities, bells, whistles and dongles then...
Parent
Good ol days (Score:3, Funny)
Re:Simplicity lost (Score:3, Insightful)
Then, when they understand the concepts, you can introduce them to the syntactic nightmare that is Java.
Teach the kids Scheme or Smalltalk. (Score:5, Insightful)
Smalltalk has, essentially, only one operation: the message send. Send object X a message Y, and get Z back as a result. Even simple things like addition are implemented this way. While not blazingly fast (except in certain specialized implementations), the message-send semantic is surprisingly efficient: many complex real-world systems have been constructed using Smalltalk.
Scheme also enjoys the advantage of being small and simple, yet powerful. You don't need to know what the lambda calculus is to see how effective and intuitive Scheme's procedural semantics is. ("Lather, rinse, repeat." See? Tail recursion. It was there all along.)
Either way, it's better to use a simple language to teach students how to formulate plans for doing things (i.e., algorithms), and then hit them with fanciful syntax later rather than drop them into a popular, but bewildering for newcomers, language (which I consider C++ and Java to be).
Parent
Oh no! (Score:4, Funny)
Er. Or, not.
Teach basics in python, algorithms in ocaml, bit-grinding in C.
Parent
Interested in learning more about these generics (Score:5, Interesting)
More constructively, maybe the implementation will improve on things from all that time and experience.
Java is the best defense against the
Generic Java (Score:5, Informative)
(Excuse my whoring, but Sun's link to GJ was 404.)
Generics (Score:5, Interesting)
It seems to me that languages like Java and C# really don't need them.
Re:Generics (Score:5, Interesting)
1) C++ is a systems programming language. The lack of pointers would make it entirely unsuitable for that purpose. For normal use, you should use references or smart pointers. Not doing so is no excuse. Using a C-style array when you don't need it is akin to deliberately writing an infinite loop. It's entirely the programmer's fault.
2) The object model doesn't lack anything that Java's model has, except introspection (which is fragile at best). If anything, Java's model is equally broken, because everything is not an object. What exactly about the object model is missing?
3) What's wrong with the C++ syntax? How is it that different from Java's syntax?
From my POV, peoples' biggest problem with C++ is that it doesn't prevent you from hurting yourself. That's okay. I hate all the consumer protection bullshit, and Nader and his "don't run with scissors" party, so I have no problem with my language having some teeth. I do a lot of low level programming, and I find that C++, more than any other language, allows one to do that will still maintaining a high level of abstraction.
Parent
Is the single instance of VM in? (Score:5, Interesting)
Kjella
Dylan (Score:3, Interesting)
But whereas the features were elegantly incorporated into Dylan since the beginning and are consistent and easy to use, I suspect that in Java they are a hack.
Wasn't Java designed to be a simple language?
The problem: Improving programmer productivity (Score:5, Interesting)
These additions seems to put Java on par with C#, but to make a quantum leap in expressiveness you need a dynamically typed scripting language.
Most applications these days can be written in higher-level languages, resulting in 5-10 times less source code compared to Java/C#, and making them correspondingly simpler to code and maintain.
Java doesn't really have a kick-ass companion scripting language. In MS world, VB plays this role. VB is really popular, but (I think most people would agree) a crap language and not really that high level. JavaScript just doesn't seem to cut it (pretty much only used in browsers).
Why doesn't Sun take a hint and phase JavaScript out in favor of a powerful multi-purpose high-level language like Python [python.org] or Ruby [ruby-lang.org]? That'll put them miles ahead of Microsoft in terms of increasing programmers' productivity... and programmers' quality of life.
Re:The problem: Improving programmer productivity (Score:4, Informative)
Look here [com.com] for more info. My guess is Sun is brewing something with the next edition of SunONE and Forte. Notice how Sun is targetting there new tool at VB users.
Its possible these features were added to java 1.5 so Forte can have a VB like ide to generate java code easier. After all, enums make things easier to read and are essential for new programmers to read your code.
Competition is great and I believe a great RAD and ide that is based on a fairly good langauge will give
Parent
Re:The problem: Improving programmer productivity (Score:5, Informative)
Parent
Re:The problem: Improving programmer productivity (Score:5, Informative)
Parent
Sun deserves all that will happen (Score:3, Insightful)
You have a company that has a strong position in the Enterprise, and you have a technology that is pretty much accepted. Meanwhile your opponent is busy with conquering the desktop since it can't provide solutions strong and stable enough for the enterprise. What in god's name did you think MS was going to do? Was Bill Gates supposed to turn the others in the room and say "hey this was fun, let's do it again!" after MS has owned the complete desktop ? OF COURSE they'll try to dominate the Enterprise too!!
Java Vs .net (Score:5, Insightful)
The ONLY reason that Sun hasn't relinquished control of Java, is that if they had done so, Microsoft would have been free to embrace/extend/ corner the market.... The same as what they did with Internet explorer.
So, how many non-geeks use anything but, or even know of anything but IE?
Businesses would standardise on MS java, and java on any other platform would become unuseable.. (just as there are web pages that are only useable in IE).
By stating "I'm using C# over Java" you are selling you sole to the devil...You wait till microsoft start extending DRM into the specification, therby relegating projects like Mono to the sidewalk, at this point it will be M$
So, Its your choice. Choose to go with the, arguabily faster/easier to code offering by our (sarcasm) good friends at Redmond, or choose to fight Microsoft by writing code that will run on all platforms from mobile phones to IBM mainframes. Believe me when I say we will all be better off in the long run.
Re:Java Vs .net (Score:5, Interesting)
Most major corporations who are planning on moving to Linux if they have not done so are cancelling and puting their plans on hold thanks to SCO.
If you use mono at work assuming its mature enough and ms pulls a sco you can kiss your linux workstation goodbye.
According to MS halloween documents, legal fud got a negative response form %80 of all bussinesses.
Parent
More Wrong Choices (Score:5, Interesting)
I program Java for several customers, from scientific to business apllications.
Autoboxing is yet another way of hiding overhead; the wrapper classes still exist, but are now a big "secret" masked by autoboxing.
Why add autoboxing to make containers look more "natural with POD types, then ignore the crying need to operator overloading in scientific and engineering applications? Why one piece of syntactic sugar as opposed to another?
Overall, I'm not terribly impressed. The new generics seem weak; I don't see an emphasis on fixing bugs, stability, or independent standardization. Much as I like Java, 1.5 does not address most of my needs.
Why a Large Bank Junked Java (Score:4, Informative)
I am working with a large bank at the moment, one of the largest in the world and they have largely junked Java, except for running browser applets.
They liked Java, the class libraries were great but, sorry, it is too slow. I'm not talking about incompetent coders. They even had Sun in looking at some of the apps. The end result was a customised virtual machine - but it was still too slow and the incompatibilities were a killer. The VM had to work identically across the bank's generations of systems from different vendors. One gotcha, IIRC, was synchronisation, making it difficult to run a JVM across processors and to exploit them properly for performance.
End result was a switch back to C++ for back end apps. Java could still be used but only for non-critical front-end stuff. The bank may consider C#, but it seems that Java has had its day.
Maybe this sounds like a troll, but Sun should release their control of the Standard. This will slow things down, think how long it takes to get stuff into C++, but that stability gives everyone room to think as to whether a change is really necessary.
I don't like the idea of C# but at least MS handed it over to ECMA.
Re:Why a Large Bank Junked Java (Score:4, Interesting)
Parent
Everyone's bashing java (Score:5, Insightful)
Generics are also a hack, but at least they are an overt, clean one.
Java is pragmatism over principals (Score:5, Insightful)
Java rarely wins in any particular niche. Relatively simple GUIs and COM objects are owned by VB (and Delphi). C++, C, and assembly rule in performance. Perl rules text processing. Python rules in ease of reading. ANSI C, Perl, Python may be more portable. Smalltalk, Eiffel, Lisp, Ruby, ML, Haskel, Forth, and a variety of others are a lot more true to a pure language concept. However, Java does an adequate job in most cases, and when you start crossing boundaries, it'll often be easier to do so in Java-land.
Java isn't innovative. However, it's constantly being improved. Sure, things like JDBC, Collections, SWING, NIO (async I/O), generics, threads, and concurrent garbage collection were available in some form elsewhere previously. They're all packaged into nice, free, portable, well documented, easy to use parts of Java though, and I'm happy to have them.
Java isn't as free as Emacs. However, it's mostly free as in beer, and it doesn't force it's freedom on you. It's certainly a whole lot freer than most things from Redmond. I admit, I don't care if a language is handled by a standards body, unless the company in question holds other monopolies it can abuse. I seriously don't think Sun is going to do anything so wacky as polluting the language to make COM (*cough* MS) or Object Pascal integration (*cough* Borland) easier.
Java's support base and (free) developer tools are just plain great. I love Eclipse, and IDEA and recent JBuilders are pretty nice too. VS.NET is good stuff as well, but contenders like Python are sorely lacking in this arena.
I still write plenty in other languages, but every year the percentage I write in Java goes up.. They keep filling holes (soft references, regexes, async I/O, .1s GC pauses) that were keeping me out of Java. I'm happy to see some more syntatic sugar in Java.. The things they're addressing will make a whole lot of code more readable.
Re:I'll care when native compilers become the norm (Score:5, Insightful)
You mean like GNU gcj?
For languages that are intended for general purpose use and especially for situations where performance/efficiency is important they're just a BAD idea.
You seem to think that by compiling stuff to native code things magically run fast when the problems are actually library design, class loader design, bad memory management, and other issues. Java's JIT is about as fast as natively compiled C code and Java's lousy performance is living proof for the fact that making a great native code compiler is not sufficient for getting good performance.
Python and Perl programs often run rings around equivalent Java programs in terms of actual, end-user visible performance and memory usage, despite being interpreted. If anything, the compromises people need to make to make languages easily compilable into native code make it much harder to build efficient systems in them.
Of course, it's not like we needed any more proof of that: the inefficiency and bloat of systems like Windows, Gnome, and KDE demonstrate the same point, as did several generations of systems before them. And generation after generation of programmers repeats the same mistake you are making.
Parent
Re:I'll care when native compilers become the norm (Score:3, Insightful)
because the JIT overhead is not re-occuring, it happens once.
Re:I'll care when native compilers become the norm (Score:5, Interesting)
That is impossible. Java has to do the same as the C code, plus the extra overhead of doing the JIT. There is no way Java can be "as fast".
Ah, the "impossible" word. ;-)
You're presuming that the ahead-of-time compiler can "know" everything that the JITC can. That isn't true, in many common cases.
Another point regarding JITC compilation is that it can be for the exact target processor, something not typically the case for traditionally compiled programs.
All that said, current JVM performance certainly varies between 'better than C++' and 'worse than C++', with pathological cases in both directions.
The current 1.4 JVMs actually took a hit on some math operations, though that is supposed to be fixed in 1.5.
I hope gcj gets to the point where it supports the latest language spec. The libraries are tougher, and many of them aren't needed for interesting projects. For certain applications, an ahead-of-time compiler is nice.
By the way, for a good example of a 'fast' Java program, check out Eclipse from www.eclipse.org [eclipse.org].
Parent
Re:I'll care when native compilers become the norm (Score:5, Informative)
Parent
Re:I'll care when native compilers become the norm (Score:5, Informative)
Anyway, there is a plenty of native compilers for java. I'm not sure if you have heard about certain compiler from free software group called Antilope or something like this - I think it is called gcc. They have a frontend for java, gcj, which compiles java source/bytecode to same intermediate stage as other compilers, thus sharing optimizing backed. If you don't care about paying few bucks, JET is very good compiler, written specifically for java, supporting 1.4.1. There is also few others, but I can tell only about these two from my experience.
Both these compilers are available for few years now. Problem is not with lack of native compilers, or performance of java in mixed mode offerred by Sun hotspot - problem is with mindset of poster. If you are not willing to use java - no problem. But please say it is 'religious' - everybody will agree with you, as you can have any beliefs you want. But do not try to back up religious statements with fake arguments.
Parent
Re:I'll care when native compilers become the norm (Score:5, Informative)
Parent
Re:Finally... (Score:3, Informative)
Introducing new keywords may break old programs if they have a variable with a name identical to that of one of the new keywords. Using the colon sidesteps this.
Re:Java is passe (Score:3, Informative)
Java:
-Java as a language is not a standard but doesn't change much at ALL.
-Every API is developped through the Java Community Process
-C# + CLR is standardized (yes only a language and a VM)
-Other API's are NOT standardized and are in full control of Microsoft
I think that mono will have some major problems in the future. Sure they can implement C# and CLR, but they virtually have to reengineer all other API's, because there are no formal specs available.
Re:Java is passe (Score:5, Insightful)
How is that different from C++ and the Win32 APIs? The fact that Microsoft controls the Win32 APIs doesn't matter to me when programming in C++--I just write my code in Gtk+ or wxWindows. Likewise, the fact that Microsoft controls the
Furthermore, you don't need Sun-style central control over everything in order to get good cross-platform toolkits, as toolkits like Qt, FLTK, and wxWindows show. C# will have good cross platform support, either by successfully cloning
You see, the fact that C# doesn't come with philosophical baggage like WORA and "100% purity" is an advantage as far as I'm concerned. What WORA and "100% purity" has brought us is lousy implementations of Java on Linux, and APIs that don't even let me access environment variables.
Parent
Re:I doubt that Java will succeed. (Score:5, Insightful)
Java is growing. Its not horribly complicated and buggy like MFC and the win32api and your not locked in with
Corporations use Java for servlets and they use if for the built in libraries, low cost and portability.
Java is a great language and I am sick and tired of legalists complaining about it. First the LISP academics complained about Unix or anything non lisp. THe unix haters manual was a result of this. It went nowhere. Now we have smalltalk and Eifel purest who claim that everything else is inferior.
Your little world may be great in University teachings but in the real world they lack functionality and libraries to accomplish real world bussiness tasks.
Mono is very alpha and lacks many of the winform libraries that are mature on Windows. If you use it your asking for vendor lockin eventually which is Microsoft's goals. Look at the hasle SCO has made in the corporate world in regards to Linux? If Microsoft begins taking a similiar approach and everyone uses Mono then they are SOL. Its all Windows lockin. The microsoft version will always be better and more supported so your PHB's have a great argument to switch to Windows.
I chose to live in the real world and use what everyone else is using and that is java.
Parent
Re:I doubt that Java will succeed. (Score:5, Insightful)
That may change over the coming years with
Parent
Re:Too litttle, too late. (Score:5, Informative)
Without seeing (in the Java source code) how the templates are implemented I can't say that I agree or disagree with your statement that they will be inefficient, though I'm inclined to disagree based on your example. Templates or not, objects are going to be stored the same way. The difference is how those objects are retrieved. Right now you have to cast everything coming out of an ArrayList (unless the Object reference is sufficient)...not only is that being moved to the language but you also gain compile-time type checking. That will only serve to reduce errors and make the software more reliable. Templates are optional anyway - you don't have to use them. I'm looking forward to them.
I don't think you're ever going to see VM sharing. If applications can share VMs then one rogue app could bring down other apps by trashing the VM (never supposed to happen) or by poor thread management.
Either way you look at it, it's a good year to finally be going to JavaOne...
Parent
Re:Too litttle, too late. (Score:5, Informative)
Slashcode swallowed some brackets even though I was in text mode
What I mean is the following: If you create for example an ArrayList of ints, the most efficient way to store these ints internally would obviously be an int[] and not an Object[]. But even though java uses templates, it still stores primitive types such as int in an Object[], so there is a huge temporary object creation overhead. Whenever you store an int in your IntArrayList, a new Integer object is created on the heap and an old Integer object has to be garbage collected. In
The
"Templates or not, objects are going to be stored the same way. The difference is how those objects are retrieved. Right now you have to cast everything coming out of an ArrayList (unless the Object reference is sufficient)...not only is that being moved to the language but you also gain compile-time type checking. That will only serve to reduce errors and make the software more reliable. Templates are optional anyway - you don't have to use them. I'm looking forward to them."
Me too. It is not that I dislike the new features. I just think that they could have been implemented better, faster and earlier.
"I don't think you're ever going to see VM sharing. If applications can share VMs then one rogue app could bring down other apps by trashing the VM (never supposed to happen) or by poor thread management."
VM sharing does not mean that all java programs must run in one process. But for most desktop applications this would make a lot of sense. You are right about the thread management, but you could always restrict the number of threads an application can create. Just have a nice XML file which describes how much resources each application may allocate. That is the way
If sun will not do VM sharing, you will never see decent client applications written in java. Just think about it: for each java application you start, the whole swing library has to be JIT-Compiled anew. What a huge waste of processing power!
Parent
Re:All the features of C++ (Score:4, Funny)
Parent