Upload
gilbert-campbell
View
212
Download
0
Embed Size (px)
Citation preview
C# Versus Java
Author: Eaddy, Marc
Source: Software Tools for the Professional Programmer. Dr. Dobb's
Journal. Feb2001, Vol. 26 Issue 2, p74
Hong Lu
CS699A Professional Seminar,
Rivier College
September 19, 2001
Java & C#
• Java: Sun Microsystems, “it is a relatively fast, small, and reliable language that is hardware neutral.”
• C# : Microsoft, “simple, modern, object-oriented, and type-safe programming language derived from C and C++.”
Hello World!
• HelloWorld.java
class HelloWorld’
{
public static void main(String[] args)
{
System.out.println(“Hello, World”);
}
}
• HelloWorld.cs
class HelloWorld
{
public static void main(string[] args)
{
System.Console.WriteLine(“Hello,world”);
}
}
Common Features of Java & C#
• Automatic garbage collection. • Reflection for type information discovery. • Source code is compiled to an intermediate bytecode. • Just-in-Time (JIT) compilation compiles bytecode into
native code. • Everything must be in a class--no global functions or data. • No multiple inheritance, although you can implement
multiple interfaces. • All classes derive from Object. • Security for restricting access to resources.
Common Features of Java & C#
• Exceptions for error handling.
• Packages/namespaces for preventing type collision.
• Code comments as documentation.
• Arrays are bounds checked.
• GUI, networking, and threading support.
• No uninitialized variables.
• No pointers.
• No header files.
C# Improvements Over Java
• Reflection, Metadata, and Custom Attributes
• Versioning
• Assertions
• Ref and out Parameters
• Virtual Methods
• enums
• decimal Data Types
• switch Statements
• C# Syntactic Sugar
• C# Performance Improvements