Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing C# and Java

Tags:

java

c#

I learned Java in college, and then I was hired by a C# shop and have used that ever since. I spent my first week realizing that the two languages were almost identical, and the next two months figuring out the little differences. For the most part, was I noticing the things that Java had that C# doesn't, and thus was mostly frustrated. (example: enum types which are full-fledged classes, not just integers with a fresh coat of paint) I have since come to appreciate the C# world, but I can't say I knew Java well enough to really contrast the two so I'm curious to get a community cross-section.

What are the relative merits and weaknesses of C# and Java? This includes everything from language structure to available IDEs and server software.

like image 358
The Digital Gabeg Avatar asked Sep 18 '08 21:09

The Digital Gabeg


People also ask

What is compare in C?

strcmp() in C/C++ The function strcmp() is a built-in library function and it is declared in “string. h” header file. This function is used to compare the string arguments. It compares strings lexicographically which means it compares both the strings character by character.

Can you compare characters in C?

We can compare the characters in C using 2 different ways: Comparison using ASCII values. Using the built-in function.

Can I use == to compare strings in C?

You can't compare strings in C with ==, because the C compiler does not really have a clue about strings beyond a string-literal.

How do you compare two variables in C?

Comparing two integer variables is one of the simplest program you can write at ease. In this program, you can either take input from user using scanf() function or statically define in the program itself.


4 Answers

Comparing and contrasting the languages between the two can be quite difficult, as in many ways it is the associated libraries that you use in association with the language that best showcases the various advantages of one of another.

So I'll try to list out as many things I can remember or that have already been posted and note who I think has the advantage:

  1. GUI development (thick or thin). C# combined with .NET is currently the better choice.
  2. Automated data source binding. C# has a strong lead with LINQ, also a wealth of 3rd part libraries also gives the edge
  3. SQL connections. Java
  4. Auto-boxing. Both languages provide it, but C# Properties provides a better design for it in regards to setters and getters
  5. Annotation/Attributes. C# attributes are a stronger and clear implementation
  6. Memory management - Java VM in all the testing I have done is far superior to CLR
  7. Garbage collection - Java is another clear winner here. Unmanaged code with the C#/.NET framework makes this a nightmare, especially when working with GUI's.
  8. Generics - I believe the two languages are basically tied here... I've seen good points showing either side being better. My gut feeling is that Java is better, but nothing logic to base it on. Also I've used C# generics ALLOT and Java generics only a few times...
  9. Enumerations. Java all the way, C# implementation is borked as far as I'm concerned.
  10. XML - Toss up here. The XML and serialization capabilities you get with .NET natively beats what you get with eclipse/Java out of the box. But there are lots of libraries for both products to help with XML... I've tried a few and was never really happy with any of them. I've stuck with native C# XML combined with some custom libraries I made on my own and I'm used to it, so hard to give this a far comparison at this point...
  11. IDE - Eclipse is better than Visual Studio for non-GUI work. So Java wins for non-GUI and Visual Studio wins for GUI...

Those are all the items I can't think off for the moment... I'm sure you can literally pick hundreds of items to compare and contrasting the two. Hopefully this lists is a cross section of the more commonly used features...

like image 184
Shire Avatar answered Nov 15 '22 09:11

Shire


One difference is that C# can work with Windows better. The downside of this is that it doesn't work well with anything but Windows (except maybe with Mono, which I haven't tried).

like image 28
Michael Myers Avatar answered Nov 15 '22 08:11

Michael Myers


Another thing to keep in mind, you may also want to compare their respective VMs.

Comparing the CLR and Java VM will give you another way to differentiate between the two.

For example, if doing heavy multithreading, the Java VM has a stronger memory model than the CLR (.NET's equivalent).

like image 25
therealhoff Avatar answered Nov 15 '22 07:11

therealhoff


C# has a better GUI with WPF, something that Java has traditionally been poor at.

C# has LINQ which is quite good.

Otherwise the 2 are practically the same - how do you think they created such a large class library so quickly when .NET first came out? Things have changed slightly since then, but fundamentally, C# could be called MS-Java.

like image 33
gbjbaanb Avatar answered Nov 15 '22 07:11

gbjbaanb