Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: C# : A language alternative or just J--? (part1)

C# : A language alternative or just J--? (part1)

Tutorial Details:

C#: A language alternative or just J--?, Part 1
C#: A language alternative or just J--?, Part 1
By: By Mark Johnson
What the new language for .Net and post-Java Microsoft means to you
# (pronounced "C sharp") is Microsoft researcher Anders Hejlsberg's latest accomplishment. C# looks astonishingly like Java; it includes language features like single inheritance, interfaces, nearly identical syntax, and compilation to an intermediate format. But C# distinguishes itself from Java with language design features borrowed from Delphi, direct integration with COM (Component Object Model), and its key role in Microsoft's .Net Windows networking framework.
In this article, I will examine common motivations for creating a new computer language, and speculate on which might have led to C#. Next I will introduce C# with regard to its similarities to Java. Then I will discuss a couple of high-level, fundamental differences in scope between Java and C#. I close the article by evaluating the wisdom (or lack thereof) in developing large applications in multiple languages, a key strategy for .Net and C#.
Currently, C# and .Net are available only as a C# language specification (not yet in final form), a "pre-beta SDK Technology Preview" for Windows 2000, and a quickly growing corpus of articles on MSDN. This article is based on those resources and some of my own speculation.
Read the whole series, "C#: A Language Alternative or Just J--?":
Part 1. What the new language for .Net and post-Java Microsoft means to you
Part 2. An in-depth look into the semantic differences and design choices between C# and Java
Enter C#
Imagine you're creating a new computer language, and you want to solve some of the traditional problems for C and C++ programmers: memory leaks, difficulty writing multithreaded applications, static linking, illegal pointer references, overly complex multiple-inheritance rules, and so on. To flatten the learning curve, you design the language to look a great deal like C and C++. Then you add garbage collection, integrated thread interlocking, and dynamic linking, you throw out pointers, you allow only single inheritance but introduce the concept of an interface, and so on. Five years ago, Sun Microsystems introduced Java technology, which did those things and was platform-neutral, to boot.
In June 2000, Microsoft preannounced C#, which was designed expressly for its nascent .Net application development framework. In addition to C#, the immensely talented Hejlsberg created the revolutionary languages Turbo Pascal and Delphi while at Borland, but also the counterrevolutionary Visual J++ while at Microsoft. C# and Java address many of the same problems with C and C++. In fact, C# looks so much like Java that you could very easily confuse them.
So why create C# at all? Is C# a "Java wannabe?" Since Microsoft obviously needs to deal with the Visual J++ developers it has left stranded, is C# just "Visual J--"; that is, Java with some new features and without the Sun logo, trademark, and narrow-eyed lawyers? Or is C# a technology that gives Windows developers the functionality of Java, could possibly compete directly with Java, and is useful in its own right?
It's easy to be skeptical of C#, given its almost surreal similarity to Java in syntax, design, and even runtime behavior. It looks almost as if, having failed to corrupt the Java marketplace with proprietary extensions and strategic omissions, Microsoft has simply created a copy of Java, with a new name and a familiar market approach. This is at least not entirely the case: in the context of COM and .Net, C# may well have a place in the world of Windows development.
Motivation for creating a new language
A new computer language could be created as part of a research project, to explore new system architectures or new ideas in programming semantics, or to pull together advances from several other language projects to produce a more powerful language. Innovations in computer technology often change basic assumptions about programming and system development, and new languages arise to take advantage of new ideas. Special applications sometimes require new languages, which are tied intimately to the domain in which they operate. General-purpose languages, however, are usually created either to address existing languages' inadequacies, to fill some business need, or both.
For example, C++ was created as an extension of the C programming language, and was originally called "C with classes." Though innovative and extremely powerful, C suffered from problems with scalability, code fragility, and memory management complexity, among others. C++ was created as an object-oriented approach to solving those problems.
C++ has been widely accepted as a system development language, but its "improvements" came at the cost of increased complexity. C, and to a lesser extent C++, are widely considered to be highly portable, exemplified by the portability of the Unix operating system.
Portability between processors is different from portability between underlying operating system APIs. Different operating systems factor access differently to similar system services. The resulting "impedance mismatch" (to appropriate a lousy metaphor) creates a layer of complexity and potential software flaws in the software layer where the application accesses system services. Anyone who has tried to create, for example, a GUI framework portable across platforms, understands this problem.
Java was created, in part, to address the issues of language complexity, memory management, and cross-platform portability. Java also addresses the business needs of consumers and companies who want to leverage their existing hardware assets, instead of being locked into a particular platform by an operating system vendor. Finally, the rise of the Internet and the ubiquity of network computing make cross-platform portability and airtight security even more important.
C#, announced by Microsoft but not yet released, addresses technical and business problems that Microsoft has recently encountered. Despite several attempts at simplification, the COM object programming framework has never been easy to use, and DCOM (Distributed Component Object Model) adds yet another layer of difficulty. Thus, COM development has been mostly limited to highly trained (and expensive) Windows C/C++ programmers, and Visual Basic users who have taken the time to learn to use a stripped-down interface to COM. The C and C++ languages alone require a great deal of skill to be used effectively and safely; Visual Basic has some object-oriented-like features, but is not a true object-oriented language.
When Java burst onto the scene in 1995, it grabbed an enormous amount of mindshare from Microsoft; people started to talk about a world where an operating system's underlying applications were irrelevant. Java looked so much like C and C++, existing programmers came up to speed in record time. Java also provided cross-platform portability at the operating-system level and addressed many problems that had limited the productivity of C and C++ programmers.
Microsoft initially embraced Java as a language that solved problems with C and C++ while maintaining the training assets of the existing C and C++ programmer base. Unfortunately, Microsoft found that when it tried to extend Java in Visual J++ and tie it more closely to the Windows operating system, Sun hit Microsoft with a lawsuit (see Resources ) for violating the terms of its licensing agreement. As a result, Microsoft dumped its Visual J++ product (as well as the developers it had attracted to the tool). There was talk last year of a possible new Microsoft language called Cool, which Microsoft did not acknowledge. Rumor has it C# is that language. (Microsoft still sells Visual J++, but there has not been a new release since October 1998 and Visual J++ has no place in the .Net platform. Java is being integrated into .Net by a separate vendor.)
So what kind of language has Microsoft created? The next section discusses C# in terms of its similarity to Java, since an understanding of Java is common to most JavaWorld readers.
C# and Java similarities
In the grand tradition of programming tutorials that began with C, my comparison of Java and C# begins with a familiar "Hello, world!" example. The code for this multilingual example appears in Table 1.
Table 1. "Hello, world!" in four languages (Java, C#, Croatian, French)
Java
C#
public class GlobalGreeting {
public static void main(String[] args) {
System.out.println("Zdravo, zemlya!");
}
}
class GlobalGreeting {
static void Main(string[] args) {
System.Console.WriteLine("Salut, le monde!");
}
}
The similarities between these two simple programs are obvious. Both encapsulate their main function, which is static, within an enclosing class. Both access a global name, System , that wraps access to system services. The similarities do not end with source code: Java, as you probably know, compiles to byte code -- operation codes in the instruction set of the Java Virtual Machine. C# compiles to MSIL (Microsoft Intermediate Language, formerly known as portable binary format), an intermediate, assembly-like language to which all .Net languages compile. MSIL could easily be called "Windows byte code"; however, just-in-time (JIT) compiling is only one of its design goals. MSIL's design was influenced heavily by the design goal of language interoperability. (Learn more about this in the section entitled Intermediate Language below.)
External reference
Usage of code external to a module is handled similarly in Java and C#. Java uses the import keyword to declare references to external names; C# provides the using keyword, as shown in Table 2.
Table 2. The Java import keyword and the C# using keyword
Java
C#
import java.lang.System;
public class GlobalGreeting2 {
public static void main(String args[]) {
System.out.pri


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
C# : A language alternative or just J--? (part1)

View Tutorial:
C# : A language alternative or just J--? (part1)

Related Tutorials:

Container support for objects
Container support for objects
 
Programming Java threads in the real world, Part 8
Programming Java threads in the real world, Part 8
 
Alternative deployment methods, Part 1: Beyond applets - JavaWorld May 2000
Alternative deployment methods, Part 1: Beyond applets - JavaWorld May 2000
 
Product Review: Kawa 4.0 - JavaWorld June 2000
Product Review: Kawa 4.0 - JavaWorld June 2000
 
Adelard, one year later - JavaWorld
Adelard, one year later - JavaWorld
 
Easy Java/XML integration with JDOM, Part 1 - JavaWorld May 2000
Easy Java/XML integration with JDOM, Part 1 - JavaWorld May 2000
 
Take control of the servlet environment, Part 1 - JavaWorld November 2000
Take control of the servlet environment, Part 1 - JavaWorld November 2000
 
C# : A language alternative or just J--? (part1)
C# : A language alternative or just J--? (part1)
 
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
 
Build your own languages with JavaCC - JavaWorld December 2000
Build your own languages with JavaCC - JavaWorld December 2000
 
An open alternative to JSP - The faults of JSP So what's wrong with JSP?
How the template-based, open source API FreeMarker trumps JSP
 
Pushlets: Send events from servlets to DHTML client browsers
Pushlets: Send events from servlets to DHTML client browsers
 
Navigate data with the Mapper framework
Navigate data with the Mapper framework
 
A good explanation
A good explanation
 
Unwrap the package statement's potential
Unwrap the package statement's potential
 
Groovy, Java\'s New Scripting Language
Groovy, Java\'s New Scripting Language When some Java developers hear about Groovy, their first reaction often is, as mine was, "Oh, no, not another scripting language for Java." We already have, after all, JavaScript and Rhino, Jython, Jelly, BeanShell,
 
From Writing Programs to Creating Compilers
From Writing Programs to Creating Compilers In this article we build a simple compiler that augments Java with tasks (independent blocks of code that execute in parallel), thus creating a new language called AJ that well supports the programming of syste
 
Jurassic Phoenix - reviving yesterday\'s data
Jurassic Phoenix - reviving yesterday\'s data Jurassic Phoenix is a simple solution to the problem of evolution of serialized data. Why use Jurassic Phoenix? The frustration Serialization is great for persistence, because it is automatic, dynamic and
 
ColdCafe ver 1.2
ColdCafe is a macro-processor servlet. This servlet parses html pages and replaces some predefined elements with their values. It is not a new language like JSP, it is just a set of html-preprocessing that keep your hands free for using any web-authoring
 
Open Source Web Frameworks in Java
Open Source Web Frameworks in Java Open Source Web Frameworks in Java Struts Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.