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

 

The chief merit of language is clearness.

 
 --Galen
 

Our life is frittered away with detail. . . . Simplify, simplify.

 
 --Henry David Thoreau
 

Man is still the most extraordinary computer of all.

 
 --John F. Kennedy
<feature> <supertitle>Objectives</supertitle>

In this chapter you’ll learn:

<objective>

Basic hardware and software concepts.

</objective>
<objective>

The different types of programming languages.

</objective>
<objective>

The history of the Visual C# programming language.

</objective>
<objective>

Some basics of object technology.

</objective>
<objective>

The history of the Internet and the World Wide Web.

</objective>
<objective>

About Microsoft’s .NET initiative, which involves the Internet in developing and using software systems.

</objective>
<objective>

To test-drive a Visual C# 2010 drawing application.

</objective>
</feature>
<feature> <supertitle>Outline</supertitle> </feature>

Introduction

Welcome to Visual C# 2010 which, from this point forward, we’ll refer to simply as C#. Computer use is increasing in almost every field. Computing costs have been decreasing dramatically due to rapid developments in hardware, software and communications technologies. Computing has become so economical that billions of computers are in use worldwide, helping people in business, industry and government, and in their personal lives.

Computers process data, using sets of instructions called computer programs. These programs guide computers through orderly sets of calculations and other actions that are specified by people known as computer programmers. Today’s personal computers can perform billions of these calculations and actions per second. A person operating a desk calculator might require a lifetime to complete the same amount of work! Today’s fastest supercomputers work so quickly that they can perform the equivalent of 150,000 actions and calculations per second for every person on the planet!

A computer consists of various devices referred to as hardware (for example, the keyboard, screen, mouse, hard drive, memory, DVD drives and processing units). The programs that run on a computer are referred to as software (for example, applications such as word processors, payroll systems, spreadsheets, e-mail systems, games, etc.).

Object-oriented programming (which models real-world objects with software counterparts), available in C# and other major programming languages, can greatly enhance your productivity. The core of this book emphasizes achieving program clarity through the proven techniques of object-oriented programming (OOP).

Computer Organization

Regardless of differences in physical appearance, virtually every computer can be envisioned as divided into various logical units or sections:

  1. Input unit. This “receiving” section obtains information (data and computer programs) from input devices and places it at the disposal of the other units so that it can be processed. Most information is entered into computers through keyboards and mouse devices. Information also can be entered in many other ways, including by speaking to your computer, scanning images and barcodes, reading from secondary storage devices (like hard drives, CD drives, DVD drives and USB drives—also called thumb drives, flash drives or memory sticks) and having your computer receive information from the Internet (such as when you download videos from YouTube™, e-books from Amazon, and the like).

  2. Output unit. This “shipping” section takes information that the computer has processed and places it on various output devices to make it available for use outside the computer. Most information that is output from computers today is displayed on screens, printed on paper, played on audio players (such as Apple’s popular iPods), or used to control other devices. Computers also can output their information to networks, such as the Internet.

  3. Memory unit. This rapid-access, relatively low-capacity “warehouse” section retains information that has been entered through the input unit, making it immediately available for processing when needed. The memory unit also retains processed information until it can be placed on output devices by the output unit. Information in the memory unit is volatile—it’s typically lost when the computer’s power is turned off. The memory unit is often called either memory or primary memory.

  4. Arithmetic and logic unit (ALU). This “manufacturing” section performs calculations, such as addition, subtraction, multiplication and division. It also contains the decision mechanisms that allow the computer, for example, to compare two items from the memory unit to determine whether they’re equal. In today’s systems, the ALU is usually implemented as part of the next logical unit, the CPU.

  5. Central processing unit (CPU). This “administrative” section coordinates and supervises the operation of the other sections. The CPU tells the input unit when information should be read into the memory unit, tells the ALU when information from the memory unit should be used in calculations and tells the output unit when to send information from the memory unit to certain output devices. Many of today’s computers have multiple CPUs and, hence, can perform many operations simultaneously—such computers are called multiprocessors. A multicore processor implements multiprocessing on a single integrated circuit chip—for example, a dual-core processor has two CPUs and a quad-core processor has four CPUs.

  6. Secondary storage unit. This is the long-term, high-capacity “warehousing” section. Programs or data not actively being used by the other units normally are placed on secondary storage devices (for example, your hard drive) until they’re needed again, possibly hours, days, months or even years later. Therefore, information on secondary storage devices is said to be persistent—it is preserved even when the computer’s power is turned off. Secondary storage information takes much longer to access than information in primary memory, but the cost per unit of secondary storage is much less than that of primary memory. Examples of secondary storage devices include CDs, DVDs and USB drives, which can hold hundreds of millions to billions of characters.

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 made it possible for computers to be much smaller and so economical that individuals and small organizations could own these machines. In 1977, Apple Computer—creator of today’s popular Mac personal computers, iPod digital music players and iPhones—popularized personal computing. In 1981, IBM, then 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”). 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.

Today’s personal computers are as powerful as the million-dollar machines of a few decades ago; complete personal computer systems often sell for as little as a few hundred dollars. 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 and various services that may be used by client computers distributed throughout the network, hence the term client/server computing. In Chapter 19, Web App Development with ASP.NET, you’ll learn how to build web apps; 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).

Hardware Trends

For decades, hardware costs have been falling rapidly. Every year or two, the computing power of computers has approximately doubled without any increase in price. This often is called Moore’s Law, named after the person who first identified and explained the trend, 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 and data, the amount of secondary storage (such as disk storage) they have, and their processor speeds—the speeds at which computers execute their programs (that is, 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. Such phenomenal improvement in the computing and communications fields is truly fostering the so-called Information Revolution.

Microsoft’s Windows® Operating System

Microsoft became the dominant software company in the 1980s and 1990s. In the mid-1980s, Microsoft developed the Windows operating system, consisting of a graphical user interface built on top of DOS (a personal computer operating system that users interacted with by typing commands). 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, enabled users to work with multiple applications simultaneously. Microsoft entered the corporate operating systems market with the 1993 release of Windows NT. Windows XP was released in 2001 and combined Microsoft’s corporate and consumer operating system lines. Windows Vista, released in 2007, offered the attractive new Aero user interface, many powerful enhancements and new applications. A key focus of Windows Vista was enhanced security. Windows 7 is Microsoft’s latest operating system—its features include enhancements to the Aero user interface, faster startup times, further refinement of Vista’s security features, touch screen and multi-touch support, and more. This book is intended for Windows XP, Windows Vista and Windows 7 users. Windows is by far the world’s most widely used operating system.

Machine Languages, Assembly Languages and High-Level Languages

Although hundreds of computer languages are in use today, they can be divided into three general types:

Machine Languages

A computer can directly understand only its own machine language, which is defined by the computer’s hardware design. Machine languages generally consist of streams of numbers (ultimately represented in the computer as combinations of 1s and 0s) that instruct computers how to perform their most elementary operations. People normally work in the decimal number system with digits in the range 0–9. The number system with only 1s and 0s is called the binary number system. Machine-language programs are sometimes called “binaries” for that reason. Machine languages are machine dependent—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

Assembly Languages

As the popularity of computers increased, machine-language programming proved to be tedious and error prone. Instead of using the strings of numbers that computers could directly understand, programmers began using English-like abbreviations (called mnemonics) 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 clearer to humans than in the machine-language example:

LOAD   BASEPAY
ADD    OVERPAY
STORE  GROSSPAY

High-Level Languages

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 simple tasks. To speed up the programming process, high-level 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’s clear why programmers prefer high-level languages. The languages we discuss in the remainder of the chapter are all high-level languages. C# is one of the world’s most popular high-level programming languages.

Visual Basic

Visual Basic evolved from BASIC (Beginner’s All-purpose Symbolic Instruction Code), developed in the mid-1960s at Dartmouth College for introducing novices to 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.

Visual Basic and C# programs are created with the use of Microsoft’s Visual Studio—a collection of software tools called an Integrated Development Environment (IDE). With the Visual Studio 2010 IDE, you can write, run, test and debug Visual Basic and C# programs quickly and conveniently.

C, C++, Objective-C and Java

The C programming language was developed in the early 1970s. C first gained widespread recognition as the development language of the UNIX operating system. C is a hardware-independent language, and, with careful design, it’s possible to write C programs that are portable to most computers.

C++, developed in the early 1980s, provides several features that “spruce up” the C language, and, more importantly, capabilities for object-oriented programming (OOP). Objects are reusable software components that model items in the real world. A modular, object-oriented approach to design and implementation can make software development groups much more productive than is possible using earlier programming techniques.

The Objective-C programming language, also developed in the early 1980s, added capabilities for object-oriented programming (OOP) to the C programming language. It eventually became the software development language for Apple’s Macintosh. Its use has exploded as the app development language for Apple’s wildly popular iPod, iPhone and iPad consumer devices.

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, which Sun eventually called Java. As the World Wide Web exploded in popularity in 1993, Sun saw the possibility of using Java to add dynamic content (for example, interactivity, animations and the like) to web pages. Sun 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 smartphones) and for many other purposes.

C#

In 2000, Microsoft announced the C# (pronounced “C-Sharp”) programming language—created specifically for the .NET platform (discussed in Section 1.12). C# has roots in C, C++ and Java. Like Visual Basic, C# is object oriented and has access to the powerful .NET Framework Class Library—a vast collection of prebuilt components, enabling programmers to develop applications quickly. Both languages have similar capabilities to Java and are appropriate for the most demanding application development tasks, especially for building today’s enterprise applications, and web-based and mobile applications.

C# is object oriented—you’ll learn some basics of object technology shortly and will study a rich treatment later in the book. C# is event driven—you’ll write programs that respond to user-initiated events such as mouse clicks, keystrokes and timer expirations. Microsoft’s Visual C# is indeed 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.

C# has been standardized internationally, enabling other implementations of the language besides Microsoft’s Visual C#, such as Mono (www.mono-project.com).

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 some ARPA-funded universities and research institutions. 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 billions of people worldwide to communicate with each other.

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. In 1989, Tim Berners-Lee of CERN (the European Organization for Nuclear Research) began to develop a technology for sharing information over the Internet via “hyperlinked” text documents. Berners-Lee 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—or simply “the web.”

In 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.

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 via the Internet and the web. In fact, as you’ll see, this is the focus of Microsoft’s .NET strategy. Later in this book we discuss how to build web-based applications with C#.

Extensible Markup Language (XML)

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 isn’t limited to web applications. For example, it’s increasingly used in databases—an XML document’s structure enables it to be integrated easily with database applications. As applications become more web enabled, it’s likely that XML will become the universal technology for data representation. Applications employing XML would be able to communicate with one another, provided that they could understand their respective XML markup schemes, or vocabularies. Microsoft’s .NET technologies use XML to mark up and transfer data over the Internet, and to enable software components to interoperate.

Introduction to Microsoft .NET

In 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, distribution and use of software. Rather than forcing developers to use a single programming language, the .NET initiative permits developers to create .NET applications in any .NET-compatible language (such as C#, Visual Basic, and others). Part of the 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 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 you to create Windows and web applications easily, using such prepackaged controls as buttons, textboxes and scrollbars.

The .NET Framework is at the heart of Microsoft’s .NET strategy. This framework executes applications, includes the .NET Framework Class Library and provides many other programming capabilities that you’ll use to build C# applications.

The .NET Framework and the Common Language Runtime

The details of the .NET Framework are found in the Common Language Infrastructure (CLI), which contains information about the storage of data types (that is, data that has predefined characteristics such as a date, percentage or currency amount), objects and so on. The CLI has been standardized, making it easier to implement the .NET Framework for other platforms. This is like publishing the blueprints of the framework—anyone can build it by following the specifications.

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.

If the .NET Framework is installed on a platform, that platform can run any .NET program. A program’s ability 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. Software can also 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 (for example, 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.

The .NET Framework Class Library can be used by any .NET language. The library contains a variety of reusable components, saving you the trouble of creating new components. This book explains how to develop .NET software with C#.

Test-Driving the Advanced Painter Application

In this section, you’ll “test-drive” an existing application that enables you to draw on the screen using the mouse. 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. The following steps show you how to test-drive the application. You’ll run and interact with the working application.

  1. Checking your setup. Confirm that you’ve 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:examplesch01 directory (Fig. 1.1)—we assume you placed the examples in the C:examples folder.

    Contents of C:examplesch01.

    Figure 1.1. Contents of C:examplesch01.

  3. Running the Advanced Painter application. Now that you’re in the proper directory, double click the file name AdvancedPainter.exe (Fig. 1.1) to run the application (Fig. 1.2). [Note: Depending on your system configuration, Windows Explorer might not display file name extensions. To display file name extensions (like .exe in Fig. 1.1), type Alt + T in Windows Explorer to open the Tools menu, then select Folder options.... In the Folder Options window, select the View tab, uncheck Hide extensions for known file types and click OK.]

    C# Advanced Painter application.

    Figure 1.2. C# Advanced Painter application.

    Figure 1.2 labels several graphical elements—called controls. These include GroupBoxes, RadioButtons, a Panel and Buttons (these controls and many others are discussed in depth throughout the text). The application allows you to draw with a red, blue, green or black brush of small, medium or large size. You can also undo your previous operation or clear the drawing to start from scratch.

    By using existing controls—which are objects—you can create powerful applications much faster than if you had to write all the code yourself.

    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. Programmers include default settings to provide reasonable choices that the application will use if the user chooses not to change the settings. Default settings also provide visual cues for users to choose their own settings. Now you’ll choose your own settings as a user of this application.

  4. Changing the brush color and size. Click the RadioButton labeled Red to change the color of the brush, then click Small to change the size of the brush. 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.3.

    Drawing with a new brush color.

    Figure 1.3. Drawing with a new brush color.

  5. Changing the brush size. Click the RadioButton labeled Green to change the color of the brush again. Then, click the RadioButton labeled Large to change the size of the brush. Draw grass and a flower stem, as shown in Fig. 1.4.

    Drawing with a new brush size.

    Figure 1.4. Drawing with a new brush size.

  6. Finishing the drawing. Click the Blue and Medium RadioButtons. Draw raindrops, as shown in Fig. 1.5, to complete the drawing.

    Finishing the drawing.

    Figure 1.5. Finishing the drawing.

  7. Closing the application. Close your running application by clicking its close box, Closing the application. (Fig. 1.5).

Introduction to Object Technology

When object-oriented programming became widely used in the 1980s and 1990s, it dramatically improved 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, paycheck objects, invoice objects, automobile objects, people objects, audio objects, video objects, file objects, record objects and so on. On your computer screen, there are button objects, textbox objects, menu objects and many more. In fact, almost any noun can be reasonably represented as a software object. Objects have attributes (also called properties), such as color, size, weight and speed; and perform actions (also called methods or behaviors), 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 attributes 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 the building is constructed. Contractors can build many buildings from the same blueprint; programmers can instantiate (create) many objects from the same class.

With object technology, properly designed classes can be reused on future projects. Some organizations report that another key benefit they get from object-oriented programming is the production of software that’s better organized and has fewer maintenance requirements than software produced with earlier technologies.

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 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’s 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, especially in the Microsoft software development community.

Basic Object-Technology Concepts

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 software design 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 (for example, 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 is withdrawing that amount of money.

OOD encapsulates (that is, 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’re not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. You can drive a car effectively, for example, without knowing the details of how engines, transmissions, brakes and exhaust systems work internally—as long as you 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.

Classes, Fields and Methods

As a C# programmer, you’ll concentrate on creating your own classes. Each class contains data as well as the set of methods that manipulate that data and provide services to clients (that is, 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.

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. Packaging software as classes makes it possible for future software systems to reuse the classes.

Software Engineering Observation 1.1

Software Engineering Observation 1.1

Reuse of existing classes when building new classes and programs saves time, money and effort. Reuse also helps you build better systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning.

You’ll be using existing classes and making objects of those classes throughout the entire book. In Chapter 4, you’ll begin building your own customized classes.

With object technology, you can build much of the new software you’ll need by combining existing classes, just as automobile manufacturers combine standardized interchangeable parts. Each class you create will have the potential to become a valuable software asset that you and other programmers can reuse to speed future software development efforts.

Introduction to Object-Oriented Analysis and Design (OOAD)

Soon you’ll be writing C# programs. How will you create the code for your programs? Perhaps, like many beginning 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 thousands of 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 determining your project’s requirements (that is, what your system is supposed to do) and developing a design that satisfies them (that is, 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’s called object-oriented analysis and design (OOAD). Experienced programmers know that proper analysis and design can help avoid an ill-planned system development approach that has to be abandoned partway through its implementation, possibly wasting considerable time, money and effort. Although many different OOAD processes exist, a single graphical language known as the UML (Unified Modeling Language) for communicating the results of any OOAD process has come into wide use. We introduce some simple UML diagrams in the early chapters and present a richer treatment in the optional ATM OOD case study.

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 some widely used languages. We presented a brief history of Microsoft’s Windows operating system, and the Internet and the web. We discussed the history of the C# programming language 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.

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 become familiar with Visual Studio’s help features.

Web Resources

The Internet and the web are extraordinary resources. This section includes links to interesting and informative websites.

www.deitel.com/books/csharp2010htp/

Visit this site for code downloads, updates, corrections and additional resources for Visual C# 2010 How To Program—such as links to our Resource Centers for C# and related Visual Studio 2010 technologies. Our Resource Centers provide links to downloads, tutorials, documentation, books, e-books, journals, articles, blogs and more that will help you develop C# applications.

www.pearsonhighered.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

  • Computers process data, using sets of instructions called computer programs.

  • A computer consists of various devices referred to as hardware.

  • The programs that run on a computer are referred to as software.

Section 1.2 Computer Organization

  • The input unit obtains information (data and computer programs) from input devices and places it at the disposal of the other units so that it can be processed.

  • The output unit takes information that the computer has processed and places it on various output devices to make it available for use outside the computer.

  • The memory unit temporarily retains information that has been entered through the input unit, making it immediately available for processing when needed. The memory unit also retains processed information until it can be placed on output devices by the output unit.

  • The arithmetic and logic unit (ALU) performs calculations and makes decisions.

  • The central processing unit (CPU) is the “administrative” section of the computer, which coordinates and supervises the operation of the other sections.

  • Many of today’s computers have multiple CPUs and, hence, can perform many operations simultaneously—such computers are called multiprocessors.

  • A multi-core processor implements multiprocessing on a single integrated circuit chip.

  • The secondary storage unit is the long-term, high-capacity “warehousing” section. Programs or data not actively being used by the other units normally are placed on secondary storage devices (for example, your hard drive) until they’re needed again. Information on secondary storage devices is persistent.

Section 1.3 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, then 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.

  • Information is shared easily across computer networks, where computers called file servers offer a common data store and various services that may be used by client computers distributed throughout the network, hence the term client/server computing.

Section 1.4 Hardware Trends

  • Moore’s Law states that the computing power of computers approximately doubles every year or two, without any increase in price. Similar growth has occurred in the communications field.

Section 1.5 Microsoft’s Windows® Operating System

  • In the mid-1980s, Microsoft developed the Windows operating system, a graphical user interface built on top of DOS (a personal computer operating system that users interacted with by typing commands).

  • 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.

  • Windows XP was released in 2001 and combined Microsoft’s corporate and consumer operating system lines.

  • Windows Vista, released in 2007, offered the attractive new Aero user interface, many powerful enhancements and new applications. A key focus of Windows Vista was enhanced security.

  • Windows 7 is Microsoft’s latest operating system. Some new features include enhancements to the Aero user interface, faster startup times, further refinement of Vista’s security features, touch screen and multi-touch support, and much more.

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

  • Computer languages can be divided into three general types—machine languages, assembly languages and high-level languages.

  • A computer can directly understand only its own machine language, which is defined by the computer’s hardware design.

  • Machine languages generally consist of streams of numbers (ultimately represented in the computer as combnations of 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 (mnemonics) 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.

  • 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.

Section 1.7 Visual Basic

  • BASIC was developed to teach novices fundamental programming techniques.

  • Visual Basic made programming Windows applications easier.

  • With Microsoft’s Visual Studio Integrated Development Environment (IDE), you can write, run, test and debug Visual Basic programs quickly and conveniently.

  • The Visual Studio IDE enables you to conveniently drag and drop predefined objects like buttons and textboxes into place on your screen, and label and resize them.

Section 1.8 C, C++, Objective-C and Java

  • The C programming language was developed in the early 1970s and gained widespread recognition as the development language of the UNIX operating system.

  • C++ provides a number of features that “spruce up” the C language and provides capabilities for object-oriented programming (OOP).

  • The Objective-C programming language also added OOP capabilities to C. It became the software development language for Apple’s Macintosh. Its use exploded as the app development language for Apple’s iPod, iPhone and iPad consumer devices.

  • Objects are reusable software components that model items in the real world.

  • A modular, object-oriented approach to design and implementation can make software development groups much more productive.

  • 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.

Section 1.9 C#

  • C#, created by Microsoft specifically for the .NET platform, has roots in C, C++ and Java.

  • C# is object oriented and has access to the powerful .NET Framework Class Library—a vast collection of prebuilt components, enabling you to develop applications quickly.

  • C# is appropriate for the most demanding application development tasks, especially for building today’s enterprise applications, and web-based and mobile applications.

  • C# is event-driven—C# programs can respond to user-initiated events such as mouse clicks, keystrokes and timer expirations.

  • Microsoft’s Visual C# is indeed a visual programming language—you can use Visual Studio’s graphical user interface to 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.

Section 1.10 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 some ARPA-funded universities and research institutions. This became known as the ARPAnet, the grandparent of the 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).

  • 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 on almost any subject.

  • HyperText Markup Language (HTML) is a technology for sharing information via “hyperlinked” text documents on the World Wide Web.

  • The Internet and the web make information instantly and conveniently accessible to billions of people worldwide.

Section 1.11 Extensible Markup Language (XML)

  • Data independence, the 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.

Section 1.12 Introduction to Microsoft .NET

  • In 2000, Microsoft announced its .NET initiative, a broad new vision for using the Internet and the web in the development, engineering, distribution and use of software.

  • You can create .NET applications in any .NET-compatible language.

  • ASP.NET technology allows you to create web applications.

  • 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.

  • The .NET Framework executes applications, contains the .NET Framework Class Library and provides many other programming capabilities that you’ll use to build C# applications.

Section 1.13 The .NET Framework and the Common Language Runtime

  • The details of the .NET Framework are found in the Common Language Infrastructure (CLI), which contains information about the storage of data types, objects and so on.

  • 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. When the application executes, a just-in-time (JIT) compiler in the CLR translates the MSIL in the executable file into machine-language code, 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.

Section 1.14 Test-Driving the Advanced Painter Application

  • You can use existing controls—which are objects—to get powerful applications running in 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.15 Introduction to Object Technology

  • Object technology is a packaging scheme for creating meaningful software units.

  • Objects have attributes (also called properties) and perform actions (also called methods or behaviors).

  • Classes are types of related objects. A class specifies the general format of its objects, and the attributes and actions available to an object depend on its class.

  • Programmers can instantiate (create) many objects from the same class.

  • Properly designed classes can be reused on future projects.

  • An application that is divided into objects is easy to understand, modify and update because it hides much of the detail.

  • 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 have the same characteristics.

  • 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.

  • Object-oriented design provides a natural and intuitive way to view the software design process—namely, modeling objects by their attributes, behaviors and interrelationships, just as we describe real-world objects.

  • OOD also models communication between objects.

  • Objects have the property of information hiding—objects may know how to communicate with one another across well-defined interfaces, but normally they’re not allowed to know how other objects are implemented.

  • Languages like C# are object oriented. Programming in such a language is called object-oriented programming (OOP), and it allows you to conveniently implement an object-oriented design as a working software system.

  • C# classes contain methods that implement operations, and data that implements attributes.

  • C# is one of the most widely used object-oriented languages, especially in the Microsoft software development community.

  • The data components of a class are called attributes or fields.

  • The operation components of a class are called methods.

  • With object technology, you can build much of the new software you’ll need by combining existing classes.

Terminology

Self-Review Exercises

1.1

Fill in the blanks in each of the following statements:

  1. Computers can directly understand only their native ______ language, which is composed only of 1s and 0s.

  2. Computers process data under the control of sets of instructions called computer ______.

  3. The three types of computer programming languages discussed in the chapter are machine languages, ______ and ______.

  4. Programs that translate high-level-language programs into machine language are called ______.

  5. Visual Studio is a(n) ______ in which C# programs are developed.

  6. C# is a(n) _______, event-driven language.

  7. ______ is a programming language that was created by Microsoft specifically for the .NET platform.

  8. _______ is a language for sharing information via “hyperlinked” text documents on the World Wide Web.

  9. The _______ executes .NET programs.

  10. Objects have _______ (also called properties) and perform actions (also called methods or _______).

  11. _______ models software in terms similar to those that people use to describe real-world objects.

  12. With _______, you can build much of the new software you’ll need by combining existing classes.

1.1

  1. machine.

  2. programs.

  3. assembly languages, high-level languages.

  4. compilers.

  5. IDE.

  6. object-oriented.

  7. C#.

  8. HyperText Markup Language (HTML).

  9. Common Language Runtime (CLR).

  10. attributes, behaviors.

  11. Object-oriented design (OOD).

  12. object technology.

1.2

State whether each of the following is true or false. If false, explain why.

  1. The UML is used primarily to implement object-oriented systems.

  2. C# is an object-oriented language.

  3. C# is the only language available for programming .NET applications.

  4. Computers can directly understand high-level languages.

  5. MSIL is the common intermediate format to which all .NET programs compile, regardless of their original .NET language.

  6. The .NET Framework is portable to non-Windows platforms.

1.2

  1. False. The UML is used primarily for communicating the results of any OOAD process.

  2. True.

  3. False. C# is one of many .NET languages (another is Visual Basic).

  4. False. Computers can directly understand only their own machine languages.

  5. True.

  6. True.

Answers to Self-Review Exercises

Exercises

1.3

Categorize each of the following items as either hardware or software:

  1. CPU

  2. Compiler

  3. Input unit

  4. A word-processor program

  5. 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:

  1. An assembler translates source-language programs into machine-language programs.

  2. High-level languages are generally machine dependent.

  3. A machine-language program requires translation before it can be run on a computer.

  4. The C# compiler translates high-level-language programs into SMIL.

1.5

Expand each of the following acronyms:

  1. W3C

  2. XML

  3. OOP

  4. CLR

  5. CLI

  6. MSIL

  7. UML

  8. IDE

1.6

What are the key benefits of the .NET Framework and the CLR? What are the drawbacks?

1.7

What are the advantages to using object-oriented techniques?

1.8

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.9

What was the key reason that Visual Basic was developed as a special version of the BASIC programming language?

1.10

What is the key accomplishment of the UML?

1.11

What did the chief benefit of the early Internet prove to be?

1.12

What is the key capability of the web?

1.13

What is the key vision of Microsoft’s .NET initiative?

1.14

How does the .NET Framework Class Library facilitate the development of .NET applications?

1.15

What is the key advantage of standardizing .NET’s CLI (Common Language Infrastructure)?

1.16

Besides the obvious benefits of reuse made possible by OOP, what do many organizations report as another key benefit of OOP?

1.17

Why is XML so crucial to the development of future software systems?

Making a Difference Exercises

1.18

(Test Drive: Carbon Footprint Calculator) Some scientists believe that carbon emissions, especially from the burning of fossil fuels, contribute significantly to global warming and that this can be combatted if individuals take steps to limit their use of carbon-based fuels. Organizations and individuals are increasingly concerned about their “carbon footprints.” Websites such as TerraPass

and Carbon Footprint

provide carbon footprint calculators. Test drive these calculators to determine your carbon footprint. Exercises in later chapters will ask you to program your own carbon footprint calculator. To prepare for this, use the web to research the formulas for calculating carbon footprints.

1.19

(Test Drive: Body Mass Index Calculator) By recent estimates, two-thirds of the people in the United States are overweight and about half of those are obese. This causes significant increases in illnesses such as diabetes and heart disease. To determine whether a person is overweight or obese, you can use a measure called the body mass index (BMI). The United States Department of Health and Human Services provides a BMI calculator at www.nhlbisupport.com/bmi/. Use it to calculate your own BMI. A forthcoming exercise will ask you to program your own BMI calculator. To prepare for this, use the web to research the formulas for calculating BMI.

1.20

(Attributes of Hybrid Vehicles) In this chapter you learned some basics of classes. Now you’ll “flesh out” aspects of a class called “Hybrid Vehicle.” Hybrid vehicles are becoming increasingly popular, because they often get much better mileage than purely gasoline-powered vehicles. Browse the web and study the features of four or five of today’s popular hybrid cars, then list as many of their hybrid-related attributes as you can. Some common attributes include city-miles-per-gallon and highway-miles-per-gallon. Also list the attributes of the batteries (type, weight, etc.).

1.21

(Gender Neutrality) Many people want to eliminate sexism in all forms of communication. You’ve been asked to create a program that can process a paragraph of text and replace gender-specific words with gender-neutral ones. Assuming that you’ve been given a list of gender-specific words and their gender-neutral replacements (e.g., replace “wife” with “spouse,” “man” with “person,” “daughter” with “child” and so on), explain the procedure you’d use to read through a paragraph of text and manually perform these replacements. How might your procedure generate a strange term like “woperchild?” You’ll soon learn that a more formal term for “procedure” is “algorithm,” and that an algorithm specifies the steps to be performed and the order in which to perform them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.250.11