C# Vs Java – Pros and Cons

Pros:

  • Easier to learn than c++
  • Easier to read code than c++
  • More rapid and potentially less error-prone development than c++ or java (you have unsigned types, you have ref/out, you can make your own value types, you have other useful things that java omits which means you have less jumping through hoops, which means less unnecessary code complexity).
  • All things are passed by reference except for value types, by default
  • Garbage collector cleaning up objects once they’re no longer used, so you don’t have to manually track everything yourself
  • Program is compiled to native binaries optimized for the platform when it is run (and yet it ran slightly slower than c++ code).
  • Easy to make multiple threads
  • Have a variety of means of suspending threads to wait for signals and such
  • lock(someObject) { code }, which is kind of like java’s synchronized but can be used anywhere and requires an object.
  • P/Invoke is much easier to use than JNI – but we probably wouldn’t use it since we want to be cross-platform
  • Has an excellent free IDE (visual c# express) – but on windows only (see cons).
  • You can make value types, which are by default pass by value instead of pass by reference, by making a struct instead of a class.
  • You have ‘ref’ and ‘out’ keywords which allow you to pass a reference to a parameter to a function, with out meaning that the parameter must be assigned by the function before it returns. Essentially, ref/out allows the function to modify the variable being passed as the parameter, like passing a reference in c++.
  • Fairly cross-platform with mono, and/but mono is still improving
  • Has unsigned integers (so does c++, java doesn’t)
  • If the program crashes, it pops up a dialog telling the user where in the code and why (on windows) or writes a stack trace to the console (with mono if run with –debug).
  • Programs are compiled to .exe files, and don’t need to be recompiled for other OSes – mono can directly run .NET exes.

Cons:

  • Uses more memory than c++
  • Garbage collector using CPU cycles and memory – (but barely any, at least CPU time)
  • Some things don’t work in mono – calling functions in some windows dlls which won’t exist on linux, mono implementation of windows forms need workarounds in code (but we probably won’t use them)
  • Mono isn’t perfect yet
  • Have to use .net 2.0 for generics (among other things), 1.1. doesn’t have them. Can’t use anything newer than 2.0 because 3.0 and up drop support for for windows 98, ME, and maybe 2000.
  • Can’t declare functions synchronized
  • No good IDE on non-windows. Eclipse has a c# plugin but it might not support most of Eclipse’s features.
  • No pointers, but they’re replaced by ref and out parameters, so they’re not needed much
  • Calling methods via delegates are significantly slower than normal method calling (or function pointers in c++, presumably)
  • Requires the (correct version of the) .NET framework to be installed to run the program, which is a several hour download on dialup.

Java
Pros:

  • Easier to learn than c++
  • Easier to read code than c++
  • More rapid and potentially less error-prone development (due to less memory management) than c++.
  • Most cross-platform since it was designed for it and Sun makes JREs and JDKs for most platforms
  • All things are passed by reference except for value types, by default
  • Garbage collector cleaning up objects once they’re no longer used, so you don’t have to manually track everything yourself
  • Apparently java 6 runs (some?) stuff slightly faster than c++ (test code ported from c++ ran faster despite having to do seemingly wasteful things!)
  • Program is compiled and optimized for the platform it’s on, if necessary?
  • Easy to make multiple threads, and you can declare functions synchronized so only one thread can be in them at a time (IIRC)
  • You can use wait() and notifyAll() and notify() to suspend threads to wait for signals and wake them up again.
  • Various free IDEs available on all platforms, such as Eclipse
  • If the program crashes, it should either tell the user where in the code and why, showing a stack trace including line numbers (if debug symbols are enabled or something like that), or it can be dumped to an error log file.
  • Programs can be packaged into jar files with various data files in different jar files and accessed by users using Java WebStart, which will auto-update the program and any other needed jar files to the latest version, only downloading what jar files have changed.
  • Easier/more cross-platform networking than c++.
  • Files are read and written as big-endian on all platforms (which is network byte order) ensuring that communications between java programs and file loading never require byte-order swapping (unless talking to a non-java program or using a file written by one).

Cons:

  • Uses more memory than c++ or c#
  • JNI is terrifying, but if we’re being cross-platform we probably won’t use it, (except that the 3d engine will?)
  • Garbage collector using CPU cycles and memory – (but barely any, at least CPU time)
  • No unsigned integers
  • No pointers, no ref or out parameters (which replace pointers in c#). To return multiple things from a java function you tend to have to return an object[] holding each thing, or make a class which holds each thing and return an object of that class.
  • Some things were renamed – const is final in java, for example
  • Java does not allow indexers or operators on objects, e.g. if you use resizable lists etc, you have to do list.get(index) instead of list[index], and you can’t do someVector + someOtherVector.
  • Java does not let you decide whether a type should be a value or a reference type (determining if it should be pass by value or pass by reference), unlike c#.
  • Jar files used by java webstart have to be signed with a certificate. Code signing certificates cost hundreds of dollars per year, or you can make a self-signed one and use that, which will make Java Webstart pop up a “This certificante can’t be verified” dialog when the user tries to run the program. (Alternately, don’t use Java Webstart and just distribute jar files directly – which requires users to check for updates themselves.)
  • Requires a JRE to be installed to run the program, which is a several hour download on dialup.
  • Have to use java 5 for generics, 1.4 doesn’t have them. Java 6 is newest and a couple years old, but – Apple releases their own java versions for Mac users, and still hasn’t released a “stable” java 6 version for its users.

 

 

 

source

C# Vs Java – Pros and Cons
Scroll to top