|
A Comparison and Contrast of C# and Java© Jose Aniceto
May 22, 2002
Everytime someone compares Java to C#, Microsoft protests. However, as more developers start to play around with C#, many are starting to see strong similarities between the two languages.
Similarities Between C# and Java
Microsoft claims that C# was derived from the C/C++ family of programming languages. C# was designed to overcome the limitations of both languages.
Can you tell from the code below whether it is a C# or Java program?
// Test: Is this C# or Java?
class TestApp {
static void Main() {
int counter = 0;
counter++;
}
}
If you said C#, then you are right. What's the giveaway? In C#, Main() always starts with an uppercase, whereas in Java it is lowercase. Other than that, everything is the same for both languages, including the comment style.
Interpreted vs. Compiled Languages and Platform Architecture
In the early days of coding, BASIC was the standard. Most BASIC environments are interpreted, which means that the BASIC source code is taken by the interpreter and translated to computer instructions for execution. In contrast, a compiled language such as C and C++ is executed directly by the computer.
For the Java environment, a Java Virtual Machine (JVM) is required to run Java applications. Similarly, C# runs on the .Net platform. From a high-level view, it may seem that both platforms do the same thing. The reality is they are not the same. In Microsoft's solution, .Net has access to all the DLL files, whereas JVM doesn't provide that facility.
Both the JVM and the .Net environment manage memory allocation. The functions malloc() and free() no longer exist in both environments. Memory is allocated as needed by the program and then freed when no longer in use. Both the JVM and .Net also rearrange memory so that it does not become too fragmented.
Although Java was initially released on a Unix operating system, the original design of Java was to make it run on different operating systems. This feature allowed Java to be written once and ported easily to different platforms.
Visual C# was designed to work with Windows. Therefore it takes advantage of the .Net platform and other Windows controls. Note however that C# as a generic programming language is not dependent on Windows; it was just the first platform it ran on.
Development of ASP and JSP
When Microsoft announced their Active Server Pages (ASP) for dynamically creating web pages, Sun quickly came up with Java Server Pages (JSP). Netscape developed Javascript, which is a scripting language that looks like Java but is not Java. Microsoft ported VBScript to the web, which is derived from Visual Basic.
Go To Page:
1
2
The copyright of the article A Comparison and Contrast of C# and Java in C# Programming is owned by . Permission to republish A Comparison and Contrast of C# and Java in print or online must be granted by the author in writing.
|