Application Development in Java and C#

Brief similarity

 Both C# and Java Are Object-Oriented Languages

Both C# and Java are designed from the ground up as object-oriented languages using dynamic dispatch, with syntax similar to C++ (C++ in turn derives from C). Neither language is a superset of C or C++, however, any class in either language implicitly (or explicitly) subclasses an object. This is a very nice idea, because it provides a default base class for any user-defined or built-in class.

 Covariance and contravariance

Covariance and contra variance is supported by both languages. Java has use-site variance that allows a single generic class to declare members using both co- and contravariance. C# has define-site variance for generic interfaces and delegates. Variance is not supported directly on classes but is supported through their implementation of variant interfaces. C# also has use-site covariance support for methods and delegates.

 Garbage Collection


 Garbage collection which simply is automatic memory management, both languages allows automatic reclaiming of memory from objects that are out of scope.


 Comparison table


 Native interoperability                                     Java                                  C#


 Cross-language interoperability                         Yes                                     Yes
 External/native methods                                     Yes                                    Yes
 Marshalling External glue code required           Yes           metadata controlled
 Pointers and arithmetic*****                             No                                    Yes
 Native types                                                        Yes                                   Yes
 Fixed-size buffers                                                No                                    Yes
 Explicit stack allocation                                      No                                    Yes
 Address-of                                                           No                                    Yes
 Object pinning (fix variable to address)              No                                    Yes

 Metadata                                                            Java                                        C#


 Metadata         annotations/attributes Interface based;   user-defined annotations can be created Class based
 Positional arguments                                         No; unless a single argument    Yes
 Named arguments                                             Yes                                             Yes
 Default values                                                   At definition        Through initialization
 Nested types                                                      Yes                                             Yes
 Specialization                                                     No                                             Yes
 Conditional metadata                                          No                                              Yes
 Class access specifies     Only One public class in file to compile  Multiple public classes allowed in same file to compile.
 #region keyword*                                             Yes                                            No
 Native code calls**                                           Yes; with JNI         Yes; using platform Invoke
 Conditional compilation***                      Yes using preprocessor directives   No
 Runtime Environment****                               Yes; JRE                                   Yes; CLR
 Extensions                                                         Yes                                           Yes
 Single-Line comments(//)                                  Yes                                           Yes
 Double-Line comments(/*...*/)                         Yes                                           Yes


 Platform support                           Java                                                                 C#

 Linux                                                Yes                                                           via Mono
 Mac OS X                                         Yes                                                          via Mono
 Solaris                                               Yes                                                         via Mono
 FreeBSD                                            Yes                                                          via Mono
 AIX                                                    Yes                                                            Partial?
 iOS                                                    via RoboVM or Codename One           via Mono
 Windows                                            Yes                                                              Yes
 Windows Mobile                               Yes                                                               Yes
 Windows Phone                                via Codename One                                       Yes
 Windows 8 Modern                           Yes                                                               Yes
 Android                                   via Dalvik, ART                                                via Mono
 Feature phones                                  Yes                                                                No
 Symbian                                            Yes                                                            Deprecated
 Blackberry                                         Yes                                                     via cross-compiler
 

Comments

Popular posts from this blog

Firebase Test Lab for Android Robo Test

C# and Java Language History and Evolution

Learn about the differences between C# and Java.