Java 1.5 vs C#
Here's the list of enhancements to the Java Language:
- Generics (C# 2.0 already supports this)
- Enhanced For-Loop (the foreach construct in C# 1.0, duh!)
- Autoboxing/Unboxing (C# 1.0 already has this, everything is an object, even the primitives - not really, but they do it so well...)
- Typesafe Enums (again C# 1.0 already implemented this, but I think they've added a little bit more twist in Java, that its actually a better implementation)
- Varargs (C# 1.0's params construct, ellipsis construct in C++)
- Static Import (I don't know if C# 1.0 has this, or C#2.0, but C# has a construct for aliasing your imports - which is way cooler. Static Import, actually promotes bad coding habits IMHO)
- Metadata/Annotations (this is C# 1.0's Attributes, Sun's upturned noses just gave it a fancier name - also, C#'s implementation is better and more intuitive)
They've beefed up the API some, and integrated several packages with the regular JSDK that used to be a part of a separate package or installation ---in my NSHO, the Java API has become bloated...
At this point (even before Whidbey) the deciding factor (as always) for Enterprise work, when choosing a language platform, should be the support it has behind it, in terms of IDE, tools, api, and longevity of the vendor pushing it (forget the OpenSource crap argument, those guys are too in love with Perl, Python, and Ruby - Java could become the child nobody wants to talk about if Sun dies) - right now that's C# and the .NET Framework ---
If you ask Paul Graham though, both language would be utter crap and fit only for idiots :) http://www.paulgraham.com/gh.html [I'm exaggerating, so hold off on those flames.]
Fix that first link. It shouldn't have a slash at the end:
a tu res.html
http://java.sun.com/j2se/1.5.0/docs/relnotes/fe
It's a bit unfair to compare the new Java 1.5 release with c# 2.0 since c# 2.0 is not due to be released until sometime Q2 or Q3 next year. But I do agree that before the 1.5 release Java had a lot of catching up to do to c#, but now c# is a bit behind (Mainly because of it's lack of support for generic classes which Java now supports).
Maybe it makes more sense to listen to what the tech lead of Java 1.5 had to say here.
(= Calvin Austin)
After templates (generics) come out in a few months, i dont expect java to have an easy time catching up.Personally, I really miss templates from C++ and would drift over to the camp that offers it.
The war with islam is a war on the beast
The war on terror is a war for peace
Perhaps /. will correct the error. I emailed the editor when the story was in preview, but it was too late.
Java has a few advantages over C# in optimization. It's very easy to analyze Java programs to be certain that certain memory locations absolutely will not be modified. That's much harder in languages with native pointers. Those invariants allow you to compile out certain calculations that would have to be done at runtime in a C# program. You can even start spreading loop cycles over multiple CPUs, but I'm pretty certain that the present JVMs aren't that smart.
CMDRTACO CHECK YOUR EMAIL!
XML Parser
You mean like JAXP and JAXB?
Attention deficit disorder is a complicated issue, spanning several major... HEY LET'S GO RIDE BIKES!
A quick Google for "java MD5" gives a code example in the first hit, http://www.bombaydigital.com/arenared/2003/10/10/1
Think before you whine.
It's not so much the language that is a question of contest, but the platform they run on. I've done Java programming since 1.1.8, and have deployed on Tomcat, Resin and Weblogic.
.Net? What the fuck is up with IIS (oh yeah, it's crap)?? Where is any sort of replicated server side session management (no, long ass hidden fields are *not* sessions - and a M$SQLServer *only* solution doesn't count).
.Net's deployment platform (singular). Man I miss working with J2EE platforms and loathe IIS...even though it is my job to keep all this stuff running on IIS! :(
Recently I switched to C# (new job) and I have to tell you, the language is pretty neat with some of the tricks you can do. Nothing ground breaking though.
What's really missing is the platform for release, and release management. Where are WARs and EARs for
The constructs and tricks of a language can be debated as long as you want. You will probably find something nice in every language. But when you have to [operationally] deploy any application, great or not, on some cheap as shit, crap ass, hard to manage, non-repeatable platform such as IIS, that's when the real rubber hits the road with Java.
J2EE deployment platforms are light years ahead of
-bk
ikvm.net ( http://www.ikvm.net ) is a java VM for .NET/Mono that uses classpath for the JDK API. It can also statically cross-compile java bytescodes into IL code. For example, you can compile a .jar into a .dll (even the resources are preserved).
/..sig file not found - permission denied.
So, were you trolling, or did you just not bother to keep up with Java?
Quick correction:
The XML APIs were part of a standard extension in 1.3. They were added to the core in 1.4. Also, I found the JavaDocs for 1.1, so here's a link to back up my statement that MD5 support has been around that long.
Javascript + Nintendo DSi = DSiCade
Trust me, we looked at that one. The "tool" can only be used in extremely simple circumstances and is not much more than a marketing trick from Microsoft.
Funny, we were talking about the 1.5 APIs last week here at work, while talking about migrating our apps over from 1.4.x. This site Official Java Programming Documentation gives you a ton to think about. I rem when we were on 1.2...
CB*($#@
free ipod and free gmail!
This is flamebait. If you have no need for seroius programming, this don't means others don't. And try to support 500 page site written in PHP and the same - in Java. There is a difference. Therefore, we need, Java. And, we need, C#. Ok, they are not ideal languages, but, they are more or less the best mainstream languages we have now. And, at least, they don't degrade programmers the way PHP do*.
Also, PHP STILL DOES NOT have anything that remotely resembles ide. Bad. Really, really, bad.
IntelliJIdea and Java allows me to be much more productive and write better code, because I don't have to live in jet another text editor with sintax coloring added just to call it an IDE. (they don't pay me. It's just a fact. I don't have to think about writing code or looking up variables, I can concentrate on functionality. And, no, I don't use wizards (especially since there are no wizards to optimize Java midlets code to bytecode level))
But, please remember, each language is for it's own purposes. Why being interpretated (PHP, Perl, Python) is better than having virtual machine?
From my point of view -
Java. A nice language, but the API sucks. It's ye good old SUN that develops MIDP standart and forgets to add function drawPixel to canvas.
C# - Also, quite good, language. Lacks proper operating envorement, is too closely tied to M$ api, but a really good one anyway.
I can work in both. Just as in LISP, Python, PHP, C++ or perl. None is better, each is more suited for it's own tasks.
le fin.
*About PHP degrading developers - Unfourtonately, I has to say, a lot of students coming out of university choose to work with PHP firsthand. It's web developement, it's easier to get first job there, et cera. But, once starting to learn PHP, quite soon they are incapable to think about software design and how their code works. Maybe because programming with some kind of architecture in PHP is a pain in the ass task and nobody knows how PHP code executes in real life?
I think you've completely misunderstood polymorphism and/or varargs.
I've never, ever had to write a Java method that would have been better implemented using varargs, but I've written plenty in C and C++ in the past that would have been better written without them...
I can only think of a couple of cases in Java where varargs would actually improve matters (have a look at MessageFormat, the work around it uses to emulate varargs is painful so varargs would be great there). But I just know varargs will get horribly absued: so overall I think Java was better off without them.
Personally I think that, overall, Java 5.0 is a mistake. Metadata is already going out of fashion: Google for "metadata hell" to read why. It's a passing fad that's passing. Autoboxing/unboxing *shrug* nice when you need it, but how often do you actually need it? Generics/templates was something I missed when I first moved from C++ to Java 10 years ago: but now it feels like more unnecessary complexity.
So overall it seems to me the 1.5 changes address some limited circumstances at the cost of additional complexity; and no doubt we'll see them mis-used and abused and that will outweigh any benefit by an order of magnitude.
What they should have done in 1.5 is strip out all the deprecated crap: Sun has this habit of constantly adding layers but never actually removing the old stuff. I really would hate to be learning Java now: it's so bloody big!
Bad analogies are like waxing a monkey with a rainbow.
The comparison only lists some baic language features, it makes no any sense! Java is NOT only a lanuage, it's a platform, it's a system, it provides all kinds of solutions for your desktop, network, micro device and enterprise web service.
"For my own opinion I prefer unchecked exceptions as the code is far cleaner. "
No, the code will just appear cleaner. Hiding exception propogation is an invitation to ignore exceptions. If someone wraps code in a single catch, you can at least see where they've been sloppy. The equivalent in a non-forced exception check is to do nothing, which is invisible.
C# doesn't really compete directly with C++, it competes with Java.
XML causes global warming.
Ditto. I'd go so far as to say that .NET has some of the same bugs as the MS JVM and class libraries, especially in the networking support, where Java is streets ahead.
Basically, Sun did a bunch of things they could do without changing the VM too much and without breaking old code. But for a bunch of other features, they punted and just added a bit of syntactic sugar to the compiler that makes Java look superficially like it's doing the same thing but is much less efficient under the covers.
For enterprise applications, those differences may not matter much (and they may even be harmful), which is probably why Sun doesn't do anything about them. But for desktop use and application programming, they do matter. Microsoft wanted to create a new language that their legions of C++ programmers could use, and C# is a pretty credible answer for that. Those people don't care about cross-platform features, they care about getting the job done, and if that involves the occasional unsafe module, it doesn't matter to them.
If I am not mistaken MS helped Mono out on their C# implementation.
In the driver arena this the prefered solution to having a closed official impementation. I would assume it is the same for the sake of a language also.
Wow, sent an e-mail as suggested when clicking on "use classic" banner, and got a fast response that addressed my msg
You state that .NET development implies having to purchase VS.NET which makes .NET inferior to Java where you can download the SDK for free and a third-party IDE for free. However you completely ignore that the .NET SDK is also freely downloadable and that there are free third-party IDEs, such as SharpDevelop. As such both stand on equal footing despite your FUD attempt.
As for docs, you find it easier to use JavaDoc because that is what you learned. Those who learned MSDN find that much easier. It has little/nothing to do with the completeness or organization of either documentation.
LoL... Write Once, Run Anywhere.... good one there... Java is Write Once, Debug Everywhere. Once you commit to one JVM, you are pretty much locked in because of the incompatibilities in other JVMs. A number of groups are using C# developed apps on both Windows and Linux without any issues at all (as long as the code uses GTK#).
There are C# development environments on other platforms... Linux for example (Mono) and one can even use Rotor on other platforms. And... at least C# is an open standard.
that I dont care which a client wants anymore. Its like asking for 6 of one and a half dozen of the other. I had been afriad of learning Java for ages but knew C# very well. Then I forced myself to learn Java and as soon as I got into it I kept saying "Wow MS copied Sun!"
When you think about it though good OO concepts tend to evlove toward similar goals. Languane and usablitly concepts are the same all around. Its to the point now where the differences between Java and C# are more syntax and available libararies. Ive even been able to easily port Java to C# and vice versa since the languges are so similar.
It has defintaly opened up things more for me, as now I leave it to the client as to what they want. If they are an MS shop then C# is an obvious choice if they use Linux or perfer alternative platforms then Java is obviously what you should build in.
"Don't mess with him, he taunts the happy fun ball."
it just does not force you to declare and handle checked exceptions, an issue of strong contention within the Java community
Um, Java supports both checked and unchecked exceptions.
Irritable, left-wing and possibly humorous bumper stickers and t-shirts
C# vs Java, mostly a tie (c# good: ref and out parameters, indexers, foreach; c# bad: properties, operator overloading)
c# library vs Java library: c# is much cleaner in some aspects.
VS.net vs Eclipse: no contest, VS.net is much worse.
I've looked at most of the posts, and I haven't yet seen someone mention about the pointers and memory allocation that can be used in C#.
This is where Java and C# differ.
Java doesn't have these features and most likely will not have them any time soon.
Of course when using them in C#, you have to label the those areas of code using those features as unsafe.
"Two wrongs don't make a right, but three rights make a left."
"Two wrongs don't make a right. But three rights make a left!" - Cosmo, "The Fairly Odd Parents"
.NET in the enterprise is currently painful.
It's not about the enterprise, it's about the desktop. Microsoft had to do something there because C++ and MFC and COM was seriously getting in the way of getting the job done. Java isn't even trying to compete seriously on the desktop, so C# wins by default on the desktop. And (crazy as those people may seem to you and me) Microsoft desktop application developers actually seem to like Visual Studio. If Microsoft can additionally win market share from Java in the enterprise, that's icing on the cake for them.
Granted I've only used a few IDEs (VS6, VS.Net2002, VS.Net2003, Tornado for vxWorks, Xcode, Kdevelop & ddd), but of all VS.Net is cleanly the easiest to get things done in overall.
I did not find Kdevelop or ddd particulary more useful than vi other than having been weaned on VS6 I am simply more comfortable with a GUI than a tty.
Xcode does every part of project management and structure more correctly than VS in my opinion. The idea that your source tree is separate from your targes and that your targets are separte from your executables just makes sense. There's a lot less special cases this way.
Tornado for vxWorks (ver 2.2.1 IIRC, its been some time since I used it) is a poor copy of VS6 -- possibly more correctly VS5 or 4, but I've never used those. The one thing that Tornado got right is the remote debugging (e.g., you build a vxWorks system, load it onto your embeded system, and you can debug through your app via ethernet, serial port, or a local pci bus). In fact, without the remote dubugging I would have considered Tornado to be utterly useless.
The things that set VS apart is its build styles and debugging features. Xcode could catch up on the both of these (esp. the build styles), but I'd say gdb has a long way to go to be on the same leve als VS's debugger. Its really nice to be able to add new code, change existing code, and arbitrarily set the execution pointer. Really the 'advanced feature' I've figured out how to replicate on gdb is changing a variable's value, but even this feels rudimentary to how in VS you can arbitrarily change the contents of memory directly.
So, in short, what I like about Visual Studio is its build styles and debugging capabilities. But I do think Xcode 1.5 is better thought out, just not as polished in these two areas.
I should add that all this does not apply to any APIs of the aforementioned products, in which I would agree with you (having used MFC, ATL, COM and WIN32), I don't see why informed person would choose these over the alternatives (wxWindows, stl, boost, Cocoa) if they had a choice.
"Dying tickles!" -- Ralph Wiggum
Java has checked exceptions
exception management in c# is so painful without them
Well, I think some people might be trying to help Java compete on the desktop. Have you heard of SWT and Eclipse? It does have IBM behind it. I agree that Sun seriously dropped the ball with desktop Java for years, so nobody used it for that. As for developing desktop apps in C++, yes Visual Studio 6 was a very solid choice. Is VS.NET as good? Many people seem to think not. I haven't spent enough time with it to know, and don't really have the desire to.
Java has had a way to write "unsafe" code from day 1.2. It's called JNI. Write your unsafe code in an unsafe language and hook it in with a dll.
You haven't been writing many cross platform applications in Java recently have you? I've been writing large, complex applications that must run on Windows, Linux, HPUX, AIX, OS/400, and Solaris for 6 years now. When I started, your statement was true. However, this has largely become a non-issue. Throughout testing we rarely come across a bug that is specific to a single platform or JVM as long as you use a robust JVM like Sun's or IBM's.
While you still need to test on all platforms just to be sure, 98% of the bugs found are in the Java code, not the JVM.
10 minutes working on a sig. What a waste.
I'd be tempted to buy into your argument if I didn't know someone who codes VOIP applications in C++.
There are books out there (Effective C++ series) that discuss how to write code so the compiler generates intelligent errors messages when it barfs on templates instead of the usual gibberish. Books that teach crazy, convoluted macros and #defines that allow you to do compile-time checks on template code, etc. Plus, the STL is buggy when used in concurrent applications.
You can learn the basics of C++ in a few weeks with Stroustroup's book. The advanced stuff takes years to learn and even longer to learn how to use effectively. I won't even get into the issues you run into with a build system for C++ code.
The problem with C++ is that it's too fscking complicated to use. Granted, there are a lot of idiots that think they're C++ coders because they could compile a Hello World! application, but they're not the sole issue.
I've done enterprise-level Java and C# implementations for financial institutions, and reckon there is one thing that people always miss when comparing the two languages: installation.
C#, despite any other flaws, Just Works(tm). Install Visual Studio, write some code, click the run button. Sure it takes a bit of thinking to get a n-tier implementation up and running properly, but the installation of the back-end stuff (IIS, db connections, remoting) is incredibly simple.
On the other hand, to get enterprise Java (J2EE, although some would argue that a class library is easier and more versatile), you need to learn how to install an app server (JBoss, Orion, or god forbid WebSphere), and how to configure that system for database connections, performance, session and object permanence, etc..
None of this really matters in a 'big-iron' enterprise environment, because there's room to hire a websphere monkey to look after the cat-herding. In anything below a mega-corp or mega-bank however, the overhead of running Java can sometimes be a burden that developers just don't want to think about.
I see it kinda like using Firefox over IE. They both do pretty much the same thing, and one does it 'better', but at the same time requires some effort to implement. Some people just can't be bothered with the effort.
gadgetophile.com
Seriously, I tried most of the IDE's you mentioned and then some, but Eclipse just blows them all away. The fact that it builds a complete syntax tree of your project which can basically be queried in any way you see fit makes refactoring so easy. It can rename method calls for an entire project, add new parameters, reorder parameters, change return code, display what methods call what method in tree form (especially if you suspect the code is dead), displays lots of very useful compiler warnings (unused parameters, variables, methods, unneeded casts, often surprising how many you can find of those in non-Eclipse projects and the possible subtle bugs they introduce). That's just scratching the surface really... it's very evident that Eclipse was written by programmers for programmers, and even after using it for more than a year it still manages to surprise me :)
while (!asleep()) sheep++
Sometime in 1999 after I'd worked at Sun for about a year, a routine all-hands meeting was held for all of the Java Software division. JDK 1.1.8 was the current version of Java on the street and JDK 1.2 was in the works, almost ready for release. We sat there and listened to the usual rah-rah speaches from the divison's head honcho (can't recall who it was at the time), and then he introduced us to a marketing guy to tell us about the launch for JDK 1.2. As he begun talking he displayed a new slide on the project and it read, in all its powerpoint glory, 'Java 2000!' And he went on to say that the new JDK would be called, not Java 2, but Java 2000. Everyone in the audience started laughing hysterically. We all thought it was a big joke. I mean, Microsoft was on the verge of releasing Windows 2000, so you don't really mean.... Turns out this marketing guy didn't have much of a sense of humor. "I'm not joking", he said. The laughs and knee slappings turned into boos and hisses. Head honcho guy says something like the marketing guys have worked hard on this and that's the name they've choosen. The Q&A session was next and, boy, did both of these guys get an earful! Anyway, I can't say for sure, but I think that had it not been for the outrage and disbelief at that all-hands we'd be stuck with even weirder Java naming convenstions today.
Rich
Behold BigInteger and its evil twin, BigDecimal. They laugh at silly-big numbers.
"Honey, it's not working out; I think we should make our relationship open-source."
Interfaces are your friends. Most of what people use multiple inheritance for can be achieved by using multiple interfaces.
That is not what generics do, that's what your base collections of type object does. Generics (at least in c#) allow you to write templated code like
where T is the type parameter. it actually comes time to create a List object, you say List or List. Now your list is a type safe list of ints or Customers, instantiated at runtime. You cannot mix ints and Customers in the same list.
The Java implementation is a compiler hack. It casts everything to objects, so in theory you could mix because it's just a compiler trick. Worse because everything is really an object you can't reflect over the List and work out what type it is a list of.
"I want C# on my *N*X/Window box"
http://www.go-mono.com/
"I want Windows.Forms support on my Mac/*N*X/Windows box"
http://www.dotgnu.org
If it's a choice of language based solely on the portablity of code, C# wins out IMHO. With Java, you're dependant on Sun to support your system, which is a royal pain. (as anyone with a *BSD box will tell you)
I did some tests and the benchmarks are really interesting. C# performs incredibly fast compared to Java. I didnt expect that much difference - may be I am doing something wrong...
Java Code:
public class Test1 {
public static void main (String [] args) {
ArrayList<Integer> l = new ArrayList<Integer> ();
System.out.println ("Started.");
for (int i = 0; i < 60; i++)
{
for (int j = 0; j < 1000000; j++)
l.add (new Integer (j));
l.clear();
}
System.out.println ("Ended.");
}
}
C# Code:
class Program
{
static void Main (string [] args)
{
System.Collections.Generic.List<int> l = new List<int> ();
Console.WriteLine ("Started.");
for (int i = 0; i < 60; i++)
{
for (int j = 0; j < 1000000; j++)
l.Add (j);
l.Clear ();
}
Console.WriteLine ("Ended.");
}
}
Java took 23 seconds to complete on an IBM Thinkpad T30 with Pentium 4M 1.8 Ghz.
C# took 1.5 seconds.
First, I want to say that I am not an expert C# or Java programmer. I use C++ mostly, and I really dont know which collections are best suitable for this job in each language. I used LinkedList and ArrayList in java and ArrayList performed 2 times faster than LinkedList. Similarly, I tried LinkedList and List in C# and List performed better than LinkedList - so I compared ArrayList in Java with List in C#.
Also, instead of adding 1,000,000 items in a list, I tried adding 10,000,000 - but java gave me an out of memory exception. I tried it with 2,000,000 and I got the exact same error. C# worked fine with larger numbers - I tried C# with 50,000,000 and it worked fine.
While 'ref' paramters are debatable, 'out' parameters are stupid. They should have created a way to return multiple values from a function. Allowing first class tuples would have been the correct way to do this (in most C-style languages, tuples are allowed as arguments to functions and disallowed everywhere else). Adding tuples would also have eliminated the need for the hacked up delegate functionality. Then again, Java doesn't have any equivalent functionality, so it could be seen as an advantage for C#.
Operator overloading is a good thing. It can be abused, but so can anything else. Removing operator overloading doesn't even come close to making it impossible to write obfuscated code. There are many situations where operator overloading makes things a lot simpler.
Properties are also good. Instead of identifying them through string matching ("get*", "set*"), language-level support for properties allows more accurate data type modelling. In the end, however, the CLR doesn't really have true support for properties. They implement them as methods (like Java, except at a lower level so most programmers don't have to care about it). This implementation mistake resulted in different opcodes for field access and property access, which means you cannot switch between fields and properties without changing the class's public interface (and breaking binary compatibility with client code). It's still better than what Java does...
Function pointers and anonymous functions. This has got to be the biggest improvement over Java. Unfortunately, class libraries were already designed before the anonymous function feature so they probably wont be designed to take advantage of it. Also, VB and C++ are probably holding things back because, as everyone knows, "language agnostic" is just a euphemism for "lowest common denominator".
You also forgot generator functions. They make it easier to write pull-style classes (a "pull" XML parser, for example). Though it isn't as powerful as full-blown continuation support, I think it'll still be useful for many coding tasks.
C# has more comprehensive generics support (aside from variance). Though both languages made the mistake of allowing arrays to be fully covariant (ArrayStoreException), Java got screwed when they decided not to maintain dynamic type information for generic type parameters. This limits the use of generics in often confusing ways. Type erasure isn't a problem in languages that have a good enough type system to avoid resorting to dynamic typing (like ML or Haskell). But C# and Java do not have good enough type systems and the C# people recognized that and chose to keep the dynamic type information around.
C# is better than Java in almost every way. Java has better enums and support for covariant and contravariant generic type parameters, but that's about it.
If you've ever had to program in J# you'll know that it isn't s stepping stone, it's more like a pit of despair.
.NET to Java abstraction layer. It just gives up on some issues cross language issues (like the signs of integers).
.NET. But honestly, with the headaches it's given me, my advice is to just bite the bullet and either port the dam thing to real Java or real .NET and relieve yourself of this bastard child of Satan.
The compatibility is ancient, and it's maintained by a klunky
The only sane person who programs in J# is someone who is forced to port old Microsoft Visual J++ to
J# is a bad April Fools joke.
Bzzzzzzt.... Wrong answer!
Interfaces are _not_ multiple inheritance. They're virtual classes. You can emulate multiple inheritance with interfaces and a stub for every inherited method, but this is _extremly_ tedious.
An anonymous inner class in java can only refer to final variables from the local scope. So you define a final array with one element to copy something out of the inner class context.
l Limitation
Here is a good example:
http://c2.com/cgi/wiki?ClosuresThatWorkAroundFina
Private property is the central institution of a free society (David Friedman)
Free C# compilator? Right here: .NET Framework SDK
.NET 2.0, go here:
.NET Framework 2.0 SDK
Or here: Mono project
Free IDE? Here: Sharp Develop
Or, if you want to test
As you see, you don't have to pay anything to try C#; since you say you're convinced, go for it!
Also, another piece from Bruce Eckel here. This is even more clear in its skewering of Java Generics. It really sounds like Sun dropped the ball on this one.
C# is just one option for .NET eh?
Hmm... if only there were some other languages that could be compiled to JVM bytecode.
Say Amen!
Just because operator overloading can be used for evil is no reason to throw the baby out with the bathwater.
Java lacks a Currency class, so I wrote a Money class some time ago that I use for common financial calculations, and it takes care of the pesky problem (and newbie mistake) of using floating point types for money.
BUT, in Java, you have to have add(), sub(), mult(), and div() methods. Reading RPN style caclulations consisting of sequenced and nested method calls instead of algebraic operators is painful. Operator overloading is wonderful in those cases.
Operator overloading certainly can be evil: What does it mean to increment an Employee? Do I really want to know? But for new types that you can actually do algebra with, it is quite helpful.
And there are other cases.
In my C++ days I wrote a FileHash class that kept an index of offsets to the start of each text line in a text file. Then I overloaded the array subscript operator so that a text file could used like an array of char pointers (or a String class if you liked). That was a perfectly good use of overloading.
Moreover I think overloading the array subscript on ordered collections also makes perfect sense.
I often wish Java had this feature. I agree with every simplifying choice they made except this one.
For covariant and contravariant exist several definitons depending on context (inheritance versus template parameters, e.g.)
Suppose you have a class like this:
class A {
A method() { return new A() }
}
And another class like this:
class B extends A {
B method() { return new B() }
}
This construct is called covariant. The class B is ingeriting from A, while the method method() is overwritten in B. Not only is the mthod redefined but also the return value is. As it is redefined to the taype of the class, this is called covariant.
If the method in A would return a B and the method in B an A, it would be called contravariant.
For template parameters there are similar definitions, but they are a bit more complex.
angel'o'sphere
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
this guy wrote an interesting list.
read the 101 reasons
here
>Can somebody explain what you mean by the covariant and contravariant things.
...=foo.ft(ba)
In an OO language with objects and types we may say that a type, ST is a subtype of T.
The meaning of this is that an object of type ST can be used where an object of type T is expected.
Objects of type ST can have more operations (functions) than objects of type T, but it must have the same operations as objects of type T. These operations must have the same number of arguments and results as operations in T. But the arguments to those operations does not necessarily have to be the same type.
Say T has an operation (signature): ft(a1:Ta) -> (r1:Tr)
ST must then have an operation: ft(a1:STa) -> (r1:STr)
Results are easy. A program that do:
foo:T
bar:Tr = foo.ft(...)
requires that bar have a type that are a subtype of Tr therefore
STr must be a subtype of Tr.
Arguments are more tricky: A program can do:
foo:T
ba:Ta
foo can be of type T or ST therefore ba must work as an argument to ft in objects of type ST.
This means that Ta must be a subtype of STa.
This is contravariance.
One consequense is that Array[T] is not a subtype of Array[ST] or the other way around. Because Array (or any other collection) must have both a set(T/ST) and get->(T/ST) functions and because of contravariance T must be a subtype of ST and ST a subtype of T, i.e. T==ST.
It does not work quite like that in Java, because in the foo.ft(ba) the "ft" function defined in the base class, T, would be used.
But in Java an array of a supertype is considered a supertype of an array of the subtype.
Object[] objects = new FooClass[10];
objects[0] = new Object();
Will give a runtime ArrayStoreException
Pure and utter FUD
m icrosoft-deliver-64-bin-dotnet/view
.NET for 64-bit Windows 2003. Infoworld in a recent analysis explains:
.Net Framework means that the hard work many Windows developers have put into migrating to the .Net development model is for naught on Windows on Itanium.
from http://www.manageability.org/blog/stuff/why-cant-
Despite having a research and development budget that is almost 7 billion dollars a year, Microsoft apparently can't deliver
The lack of a 64-bit implementation of the
In the meantime, IT shops that wish to employ 64-bit Windows as an application server or Web services platform will be forced to revert to the older, Windows DNA (Distributed Internet Applications) environment.
In stark contrast, BEA Systems and Sun have been shipping JRockit and J2SE with Itanium support ever since JDK 1.4.1 was released. Furthermore, according to the reports 64-bit Opteron support is expected at the same time JDK 1.5 is released.
The CLR VM knows about generics so it can safely get rid of the casts. The Sun idiots chose not to modify the JVM bytecode to accomodate generics, so the casts need to be there. You don't see the casts because "javac" inserts them for you, but they're still in there, doing what they do best: kill performance.
While the 50%-70% improvement is definitely not typical, if you do some intense algorithms on collection classes, then you'll probably see that kind of speed up. Just don't expect that kind of speedup for a real-world application.
You press CTRL-Break. It's undocumented but it works, even when you're surrogate-debugging a COM object.