C# and JAVA

C# and JAVA are two different Object Oriented Languages , both have some similarities and differences also. The Csharp and JAVA derived from their own single ancestor Class "Object". All Classes in C# are descended from System.Object Class and in JAVA all classes are subclasses of java.lang.Object Class. C# tries to be modern, to shine with new features, to ride ahead of time, to adopt cryptic syntax for things. C# is more a "commercial" language with many powerful libraries commercially available. While Java tries to be conservative, slowly adopting new things, stable, clear, plain, easily understandible by a beginner. Java is more like an "opensource" language with tons and tons of opensource libraries available.

Runtime Environments

Both C# and JAVA have their own runtime environments . C# source codes are compiled to Microsoft Intermediate Language (MSIL) and during the execution time runs it with the help of runtime environments - Common Language Runtime (CLR). Like that JAVA source codes are compiled to Java Byte Code and during the execution time runs it with the help of runtime environments - Java Virtual Machine (JVM). Both CSharp and JAVA supports native compilation via Just In Time compilers.

Type-Safe Languages

Java and C# were designed to be type-safe . An illegal casting will be caught at compile time if it can be shown that the cast is illegal; or an exception will be thrown at runtime if the object cannot be cast to the new type. Type safety is therefore more important because it not only forces a programmer to write more correct code, but also helps a system become more secure from code hackers.

Garbage Collection

In lower-level languages, memory management can be tedious work because you have to remember to properly delete new objects to free up resources. That’s not the case in C# and Java , where built-in garbage collection helps prevent memory leaks by removing objects that are no longer being used by the application. While memory leaks can still occur, the basics of memory management have already been taken care of for you.

Generics

Generics improve compiler-assisted checking of types largely by removing casts from source code. In Java, generics are implemented using erasures. Generic type parameters are "erased" and casts are added upon compilation into bytecode. C# takes generics even further by integrating it into the Common Language Infrastructure (CLI) and allowing type information to be available at runtime, yielding a slight performance gain.

Pointers

C# allows the use of pointers, which some language designers consider to be unsafe, but certain language features try to ensure this functionality is not misused accidentally. Pointers also greatly complicate technologies such as Java's Remote Method Invocation (RMI), where program objects resident on one computer can be referenced within a program running on an entirely separate computer. Some have speculated that the lack of memory pointers in Java was a nod towards the coming of grid computing, where a single application may be distributed across many physical pieces of hardware.

Methods

Methods in c-sharp are non-virtual by default. In Java however, methods are virtual by default. Virtual methods guarantee that the most overridden method of an object will be called which is determined by the runtime . You always have to keep that in mind when calling or writing any virtual method! If the method is declared as non-virtual, the method to invoke will be determined by the compiler. This is a major difference of philosophy between the designers of the Java and .NET platforms.

More.... Java Tutorial