PART I
C h a p t e r 1 :
T h e C r e a t i o n o f C #
5
PART IPART I
compiled, and targeted for a specific CPU and a specific operating system. While it has always
been true that programmers like to reuse their code, the ability to port a program easily from
one environment to another took a backseat to more pressing problems. However, with the
rise of the Internet, in which many different types of CPUs and operating systems are
connected, the old problem of portability reemerged with a vengeance. To solve the problem
of portability, a new language was needed, and this new language was Java.
Although the single most important aspect of Java (and the reason for its rapid acceptance)
is its ability to create cross-platform, portable code, it is interesting to note that the original
impetus for Java was not the Internet, but rather the need for a platform-independent
language that could be used to create software for embedded controllers. In 1993, it became
clear that the issues of cross-platform portability found when creating code for embedded
controllers are also encountered when attempting to create code for the Internet. Remember:
the Internet is a vast, distributed computing universe in which many different types of
computers live. The same techniques that solved the portability problem on a small scale
could be applied to the Internet on a large scale.
Java achieved portability by translating a program’s source code into an intermediate
language called
bytecode.
This bytecode was then executed by the Java Virtual Machine
(JVM). Therefore, a Java program could run in any environment for which a JVM was
available. Also, since the JVM is relatively easy to implement, it was readily available for
a large number of environments.
Java’s use of bytecode differed radically from both C and C++, which were nearly
always compiled to executable machine code. Machine code is tied to a specific CPU and
operating system. Thus, if you wanted to run a C/C++ program on a different system, it
needed to be recompiled to machine code specifically for that environment. Therefore, to
create a C/C++ program that would run in a variety of environments, several different
executable versions of the program would be needed. Not only was this impractical, it was
expensive. Java’s use of an intermediate language was an elegant, cost-effective solution.
It is also a solution that C# would adapt for its own purposes.
As mentioned, Java is descended from C and C++. Its syntax is based on C, and its object
model is evolved from C++. Although Java code is neither upwardly nor downwardly
compatible with C or C++, its syntax is sufficiently similar that the large pool of existing
C/C++ programmers could move to Java with very little effort. Furthermore, because Java
built upon and improved an existing paradigm, Gosling, et al., were free to focus their
attention on the new and innovative features. Just as Stroustrup did not need to “reinvent
the wheel” when creating C++, Gosling did not need to create an entirely new language
when developing Java. Moreover, with the creation of Java, C and C++ became an accepted
substrata upon which to base a new computer language.
Do'stlaringiz bilan baham: |