one important difference between Java and .Net is Java is more SECURE over .Net and dats because of following reasons-
java needs a JVM for it's source code to be executed,which is independent of the system n works on any platform...
so,java codes cannot b executed elsewhere but only with JVM which provides no clue ab the code.
1. auto garbage collector
developer does not have to worries about a memory leak (most of the time - for dangling reference, etc). Java does the releasing of unreferenced object for you
2. hide pointer
Java hide pointer from developer. Allowing direct access to memory can be dangerus. Hacker can takes advantages of this to try to overwrite memory outside of application..or you accident overwrite the wrong address in your pointer arithmetic.
3. try-catch
java provides try - catch - finally that is different from C++ try-catch.
Java guareentee that when the an Exception occurs, the thread will goto the end of the method before unwinding the stack to where the call was..and keep doing this till the exception is handled. This is important when working with thread. When the thread exit the method..and if the thread have the object lock..then it release the lock upon exiting the method. Java try-catch-finally guareentee the release of the lock (because Java exit the method).
4. Java is a String type language
you have two type in Java
primitive type and object type.
At runtime, Java knows the type of object, so Java knows what operating allows on th etype...this eliminate bad casting (for the most part)
you can still cast wrongly:
Person p = new Person();
Object o = p;
Cat c = (Cat) o;
compile fine, but will catch runtime exception..because Java knows the type at runtime..so trying to cast to a Cat for the Person object will generate an Exception...
5. Applet provides better security
Applet by default does not gives the Applet application permission to read or write on your computer. ActiveX (from Miscrosoft) default to allow these access.
This encapsulte the applet..and prevent malacious code.
as stated before..you can still write code that is not so "secure," it's just harder to do so, than any other language..Java try to protect developers from making these mistakes..and try to protect the end-user from malacious code.
These are few reasons for why java is more secure than .net or any other language there are many more that confirms the same..