×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Summary of JDK1.5 Language Changes

michael posted more than 10 years ago | from the better-faster-stronger-more-caffeine dept.

Java 839

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."

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

839 comments

enumerators (4, Insightful)

billnapier (33763) | more than 10 years ago | (#5919637)

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?

Re:enumerators (-1, Troll)

Surak (18578) | more than 10 years ago | (#5919669)

No. I totally prefer writing buggy, insecure garbage code, especially for Internet and P2P apps and such.

Re:enumerators (0)

Anonymous Coward | more than 10 years ago | (#5919684)

Considering Java's performance, I wouldn't bet against those enumerators staying as actual objects with an Integer object for a count.

Re:enumerators (2, Insightful)

Anonymous Coward | more than 10 years ago | (#5919720)

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.

Re:enumerators (2, Insightful)

MilesParker (572840) | more than 10 years ago | (#5919775)

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..

Re:enumerators (4, Informative)

customiser (150740) | more than 10 years ago | (#5919877)

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 [apache.org] to make it a bit easier.

Looking to Get Back into Java (1, Offtopic)

ackthpt (218170) | more than 10 years ago | (#5919646)

I worked in Java a few years ago and haven't kept up much with development kits, etc. The language I could pop right back into, but could use some advice on good/affordable IDE.

Re:Looking to Get Back into Java (5, Informative)

stevenknight (60620) | more than 10 years ago | (#5919660)

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

Re:Looking to Get Back into Java (1)

ackthpt (218170) | more than 10 years ago | (#5919674)

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

Thanks for the tip. The last IDE I used was Kawa, it was OK, but have no idea where it's at (in terms of function and features) these days.

Re:Looking to Get Back into Java (1)

KDan (90353) | more than 10 years ago | (#5919730)

In the non-affordable range, try JBuilder 8 Enterprise Edition. But Eclipse is pretty sweet.

Daniel

Re:Looking to Get Back into Java (1)

ChristTrekker (91442) | more than 10 years ago | (#5919780)

That's what we're using here at work. It's OK, but seems a bit flaky at times, to me. I'm currently wrestling with a corrupted XML file. No idea how that happened.

I haven't tried Eclipse yet (no time), but I've heard enough good things about it that it's probably what I'll use for personal development.

Re:Looking to Get Back into Java (4, Informative)

Schezar (249629) | more than 10 years ago | (#5919694)

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.

Re:Looking to Get Back into Java (2, Troll)

pygeek (649716) | more than 10 years ago | (#5919687)

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

*puts on flamesuit*

Re:Looking to Get Back into Java (0)

Anonymous Coward | more than 10 years ago | (#5919728)

i do agree, especially since the emacs from cvs is very pleasing to the eyes. I know thats not everything, but it sure makes it comfortable for me to learn. Emacs is just one of those things that can help in the future. maybe it wont, but hey its still versatile and powerful.

Re:Looking to Get Back into Java (4, Informative)

gray peter (539195) | more than 10 years ago | (#5919688)

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 [intellij.com] product. It's a few hundred $$$. Lots of folks like Netbeans [netbeans.org] and IBM's Eclipse as well (sorry, no url to eclipse, but I'm sure you can find it). The latter 2 are opensource.

Re:Looking to Get Back into Java (1, Informative)

Anonymous Coward | more than 10 years ago | (#5919702)

How does free sound? http://www.eclipse.org/

Re:Looking to Get Back into Java (0)

Anonymous Coward | more than 10 years ago | (#5919767)

I would also suggest eclipse. The lastest version 2.1 is really nice and is better than JBuilder in my biased opinion. I used to use the free version of JBuilder, but since I switched, there's no comparison.

Re:Looking to Get Back into Java (0)

Anonymous Coward | more than 10 years ago | (#5919815)

Use vim or netbeans.org
Both are free.

Emacs for Java (0)

Anonymous Coward | more than 10 years ago | (#5919821)

Check this out at IBM's developerWorks:
http://www-106.ibm.com/developerw orks/java/library /j-emacs/

Re:Looking to Get Back into Java (1)

p5 (102346) | more than 10 years ago | (#5919860)

You will want to check out jGrasp;

http://www.eng.auburn.edu/grasp/

Nice IDE, free, works with windows and about everything else.

Does nice things with projects and other stuff you might be interested in.

Re:Looking to Get Back into Java (0)

Anonymous Coward | more than 10 years ago | (#5919874)

If you're looking for a Java Programmers IDE (i.e. not one that has a Swing/AWT dialog designer type thing), look at IDEA [intellij.com] . It's worth every penny of the price. Eclipse [eclipse.org] is catching up to a lot of IDEA's features but doesn't stand a chance for a while to come.

My $0.02 C

Netbeans (2, Informative)

truthsearch (249536) | more than 10 years ago | (#5919878)

While eclipse is great, Netbeans [netbeans.org] 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.

Generics (3, Interesting)

boxhead609 (671383) | more than 10 years ago | (#5919654)

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?

Re:Generics (5, Interesting)

gray peter (539195) | more than 10 years ago | (#5919738)

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.

Re:Generics (1)

Caoch93 (611965) | more than 10 years ago | (#5919864)

I don't think that adding generics requires a change to the bytecode. IIRC, Java generics are actually just a pre-processing of the source to apply the correct type at compile time. The end result is that, at the bytecode level, nothing changes.

In many ways, I am actually for something of this nature. Runtime typecasting isn't the most efficient use of processor time, and this pushes back the type check to compile time. All in all, this should be a Good Thing.

I could be off my rocker on this one though. I have nothing to cite, and I'm only going by what appears in this strange thing I call my memory.

Give billg his due... (2, Insightful)

PHAEDRU5 (213667) | more than 10 years ago | (#5919657)

...he's forcing improvements in Java.

Re:Give billg his due... (1)

gl4ss (559668) | more than 10 years ago | (#5919696)

well, how else would billg get new features to rip into his .net_2005_gold_edition?

it's a joke.

Re:Give billg his due... (2, Informative)

rpk (9273) | more than 10 years ago | (#5919700)

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.

Re:Give billg his due... (1)

Chokolad (35911) | more than 10 years ago | (#5919747)

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

----
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.

Re:Give billg his due... (4, Insightful)

Hobbex (41473) | more than 10 years ago | (#5919810)

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.

Re:Give billg his due... (1, Informative)

Anonymous Coward | more than 10 years ago | (#5919893)

But don't forget that features like Metadata have been a part of Java for at least a year via the widely used open source XDoclet project. It's only now being added to the Java standard because XDoclet is so popular and it makes writing EJBs *a lot* easier. XDoclet's ideas about metadata came from the Aspect-Oriented-programming movement, not C#.

The idea of autoboxing came from C++ where you can define your own conversions. Autoboxing becomes necessary to reduce syntax clutter when you add Generics to Java. This is because the Java implementation of Generics only works for Objects, not base types.

Foreach and enum is in more languages than you can shake a stick at, so you can't say they came from C#.

The "static import" idea is new. If C# has it, then it's likely Java took it from C#. Other than that, I can't see anything that Java took from C#.

Re:Give billg his due... (2, Interesting)

Grievance (102243) | more than 10 years ago | (#5919822)

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.

Re:Give billg his due... (0)

Anonymous Coward | more than 10 years ago | (#5919718)

I am confused - how is BillG helping?

Generics are inspired by C++, and BillG still hasn't been able to put out a fully compliant implementation of generics in C++.

Programming shortcuts (5, Funny)

GGardner (97375) | more than 10 years ago | (#5919661)

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.

Re:Programming shortcuts (5, Insightful)

NReitzel (77941) | more than 10 years ago | (#5919758)

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.

Re:Programming shortcuts (2, Funny)

Angry White Guy (521337) | more than 10 years ago | (#5919841)

Makes for great job security!

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

Re:Programming shortcuts (4, Insightful)

radish (98371) | more than 10 years ago | (#5919862)

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.

Re:Programming shortcuts (3, Interesting)

eGabriel (5707) | more than 10 years ago | (#5919840)

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.

Re:Programming shortcuts (1)

f00zbll (526151) | more than 10 years ago | (#5919856)

this would be more funny if I never have to read another class that has everything in one method. it's still funny, except when I remember the times I've had to fix other people's code.

Everything must change... (1)

Toy G (533867) | more than 10 years ago | (#5919663)

... for the things remaining the same.

It seems to me that the suggested syntax for generics simply moves the pain from casting at retrieval time to casting at declaration time. That is, dynamic typing is still far away. Sigh.

Re:Everything must change... (3, Insightful)

Grievance (102243) | more than 10 years ago | (#5919869)

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.

Agreed.. (5, Insightful)

MilesParker (572840) | more than 10 years ago | (#5919671)

..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.

Re:Agreed.. (1)

Erwos (553607) | more than 10 years ago | (#5919746)

"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"

This hasn't been my experience at all. There's rarely ever any one right way to do things in any language.

Let's take a simple one in C: int x needs to become one larger. You get a few options:
1. x++;
2. ++x;
3. x+=1;
4. x=x+1;

All of them are "the right way" of simply incrementing x. And, if the simple stuff is this varied, I have a hard time believing that more complex code won't have similar divergence from "the one path". Java is similar.

-Erwos

Re:Agreed.. (0)

MilesParker (572840) | more than 10 years ago | (#5919828)

Sorry, I should have been clearer; let's say one "best" way. You know like on the SAT, when they ask you what is the one best word and two or three of them sort of fit?

In this case, the one righ (ok, best) case is always nearly always the simplest, least obsfucated and, most importantly, the most expected. In this case, that is clearly:

1. x++.

I'd be delighted to address more compex examples.

Re:Agreed.. (1)

stratjakt (596332) | more than 10 years ago | (#5919872)

each of your examples, by itself, is functionally equivalent, but completely different depending on it's use.

while (++i 10) { } (preincrement)

vs

while (i++ 10) {} (postincrement)

vs

while (i 10 ) { i+=1; } (assignment with register increment)

vs

while (i 10) { i = i+1; } (assignment)

They refer to the pre and post increment operators present on most CPUs and post increment with a register vs straight assignment in memory. C is inherently a lower level OS, and things like this are greatly useful when optimizing code.

In a high level pseudo-interpreted language like Java, it's useless. But it serves its intended purpose when it comes to systems level programming.

There's a fine line to be tread between orthagonality and optimization. Of course, these days, we just throw a faster CPU and more RAM at the problem, which is akin to "the door i bought doesnt fit in the opening of the house, so lets buy a new house"

Shortcuts (0, Troll)

xmutex (191032) | more than 10 years ago | (#5919675)

Unlike some people, I feel using programming shorthand leads to increased maintenance.

I hope you never have to look at any PHP; you'll go blind.

So basically C# minus generics (3, Insightful)

earache (110979) | more than 10 years ago | (#5919677)

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

Where are true properties though?

Re:So basically C# minus generics (1)

anonymous loser (58627) | more than 10 years ago | (#5919814)

You really don't want to underestimate the generics. This will make code so much easier to read and understand, as well as make it clear when you are using someone else's library that they expect that ArrayList to be of type Pumpkin, and passing in a few Pumpkins mixed with Legumes is bad.

So C# is basically Ada without strong typing? (2, Interesting)

coyote-san (38515) | more than 10 years ago | (#5919849)

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.

Longing for the good ol' days (5, Funny)

hrbrmstr (324215) | more than 10 years ago | (#5919683)

I remember - back in the day - when new language feature discussions weren't so contrived and "happy!"

Q: What's wrong with happy/contrived Q&A "articles"?

A: I was hoping you'd ask!

While humor and a semi-light tone are good ways to make technical discussions accessible to more people, treating folks like children who need to be entertained and talked-down to does more to alienate professional developers than it does to attract new converts.

Having said that, I am *really* looking forward to the "foreach" in 1.5 and the auto-boxing/un-boxing. While mucking with an established language is tricky - and potentially dangerous (from an acceptance p.o.v.) - the community process seems to be working out well for Sun and giving developers what they have wanted for years.

Let's just hope that the next "preview" of new features is more in the style of traditional FAQ's.

Wow, how intelligent (5, Funny)

Rombuu (22914) | more than 10 years ago | (#5919689)

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

Hell, lets write everything on fucking Turing machines then.

Write once, Rewrite forever? (1, Troll)

HidingMyName (669183) | more than 10 years ago | (#5919699)

This looks to me like they are changing a language so that existing apps no longer compile which is a bad idea. While I like many features of Java, I try hard to avoid authoring code in a language that has unstable syntax which results in a flux in the semantics. While it is O.K. to extend the language, the grammar has changed and many existing apps are not likely to compile without manual intervention (otherwise the compilers would be smart enough to figure it out). It is exactly this kind of "oh, we will revise the standard" years after the initial offering that hinders wide spread adoption, and opens the doors for the competitors (e.g. .NET).

Re:Write once, Rewrite forever? (5, Informative)

customiser (150740) | more than 10 years ago | (#5919765)

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.

Re:Write once, Rewrite forever? (1)

jjohnson (62583) | more than 10 years ago | (#5919778)

There's no mention of deprecating any language features. FUD, much?

Re:Write once, Rewrite forever? (2, Insightful)

Knight2K (102749) | more than 10 years ago | (#5919784)

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.

Re:Write once, Rewrite forever? (0, Flamebait)

Grievance (102243) | more than 10 years ago | (#5919786)

Are you retarded, or astroturfing? did you bother to read the freaking article? (duh, no.)

Nothing mentioned in this article should break existing Java code. In fact, the author specifically mentions (regarding 'enhanced for loops') that the designers are avoiding introducing new keywords where possible to preserve compatibility with existing code.

Re:Write once, Rewrite forever? (2, Insightful)

Ageless (10680) | more than 10 years ago | (#5919790)

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?

Does it have this feature? (0, Troll)

BillsPetMonkey (654200) | more than 10 years ago | (#5919701)

public class Sun extends Profitability
{
while (revenue < 0) {
versionNumber ++;
}
}

Re:Does it have this feature? (0)

Anonymous Coward | more than 10 years ago | (#5919770)

but isnt sun becomming irrelevant in the future of java?

i do like your code/joke, but how much is sun really important? is the JCP going to take full reigns or how does that all work?

programming shorthand (4, Funny)

nother_nix_hacker (596961) | more than 10 years ago | (#5919709)

I feel using programming shorthand leads to increased maintenance

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

Re:programming shorthand (2, Insightful)

Usquebaugh (230216) | more than 10 years ago | (#5919762)

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

Re:programming shorthand (0)

Anonymous Coward | more than 10 years ago | (#5919797)

If your post is any sign, the code was probably hard to write because you have a knack for leaving out spelling and punctuation. Compilers aren't as forgiving as your ./ compadres (excluding me).

rob malda DDOSed kuro5hin.org (-1, Troll)

Anonymous Coward | more than 10 years ago | (#5919750)

i am sick of this /. aggression. the time is now to take a stand for what is right. we need to preserve freedom and democarcy on the internet. i give rob malda 48 hours to leave the geek compound. then we will 'shock and awe' him into submission.

JAVA (1, Troll)

SpanishInquisition (127269) | more than 10 years ago | (#5919753)

the strongly typed language, that was good in 1996, now is weakly typed, now THAT's good in 2003, can anyone explain this to me?

Re:JAVA (1)

Ageless (10680) | more than 10 years ago | (#5919816)

How has Java become weakly typed? Many of the features that are being added are specifically to enforce typing.

Re:JAVA (0)

Anonymous Coward | more than 10 years ago | (#5919825)

What gives you the idea that it's weakly typed? They've added generics and type-safe enums, which strengthens the type system, and auto-boxing, which basically just adds a handful of implicit coercions. Other than that, there don't look to be any type-system implications at all.

Re:JAVA (1)

Grievance (102243) | more than 10 years ago | (#5919842)

Do tell what in this article transforms Java (*) into a weakly-typed language?

(* NB: Java is not an acronym.)

Re:JAVA (0)

Anonymous Coward | more than 10 years ago | (#5919845)

The problem is you have no idea what strongly typed and weakly typed mean. It's easy to find contradictions in the world when you make stuff up.

Much, much more than syntactic sugar (5, Insightful)

jameson (54982) | more than 10 years ago | (#5919760)

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.

Re:Much, much more than syntactic sugar (1, Interesting)

Anonymous Coward | more than 10 years ago | (#5919888)

Agree.

It will also make code easier to write in another way:

Modern java editors (in particular the almost magical Intellij IDEA) provide code completion based on valid types in a given context. The more the editor knows about the types involved, the better this feature will work.

Uglification? (4, Insightful)

oblom (105) | more than 10 years ago | (#5919763)

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?

Re:Uglification? (1)

ornil (33732) | more than 10 years ago | (#5919811)

But it looks like you don't have to use generics if you don't want to. Presumably it
simply defaults to Collection which is
exactly what we are used to in Java now. You
can then typecast to the real type if you prefer.

Read the article, look at examples.

Re:Uglification? (1)

ornil (33732) | more than 10 years ago | (#5919843)

I meant to say that Collection means Collection<Object>. Should have used preview :(

I agree (1)

rebelcool (247749) | more than 10 years ago | (#5919865)

These new improvements don't do much for improving readability (check out the enhanced for loop).

They may be useful, but they need to avoid C++ing themselves with hard to read shortcut characters.

Re:Uglification? (2, Insightful)

ptomblin (1378) | more than 10 years ago | (#5919881)

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();

Retro... (3, Interesting)

dance2die (596340) | more than 10 years ago | (#5919769)

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... :)

Generics vs Enumeration. (0)

Anonymous Coward | more than 10 years ago | (#5919772)

I feel the opposite. Enumeration types provide for strong type checking at compile time thus catching a lot of subtle bugs.

Generics worry me. Soon, someone will write something like ATL and we will have to have "Wizards" generating the code like for those poor COM programmers. As I understand it, Generics does not require a change to the byte code. The compiler just does checking and then provides the cast. In Java, all objects derive from Object and are allocated on the heap. Generics really doesn't provide the additional functionality that templates do in C++.

One line summary (5, Funny)

Anonymous Coward | more than 10 years ago | (#5919773)

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.

compilers never make mistakes? (5, Insightful)

cheezfreek (517446) | more than 10 years ago | (#5919785)

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.

not just sugar (4, Interesting)

Anonymous Coward | more than 10 years ago | (#5919796)

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.

Re:not just sugar (0)

Anonymous Coward | more than 10 years ago | (#5919889)

Python could come to the rescue here. Define __getitem__ and __setitem__ member functions, and then you can use the object with an index operator.

Shorthand programming (5, Funny)

Shamashmuddamiq (588220) | more than 10 years ago | (#5919798)

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)

FreeBSD Support (1)

rf0 (159958) | more than 10 years ago | (#5919820)

Don't suppose with this there will be a native FreeBSD port will there rather than having to patch and have 3GB have disk space free to compile it?

Rus

Hope it fixes issues with 1.4.x (1, Insightful)

cprice (143407) | more than 10 years ago | (#5919823)

1.4.x is rife with issues; corefiles or memory leaks (StringBuffer ToString anyone?). I sure hope that this is a stability improvement release rather than another round of 'improvements'.

Why I don't like Java (2, Insightful)

pygeek (649716) | more than 10 years ago | (#5919824)

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.

Re:Why I don't like Java (1)

Ageless (10680) | more than 10 years ago | (#5919848)

Did you miss the entire article, or what? Every single issue you mentioned up there is addressed in 1.5 and regex was added for your text processing in 1.4.

ClassCastException (1)

roalt (534265) | more than 10 years ago | (#5919831)

The upside is that if you try to insert something that's not a string, you find out at compile time and fix the problem. Without generics, you discover such a bug when your most important customer calls your VP to tell him that the program on which his business depends just crashed with a ClassCastException.

Please, please, tell me that there exists a company where the VP knows what a ClassCastException is!

Some quality stuff - competition is good! (4, Insightful)

Fnkmaster (89084) | more than 10 years ago | (#5919853)

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.

Those who don't understand Perl (1, Insightful)

Anonymous Coward | more than 10 years ago | (#5919876)

. . . are doomed to reinvent it.

foreach anyone?

null is zero?

That said, I've wanted Generics in Perl since the first week of using the language and I can't wait until they are available.

Disclaimer: I use Java professionally and Perl amateurly and I love them both.

An Extended Futile Example of Using GJ (1)

AlxBarker (672202) | more than 10 years ago | (#5919886)

By Yours Truly (Shameless Plug): (And GPL/Artistic'd to boot) http://freshmeat.net/projects/gjal/
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...