« export to excel but in new page | Java learning videos »

Comparision between C# and JAVA

by Vahid 25. January 2009 15:30

here is a quick comparision between microsoft c# (.net) and java

ConceptC#JavaNotes
Virtual machineCLRJVMCLR is not quite the same as JVM concept, but very similar.
Namespacenamespace/ usingpackage/ importsC# allows multiple namespaces in a file, Java does not.
Attributes[attribute]@annotationC# 1.0, Java 1.5
Base classbasesuper
abstract objectsabstract classabstract class
abstract methodsabstractabstract
sealed objectssealedfinalIn both cases, sealing is discouraged.
sealed methodssealedfinal
replacement methodsnew keywordnot supportedEffectively ignores the base method.
constantsconst / readonlyfinal static
Enum’senum keywordenum keywordC# 1.0, Java 1.5
virtual functionsexplicit virtualalways virtualThis is one of the gotcha’s when working between the two languages
override intentionoverride@Override (though members override by default)Causes compiler error if method is not actually overriding a base method.
Class/Type representation of simple typesMap 1:1 with the simple type keywords.Behave different to simple type keywords.C# seems more natural than Java in it’s behavior
Getters/Settersget/set keywords, behave like propertiesExplicit get/set methodsAgain, C# seems more natural with this.
EventsTypically via delegatesTypically via interfaces
Reference equivalenceObject. ReferenceEquals()==Another C# vs Java gotcha.
Value equivalence== or Object.Equals()object.equals(), == for value typesJava’s choice of using == for reference equals adds to the need to distinguish between objects and value types.
Object introspectionObject.GetType()object.classVery similar
Exceptions thrown by methodimplicitthrows keywordActually liking Java’s philosophy here, albeit taking some getting used to.
Stack scopingusing keyword, or try/finally keywordstry/finally keywords‘using’ keyword is syntax sugar that calls IDisposable.Dispose() method at end of block.
Simple synchronizationlock keywordsynchronized keyword‘synchronized’ can also be used on a method.
Genericsclass<type>class<type>C# 2.0. Java 1.5. C# has a cleaner implementation and discovery of generics in reflection. In Java, class and class<type> cannot co-exist. class becomes synonymous to class.
Output parametersout, refNot allowedNot a huge loss in Java, there are simple workarounds.
Switch fall-throughNot allowedAllowed
iterationforeach(type x in y)for (type x : y)C# 1.0. Java 1.5.
Lambda/Closures=>(future)C# 3.0. Java 1.7 (maybe)

.Net | JAVA | Technical

Comments (0)

Related posts

Differences between XML and JSON Here are some key differences between JavaScript Object Notation (or JSON), an open and text-…The C# Programming Language Version 4.0c# 4.0 by vahidDifferences between asp.net web Site and asp.net Web ApplicationHave ever wondered what the differences between 2 types of asp.net web projects in visual studio 200…

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen