Java API and Microsoft's .NET API: a Comparison
Nerval's Lobster writes "Previously, developer Jeff Cogswell focused on the respective performances of C# and Java. Now he's looking at yet another aspect of the languages: the runtime libraries—what exactly the libraries are, how they are called, and what features the languages provide for calling into them. Examining the official Java API (now owned by Oracle) and the official .NET API owned by Microsoft, he finds both pretty complete and pretty much a 'tie' with regard to ease-of-use and functionality, especially since Java version 7 release 6 allows for automatic resource management. Read on and see if you agree."
Whoever wins, we lose.
Get free satoshi (Bitcoin) and Dogecoins
However, I mostly code in C# .NET and I dabble in Java in my spare time to model financial markets. What I have found is that C# has some powerful features that other languages do not have. This allows the .NET framework to be a little more robust than Java. Also my opinion is that C# and .NET creates a more syntactically elegant and coder friendly experience whereas Java is good, but not as good as .NET.
In closing, C# .NET > Java.
Please address .NET hate-responses to /dev/null
Try download that
Damn my Java client!
As much as I like Java, there's a few obvious features that it's somehow still missing:
C# has all of these, of course.
There's no -1 for "I don't get it."
C# was the direct result of MS being blocked from using Java, and was their J# product re-branded into .net. The core is nearly identical with the exception that C# has access to things like DirectX, and a few other nice to have APIs from MS
C# does not appear to have 40 Critical bug fixes every quarter like Java does either. The latest Java update has caused a _lot_ of business systems to crash.
Once I was a four stone apology. Now I am two separate gorillas.
As they are the harbingers of the new age, post dotcom world, where overspecced hardware fixes everything, where there are legions of entitled douchebag "developers" who took a certification course, and of apps which can't run in less than 8GB of memory (our resident BOFH hung up on our developers when they asked for a 64GB VM because they kept getting OOM errors in Java).
In short, both languages rode the crest of the cultural revolution where it is now OK to suck, to offshore code development with no expectation of quality coming back, of "agile" methods where your next version is always going to be the stable one. I'm not exactly saying that these languages CAUSED any of this, but there is at least a temporal correlation.
Yes, I am a Unix guy, and yes, I have grey hair.
I want to delete my account but Slashdot doesn't allow it.
Async methods (huge!)
Generator methods
Partial classes/methods
Reified generics
LINQ (as in LINQ to objects, LINQ to Entities, LINQ to XML - all part of the core framework)
Dynamic typing and -interop
Value types
Operator overloading
Implicit/explicit type conversions
Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
Lack of brain stems
I use both, and I find that .NET really shines when you're in unfamiliar territory and working with a part of the framework that you don't touch every day. Features are more easily discovered and idioms tend to be more consistently applied in .NET, whereas it feels like Java suffers from implementers applying the pattern du jour, forcing you to wade through more docs.
I attribute much of .NET's success in this regard to the absolutely awesome book "Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries," which includes a lot of direct insights from the designers of the framework. Microsoft has been really good about sticking to those guidelines, and it shows.
http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321545613 ...or maybe I just understand the .NET Framework better because I read that book. I'm not aware of a Java corollary that would give me the same insights, though.
Try to develop a Web app in .NET and run it on Linux server (translate: .NET is Windows only. who can afford that these days?)
2003 called, it wants its article back.
Don't blame me, I voted for Baltar.
Both have big APIs.
The bit at the end about type erasure in Java is either misleading or incorrect. For an explanation that doesn't suck, see here:
http://docs.oracle.com/javase/tutorial/java/generics/erasure.html
.NET devs make more money.
You could do it in apache in mod_mono - it would be c# at least though not strictly speaking ASP.NET .NET for you?
does that count as
This. .NET-Framework:
Also, I got a nice anekdote about the
Today I got to do XML processing. I needed to get the entity definition of a documents doctype.
It's totally possible to get that entity name - but it's not possible to get the content. To illustrate:
Entity:
Content:
(child-a|child-b|child-c)
So a coworker of mine used ILSpy (a .NET-disassembler) and we found out, that this content is saved in a private string.
The method InnerText was left unimplemented.
So my coworker used some funny introspection workaround to get that private field.
WFT, Microsoft?
Java has this kind of doucheness, too. Compare Unicode vs. property ISO-Encoding, for example.
You can add lambda expressions as well, although, that's coming in JRE 7, no, 8 maybe.
Yup. I actually forget how often I use those.
Recently we have also seen expression trees put to good use, e.g. in Entity Framework code first to define relations, keys etc.
Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
I'm wondering how a comparison of the event models got skipped. Rather useless article.
I object to power without constructive purpose. --Spock
I'm wondering how C# async methods got skipped. Because there's nothing similar in Java?
Async/await is huge. It makes composing async methods as terse as regular synchronous code. Unlike with the library defined task/future models, async/await adds a composable model which lets you write async methods that can loop, branch, try-catch etc. while staying perfectly async.
Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
What an asshole.
So my coworker used some funny introspection workaround to get that private field.
WFT, Microsoft?
Did you think that the private modifier is a security feature?
...over all these wonderful features of both languages. And here I am, a mobile developer on the vanguard of technology, still stuck with dumbshits that suggest maybe we ought to somehow shoehorn ourselves back into JS.
I can hear them now: "Here, just use this mile high stack of libraries with hipster names and it'll be workable, I swear. It really is a functional language, and the New Assembly, after all. P.S. CSS3 Sucks Less(TM)!"
Forgive the troll.
WTF are/were you using for the XML processing? If you are using stream processing on an XMLReader, you will get some quirkiness... I find that getting the XML string for a given node (in, for example a larger stream with lots of the same node) then parsing each node into an XElement for handling logic against works well enough.
Fuck the api, lets compare developer salaries.
TFA is moot .. that's like comparing the Boost C++ libraries to using C++.NET .. every 'API' has a it's own set of functionality that a developer needs to know and understand in order to use ..
C# has delegates/events which allow me to attach certain areas of code to other via (obvious) function pointers .. Java doesn't have (obvious) function pointers, instead 'everything is/has something' is the model. Want to catch when a window is closing? In Java: implement EVERY window 'event' that 'window' (JFrame as it is) interface defines ... In C#: just create a function with the same signature as the event and assign the function pointer to it
Also, why did the original Java language developers decide to go against the grain and forgo the ability to have 'unsigned' values .. Want to know if an 'int' is above 3 million? Cast it to a long first then check
As has been stated before too, Java (the language) forces you to do certain things .... Have a static function that you want to let other developers know could throw a specific error? Attach 'throws' on the end of the function declaration ........ oh wait, now EVERYWHERE that calls that code either has to rethrow or try...catch ....... Yes, let's enter an entire new try...catch context just to do a Thread.sleep .....
Java as a language has certain constructs that need to be observed just as the C# language does (just as the C, C++, JS, PHP, HTML, or any other language for that matter) .. as with the API's .. well they both give my jr. guy's enough rope to hang themselves so meh to both of them ......
Personal preference is C# for RAD or quick prototyping .. then C/C+ (with cross platform frameworks) for anything else ... Java is a bane .. not as a language or API, but to read and maintain ...
They serve absolutely opposite purposes. Java is all about cross-platform support. .NET, on the other hand, was created by Microsoft for Microsoft lock-in. Don't even start about Mono.
The shop that I work for develops software for 5 platforms: Windows, RHEL, HP-UX, AIX, and Solaris. For our core performance demanding jobs we code in C++. Everything else - mostly Java + few scripting languages. .NET is simply not in our lexicon for a good reason. It would be utterly useless for us.
I was hoping to provide some insights, but the article is just riddled with misunderstandings. I stopped reading after this line:
"Generally speaking, the API makes use of properties in the case where you supply a class or object; but the classes in the API typically donâ(TM)t make use of properties."
No, not at all. Properties are used pretty much everywhere in the API. Examples abound with get only properties (ahem Length?).
Methinks Mr. Cogswell is in way over his head. Language design is not an easy subject, and it requires more than a cursory glance for the perspective of everyday programming.
As others have noted here, C# does seem to be adopting more language features. And, having used the new async programming model, I have to say C# has taken a noticeable lead in useful features.
Nothing prevents Java from doing the same, but given the slow progress of implementing and adopting things like lambdas, I can't say the future of Java will look all that different than today. Which is too bad; there are new ideas that are worth the effort.
How can you call it a tie after listing tons of features that java doesn't even have? C# is the clear winner with the following features that are lacking in Java: -Properties -REAL generics (not type erasure) -async/await -value types (struct) -the ref and out keywords -the dynamic keyword (and dynamic types) -the var keyword (or type inference) -LINQ -Better introspection and reflection (Reflection.Emit) -Named parameters -Partial classes -Extension Methods -The new Roslyn (Complier-as-a-service) in C# 5 -Better built-in bindings to C++ -The ability to pin memory and get pointers to it for high-performance operations -The but-in HttpClient library -Far better GUI WYSIWYG editors and development tools for desktop, mobile and web applications C# pretty much destroys Java. It sounds like Jeff Cogswell is a Java developer that barely knows C# and therefore doesn't know what he doesn't know.
East machinery(http://www.eastmachinery.com/) is a family of Internet-based machinery businesses which makes it easy for anyone to buy or sell online anywhere in the world. Since its inception, it has developed leading businesses in consumer e-commerce, online payment, business-to-business marketplaces and cloud computing, reaching Internet users in more than 240 countries and regions. East machineryconsists of 25 business units and is focused on fostering the development of an open, collaborative and prosperous e-commerce ecosystem.
East machinery was founded in 2012 by pango,China who has aspired to help make the Internet accessible, trustworthy and beneficial for everyone. The privately held pango.
I code in both C# and Java. I believe the biggest difference in these 2 platforms is debugger capabilities. Microsoft has a huge advantage in owning the OS and the database in addition to C#. In Visual Studio you can seamlessly step into a program running on one computer through a service call onto another computer into a database call on yet a third computer and then on into a custom stored proc inside that database engine on computer 3. You can see all the transitions that led to this point on the current stack viewer in the debugger. This even works for browser based code. In today's computing environment where many bugs are the result of miscommunication between the front end guys and the back end guys, this is a HUGE convenience.
Check out EL 3.0 / JSR 341
https://java.net/projects/el-spec/pages/CollectionOperations
His analysis is superficial, and his conclusion makes everyone dumber. "And then they ate ice cream," might as well been the result. Talk about s
Oracle does not own the Java API. They own the Java trademark, and they are the current curators of the API.
Wow, no one has pointed out .NET churn vs. Java's serendipitous and unplanned freeze? Microsoft is always churning through technologies, abandoning them as fast as they can make new ones. Over the years, database activities alone have churned through ODBC, DAO, ADO, ADO.NET, LINQ to a database, EF, LINQ to EF, and now back to ODBC. All that investment in COM, COM+, DCOM, ATL, etc and then .NET happens. Microsoft tried moving C++ programmers to C#, and now they want to move back to C++. Meanwhile, Java was frozen and stable, largely because of the Sun/Oracle mess. I shudder to think what Java would be today if this freeze had not stopped "innovation".
I'm sorry. C# being ahead in desktop might hold true if you run your clients on Windows. If you want cross-platform apps, (and I plain refuse to work on systems that won't run on Linux), then C# is completely useless.
--Coder
... management is, at least most of the time.
Let me say that it is easy to create GREAT systems in Java (and I assume in C#/.NET). However, in enterprise world, that seldom happens. That is not because of languages, but because of several management related issues:
1. Technical excelence is rarely seen as a goal, implementing features is.
2. Technical fixes do not drive development, satisfying business requirements does.
3. Things are rarely if ever refactored, consolidated or tidied up, as business does not see the benefit of doing that. And they do see the risk of regressions and breakage caused by refactoring.
4. There are few really good architects & developers, and because of lack of refactoring and technically driven changes, any problems in design or mistakes in code will stay there forever.
5. Management sometimes makes insane technical decisions, because of stupidity or corruption, or because they read an article that X is great and now everyone must use X, or whatever. Technical decisions must be made by technical people, otherwise bad things happen.
6. When system becomes unmaintainable and unusable, it gets rewritten, causing all "Version 2" problems. Everything and the kitchen sink gets included into Version 2, and it ends up worse than Version 1.
7. Hardware costs less than developer time, so throwing hardware at the performance problems is often easier and cheaper.
--Coder
IMHO one of the worst aspects of C# is that Microsoft have decided to use XML for documentation.
I've already complaining a lot to use HTML for Javadoc in the source code, but XML is so many orders of magnitude worst.
I understand why Javadoc is using Html, because Html is hipp and modern or whatever.
But there are so many better altrenatives. For example Textile.
At least with Javadoc they saw the trouble and introduced tags:
@author
@version
@since
etc.
It's already difficult to write and read Javadoc comments:
/**
* <code>JPanel</code> is a generic lightweight container.
* For examples and task-oriented documentation for JPanel, see
* <a
href="http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html">How to Use Panels</a>,
* a section in <em>The Java Tutorial</em>.
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
* Policy</a>.
* <p>
* <strong>Warning:</strong>
But to read or to write C# XML comments you have to be really a masochist.
<summary>
btnImport control.
</summary>
<remarks>
Auto-generated field.
To modify move field declaration from designer file to code-behind file.
</remarks>
<list type=""table"">
<listheader>
<term>Employee</term>
<description>Employee Type</description>
</listheader>
<item>
<term>XXXX</term>
<description>Administrator</description>
</item>
<item>
<term>YYYY</term>
<description>User</description>
</item>
</list>
PS: Filter error: Please use fewer 'junk' characters. with the XML stuff.
http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
No, but an encapsulation feature.
Someone compares A with B and claims that one of those lacks featers the other has.
Then a lot of people give comments how A and B both lack even more featers.
The only thing you clearly understand as someone who *actually* used BOTH *extensive* is:
The people who claim A is better don't know much about B ... e.g. recently added featrues etc.
The people who claim B is better usually don't know much about A ... as we obviously don't use it.
Example: in what practical purpose is there any significant (if at all) difference between Java Generics and C# Generics? From a programmers point of view: there is none at all!
Ofc the .Net IDE is superiour to Eclipse, IDEA IntelliJ, Netbeans ... we all know that.
Windows forms is much better than Swing, seriously! (Did you ever do a big App in *both*of them? Likely not, so your statement is not valid). That was sarcasm ... btw. Swing is one of the best GUI Frameworks ever written, only topped by Qt.
Anyway, there are only a few people who indeed work with both platforms/languages intensively. Those might care about a comparision.
No one who read this comparision or this article about it or my comment here will switch.
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
The private modifier *is* a security feature, and in Java you can set up a SecurityManager that prevents you to use introspection/reflection to accessing such a field.
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
In recent posts about implementing languages like Clojure over .NET's virtual machine (and why those projects tend to atrophy and die), the point was made that C# has a very good compiler, so the VM running underneath need not be as powerful as compared to what the JVM offers.
Well, apparently, you only have to fool the majority of people for a little while.
Every new version of Java breaks every enterprise application I work with including Oracle's own shit. Supporting Java is one of the biggest nightmares for any large organization especially if you have macs.
Lolwut? The private modifier is not a security feature, it's to enforce build-time encapsulation.
I suggest to read a book about security then.
How do you plan to ninja my private RSA key on a JVM, when it is hold in a private variable? Hint: you can't!
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
Shut the fuck up, you stupid piece of shit.
Stop. Just stop. The stupid is burning my face.
Thanks!
Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
I suggest to read a book about security then.
You go first.
Private modifier is not a security feature IN ANY LANGUAGE. Neither in C#, neither in Java, neither in C++. C# reflection can read private fields just like Java. To have any kind of security, you mustn't allow untrusted code to run in your JVM/CLR.
If configured correctly you CAN NOT read private fields in Java.
Hint: Security Manager.
Obviosly, you have no clue about JVM security mechanisms ...
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
And it is not configured that way by default neither in the JVM or the CLR.
It is, e.g. when an Applet is run.
In a standard JV which I start by typing "java.exe" (or just "java") it is not configured, as it it up to the Java Application that I run to decide if it needs security features or not.
My point is: with java bytecode you can not access private attributes or methods (of another class). You can only do it with reflection and only if you know what you are doing (setting the 'access private' flag). Reflection however can easily be disabled by a security manager.
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.