C# Versus Java
By Marc Eaddy, February 01, 2001
Microsoft describes C# ("C sharp") as a "simple, modern, object-oriented, and type-safe programming language derived from C and C++." That statement would apply equally well to Java. In fact, after comparing the two languages, it's obvious that prerelease descriptions of C# resemble Java more than C++. As Example 1 illustrates, the language features and syntax are similar. Example 1(a) is the canonical "Hello World" program in Java, while Example 1(b) is the program in C#.
Feb01: C# Versus Java
<b>(a) </b>
// Create an object array
Object args[] = { "File not found.", new Integer(2) };
// Format the message
System.out.println(
java.text.MessageFormat.format("Error: {0} (Code {1})",args));
<b>(b)</b>
System.Console.WriteLine("Error: {0} (Code {1})", "File not found.", 2);
Example 4: String formatting. (a) in Java; (b) in C#.