CSharp and Java

I was reading through this wikipedia article which i think is the best article to read about the differences between the C# and Java. Here are the interesting differences I found:

* By Default all the methods in Java are virtual. C# doesn't have virtual by default, in fact the virtual methods should have another keyword new or override to specify if the method is overrided or not.
* C# allows pointers (within unsafe block) but Java doesn't
* C# can have all public classes in one file, but Java needs to have a public class in a file name and the filename and classname should match.
* C# implements get set properties as part of syntax. (Java, C++ obviously doesn't have this)
* In C# switch statement can also have strings (Java, C++ doesn't allow this)
* More discussion on data type differences can be found here
* C# supports operator overloading but Java does not

More to be updated...

* Checked exceptions are special kind of exceptions in java which are mentioned in the method header. The method header should have all the exceptions its going to throw, otherwise it would be a compiler error. C# doesn't have checked exceptions.
* JNI for java allows to call non-java code from java. Similarly C# has "Platform Invoke" (P/Invoke) which enables C# to call unmanaged code. P/Invoke can be used to call WIN32 APIs but not C++ libraries.
* .NET framework has .NET-COM bridge which allows to call COM components are .NET code.

0 comments: