Differences between C# and Java

Started by
17 comments, last by meeshoo 12 years, 2 months ago
Right now I am programming in Java and enjoy it, I've made some decent progress, but in no manner would I refer to myself as a master. I would like to transition over to C# sometime, and would like to know some of the similarities and differences between the languages. I am mainly switching so I can use XNA. I'm not sure if now is a good time to switch or if I should stick with Java for a bit longer.

opinions?
Thanks.
Advertisement
Or would you suggest to just move onto C++, which is my final goal?

Right now I am programming in Java and enjoy it, I've made some decent progress, but in no manner would I refer to myself as a master. I would like to transition over to C# sometime, and would like to know some of the similarities and differences between the languages.


You could look at here.


I am mainly switching so I can use XNA. I'm not sure if now is a good time to switch or if I should stick with Java for a bit longer.

opinions?


Imho they are two languages which are close from a programmer's point of view. There are differences, but the main concepts are the same, so the transition shouldn't be hard.


Or would you suggest to just move onto C++, which is my final goal?


Obviously it depends on many factors, the transition to C# should be easier than the C++ one, and you're also considering XNA, which is another element that might help you. So, it depends on your will and your constraints (time, for example): you can do an intermediate step (with some result) or an harder one. Imho, if your final goal is C++ and you've no time constraints and no need to produce results to keep up your motivation, you can avoid learning C# and XNA and jump to C++, imho.

[ About me ]

I have only used Java briefly so I cant really comment for the whole language but from what I saw it was a lot like C#.

As for C#, it is a great language and the .net framework is amazing but then I havent really tried out other languages outside .net (minus PHP). Sadly if you did a google search you will likely come across hundreds of outdated threads where the languages are compared and degraded, I would avoid reading them simply because the internet in flooded with comparison wars (not just C# / Java) making it really frustrating finding 'real' comparisons and all you really find are "join my club, its better!" threads / articles.

Same applies to C++ vs ??? and well MS vs Apple and whatever else, I would stay clear away from those threads, because if anything they will be outdated and put you off, if you like Java, stick with it, if you want to try C#, go for it and if you want to play around with C++ then by all means do. Be weary of the "unmanaged languages are bad" that follows literally every C++ vs ??? thread / article, if the language was so bad millions of people wouldnt put their blood and sweat advancing in it.

Sorry if that sounds like a rant but I felt it was necessary to say with the amount of comparison articles / threads around :D

As for C# (.net) itself, theres many many features, Linq, EF, XNA, WCF, WPF, SL5 (which now has many features of XNA), ASP.NET MVC (which made all my web related work simple and easy in ways I couldnt imagine) and in the next few months massive improvements to Async programming. Theres many features about .net that havent been mentioned here and really I could go on and on, but tbh if you want to try then try it, theres no reason why a person couldnt advance in every language, learning something in one language will likely benefit you in the other.

In regards to limitations, the main one really is .net is for MS machines only, there mono which helps overcome this limitation, to me this is hardly a limitation, I have never used an apple product, no criticism to apple but I have never had any desire or need to use or buy an apple product.

One thing I will say about C++ though, you may want to check out native C before doing any C++, the learning will be relatively quick and straight forward since most of the language could be easily compared to Java and definitely C#, I did a little bit of reading back in the day with pointers on C++ and oddly enough it was only when I started learning about native C that I actually understood pointers and memory management in general

Or would you suggest to just move onto C++, which is my final goal?


If C++ is your final goal then need to reconsider what your final goal should be. (C++ is a good language to know but you're fooling yourself if you think its the only language you need as a programmer), I did consider C++ to be my final goal when i started out and as such it was the fourth (i covered BASIC, Pascal and x86 asm before that) language i learned, now i know over 15 languages and got 2 languages on my "to learn" list, (C# and Python and i'm working on C# atm).

When it comes to learning C++ i strongly advice against learning C first as you risk picking up some very nasty habits that way.

As for C# vs Java, the main differences i can think of is LINQ which is just pure awesome and the platform support, (Java is required for Android development while C# is required for WP7), on the desktop it really doesn't matter which one you go with allthough running .jars on Windows can be a bit of a pain since some stupid applications (WinRAR) insist on stealing the extensions by default. (Packaging them in an .exe or using a launcher solves that problem though)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

When it comes to learning C++ i strongly advice against learning C first as you risk picking up some very nasty habits that way.


Cannot have agreed more. I had C background and I never thought I would lug around so much excess baggage when I started C++. Even the programming paradigm is different. I took my much effort to get rid of all that baggage and really start to think in C++ rather than think in C and code in C++.

Even the great man himself says --

In the continuing debate on whether one needs to learn C before C++, I am firmly convinced that it is best to go directly to C++. C++ is safer, more expressive, and reduces the need to focus on lowlevel techniques. It is easier for you to learn the trickier parts of C that are needed to compensate for its lack of higherlevel facilities after you have been exposed to the common subset of C and C++ and to some of the higherlevel techniques supported directly in C++.
- Dr. Bjarne Stroustrup
[/quote]

Someone else had rightfully said, "The more experienced C programmer you are, the more time you will take to become a C++ programmer."
Ah, I guess I should have left that C first comment out, truth be told when I checked out C it was really only to get my head around pointers, its hard to explain but I couldnt seem to make much sense of pointers in C++ and when I thought I did references popped up, pointers oddly enough then made sense from a C text.

Oh also I should mention my comment was purely todo with pointers only, I have like a max of 1 week experience from 2010 on both C / C++ and that really was to find out the usefulness of pointers :D, well 1 week and 1 day (decided to check out C++ for the sake of DX)

and would like to know some of the similarities and differences between the languages.


C# up to 2.0 was essentially 'Java with lessons learned'. It does away with checked exceptions, has a concept for interfaces, a sane DateTime instance, and good generic support. It shared the same sort of OO approach, garbage collection and bytecode ideas.

Since 2.0 (around the same time Java stagnated) C# has added support for dynamic variables/execution, extension methods, generators, expression trees, concurrent data structures in the standard library, and better use of methods as data (including better anonymous method syntax),

This last one is the big day to day difference you'll see between modern C# and Java. Modern C# tends to make fairly heavy use of in-line anonymous methods which are antithetical to the Java way of doing things.
Not to mention the obvious fact that Java is entirely cross-platform (And by the way, converting java code to an exe file seemse counter productive to me, as perhaps the biggest advantage to using java IS its cross-platform nature), where-as C# is Microsoft only (unless you take into account Mono, which is another argument all together).
Co-founder/Lead Programmer
Bonafide Software, L.L.C.
Fairmont, WV 26554 US

[quote name='stein102' timestamp='1328343637' post='4909455']
and would like to know some of the similarities and differences between the languages.


C# up to 2.0 was essentially 'Java with lessons learned'. It does away with checked exceptions, has a concept for interfaces, a sane DateTime instance, and good generic support. It shared the same sort of OO approach, garbage collection and bytecode ideas.

Since 2.0 (around the same time Java stagnated) C# has added support for dynamic variables/execution, extension methods, generators, expression trees, concurrent data structures in the standard library, and better use of methods as data (including better anonymous method syntax),

This last one is the big day to day difference you'll see between modern C# and Java. Modern C# tends to make fairly heavy use of in-line anonymous methods which are antithetical to the Java way of doing things.
[/quote]
Ditto.
As a beginner writing trivial small programs you may be forgiven for thinking C# is just Microsoft's version of Java since they are so similar laugh.png
After you learn more and use them for a while you'll start to see they really are different though.
For example, C# has the keyword unsafe which allows you to use pointers which is the a big difference between the languages.
C# being able to use the .Net framework classes allows a lot easier integration with other languages and is tied a lot more with Windows via Winforms, WPF, etc...
On a practical level as a beginner I found C# easier to learn just because Visual Studio helps so much when writing C# code.
Java is just as easy to write from command line but I never found Eclipse to be as easy, enjoyable to use myself.
Also C# seems to be evolving way faster than Java that some of the new stuff like LINQ wasn't even around when I started learning C# that there might be quite different ways to do stuff now.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement