You are on page 1of 33

The chief merit of language is clearness. —Galen High thoughts must have high language.

—Aristophanes

Introduction to Computers, the Internet and Visual C#
OBJECTIVES
In this chapter you’ll learn:
■ ■ ■ ■

1

Our life is frittered away with detail. . . . Simplify, simplify.
—Henry David Thoreau

Basic hardware and software concepts. The different types of programming languages. Which programming languages are most widely used. The history of the Visual C# programming language. Some basics of object technology. The history of the UML—the industry-standard objectoriented system modeling language. The history of the Internet and the World Wide Web. The motivation behind and an overview of Microsoft’s .NET initiative, which involves the Internet in developing and using software systems. To test-drive a Visual C# 2008 application that enables you to draw on the screen.

My object all sublime I shall achieve in time.
—W. S. Gilbert

■ ■

Man is still the most extraordinary computer of all.
—John F. Kennedy

■ ■

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

2

Chapter 1 Introduction to Computers, the Internet and Visual C#
1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 Introduction What Is a Computer? Computer Organization Personal Computing, Distributed Computing and Client/Server Computing Hardware Trends Microsoft’s Windows® Operating System Machine Languages, Assembly Languages and High-Level Languages Visual Basic C, C++ and Java Visual C# Other High-Level Languages Structured Programming Key Software Trend: Object Technology The Internet and the World Wide Web Extensible Markup Language (XML) Introduction to Microsoft .NET The .NET Framework and the Common Language Runtime Test-Driving a C# Advanced Painter Application (Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML 1.20 Wrap-Up 1.21 Web Resources
Summary | Terminology | Self-Review Exercises | Answers to Self-Review Exercises | Exercises

O ut line

Welcome to Visual C# 2008! We’ve worked hard to provide you with accurate and complete information regarding this powerful computer programming language—which, we’ll frequently refer to simply as C# (pronounced “C Sharp”). C# is appropriate for technically oriented people with little or no programming experience, and for experienced programmers to use in building substantial information systems. Visual C# 2008 How to Program, 3/e, is an effective learning tool for both audiences. We hope that working with this text will be an informative, challenging and entertaining learning experience for you. How can this book appeal to both novices and skilled programmers? Its core emphasizes achieving program clarity through the proven techniques of object-oriented programming (OOP) and event-driven programming. Nonprogrammers learn skills that underlie good programming; experienced developers get a rigorous explanation of the language and may improve their programming styles. Perhaps most important, the book presents hundreds of complete, working C# programs and depicts their inputs and outputs. We call this the live-code approach. All of the book’s examples may be downloaded from www.deitel.com/books/csharphtp3/. Computer use is increasing in almost every field of endeavor. Computing costs have been decreasing dramatically, owing to rapid developments in both hardware and software technologies. Computers that might have filled large rooms and cost millions of dollars a
2008935881

1.1 Introduction

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.2 What Is a Computer?

3

few decades ago can now be inscribed on silicon chips smaller than a fingernail, costing a few dollars each. Fortunately, silicon is one of the most abundant materials on earth—it’s an ingredient in common sand. Silicon-chip technology has made computing so economical that about a billion general-purpose computers are in use worldwide, helping people in business, industry and government, and in their personal lives. We hope that you’ll enjoy learning with Visual C# 2008 How to Program, 3/e. You are embarking on a challenging and rewarding path. As you proceed, if you have any questions, send e-mail to
deitel@deitel.com

To keep current with C# developments at Deitel & Associates and to receive updates to this textbook, register for our free e-mail newsletter, the Deitel® Buzz Online, at
www.deitel.com/newsletter/subscribe.html

Check out our growing list of C# and related Resource Centers at
www.deitel.com/ResourceCenters.html

A computer is a device that can perform calculations and make logical decisions millions, billions and even trillions of times faster than humans can. For example, many of today’s personal computers can perform billions of additions per second. A person operating a desk calculator might require a lifetime to complete as many calculations as a powerful personal computer can perform in one second. Today’s fastest supercomputers are already performing trillions of additions per second! Computers process data, using sets of instructions called computer programs. These programs guide computers through orderly sets of actions that are specified by people known as computer programmers. A computer consists of various devices referred to as hardware (e.g., the keyboard, screen, mouse, hard drive, memory, DVDs and processing units). The programs that run on a computer are referred to as software (e.g., word-processing programs, e-mail and games). Hardware costs have been declining dramatically for several decades, to the point that personal computers have become a commodity. Historically, however, softwaredevelopment costs have risen steadily, as programmers develop ever more powerful and complex applications without being able to significantly improve the software-development process. Object-oriented programming (which models real-world objects with software counterparts), available in C# and other programming languages, is a significant breakthrough that can greatly enhance your productivity.

1.2 What Is a Computer?

1.3 Computer Organization

Computers can be thought of as being divided into six units: 1. Input unit. This “receiving” section of the computer obtains information (data and computer programs) from various input devices, such as the keyboard and the mouse. Other input devices include microphones (for recording speech to the computer), scanners (for scanning images) and digital cameras (for taking photographs and making videos).

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

4

Chapter 1 Introduction to Computers, the Internet and Visual C# 2. Output unit. This “shipping” section of the computer takes information that the computer has processed and places it on various output devices, making it available for use outside the computer. Output can be displayed on screens, printed on paper, played on audio/video devices, transmitted over the Internet, and so on. Output also can be used to control other devices, such as robots used in manufacturing. 3. Memory unit. This rapid-access, relatively low-capacity “warehouse” section of the computer stores data temporarily while an application is running. The memory unit retains information that has been entered through input devices, so that information is immediately available for processing. To be executed, computer programs must be in memory. The memory unit also retains processed information until it can be sent to output devices on which it is made available to users. Often, the memory unit is called either memory or primary memory. Randomaccess memory (RAM) is an example of primary memory. Primary memory is usually volatile, which means that it is erased when the machine is powered off. 4. Central processing unit (CPU). The CPU serves as the “administrative” section of the computer, supervising the operation of the other sections. The CPU alerts the input unit when information should be read into the memory unit, instructs the ALU (see below) when to use information from the memory unit in calculations and tells the output unit when to send information from the memory unit to certain output devices. Many of today’s more powerful desktop computers have several CPUs. 5. Arithmetic and logic unit (ALU). The ALU (a part of the CPU) is the “manufacturing” section of the computer. It performs calculations such as addition, subtraction, multiplication and division. It also makes decisions, allowing the computer to perform such tasks as determining whether two items stored in memory are equal. 6. Secondary storage unit. This unit is the long-term, high-capacity “warehousing” section of the computer. Secondary storage devices, such as hard drives, CDROM drives, DVD drives, and USB memory sticks, normally hold programs or data that other units are not actively using. The computer can retrieve this information when it is needed—immediately or possibly hours, days, months or even years later. Information in secondary storage takes much longer to access than information in primary memory. However, secondary storage is much less expensive than primary memory. Secondary storage is nonvolatile, retaining information even when the computer is powered off.

1.4 Personal Computing, Distributed Computing and Client/Server Computing

In the early years of computing, computer systems were too large and expensive for individuals to own. In the 1970s, silicon chip technology appeared, making it possible for computers to be much smaller and so economical that individuals and small organizations could own them. In 1977, Apple Computer—creator of today’s popular Mac personal computers and iPod digital music players—popularized personal computing. In 1981,
2008935881

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.5 Hardware Trends

5

IBM, the world’s largest computer vendor, introduced the IBM Personal Computer, legitimizing personal computing in business, industry and government organizations. These computers were “stand-alone” units—people transported disks back and forth between computers to share information (creating what was often called “sneakernet”). Although early personal computers were not powerful enough to support several users simultaneously, these machines could be linked together in computer networks, sometimes over telephone lines and sometimes in local area networks (LANs) within an organization. This led to the phenomenon of distributed computing, in which an organization’s computing, instead of being performed only at some central computer installation, is distributed over networks to the geographically dispersed sites where the organization’s work is performed. Personal computers were powerful enough to handle the computing requirements of individual users as well as the basic communications tasks of passing information between computers electronically. Today’s personal computers are as powerful as the million-dollar machines of just a few decades ago; complete personal computer systems often sell for as little as $500–1000. The most powerful desktop machines provide individual users with enormous capabilities. Information is shared easily across computer networks, where computers called servers offer a common data store that may be used by client computers distributed throughout the network, hence the term client/server computing. In Chapters 22–24 you’ll learn how to build Internet- and web-based applications; we’ll talk about web servers (computers that distribute content over the web) and web clients (computers that request and receive the content offered up by web servers).

Every year, people generally expect to pay at least a little more for most products and services. The opposite has been the case in the computer and communications fields, especially with regard to the costs of hardware supporting these technologies. For many decades, hardware costs have fallen rapidly, if not precipitously. Every year or two, the capacities of computers have approximately doubled without any increase in price. This trend often is called Moore’s Law, named after the person who first identified and explained it, Gordon Moore, co-founder of Intel—the company that manufactures the vast majority of the processors in today’s personal computers. Moore’s Law is especially true in relation to the amount of memory that computers have for programs, the amount of secondary storage (such as disk storage) they have to hold programs and data over longer periods of time, and their processor speeds—the speeds at which computers execute their programs (i.e., do their work). Similar growth has occurred in the communications field, in which costs have plummeted as enormous demand for communications bandwidth has attracted intense competition. We know of no other fields in which technology improves so quickly and costs fall so rapidly. Such phenomenal improvement in the computing and communications fields is truly fostering the Information Revolution. When computer use exploded in the 1960s and 1970s, many people discussed the dramatic improvements in human productivity that computing and communications would cause, but these improvements did not materialize. Organizations were spending vast sums of money on these technologies, but without realizing the expected productivity gains. The invention of microprocessor chip technology and its wide deployment in the
2008935881

1.5 Hardware Trends

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

6

Chapter 1 Introduction to Computers, the Internet and Visual C#

late 1970s and 1980s laid the groundwork for the productivity improvements that individuals and businesses have achieved in recent years.

An operating system is software that manages all of a computer’s hardware resources—helping you conveniently access your computer and get the best performance from it. Operating systems also help you accomplish many tasks in parallel and make it easier for developers to build useful applications. Microsoft Corporation became the dominant software company in the 1980s and 1990s. In 1981, Microsoft released the first version of its DOS for the IBM Personal Computer (DOS is an acronym for “Disk Operating System”). In the mid-1980s, Microsoft developed the Windows operating system, a graphical user interface built on top of DOS. Microsoft released Windows 3.0 in 1990; this new version featured a user-friendly interface and rich functionality. The Windows operating system became incredibly popular after the 1993 release of Windows 3.1, whose successors, Windows 95 and Windows 98, virtually cornered the desktop operating-systems market by the late 1990s. These operating systems, which borrowed from many concepts (such as icons, menus and windows) popularized by early Apple Macintosh operating systems after being initially devised at Xerox’s Palo Alto Research Center (PARC), enabled users to navigate multiple applications simultaneously. Microsoft entered the corporate operating-systems market with the 1993 release of Windows NT®. Windows XP, which is based on the Windows NT operating system, was released in 2001 and combines Microsoft’s corporate and consumer operating-system lines. Windows Vista, released in 2007, is Microsoft’s latest operatingsystem offering. This book is intended for Windows XP and Windows Vista users. Windows today is by far the world’s most widely used operating system. The biggest competitor to the Windows operating system is Linux. The name Linux derives from Linus (after Linus Torvalds, who developed Linux) and UNIX (the operating system on which Linux is based). UNIX was developed at Bell Laboratories and was written in the C programming language. Linux is a free, open-source operating system, unlike Windows, which is proprietary (owned and controlled by Microsoft). The source code for Linux is freely available to users, and they can modify it to fit their needs. Another popular operating system is Apple Computer’s Mac OS X. One of its interesting features for developers is that they can run Windows, Linux and Mac OS X on the same computer (using so-called virtualization software). This means that Mac users can develop applications for all three platforms. Virtualization software is offered by many of today’s leading software vendors.

1.6 Microsoft’s Windows® Operating System

1.7 Machine Languages, Assembly Languages and HighLevel Languages

Programmers write instructions in various programming languages. Some of these are directly understandable by computers; others require intermediate translation steps. Although hundreds of computer languages are in use today, they can be divided into three general types: 1. Machine languages
2008935881

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.7 Machine Languages, Assembly Languages and High-Level Languages 2. Assembly languages 3. High-level languages

7

A computer can directly understand only its own machine language. As the “natural language” of a particular computer, machine language is defined by the computer’s hardware design. Machine languages generally consist of streams of numbers (ultimately reduced to 1s and 0s) that instruct computers how to perform their most elementary operations. You normally work in the decimal number system with digits in the range 0–9. The system with only 1s and 0s is called the binary number system. Machine-language programs are often called “binaries” for that reason. Machine languages are machine dependent, which means that a particular machine language can be used on only one type of computer. The following section of an early machine-language program, which adds overtime pay to base pay and stores the result in gross pay, demonstrates the incomprehensibility of machine language to humans:
+1300042774 +1400593419 +1200274027

As the popularity of computers increased, machine-language programming proved to be slow and error prone. Instead of using the strings of numbers that computers could directly understand, programmers began using English-like abbreviations to represent the computer’s basic operations. These abbreviations formed the basis of assembly languages. Translator programs called assemblers convert assembly-language programs to machine language at computer speeds. The following section of an assembly-language program also adds overtime pay to base pay and stores the result in gross pay, but the steps are somewhat clearer to human readers than in the machine-language example:
LOAD ADD STORE BASEPAY OVERPAY GROSSPAY

Although it is clearer to humans, computers cannot understand assembly-language code until it is translated into machine language by an assembler program. The speed at which programmers could write programs increased rapidly with the creation of assembly languages, but these languages still require many instructions to accomplish even the simplest tasks. To speed up the process of developing applications, highlevel languages (in which single program statements accomplish more substantial tasks) were developed. Translator programs called compilers convert high-level-language programs into machine language. High-level languages enable programmers to write instructions that look almost like everyday English and contain common mathematical notations. For example, a payroll application written in a high-level language might contain a statement such as
grossPay = basePay + overTimePay

From these examples, it is clear why programmers prefer high-level languages to either machine languages or assembly languages. Figure 1.1 compares machine, assembly and highlevel languages. Visual C# is a popular high-level programming language.
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

8

Chapter 1 Introduction to Computers, the Internet and Visual C#

Sample code
+1300042774 +1400593419 +1200274027

Translator

From the programmer's perspective

From the computer's perspective Natural language of a computer; the only language the computer can understand directly Assemblers convert assembly language into machine language so the computer can understand Compilers convert high-level languages into machine language so the computer can understand

Machine language

None

Slow, tedious, error prone

Assembly language

LOAD ADD STORE

BASEPAY OVERPAY GROSSPAY

Assembler

English-like abbreviations, easier to understand Instructions resemble everyday English; single statements accomplish substantial tasks

High-level language

grossPay = basePay + overTimePay

Compiler

Fig. 1.1 | Comparing machine, assembly and high-level languages.
Visual Basic evolved from BASIC (Beginner’s All-purpose Symbolic Instruction Code), developed in the mid-1960s by Professors John Kemeny and Thomas Kurtz of Dartmouth College as a language for writing simple programs quickly and easily. BASIC’s primary purpose was to teach novices fundamental programming techniques. When Bill Gates founded Microsoft Corporation in the 1970s, he implemented BASIC on several early personal computers. In the late 1980s and the early 1990s, Microsoft developed the Microsoft® Windows® graphical user interface (GUI)—the visual part of the operating system with which users interact. With the creation of the Windows GUI, the natural evolution of BASIC was to Visual Basic, introduced by Microsoft in 1991 to make programming Windows applications easier. Until Visual Basic (and more recently, C#) appeared, developing Microsoft Windows-based applications was a difficult process. Visual Basic and Visual C# are object-oriented, event-driven visual programming languages in which programs are created with the use of a software tool called an Integrated Development Environment (IDE). With Microsoft’s Visual Studio IDE, you can write, run, test and debug Visual Basic and C# programs quickly and conveniently.

1.8 Visual Basic

1.9 C, C++ and Java

C The C programming language was invented and implemented by Dennis Ritchie at Bell Laboratories in 1973. C first gained widespread recognition as the development language
2008935881

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.10 Visual C#

9

of the UNIX operating system. C is a hardware-independent language, and, with careful design, it is possible to write C programs that are portable to most computers.

C++ C++ was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories. C++ provides a number of features that “spruce up” the C language, but, more important, it provides capabilities for object-oriented programming (OOP). Many of today’s major operating systems are written in C or C++. At a time when the demand for new and more powerful software is soaring, the ability to build software quickly, correctly and economically remains an elusive goal. This problem can be addressed in part through the use of objects, or reusable software components that model items in the real world (we’ll discuss object technology in Section 1.19). A modular, object-oriented approach to design and implementation can make software-development groups much more productive than is possible using earlier programming techniques. Furthermore, object-oriented programs are often easier to understand, correct and modify. Java Microprocessors are having a profound impact in intelligent consumer electronic devices. Recognizing this, Sun Microsystems in 1991 funded an internal corporate research project that resulted in the development of a C++-based language. When a group of Sun people visited a local coffee shop, the name Java was suggested and it stuck. As the World Wide Web exploded in popularity in 1993, Sun saw the possibility of using Java to add dynamic content (e.g., interactivity, animations and the like) to web pages. Sun formally announced the language in 1995. This generated immediate interest in the business community because of the commercial potential of the web. Java is now used to develop large-scale enterprise applications, to enhance the functionality of web servers (the computers that provide the content we see in our web browsers), to provide applications for consumer devices (such as cell phones, pagers and personal digital assistants) and for many other purposes. Visual C# and Visual Basic are similar in capability to Java.

The advancement of programming tools and consumer electronic devices (e.g., cell phones and PDAs) created problems and new requirements. The integration of software components from various languages proved difficult, and installation problems were common because new versions of shared components were incompatible with old software. Developers also discovered they needed web-based applications that could be accessed and used via the Internet. As a result of the popularity of mobile electronic devices, software developers realized that their clients were no longer restricted to desktop computers. Developers recognized the need for software that was accessible to anyone and available via almost any type of device. To address these needs, in 2000, Microsoft announced the C# programming language. Developed at Microsoft by a team led by Anders Hejlsberg and Scott Wiltamuth, C# was designed specifically for the .NET platform (which is discussed in Section 1.16) as a language that would enable programmers to migrate easily to .NET. It has roots in C, C++ and Java, adapting the best features of each and adding new features of its own. C# is object oriented and has access to a powerful class library of prebuilt com2008935881

1.10 Visual C#

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

10

Chapter 1

Introduction to Computers, the Internet and Visual C#

ponents, enabling programmers to develop applications quickly—C# and Visual Basic share the .NET Framework Class Library, which is discussed in Section 1.17. Visual C# is an event-driven, visual programming language in which programs are created using an IDE. You’ll write programs that respond to timer expirations and userinitiated events such as mouse clicks and keystrokes. In addition to writing program statements to build portions of your C# applications, you’ll also use Visual Studio’s graphical user interface to conveniently drag and drop predefined objects like buttons and textboxes into place on your screen, and label and resize them. Visual Studio will write much of the GUI code for you. With the IDE, a programmer can create, run, test and debug C# programs conveniently, thereby producing a working program in a fraction of the time it would have taken without the IDE. Microsoft introduced its .NET (pronounced “dot-net”) strategy in 2000. The .NET platform—the set of software components that enables .NET programs to run—allows applications to be distributed to a variety of devices (such as cell phones) as well as to desktop computers. The .NET platform offers a programming model that allows software components created in different programming languages (such as C# and Visual Basic) to communicate with one another. We discuss .NET in more detail in Section 1.16. The original C# programming language was standardized by Ecma International (www.ecma-international.org) in December, 2002, as Standard ECMA-334: C# Language Specification (located at www.ecma-international.org/publications/standards/ Ecma-334.htm). Since that time, Microsoft has proposed several language extensions that have been adopted as part of the revised Ecma C# standard. In this book, we discuss Visual C# 2008 and C# 3.0—the latest version of the language, which is included in Visual Studio 2008. This new version provides great new features that we’ll discuss throughout this book. You can find a link to the Microsoft version of the C# Language Specification at msdn.microsoft.com/en-us/vcsharp/aa336809.aspx. This version provides annotations that are geared toward developers working with C#.

Although hundreds of high-level languages have been developed, only a few have achieved broad acceptance. IBM Corporation developed Fortran (Formula Translator) in the mid1950s to create scientific and engineering applications that require complex mathematical computations. Fortran is still widely used. COBOL (COmmon Business-Oriented Language) was developed in the late 1950s by a group of computer manufacturers in conjunction with government and industrial computer users. COBOL is used primarily for business applications that require the manipulation of large amounts of data. A considerable portion of today’s business software is still programmed in COBOL.

1.11 Other High-Level Languages

During the 1960s, software-development efforts often ran behind schedule, costs greatly exceeded budgets and the finished products were unreliable. People began to realize that software development was a far more complex activity than they had imagined. Research activity intended to address these issues resulted in the evolution of structured programming—a disciplined approach to creating clear, correct and easy to modify programs.
2008935881

1.12 Structured Programming

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.13 Key Software Trend: Object Technology

11

One result of this research was the development in 1971 of the Pascal programming language. Pascal, named after the 17th-century mathematician and philosopher Blaise Pascal, was designed for teaching structured programming and rapidly became the preferred introductory programming language in most colleges. Unfortunately, it lacked many features needed to make it useful in commercial, industrial and government applications. By contrast, C, which also arose from research on structured programming, did not have the limitations of Pascal, and professional programmers quickly adopted it. The Ada programming language, based on Pascal, was developed under the sponsorship of the U.S. Department of Defense (DOD) during the 1970s and early 1980s. The language was named after Ada Byron, Lady Lovelace, daughter of the poet Lord Byron. Lady Lovelace is generally acknowledged as the world’s first computer programmer, having written an application in the early 1800s for Charles Babbage’s Analytical Engine mechanical computing device.

As the benefits of structured programming were realized in the 1970s, improved software technology began to appear. Not until object-oriented programming became widely used in the 1980s and 1990s, however, did software developers feel they had the tools to dramatically improve the software-development process. What are objects, and why are they special? Object technology is a packaging scheme for creating meaningful software units. There are date objects, time objects, invoice objects, automobile objects, people objects, audio objects, video objects, file objects and so on. In fact, almost any noun can be reasonably represented as a software object. Objects have properties (also called attributes), such as color, size and weight; and perform actions (also called behaviors or methods), such as moving, sleeping or drawing. Classes are types of related objects. For example, all cars belong to the “car” class, even though individual cars vary in make, model, color and options packages. A class specifies the general format of its objects, and the properties and actions available to an object depend on its class. An object is related to its class in much the same way as a building is related to the blueprint from which it is constructed. Contractors can build many buildings from the same blueprint; programmers can instantiate (create) many objects from the same class. Before object-oriented languages appeared, procedural programming languages (such as Fortran, Pascal, BASIC and C) focused on actions (verbs) rather than things or objects (nouns). This made programming a bit awkward. However, using today’s popular object-oriented languages, such as C#, C++, Java and Visual Basic, you can program in an object-oriented manner that more naturally reflects the way in which you perceive the world. This has resulted in significant productivity gains. With object technology, properly designed classes can be reused on future projects. Using class libraries can greatly reduce the effort required to implement new systems. Some organizations report that the key benefit they get from object-oriented programming is not, in fact, software reusability. Rather, it is the production of software that is more understandable because it is better organized and has fewer maintenance requirements. Object orientation allows you to focus on the “big picture.” Instead of worrying about the minute details of how reusable objects are implemented, you can focus on the behaviors and interactions of objects. A road map that showed every tree, house and driveway would be difficult, if not impossible, to read. When such details are removed and only the
2008935881

1.13 Key Software Trend: Object Technology

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

12

Chapter 1

Introduction to Computers, the Internet and Visual C#

essential information (roads) remains, the map becomes easier to understand. In the same way, an application that is divided into objects is easy to understand, modify and update because it hides much of the detail. It is clear that object-oriented programming will be the key programming methodology for the next several decades. C# is one of the world’s most widely used object-oriented languages.

In the late 1960s, ARPA—the Advanced Research Projects Agency of the Department of Defense—rolled out plans to network the main computer systems of approximately a dozen ARPA-funded universities and research institutions. The computers were to be connected with communications lines operating at a then-stunning 56 Kbps (1 Kbps is equal to 1,024 bits per second), at a time when most people (of the few who even had networking access) were connecting over telephone lines to computers at a rate of 110 bits per second. Academic research was about to take a giant leap forward. ARPA proceeded to implement what quickly became known as the ARPAnet, the grandparent of today’s Internet. Things worked out differently from the original plan. Although the ARPAnet enabled researchers to network their computers, its main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail). This is true even on today’s Internet, with e-mail, instant messaging and file transfer allowing more than a billion people worldwide to communicate with each other. The protocol (in other words, the set of rules) for communicating over the ARPAnet became known as the Transmission Control Protocol (TCP). TCP ensured that messages, consisting of pieces called “packets,” were properly routed from sender to receiver, arrived intact and were assembled in the correct order. In parallel with the early evolution of the Internet, organizations worldwide were implementing their own networks for both intraorganization (that is, within an organization) and interorganization (that is, between organizations) communication. A huge variety of networking hardware and software appeared. One challenge was to enable these different networks to communicate with each other. ARPA accomplished this by developing the Internet Protocol (IP), which created a true “network of networks,” the current architecture of the Internet. The combined set of protocols is now called TCP/IP. Businesses rapidly realized that by using the Internet, they could improve their operations and offer new and better services to their clients. Companies started spending large amounts of money to develop and enhance their Internet presence. This generated fierce competition among communications carriers and hardware and software suppliers to meet the increased infrastructure demand. As a result, bandwidth—the information-carrying capacity of communications lines—on the Internet has increased tremendously, while hardware costs have plummeted. The World Wide Web is a collection of hardware and software associated with the Internet that allows computer users to locate and view multimedia-based documents (documents with various combinations of text, graphics, animations, audios and videos) on almost any subject. Even though the Internet was developed more than three decades ago, the introduction of the World Wide Web (WWW) was a relatively recent event. In 1989, Tim Berners-Lee of CERN (the European Organization for Nuclear Research) began to
2008935881

1.14 The Internet and the World Wide Web

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.15 Extensible Markup Language (XML)

13

develop a technology for sharing information via “hyperlinked” text documents. He called his invention the HyperText Markup Language (HTML). He also wrote communication protocols such as HyperText Transfer Protocol (HTTP) to form the backbone of his new hypertext information system, which he referred to as the World Wide Web. In October 1994, Berners-Lee founded an organization, called the World Wide Web Consortium (W3C, www.w3.org), devoted to developing technologies for the World Wide Web. One of the W3C’s primary goals is to make the web universally accessible to everyone regardless of disabilities, language or culture. The Internet and the web will surely be listed among the most important creations of humankind. In the past, most computer applications ran on “stand-alone” computers (computers that were not connected to one another). Today’s applications can be written with the aim of communicating among the world’s computers—this is the focus of Microsoft’s .NET strategy. The Internet and the web make information instantly and conveniently accessible to large numbers of people, enabling even individuals and small businesses to achieve worldwide exposure. They are profoundly changing the way we do business and conduct our personal lives.

As the popularity of the web exploded, HTML’s limitations became apparent. HTML’s lack of extensibility (the ability to change or add features) frustrated developers, and its ambiguous definition allowed erroneous HTML to proliferate. The need for a standardized, fully extensible and structurally strict language was apparent. As a result, XML was developed by the W3C. Data independence, the separation of content from its presentation, is the essential characteristic of XML. Because XML documents describe data, any application conceivably can process them. Software developers are integrating XML into their applications to improve web functionality and interoperability. XML is not limited to web applications. For example, it is increasingly being employed in databases—the structure of an XML document enables it to be integrated easily with database applications. As applications become more web enabled, it is likely that XML will become the universal technology for data representation. All applications employing XML will be able to communicate with one another, provided that they can understand their respective XML markup schemes, or vocabularies. The Simple Object Access Protocol (SOAP) is a technology for the transmission of objects (marked up as XML) over the Internet. Microsoft’s .NET technologies (discussed in the next two sections) use XML and SOAP to mark up and transfer data over the Internet. XML and SOAP are at the core of .NET—they allow software components to interoperate (i.e., communicate easily with one another). Since SOAP’s foundations are in XML and HTTP (HyperText Transfer Protocol—the key communication protocol of the web), it is supported on most types of computer systems. We discuss XML in Chapter 20 and SOAP in Chapter 23.

1.15 Extensible Markup Language (XML)

1.16 Introduction to Microsoft .NET
2008935881

In June 2000, Microsoft announced its .NET initiative (www.microsoft.com/net), a broad new vision for using the Internet and the web in the development, engineering, dis-

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

14

Chapter 1

Introduction to Computers, the Internet and Visual C#

tribution and use of software. Rather than forcing developers to use a single programming language, the .NET initiative lets them create .NET applications in any .NET-compatible language (such as C#, Visual C++, Visual Basic and others). Part of the initiative includes Microsoft’s ASP.NET technology, which allows you to create web applications. You’ll use ASP.NET 3.5 (the current version) to build the web-based secure-books database application later in the book. The .NET strategy extends the idea of software reuse to the Internet by allowing programmers to concentrate on their specialties without having to implement every component of every application. Visual programming (which you’ll learn throughout this book) has become popular because it enables programmers to create Windows and web applications easily, using such prepackaged controls as buttons, textboxes and scrollbars. The Microsoft .NET Framework is at the heart of the .NET strategy. This framework executes applications and web services, contains a class library (called the .NET Framework Class Library) and provides many other programming capabilities that you’ll use to build C# applications. Steve Ballmer, Microsoft’s CEO, has stated that Microsoft is “betting the company” on .NET. Such a dramatic commitment surely indicates a bright future for Visual C# 2008 programmers.

The Common Language Runtime (CLR) is the central part of the .NET Framework—it executes .NET programs. Programs are compiled into machine-specific instructions in two steps. First, the program is compiled into Microsoft Intermediate Language (MSIL), which defines instructions for the CLR. Code converted into MSIL from other languages and sources can be woven together by the CLR. The MSIL for an application’s components is placed into the application’s executable file. When the application executes, another compiler (known as the just-in-time compiler or JIT compiler) in the CLR translates the MSIL in the executable file into machine-language code (for a particular platform), then the machine-language code executes on that platform. The .NET Framework is needed to run a .NET program and consists mainly of the Common Language Runtime (CLR) and the Framework Class Library. If the .NET Framework exists (and is installed) for a platform, that platform can run any .NET program. The ability of a program to run (without modification) across multiple platforms is known as platform independence. Code written once can be used on another type of computer without modification, saving time and money. In addition, software can target a wider audience—previously, companies had to decide whether converting their programs to different platforms (sometimes called porting) was worth the cost. With .NET, porting programs is no longer an issue (at least once .NET itself has been made available on the platforms). The .NET Framework also provides a high level of language interoperability. Programs written in different languages (e.g., C# and Visual Basic) are all compiled into MSIL—the different parts can be combined to create a single unified program. MSIL allows the .NET Framework to be language independent, because .NET programs are not tied to a particular programming language. Any language that can be compiled into MSIL is called a .NET-aware language.
2008935881

1.17 The .NET Framework and the Common Language Runtime

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.18 Test-Driving a C# Advanced Painter Application

15

The .NET Framework Class Library can be used by any .NET language. The library contains a variety of reusable components, saving programmers the trouble of creating new components. This book explains how to develop .NET software with C#. The details of the .NET Framework are found in the Common Language Infrastructure (CLI), which contains information about the storage of data types (i.e., data that has predefined characteristics such as a date, percentage or currency amount), objects and so on. The CLI has been standardized by Ecma International, making it easier to create the .NET Framework for other platforms. This is like publishing the blueprints of the framework—anyone can build it by following the specifications. The specification is available from www.ecma-international.org/publications/standards/Ecma-335.htm.

In this section, you’ll “test-drive” a C# application that enables you to draw on the screen using the mouse. You’ll run and interact with the working application. You’ll build a similar application in Chapter 16, GUI with Windows Presentation Foundation. The Advanced Painter application allows you to draw with different brush sizes and colors. The elements and functionality you see in this application are typical of what you’ll learn to program in this text. We use fonts to distinguish between IDE features (such as menu names and menu items) and other elements that appear in the IDE. Our convention is to emphasize IDE features (such as the File menu) in a bold sans-serif Helvetica font and to emphasize other elements, such as file names (e.g., Form1.cs), in a sans-serif Lucida font. The following steps show you how to test-drive the application. 1. Checking your setup. Confirm that you have set up your computer properly by reading the Before You Begin section located after the Preface. 2. Locating the application directory. Open a Windows Explorer window and navigate to the C:\Examples\ch01 directory (Fig. 1.2) or the directory where you saved the chapter’s examples.

1.18 Test-Driving a C# Advanced Painter Application

Double click this file to run the application

Fig. 1.2 | Contents of C:\Examples\ch01.
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

16

Chapter 1

Introduction to Computers, the Internet and Visual C#

3. Running the Advanced Painter application. Now that you are in the proper directory, double click the file name AdvancedPainter.exe (Fig. 1.2) to run the application (Fig. 1.3). In Fig. 1.3, several graphical elements—called controls—are labeled. The controls include GroupBoxes, RadioButtons, a Panel and Buttons (these controls are discussed in depth later in the text). The application allows you to draw with a red, blue, green or black brush of small, medium or large size. You’ll explore these options in this test-drive. You can also undo your previous operation or clear the drawing to start from scratch. By using preexisting controls—which are objects—you can create powerful applications in Visual C# much faster than if you had to write all the code yourself. In this text, you’ll learn how to use many preexisting controls, as well as how to write your own program code to customize your applications. The brush’s properties, selected in the RadioButtons labeled Black and Medium, are default settings—the initial settings you see when you first run the application. You include default settings to provide visual cues for users to choose their own settings. Now you’ll choose your own settings. 4. Changing the brush color and size. Click the RadioButton labeled Red to change the brush’s color and Small to change its size. Position the mouse over the white Panel, then press and hold down the left mouse button to draw with the brush. Draw flower petals, as shown in Fig. 1.4. Then click the RadioButton labeled Green to change the color of the brush again. 5. Changing the brush size. Click the RadioButton labeled Large to change the size of the brush. Draw grass and a flower stem, as shown in Fig. 1.5. 6. Finishing the drawing. Click the Blue and Medium RadioButtons. Draw raindrops, as shown in Fig. 1.6, to complete the drawing. 7. Closing the application. Close your running application by clicking its close box, (Fig. 1.6).

RadioButtons Gro upBoxe s

Panel Buttons

Fig. 1.3 | Advanced Painter application.
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.18 Test-Driving a C# Advanced Painter Application

17

Fig. 1.4 | Drawing with a new brush color.

Fig. 1.5 | Drawing with a new brush size.
Close box

Fig. 1.6 | Finishing the drawing.
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

18

Chapter 1

Introduction to Computers, the Internet and Visual C#

Additional Applications in Visual C# 2008 How to Program, 3/e Figure 1.7 lists a few of the hundreds of applications in the examples and exercises in this text. We encourage you to test-drive each of them. The examples folder for Chapter 1 contains the files required to run each application listed in Fig. 1.7. Simply double click the file names for any application you would like to run. [Note: The Garage.exe application assumes that the user inputs a value from 0 to 24.]
Application name
Parking Fees Tic Tac Toe Drawing Stars Drawing Shapes Drawing Polygons

File to execute
Garage.exe TicTacToe.exe DrawStars.exe DrawShapes.exe DrawPolygons.exe

Fig. 1.7 | Examples of C# applications found in this book.

Now we begin our early introduction to object orientation, a natural way of thinking about the world and writing computer programs. Chapters 1, 3–8, 10 and 12 each end with a brief Software Engineering Case Study section, in which we present a carefully paced introduction to object orientation. Our goal here is to help you develop an objectoriented way of thinking and to introduce you to the Unified Modeling Language™ (UML™)—a graphical language that allows people who design object-oriented software systems to use an industry-standard notation to represent them. In this, the only required section of the case study (because it contains foundational information for all readers), we introduce basic object-oriented concepts and terminology. The optional case study sections in Chapters 3–8, 10 and 12, and in Appendix D present an object-oriented design and implementation of the software for a simple automated teller machine (ATM) system. The Software Engineering Case Study sections at the ends of Chapters 3–8: • • • • • analyze a typical requirements document that describes a software system (the ATM) to be built determine the objects required to implement that system determine the attributes the objects will have determine the behaviors these objects will exhibit specify how the objects will interact with one another to meet the system requirements
2008935881

1.19 (Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.19 Introduction to Object Technology and the UML

19

The Software Engineering Case Study sections at the ends of Chapters 8, 10 and 12 modify and enhance the design presented in Chapters 3–7. Appendix D contains a complete, working C# implementation of the object-oriented ATM system. Although our case study is a scaled-down version of an industry-level problem, we nevertheless cover many common industry practices. You’ll experience a solid introduction to object-oriented design with the UML. Also, you’ll sharpen your code-reading skills by touring a complete, straightforward and well-documented C# implementation of the ATM.

Basic Object-Technology Concepts We begin our introduction to object orientation with some key terminology. Everywhere you look in the real world you see objects—people, animals, plants, cars, planes, buildings, computers and so on. Humans think in terms of objects. Telephones, houses, traffic lights, microwave ovens and water coolers are just a few more objects we see around us every day. We sometimes divide objects into two categories: animate and inanimate. Animate objects are “alive” in some sense—they move around and do things. Inanimate objects do not move on their own. Objects of both types, however, have some things in common. They all have attributes (e.g., size, shape, color and weight), and they all exhibit behaviors (e.g., a ball rolls, bounces, inflates and deflates; a baby cries, sleeps, crawls, walks and blinks; a car accelerates, brakes and turns; a towel absorbs water). We’ll study the kinds of attributes and behaviors that software objects have. Humans learn about objects by studying their attributes and observing their behaviors. Different objects can have similar attributes and can exhibit similar behaviors. Comparisons can be made, for example, between babies and adults and between humans and chimpanzees. Object-oriented design (OOD) models software in terms similar to those that people use to describe real-world objects. It takes advantage of class relationships, where objects of a certain class, such as a class of vehicles, have the same characteristics—cars, trucks, little red wagons and roller skates have much in common. OOD takes advantage of inheritance relationships, where new classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. An object of class “convertible” certainly has the characteristics of the more general class “automobile,” but more specifically, the roof goes up and down. Object-oriented design provides a natural and intuitive way to view the softwaredesign process—namely, modeling objects by their attributes, behaviors and interrelationships, just as we describe real-world objects. OOD also models communication between objects. Just as people send messages to one another (e.g., a sergeant commands a soldier to stand at attention), objects also communicate via messages. A bank-account object may receive a message to decrease its balance by a certain amount because the customer has withdrawn that amount of money. OOD encapsulates (i.e., wraps) attributes and operations (behaviors) into objects—an object’s attributes and operations are intimately tied together. Objects have the property of information hiding. This means that objects may know how to communicate with one another across well-defined interfaces, but normally they are not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. You can drive a car effectively, for instance, without knowing the details of how engines, transmissions, brakes and exhaust systems work internally—as long as you
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

20

Chapter 1

Introduction to Computers, the Internet and Visual C#

know how to use the accelerator pedal, the brake pedal, the steering wheel and so on. Information hiding, as you’ll see, is crucial to good software engineering. Languages like C# are object oriented. Programming in such a language is called objectoriented programming (OOP), and it allows computer programmers to conveniently implement an object-oriented design as a working software system. Languages like C, on the other hand, are procedural, so programming tends to be action oriented. In C, the unit of programming is the function. In C#, the unit of programming is the class from which objects are eventually instantiated (an OOP term for “created”). C# classes contain methods (C#’s equivalent of C’s functions) that implement operations, and data that implements attributes. Message passing between objects is implemented through method calls.

Classes, Fields and Methods C# programmers concentrate on creating their own user-defined types called classes. Each class contains data as well as the set of methods that manipulate that data and provide services to clients (i.e., other classes that use the class). The data components of a class are called attributes or fields. For example, a bank-account class might include an account number and a balance. The operation components of a class are called methods. For example, a bank-account class might include methods to make a deposit (increase the balance), make a withdrawal (decrease the balance) and inquire what the current balance is. Programmers use built-in types and user-defined types as the “building blocks” for constructing new user-defined types (classes). The nouns in a system specification help the C# programmer determine the set of classes from which objects are created that work together to implement the system. Classes are to objects as blueprints are to houses—a class is a “plan” for building objects of the class. Just as we can build many houses from one blueprint, we can instantiate (create) many objects from one class. You cannot cook meals in the kitchen of a blueprint, but you can cook meals in the kitchen of a house. You cannot sleep in the bedroom of a blueprint, but you can sleep in the bedroom of a house. Classes can have relationships with other classes. For example, in an object-oriented design of a bank, the “bank teller” class needs to relate to other classes, such as the “customer” class, the “cash drawer” class, the “safe” class, and so on. These relationships are called associations. Packaging software as classes makes it possible for future software systems to reuse the classes. Groups of related classes often are packaged as reusable components. Just as realtors often say that the three most important factors affecting the price of real estate are “location, location and location,” people in the software-development community often say that the three most important factors affecting the future of software development are “reuse, reuse and reuse.”

Software Engineering Observation 1.1
Reuse of existing classes when building new classes and programs saves time, money and effort. Reuse also helps programmers build more reliable and effective systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning.
1.1

Indeed, with object technology, you can build much of the new software you’ll need by combining existing classes, just as automobile manufacturers combine interchangeable parts. Each new class you create will have the potential to become a valuable software asset
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.19 Introduction to Object Technology and the UML

21

that you and other programmers can reuse to speed and enhance the quality of future software-development efforts.

Introduction to Object-Oriented Analysis and Design (OOAD) Soon you’ll be writing programs in C#. How will you create the code for your programs? Perhaps, like many novice programmers, you’ll simply turn on your computer and start typing. This approach may work for small programs (like the ones we present in the early chapters of the book), but what if you were asked to create a software system to control thousands of automated teller machines for a major bank? Or what if you were asked to work on a team of 1000 software developers building the next generation of the U.S. air traffic control system? For projects so large and complex, you could not simply sit down and start writing programs. To create the best solutions, you should follow a detailed process for analyzing your project’s requirements (i.e., determining what your system is supposed to do) and developing a design that satisfies them (i.e., deciding how your system should do it). Ideally, you would go through this process and carefully review the design (and have your design reviewed by other software professionals) before writing any code. If this process involves analyzing and designing your system from an object-oriented point of view, it is called object-oriented analysis and design (OOAD). Experienced programmers know that proper analysis and design can save many hours by helping avoid an ill-planned systemdevelopment approach that has to be abandoned partway through its implementation, possibly wasting considerable time, money and effort. OOAD is the generic term for analyzing a problem and developing an approach for solving it. Small problems, such as the ones discussed in the first few chapters of this book, do not require an exhaustive OOAD process. It may be sufficient, before you begin writing C# code, to write pseudocode—an informal text-based means of expressing program logic. Pseudocode is not actually a programming language, but we can use it as a kind of outline to guide us as we write our code. We introduce pseudocode in Chapter 5. As problems and the groups of people solving them increase in size, OOAD quickly becomes more appropriate than pseudocode. Ideally, a group should agree on a strictly defined process for solving its problem and a uniform way of communicating the results of that process to one another. Although many different OOAD processes exist, a single graphical language for communicating the results of any OOAD process has come into wide use. This language, known as the Unified Modeling Language (UML), was developed in the mid-1990s under the initial direction of three software methodologists: Grady Booch, James Rumbaugh and Ivar Jacobson. History of the UML In the 1980s, many organizations began using OOP to build their applications, and a need developed for a standard object-oriented analysis and design (OOAD) process. Many methodologists—including Grady Booch, James Rumbaugh and Ivar Jacobson—individually produced and promoted separate processes to satisfy this need. Each process had its own notation, or “language” (in the form of graphical diagrams), to convey the results of analysis (i.e., determining what a proposed system is supposed to do) and design (i.e., determining how a proposed system should be implemented to do what it is supposed to do). By the early 1990s, different organizations were using their own unique processes and notations. At the same time, these organizations also wanted to use software tools that
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

22

Chapter 1

Introduction to Computers, the Internet and Visual C#

would support their particular processes. Software vendors found it difficult to provide tools for so many processes. A standard notation and standard process were needed. In 1994, James Rumbaugh joined Grady Booch at Rational Software Corporation (now a division of IBM), and the two began working to unify their popular processes. They soon were joined by Ivar Jacobson. In 1996, the group released early versions of the UML to the software engineering community and requested feedback. Around the same time, an organization known as the Object Management Group™ (OMG™) invited submissions for a common modeling language. The OMG (www.omg.org) is a nonprofit organization that promotes the standardization of object-oriented technologies by issuing guidelines and specifications, such as the UML. Several corporations—among them HP, IBM, Microsoft, Oracle and Rational Software—had already recognized the need for a common modeling language. In response to the OMG’s request for proposals, these companies formed the UML Partners—the consortium that developed the UML version 1.1 and submitted it to the OMG. The OMG accepted the proposal and, in 1997, assumed responsibility for the continuing maintenance and revision of the UML. We present the current UML 2 terminology and notation throughout this book.

What Is the UML? The Unified Modeling Language (UML) is the most widely used graphical representation scheme for modeling object-oriented systems. It has indeed unified the various popular notational schemes. Those who design systems use the language (in the form of diagrams, many of which we discuss throughout our ATM case study and other portions of the book) to model their systems. An attractive feature of the UML is its flexibility. The UML is extensible (i.e., capable of being enhanced with new features) and is independent of any particular OOAD process. UML modelers are free to use various processes in designing systems, but all developers can now express their designs with one standard set of graphical notations. The UML is a feature-rich graphical language. In our subsequent (and optional) Software Engineering Case Study sections on developing the software for an automated teller machine (ATM), we present a simple, concise subset of these features. We then use this subset to guide you through a first design experience with the UML. We sincerely hope you enjoy working through it. Section 1.19 Self-Review Exercises
1.1 List three examples of real-world objects that we did not mention. For each object, list several attributes and behaviors. 1.2 Pseudocode is . a) another term for OOAD b) a programming language used to display UML diagrams c) an informal means of expressing program logic d) a graphical representation scheme for modeling object-oriented systems The UML is used primarily to a) test object-oriented systems b) design object-oriented systems c) implement object-oriented systems d) Both a and b .

1.3

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

1.20 Wrap-Up

23

Answers to Section 1.19 Self-Review Exercises
1.1 [Note: Answers may vary.] a) A television’s attributes include the size of the screen, the number of colors it can display, and its current channel and volume. A television turns on and off, changes channels, displays video and plays sounds. b) A coffee maker’s attributes include the maximum volume of water it can hold, the time required to brew a pot of coffee and the temperature of the heating plate under the coffee pot. A coffee maker turns on and off, brews coffee and heats coffee. c) A turtle’s attributes include its age, the size of its shell and its weight. A turtle crawls, retreats into its shell, emerges from its shell and eats vegetation. 1.2 1.3 c. b.

1.20 Wrap-Up

This chapter introduced basic hardware and software concepts and basic object-technology concepts, including classes, objects, attributes and behaviors. We discussed the different types of programming languages and which languages are most widely used. We presented a brief history of operating systems, including Microsoft’s Windows. We discussed the history of the Internet and the web. We presented the history of C# programming and Microsoft’s .NET initiative, which allows you to program Internet and web-based applications using C# (and other languages). You learned the steps for executing a C# application. You test-drove a sample C# application similar to the types of applications you’ll learn to program in this book. You learned about the history and purpose of the UML— the industry-standard graphical language for modeling software systems. We launched our early objects and classes presentation with the first of our Software Engineering Case Study sections (and the only one which is required). The remaining (all optional) sections of the case study use object-oriented design and the UML to design the software for our simplified automated teller machine system. We present the complete C# code implementation of the ATM system in Appendix D. In the next chapter, you’ll use the Visual Studio IDE (Integrated Development Environment) to create your first C# application, using the techniques of visual programming. You’ll also learn about Visual Studio’s help features.

1.21 Web Resources

The Internet and the web are extraordinary resources. This section includes links to interesting and informative websites. Reference sections like this one are included where appropriate throughout the book.
www.deitel.com/VisualCSHarp2008/

Our C# Resource Center focuses on the enormous amount of C# content available online. Search for resources, downloads, tutorials, documentation, books, e-books, journals, articles, blogs and more that will help you develop C# applications. Deitel.com has a growing list of C# and related Resource Centers, including ASP.NET, ASP.NET 3.5, ASP.NET AJAX, Microsoft LINQ, Microsoft Popfly, .NET 3.0, .NET 3.5, Silverlight 2, SQL Server 2008, Visual C# 2008, Visual C++, Visual Basic 2008 and C# 3.0 Resource Center, Windows Communication Foundation, Windows Presentation Foundation, Windows Vista, XAML and many more.
2008935881

www.deitel.com/ResourceCenters.html

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

24

Chapter 1

Introduction to Computers, the Internet and Visual C#

msdn.microsoft.com/en-us/vcsharp/aa336809.aspx

Thia Microsoft website provides a quick tour of C#. It contains links to various reference information, including Microsoft’s version of the C# Language Specification 3.0. This version of the specification is annotated with information for developers.
www.ecma-international.org/publications/standards/Ecma-334.htm

You can download the C# Language Specification in PDF format from here. This version of the specification is geared toward compiler developers.
www.deitel.com

Visit this site for code downloads, updates, corrections and additional resources for Deitel & Associates publications, including Visual C# 2008 How To Program, 3/e, errata, Frequently Asked Questions (FAQs), hot links and code downloads.
www.prenhall.com/deitel

The Deitel & Associates page on the Prentice Hall website contains information about our publications and code downloads for this book.

Summary
Section 1.1 Introduction
• C# is appropriate for technically oriented people with little or no programming experience, and for experienced programmers to use in building substantial information systems. • Computer use is increasing in almost every field of endeavor. • Computing costs have been decreasing dramatically, owing to rapid developments in both hardware and software technologies. • Silicon-chip technology has made computing so economical that about a billion general-purpose computers are in use worldwide, helping people in business, industry and government, and in their personal lives.

Section 1.2 What Is a Computer?

• A computer is a device that can perform calculations and make logical decisions millions, billions and even trillions of times faster than humans can. • Today’s fastest supercomputers are already performing trillions of additions per second! • Computer programs guide computers through orderly sets of actions that are specified by computer programmers. An application is a program that does something particularly useful. • A computer is composed of various devices (such as the keyboard, screen, mouse, hard drives, memory, DVD drives, printer and processing units) known as hardware. • The programs that run on a computer are referred to as software. • Object-oriented programming, available in C# and other programming languages, is a significant breakthrough that can greatly enhance your productivity. • The input unit obtains information (data and computer programs) from various input devices, such as the keyboard and the mouse. • The output unit takes information that the computer has processed and places it on various output devices, making the information available for use outside the computer. • The memory unit stores information temporarily that has been entered through input devices, so the information is immediately available for processing. The memory unit also retains processed information until it can be sent to output devices.
2008935881

Section 1.3 Computer Organization

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

Summary

25

• The central processing unit (CPU) serves as the “administrative” section of the computer, supervising the operation of the other sections. • The arithmetic and logic unit (ALU) is the “manufacturing” section of the computer—it performs calculations and makes decisions. • The secondary storage unit is the long-term, high-capacity “warehousing” section of the computer. Secondary storage devices normally hold programs or data that other units are not actively using. Secondary storage is nonvolatile, retaining information even when the computer is powered off.

Section 1.4 Personal Computing, Distributed Computing and Client/Server Computing
• Silicon-chip technology made it possible for computers to be much smaller and more economical—individuals and small organizations could own these machines. • In 1977, Apple Computer—creator of today’s popular Macintosh personal computers and iPod digital music players—popularized personal computing. • In 1981, IBM, the world’s largest computer vendor, introduced the IBM Personal Computer, legitimizing personal computing in business, industry and government organizations. • Personal computers could be linked together in computer networks, sometimes over telephone lines and sometimes in local area networks (LANs) within an organization. This led to the phenomenon of distributed computing, in which an organization’s computing is distributed over networks to the geographically dispersed sites where the organization’s work is performed. • Personal computers were powerful enough to handle the computing requirements of individuals and the basic communications tasks of passing information between computers electronically. • Information can be shared easily across computer networks, where computers called file servers offer a common data store that may be used by client computers distributed throughout the network, hence the term client/server computing. • Moore’s Law states that the capacities of computers approximately double every year or two, without any increase in price. Similar growth has occurred in the communications field, in which costs have plummeted as enormous demand for communications bandwidth has attracted intense competition. • The invention of microprocessor-chip technology and its wide deployment in the late 1970s and 1980s laid the groundwork for the productivity improvements that individuals and businesses have achieved in recent years. • In 1981, Microsoft released the first version of its DOS for the IBM Personal Computer (DOS is an acronym for “Disk Operating System”). • In the mid-1980s, Microsoft developed the Windows operating system, a graphical user interface built on top of DOS. • Microsoft released Windows 3.0 in 1990; this new version featured a user-friendly interface and rich functionality. • The Windows operating system became incredibly popular after the 1993 release of Windows 3.1, whose successors, Windows 95 and Windows 98, virtually cornered the desktop operatingsystems market by the late 1990s. • Windows XP was released in 2001 and combines Microsoft’s corporate and consumer operatingsystem lines.

Section 1.5 Hardware Trends

Section 1.6 Microsoft’s Windows® Operating System

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

26

Chapter 1

Introduction to Computers, the Internet and Visual C#

• Windows Vista, released in 2007, is Microsoft’s latest operating-system offering. • The biggest competitor to the Windows operating system is Linux.

Section 1.7 Machine Languages, Assembly Languages and High-Level Languages

• The hundreds of computer languages in use today can be divided into three general types—machine languages, assembly languages, high-level languages. • As the “natural language” of a particular computer, machine language is defined by the computer’s hardware design. Machine languages generally consist of streams of numbers (ultimately reduced to 1s and 0s) that instruct computers how to perform their most elementary operations. • The number system with only 1s and 0s is called the binary number system. Machine-language programs are sometimes called “binaries” for that reason. • A particular machine language can be used on only one type of computer. • Programmers began using English-like abbreviations to represent the computer’s basic operations. These abbreviations formed the basis of assembly languages. • Translator programs called assemblers convert assembly-language programs to machine language at computer speeds. • High-level languages enable programmers to write instructions that look almost like everyday English and contain common mathematical notations. Translator programs called compilers convert high-level-language programs into machine language. • Visual Basic evolved from BASIC (Beginner’s All-purpose Symbolic Instruction Code), developed by Professors John Kemeny and Thomas Kurtz of Dartmouth College. BASIC’s primary purpose was to teach novices fundamental programming techniques. • With the creation of the Windows GUI, the natural evolution of BASIC was to Visual Basic, which made programming Windows applications easier. • Visual Basic is an object-oriented, event-driven language. • With Microsoft’s Visual Studio Integrated Development Environment (IDE), you can write, run, test and debug programs quickly and conveniently.

Section 1.8 Visual Basic

Section 1.9 C, C++ and Java

• The C programming language, implemented by Dennis Ritchie at Bell Laboratories in 1973, gained widespread recognition as the development language of the UNIX operating system. • C is a hardware-independent language, and, with careful design, it is possible to write C programs that are portable to most computers. • C++ provides a number of features that “spruce up” the C language and provides capabilities for object-oriented programming (OOP). • A modular, object-oriented approach to design and implementation can make software-development groups much more productive. Object-oriented programs are often easier to understand, correct and modify. • Sun Microsystems developed Java, a C++-based language, which is used to develop large-scale enterprise applications, to enhance the functionality of web servers, to provide applications for consumer devices and for many other purposes. • C#, created by Microsoft in 2000 specifically for the .NET platform, has roots in C, C++ and Java. C# is object oriented and has access to powerful prebuilt components, enabling programmers to develop applications quickly.
2008935881

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

Summary

27

Section 1.10 Visual C#

• C#, developed at Microsoft by a team led by Anders Hejlsberg and Scott Wiltamuth, was designed specifically for the .NET platform as a language that would enable programmers to migrate easily to .NET. • C# has roots in C, C++ and Java. • C# is object oriented and shares with Visual Basic the .NET Framework Class Library—a powerful set of prebuilt components, enabling programmers to develop applications quickly. • Visual C# is a visual programming language—in addition to writing program statements to build portions of your applications, you’ll also use Visual Studio’s graphical user interface to conveniently drag-and-drop predefined objects like buttons and textboxes into place on your screen, and label and resize them. Visual Studio will write much of the GUI code for you. • With the IDE, a programmer can create, run, test and debug C# programs conveniently, thereby producing a working program in a fraction of the time it would have taken without the IDE. • Microsoft introduced its .NET (pronounced “dot-net”) strategy in 2000. • The .NET platform allows applications to be distributed to a variety of devices (such as cell phones) as well as to desktop computers. • The .NET platform offers a programming model that allows software components created in different programming languages to communicate with one another. • The original C# programming language was standardized by Ecma International in December, 2002, as Standard ECMA-334: C# Language Specification. • You’ll use Visual Studio’s graphical user interface to conveniently drag-and-drop predefined objects like buttons and textboxes into place on your screen, and label and resize them. • The .NET platform, introduced in 2000, is a set of software components that allow applications to be distributed to a variety of devices (such as cell phones) as well as to desktop computers. • IBM Corporation developed Fortran (Formula Translator) in the mid-1950s to create scientific and engineering applications that require complex mathematical computations. • COBOL was developed in the late 1950s for business applications that require the manipulation of large amounts of data. • Structured programming is a disciplined approach to creating programs that are clear, correct and easy to modify. • The Pascal programming language was designed for teaching structured programming and rapidly became the preferred introductory programming language in most colleges. • The Ada programming language, based on Pascal, was developed under the sponsorship of the U.S. Department of Defense (DOD). • Ada is named after Ada Byron, Lady Lovelace, daughter of the poet Lord Byron. Lady Lovelace is generally acknowledged as the world’s first computer programmer, having written an application in the early 1800s for Charles Babbage’s Analytical Engine mechanical computing device. • Object technology is a packaging scheme for creating meaningful software units. • Objects have properties (also called attributes), such as color, size and weight, and they perform actions (also called behaviors or methods), such as moving, sleeping or drawing.

Section 1.11 Other High-Level Languages

Section 1.12 Structured Programming

Section 1.13 Key Software Trend: Object Technology

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

28

Chapter 1

Introduction to Computers, the Internet and Visual C#

• Classes are types of related objects. A class specifies the general format of its objects, and the properties and actions available to an object depend on its class. • Using class libraries can greatly reduce the amount of effort required to implement new systems. • Object orientation allows you to focus on the “big picture”—the behaviors and interactions of objects. An application that is divided into objects is easy to understand, modify and update because it hides much of the detail.

Section 1.14 The Internet and the World Wide Web

• In the late 1960s, ARPA—the Advanced Research Projects Agency of the Department of Defense—rolled out plans to network the main computer systems of approximately a dozen ARPAfunded universities and research institutions. This became known as the ARPAnet, the grandparent of today’s Internet. • ARPAnet’s main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail). • Transmission Control Protocol (TCP) ensured that messages, consisting “packets,” were properly routed from sender to receiver, arrived intact and were assembled in the correct order. • The Internet Protocol (IP) created a true “network of networks,” allowing different networks to communicate with each other. • TCP/IP makes up the current architecture of the Internet. • Bandwidth—the information-carrying capacity of communications lines—on the Internet has increased tremendously, while hardware costs have plummeted. • The World Wide Web is a collection of hardware and software associated with the Internet that allows computer users to locate and view multimedia-based documents (documents with various combinations of text, graphics, animations, audios and videos) on almost any subject. • HyperText Markup Language (HTML) is a technology for sharing information via “hyperlinked” text documents. HyperText Transfer Protocol (HTTP) forms the backbone of the hypertext information system, which is referred to as the World Wide Web. • The World Wide Web Consortium (W3C, www.w3.org) is devoted to developing technologies for the World Wide Web. • In the past, most computer applications ran on “stand-alone” computers (computers that were not connected to one another). • The Internet and the web make information instantly and conveniently accessible to large numbers of people, enabling even individuals and small businesses to achieve worldwide exposure. • Data independence (separation of content from its presentation) is the essential characteristic of XML. • As applications become more web enabled, it is likely that XML will become the universal technology for data representation. • The Simple Object Access Protocol (SOAP) is a technology for the transmission of objects (marked up as XML) over the Internet. • XML and SOAP are at the core of .NET—they allow software components to interoperate (i.e., communicate easily with one another). • Microsoft’s .NET initiative (www.microsoft.com/net) is a broad new vision for using the Internet and the web in the development, engineering, distribution and use of software.
2008935881

Section 1.15 Extensible Markup Language (XML)

Section 1.16 Introduction to Microsoft .NET

Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

Summary

29

• The .NET initiative permits developers to create .NET applications in any .NET-compatible language (such as Visual C#, Visual C++, Visual Basic and others). • Part of the .NET initiative includes Microsoft’s ASP.NET technology, which allows you to create web applications. • The .NET strategy extends the idea of software reuse to the Internet—allowing you to concentrate on your specialty without having to implement every component of every application. • Visual programming has become popular because it enables programmers to create Windows and web applications easily, using prepackaged graphical components. • The Microsoft .NET Framework is at the heart of the .NET strategy. This framework executes applications and web services, contains a class library (called the Framework Class Library) and provides many other programming capabilities that you’ll use to build C# applications.

Section 1.17 The .NET Framework and the Common Language Runtime

• The Common Language Runtime (CLR) executes .NET programs. Programs are compiled into machine-specific instructions in two steps. First, the program is compiled into Microsoft Intermediate Language (MSIL), which defines instructions for the CLR. Code converted into MSIL from other languages and sources can be woven together by the CLR. • The MSIL for an application’s components is placed into the application’s executable file. When the application executes, another compiler (known as the just-in-time compiler or JIT compiler) in the CLR translates the MSIL in the executable file into machine-language code (for a particular platform), then the machine-language code executes on that platform. • If the .NET Framework exists (and is installed) for a platform, that platform can run any .NET program. The ability of a program to run (without modification) across multiple platforms is known as platform independence. • The .NET Framework also provides a high level of language interoperability. Programs written in different languages are all compiled into MSIL—the different parts can be combined to create a single unified program. MSIL allows the .NET Framework to be language independent, because .NET programs are not tied to a particular programming language. • The .NET Framework Class Library can be used by any .NET language.

Section 1.18 Test-Driving a C# Advanced Painter Application

• You can use existing controls—which are objects—to get powerful applications running in Visual C# much faster than if you had to write all of the code yourself. • The default settings for controls are the initial settings you see when you first run the application. Programmers include default settings to provide reasonable choices that the application will use if the user chooses not to change the settings.

Section 1.19 (Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML

• The Unified Modeling Language (UML) is a graphical language that allows people who build systems to represent their object-oriented designs in a common notation. • Object-oriented design (OOD) models software components in terms of real-world objects. It takes advantage of class relationships, where objects of a certain class have the same characteristics. It also takes advantage of inheritance relationships, where newly created classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. OOD encapsulates data (attributes) and functions (behavior) into objects—the data and functions of an object are intimately tied together.

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

30

Chapter 1

Introduction to Computers, the Internet and Visual C#

• Objects have the property of information hiding—objects of one class are normally not allowed to know how objects of other classes are implemented. • Object-oriented programming (OOP) allows programmers to implement object-oriented designs as working systems. • C# programmers concentrate on creating their own user-defined types called classes. Each class contains data as well as the set of methods that manipulate that data and provide services to clients (i.e., other classes or methods that use the class). • The data components of a class are called attributes or fields. The operation components of a class are called methods. • Classes can have relationships with other classes. These relationships are called associations. • Packaging software as classes makes it possible for future software systems to reuse the classes. Groups of related classes are often packaged as reusable components. • An instance of a class is called an object. • With object technology, programmers can build much of the software they will need by combining standardized, interchangeable parts called classes. • The process of analyzing and designing a system from an object-oriented point of view is called object-oriented analysis and design (OOAD).

Terminology
action action oriented Ada Byron, Lady Lovelace Ada programming language “administrative” section of the computer arithmetic and logic unit (ALU) ARPAnet ASP.NET assembler assembly language association attribute of a class bandwitdth BASIC (Beginner’s All-purpose Symbolic Instruction Code) behavior of an object C programming language C# programming language C++ programming language central processing unit (CPU) class class library client of a class client/server computing COBOL programming language Common Language Infrastructure (CLI) Common Language Runtime (CLR) compiler component computer computer program computer programmer control data data independence debugging design distributed computing dynamic content e-mail (electronic mail) encapsulate event-driven program extensible field of a class Fortran programming language function graphical user interface (GUI) hardware hardware platform high-level language HTML (HyperText Markup Language) HTTP (Hypertext Transfer Protocol) information hiding inheritance input device input unit instantiate an object of a class Integrated Development Environment (IDE)
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

Self-Review Exercises
interface Internet Java programming language just-in-time ( JIT) compiler language independence language interoperability in .NET Linux operating system live-code approach local area network (LAN) logical unit Mac OS X operating system machine dependent machine language “manufacturing” section of the computer memory memory unit method microprocessor Microsoft Intermediate Language (MSIL) Microsoft .NET Moore’s Law multiprocessor .NET Framework .NET Framework Class Library .NET initiative .NET platform nouns in a system specification object object oriented object-oriented analysis and design (OOAD) object-oriented design (OOD) object-oriented programming (OOP) object technology operating system operation of a class output device output unit Pascal programming language

31

personal computer personal computing platform independence portability primary memory procedural programming properties random-access memory (RAM) “receiving” section of the computer requirements reusable software component secondary storage unit server “shipping” section of the computer SOAP (Simple Object Access Protocol) software software reuse structured programming supercomputer translation translator program Transmission Control Protocol/Internet Protocol (TCP/IP) UML (Unified Modeling Language) user-defined type Visual Basic programming language Visual C# programming language visual programming Visual Studio volatile memory W3C (World Wide Web Consortium) web web service Windows operating system World Wide Web (WWW) XML (Extensible Markup Language) XML vocabulary

Self-Review Exercises
1.1 Fill in the blanks in each of the following statements: language, which is a) Computers can directly understand only their native composed only of 1s and 0s. b) Computers process data under the control of sets of instructions called computer . c) The three types of languages discussed in the chapter are machine languages, and . d) Programs that translate high-level-language programs into machine language are called . e) Visual Studio is a(n) in which C# programs are developed.

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

32

Chapter 1

Introduction to Computers, the Internet and Visual C#

f) C is widely known as the development language of the operating system. g) Web services use and to mark up and send information over the Internet, respectively. 1.2 State whether each of the following is true or false. If false, explain why. a) The UML is used primarily to implement object-oriented systems. b) C# is an object-oriented language. c) C# is the only language available for programming .NET applications. d) Procedural programming models the world more naturally than object-oriented programming. e) Computers can directly understand high-level languages. f) MSIL is the common intermediate format to which all .NET programs compile, regardless of their original .NET language. g) The .NET Framework is portable to non-Windows platforms.

Answers to Self-Review Exercises
1.1 a) machine. b) programs. c) assembly languages, high-level languages. d) compilers. e) Integrated Development Environment (IDE). f) UNIX. g) XML, SOAP. 1.2 a) False. The UML is used primarily to design object-oriented systems. b) True. c) False. Visual C# is one of many .NET languages (others include Visual Basic, Visual C++ and many more). d) False. Object-oriented programming (because it focuses on things) is a more natural way to model the world than procedural programming. e) False. Computers can directly understand only their own machine languages. f) True. g) True.

Exercises
1.3 Categorize each of the following items as either hardware or software: a) CPU b) Compiler c) Input unit d) A word-processing program e) A C# program 1.4 Translator programs, such as assemblers and compilers, convert programs from one language (referred to as the source language) to another language (referred to as the target language). Determine which of the following statements are true and which are false: a) A compiler translates high-level language programs into target-language programs. b) An assembler translates source-language programs into machine-language programs. c) A compiler converts source-language programs into target-language programs. d) High-level languages are generally machine dependent. e) A machine-language program requires translation before it can be run on a computer. f) The Visual C# compiler translates high-level-language programs into SMIL. 1.5 What are the basic requirements of a .NET language? What is needed to run a .NET program on a new type of computer (machine)? 1.6 Expand each of the following acronyms: a) W3C b) XML c) SOAP d) OOP e) CLR f) CLI
2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.

Exercises

33

g) MSIL h) UML i) OMG j) IDE 1.7 What are the key benefits of the .NET Framework and the CLR? What are the drawbacks? 1.8 What are the advantages to using object-oriented techniques? 1.9 You are probably wearing on your wrist one of the world’s most common types of objects—a watch. Discuss how each of the following terms and concepts applies to the notion of a watch: object, attributes and behaviors. 1.10 What was the key reason that Visual Basic was developed as a special version of the BASIC programming language? 1.11 What is the key accomplishment of the UML? 1.12 What did the chief benefit of the early Internet prove to be? 1.13 What is the key capability of the web? 1.14 What is the key vision of Microsoft’s .NET initiative? 1.15 How does the .NET Framework Class Library facilitate the development of .NET applications? 1.16 What is the key advantage of standardizing .NET’s CLI (Common Language Infrastructure) with Ecma? 1.17 Why is programming more “natural” in an object-oriented language such as C# than in a procedural programming language such as C? 1.18 Despite the obvious benefits of reuse made possible by OOP, what do many organizations report as the key benefit of OOP? 1.19 Why is C# said to be an event-driven language? 1.20 Why is XML so crucial to the development of future software systems?

2008935881 Visual C# 2008: How to Program, Third Edition, by P.J. Deitel and H.M. Deitel. Published by Prentice Hall. Copyright © 2009 by Pearson Education, Inc.