530 likes | 658 Views
BIS305: Advanced Business Programming Introduction. Toru Sakaguchi, Ph.D. Chapter 1: Introduction. Introduction to Programming the .NET Framework. Introduction to Software Development. The software development life cycle consists of a sequence of well-defined steps Problem identification
E N D
BIS305: Advanced Business ProgrammingIntroduction Toru Sakaguchi, Ph.D.
Chapter 1: Introduction • Introduction to Programming • the .NET Framework
Introduction to Software Development • The software development life cycle consists of a sequence of well-defined steps • Problem identification • System design • System implementation • System documentation • System testing • System deployment • Postimplementation audit
System Analysis Methodologies • Pseudocode uses English-like statements to depict an application’s actions • Top-down design (HIPO chart) is used to subdivide general tasks into more specific tasks • Flowcharting uses graphical symbols to depict an application’s actions • The Unified Modeling Language (UML) supplies several graphical templates to model a system
The Evolution of Programming Languages • Programming languages can be categorized into four generations • Machine languages (1st generation) • Assembly languages (2nd generation) • Machine independent languages (3rd generation) • Natural languages (4th generation)
Figure 1-14: Relationship Between Assembly Language and Machine Language
Compiling a .NET Program • Visual Studio compiles a program into machine independent assembly language called intermediatelanguage (IL) • IL gets translated into executable code using the just-in-time compiler (JIT) • The process is automatic
Introduction to Object-oriented Programming • Hardware costs are falling but software development costs are rising • Software systems are becoming increasingly complex • Object-oriented programming attempts to reduce software costs through code reuse
Characteristics of Object-oriented Programming • Objects are created from classes • A class is a template or blueprint for an object • A class describes the data stored in the class and the actions performed by the class • Multiple objects can be created from the same class
Figure 1-17: Relationship Between a Class and Objects Created From the Class
Characteristics of Object-oriented Programming Languages • Encapsulation: Data and processes are coupled together • Inheritance: A new class can be created from an existing class • Informationhiding: Some information is hidden in a class while other information is exposed to the developers using the class • Polymorphism: members have multiple forms
The Visual Studio Implementation of Object-oriented Programming • The interface of a class is the formal specification of the data stored in the class and the actions supported by the class • Objects are created from a class by calling a constructor • Data items stored in a class are called properties • Actions performed by a class are called methods • A class can have events • Statements in an event handler execute in response to an event
Procedural and Event-driven Programming Languages • In a procedurallanguage, the sequence of activities can be predicted by the application • In an event-drivenlanguage, the execution path of the application is based on the various events that fire • Users and the system itself can cause events to fire • It's impossible to predict exactly when an event will fire
The Syntax of Programming Languages • The rules of a programming language are called syntax • Each programming language has its own syntax • C# and Visual Basic have a different syntax, for example • Syntax rules are absolute • Statements with incorrect syntax are considered syntaxerrors
Types of Programming Statements • A statement expresses a complete thought or action • Statements can be categorized into two types • Declaration statements are used to create variables and define the structure of an application • Executable statements perform an action while a program is running
Types of Programming Statements (Example) Module Hello Sub Main() System.Console.WriteLine("Hello World") End Sub End Module Executable statement
Reserved Words and Operators • Language keywords are called reserved words • Every programming language has a set of reserved words • Reserved words differ from programming language to programming language • Module and Sub are Visual Basic reserved words, for example • + and – are the Visual Basic operators for addition and subtraction
Identifiers and Their Names • The term identifier describes the name of a programming element • Identifier names must • Begin with a letter • Only contain alphabetic characters, digits, or the underscore character • Have a maximum length of 1023 characters
The Structure of a Visual Basic Application • Every program has a well-defined structure • Visual Basic is a block structured language • The outermost block is the Namespace block • Namespace blocks contain Module blocks • Module blocks contain Sub procedure blocks • Procedure blocks contain declaration and executable statements
Namespace Blocks • Conceptually, Namespace blocks are similar to file folders • An application can contain one or many Namespace blocks • Every namespace has an identifier (name) • A Namespace block is marked by the Namespace and EndNamespace keywords
Namespace Block (Example) • Declare a namespace named Chapter01: Namespace Chapter01 End Namespace
The Contents of a Namespace • A Namespace block can contain • Class blocks • Structure blocks • Module blocks • Interface blocks
Introduction to Module Bocks • A Namespace block can contain one or more Module blocks • A Module block begins with the Module statement • A Module block ends with the EndModule keywords • Module blocks cannot be nested
Module Block (Example) • The Namespace block named Chapter01 contains a Module block named Hello Namespace Chapter01 Module Hello End Module End Namespace
Introduction to Procedure Blocks • A Module block can contain one or many Procedure blocks • Procedure blocks cannot be nested • Procedure blocks contain declaration and executable statements • The Sub and EndSub statements mark the beginning and end of a procedure
Procedure Block (Example) • The Namespace named Chapter01 contains a Module block named Hello with a Sub procedure block named Main() Namespace Chapter01 Module Hello Sub Main() End Sub End Module End Namespace
Figure 1-20: Organization of a Namespace, Module, and Procedure
Writing Executable Statements • Executable statements can be used to call (execute) a procedure • Executable statements can be used to make decisions and execute loops • Assignment statements are executable statements
Calling a .NET Framework Class Library Method • The .NET Framework supplies general services used by all applications • The Console class has methods used to read input and to write output • The SystemInformation class gets information about the local computer
Organization of the .NET Framework Class Library • The .NET Framework class library is made up of several disk files called libraries • Physical library files are called assemblies • Physical assemblies contain one or more logical namespaces • Namespaces are organized hierarchically • Namespaces contain classes and other types
Common Namespaces • System defines the primary data types • System.Data contains classes used to work with databases • System.Drawing supplies graphics functionality • System.Windows.Forms contains classes to create visual forms • System.XML contains classes to work with the XML language
Figure 1-21: Categorization of Types That Make Up the .NET Framework Class Library
Referencing Namespaces and Classes • A period separates a namespace name and a class name • Reference the Console class of the System namespace System.Console • Call the WriteLine method of the System.Console class System.Console.WriteLine()
Method Arguments • Methods accept 0, one, or many arguments • Arguments are used to send data to a method • Arguments appear as a comma separated list • The list appears in parenthesis • Example to display the text "Hello World”: System.Console.WriteLine("Hello World")
Continuation Lines • Complicated statements might not fit on one line • Use the continuation character to split a statement across multiple lines • The continuation character is the underscore (_) • The continuation character must appear at the end of a line • A space must precede the continuation character • The continuation character cannot break up words
Continuation Lines (Example) • The following statement appears on two lines: System.Console.WriteLine( _ "Hello World")
Methods of the System.Console Class • The Read method reads one character from the console • The ReadLine method reads a line from the console • The Write method writes a character or characters to the console • The WriteLine method writes a character or characters, followed by a carriage return, to the console
The SystemInformationClass • The SystemInformation class gets information about the system • The ComputerName property gets the name of the computer • The MouseButtons property gets information about the mouse • The MouseWheelPresent property indicates whether the mouse has a mouse wheel • The Network property indicates whether the computer is connected to a network • The UserName property returns the name of the current user
Using a Command Prompt Window • The Command Prompt window is used to execute commands and compile programs • Type a command and press Enter to execute the command • The Command Prompt window can be used to navigate through the Windows file system
The Windows File System • A path defines the hierarchical location of a directory within the Windows file system • Path references are of two types • Absolute paths begin with a drive designator and a leading backslash C:\CourseTechnology\Chapter01 • Relative paths begin with a period (.) to denote the current directory and two periods (..) to denote the parent directory of the current directory ..\Data.Chapter01 .\Chapter01
Windows Navigation Commands • DIR lists the files and directories in the current directory • CD changes directories • RENAME changes the name of a file or directory • DEL deletes a file • There are many other commands and command options
Windows Navigation Commands (Examples) • Display the contents of the current directory DIR • Change the current directory to the root directory on the current drive CD \ • Rename FileOld to FileNew RENAME FileOld FileNew • Delete FileNew DEL FileNew
Compiling and Executing a Visual Basic Application • Visual Basic programs are compiled into intermediate language (IL) • IL code is translated into an executable form using the JIT compiler • The JIT compiler is called automatically when an application is run • The Visual Basic compiler is named vbc.exe
Figure 1-23: Translation of .NET Source Code to Executable Code
Calling the Visual Basic Compiler • The compiler is called with directives that define how the application is compiled • /main specifies the module containing the entry point • /out specifies the name of the executable file • /verbose causes the compiler to display informational messages
Calling the Visual BasicCompiler (Example) • Compile the Visual Basic file named Hello.vb to produce an executable file named Hello.exe • The Main procedure appears in the Namespace and Module named Chapter01.Hello vbc /main:Chapter01.Hello /out:Hello.exe Hello.vb