Chapter 2: Introduction to Programming

TRUE/FALSE

1.The <? ?> tags is used to indicate inline server code within a Web Form.

ANS:FREF:62

2.The code behind the page contains programming routines that are directly related to the various server controls on a Web Form.

ANS:TREF:62

3.The Class property indicates that the code behind the page inherits the partial class.

ANS:FREF:63

4.When the code is very long, use a semi-colon to continue the code to the next line.

ANS:FREF:63

5.A variable declaration consists of three parts: the declaration keywords, a file name, and a data type.

ANS:FREF:64

6.Global variables are defined within a procedure and can be used only by the procedure in which they were declared

ANS:FREF:64

7.Public keyword defines variables that can be used only by the procedure in which they were declared.

ANS:FREF:65

8.You can use a period or space within a variable name

ANS:FREF:65

9.Visual Basic .NET commands and variables are case sensitive.

ANS:FREF:65

10.The names of constants are usually all uppercase.

ANS:TREF:66

11.The Char data type allows you to store a single text value as a number between 0 and 65,535.

ANS:TREF:66

12.The Split method returns a string that has been split, using a delimiter to identify where to split the string

ANS:TREF:67

13.The Bind method allows you to join strings together without using the concatenation operator.

ANS:FREF:67

14.It is recommended to use the plus sign as the concatenation operator.

ANS:FREF:67

15.Real number data types are represented by the types Single, Double, and Byte.

ANS:FREF:68

16.The Byte data type stores an integer between 0 and 255.

ANS:TREF:68

17.The Money data type can store numbers up to 28 decimal places and is often used to store currency data.

ANS:FREF:68

18.Formatting with Decimal (D or d) will insert the dollar symbol and two decimals.

ANS:FREF:68

19.Format(1231.08, "#,###") will format the number as 1,231.

ANS:TREF:69

20.Coordinated Universal Time (UTC) was previously known as Greenwich Mean Time (GMT).

ANS:TREF:69

21.When boolean values are converted to an integer, the True value is converted to -1, and the False value is converted to 0.

ANS:TREF:70

22.You could convert the string to an integer using the System.Convert class or you could use the CStr function to convert the string as in CStr(strVariable).

ANS:FREF:71

23.You can set the Strict property of the Page directive to True so that any narrowing conversion that would result in data loss is halted.

ANS:TREF:71

24.When you declare the ArrayList, you do not need to specify the size.

ANS:TREF:72

25.The Count property of the ArrayList is the number of items the list can hold.

ANS:FREF:72

26.The IndexOf property returns an integer which represents the index position of the element in the list.

ANS:TREF:73

27.The code to add a value to the HashTable is HashTableName.Add(value, key).

ANS:FREF:73|74

28.The Queue is a collection object that provides sequential access but stores the elements in last in, first out (LIFO) order.

ANS:FREF:75

29.The SelectedIndex property can be used to determine which radio button was checked.

ANS:FREF:75

30.If nothing has been selected, the SelectedIndex property returns the value NULL.

ANS:FREF:75

31.Server variables can be retrieved by using an HTTPRequest object with Request.ServerVariables(“VARIABLE_NAME”).

ANS:TREF:77

32.If the value of the form method identified in the HTML Form element is Post, then the form results are HTML encoded and appended with a question mark to the URL requested as a single string called the QueryString.

ANS:FREF:78

33.To retrieve the value of a field named CompanyName, you would enter Request.Form("CompanyName").

ANS:FREF:78

34.The WriteLine method allows you to send a string to the browser.

ANS:FREF:79

35.A special session cookie is used to maintain the session information.

ANS:TREF:79

36.The application variables are released from memory only when the Web application is stopped, when the Web server is stopped, or when the server is stopped.

ANS:TREF:80

37.The base class libraries are organized into hierarchical logical groupings of code called namespaces.

ANS:TREF:83

38.Instantiation is the process of declaring and initializing an object from a class.

ANS:TREF:84

39.The source file for the class ends in .vb, and by default it is placed in a directory named App_Bin.

ANS:FREF:84

40.An event procedure is a type of subprocedure that is attached to an object with events.

ANS:TREF:86

41.The page lifecycle is the order that the Web Form is processed on the server and rendered in the browser.

ANS:TREF:86

42.The Trace feature allows you to view the page controls, the order in which they are loaded, and the time it takes to load each control.

ANS:TREF:87

43.A Property method sets the value of a variable defined within an object and is often used to expose private variables that are defined within the class.

ANS:TREF:88

44.With the Graphics class, you can create visual objects such as lines, and shapes such as rectangles and ellipses, paint the background, include and scale existing images, build custom objects, and even insert charts into your Web applications.

ANS:TREF:89

45.The Placeholder control is used as a container to store dynamically added server controls.

ANS:TREF:92

46.You can also use a Literal control to write content directly to the page.

ANS:TREF:92

47.Control statements allow you to conditionally determine whether and how an action statement is executed, and the order in which action statements are executed.

ANS:TREF:93

48.Debugging is the process of detecting programming errors within the application.

ANS:TREF:98

49.The goal of the Try-Catch-Finally statement is to gracefully recover when an exception occurs.

ANS:TREF:99

50.NullReferenceException is thrown when an error occurs when a null object is referenced.

ANS:TREF:99

51.When the Mode attribute of the customErrors node is set to RemoteOnly, then only remote clients are redirected to the new page.

ANS:TREF:101

52.The Call Stack window displays the properties of the current object.

ANS:FREF:104

MULTIPLE CHOICE

1.The default ____ property is set to VB to indicate that the code behind the page is written in Visual Basic .NET.

a. / CodeFile / c. / Partial classes
b. / Inherits / d. / Language

ANS:DREF:62

2.Which of the following is the only variable name that is allowed in Visual Basic .NET?

a. / My_ImageName / c. / Image Name
b. / Public / d. / $NewImage

ANS:AREF:65

3.A variable declaration consists of three parts: the declaration keywords, a variable name, and a ____.

a. / mode / c. / data type
b. / language / d. / semi-colon

ANS:CREF:64

4.This is used to declare a variable global or public, and therefore available.

a. / Dim / c. / Global
b. / Friend / d. / Protected

ANS:AREF:65

5.Which rule does not apply to naming variables in Visual Basic .NET?

a. / You cannot use any of the Visual Basic .NET commands or keywords as your variable name
b. / You cannot use a period or space within a variable name.
c. / Variable names must begin with a letter
d. / Avoid using any special characters in a variable name except for the ampersand

ANS:DREF:65

6.The ____ property of the Page directive is used to configure the page to require you to declare all variables before they are used?

a. / Explicit / c. / Strict
b. / Option Strict / d. / Inherits

ANS:AREF:65

7.Which keyword is used to declare a constant variable?

a. / Var / c. / Con
b. / Dim / d. / Const

ANS:DREF:66

8.The ____ method replaces one string with another.

a. / Replace / c. / Concat
b. / Split / d. / Trim

ANS:AREF:67

9.What is the concatenation operator in Visual Basic .NET?

a. / $ (dollar sign) / c. / ‘’ (quotation marks)
b. / ‘ (single quotation mark) / d. / & (ampersand)

ANS:DREF:67

10.Which numeric data type is a 32-bit number?

a. / Byte / c. / Long
b. / Short / d. / Integer

ANS:DREF:68

11.Which data type stores values between -32,768 and 32,767?

a. / Byte / c. / Long
b. / Short / d. / Integer

ANS:BREF:68

12.Which would be the output for Format(24.99, "$#,###.##") ?

a. / 24.99 / c. / 2499.00
b. / $24.99 / d. / $2499

ANS:BREF:69

13.Which would result in the output for the date MyDT as Sunday, Sep 9 2007?

a. / Format(MyDT, "dddd, MMM d yyyy") / c. / Format(MyDT, "DD, MM dd yyyy")
b. / Format(MyDT, "dd, MM d yyyy") / d. / Format(MyDT, "DD, mmm dd yyyy")

ANS:AREF:70

14.Which are possible values for a Boolean variable?

a. / 0 or 1 / c. / True or False
b. / T or F / d. / On or Off

ANS:CREF:70

15.You can set the ____ property of the Page directive to True so that any narrowing conversion that would result in data loss is halted?

a. / Strict / c. / Explicit
b. / Var / d. / Option

ANS:AREF:71

16.The ____ is a collection object that stores each item in sequential order, and each item is indexed with a number?

a. / ArrayList / c. / Queue
b. / HashTable / d. / SortIndex

ANS:AREF:72

17.What method is used to remove all the items in an ArrayList control?

a. / Remove / c. / Clear
b. / Delete / d. / Add

ANS:DREF:72

18.____ object of the Page class allows you to retrieve any data sent by the browser, including the names and values of form fields and the server variables.

a. / Request / c. / User-Agent
b. / Header / d. / Response

ANS:AREF:77

19.If the value of the form method identified in the HTML Form element is Post, to retrieve the value of a field named CompanyName, you would enter ____.

a. / Request.Form("CompanyName")
b. / Request.QueryString("CompanyName")
c. / Request.ServerVariables("COMPANYNAME")
d. / Request.Page("CompanyName")

ANS:AREF:78

20.If the value of the form method identified in the HTML Form element is Get, then the form results are HTML encoded and appended with a question mark to the URL requested as a single string called the ____?

a. / Server Variables / c. / QueryString
b. / Form Fields / d. / URL

ANS:CREF:78

21.Which code will redirect the visitor to another page?

a. / Location.Href("Page2.aspx", true)
b. / Response.Redirect("
c. / Response.Write("
d. / Response.WriteFile("

ANS:BREF:79

22.Which example will assign the Session identifier to the variable named SID?

a. / Session("SessionID ") = Session. SID
b. / Session("Session ID") = Session.SessionID
c. / Session("SessionID") = SID
d. / Session("SID ") = Session.SessionID

ANS:DREF:80

23.Which access modifier makes an element available anywhere to any class?

a. / Public / c. / Friend
b. / Private / d. / Protected

ANS:AREF:84

24.Which of the following returns a value?

a. / subprocedure / c. / event procedure
b. / procedure / d. / function

ANS:DREF:85

25.What is used to separate multiple arguments passed to a procedure?

a. / ; (semicolon) / c. / / (forward slash)
b. / : (colon) / d. / , (comma)

ANS:DREF:85

26.The ____ event initializes the page framework hierarchy, creates all of the controls, deserializes the ViewState, and applies the previous settings to the controls.

a. / Page_Init / c. / Page_PreRender
b. / Page_Load / d. / Page_Unload

ANS:AREF:86

27.The ____ control is used as a container to store dynamically added server controls.

a. / Panel / c. / Placeholder
b. / Literal / d. / Page

ANS:CREF:92

28.The ____ target property renders the content in a new window without frames

a. / _blank / c. / _top
b. / _parent / d. / _self

ANS:AREF:92

29.A____ is a program used to detect programming errors within the application.

a. / virus detection program / c. / dewormer
b. / debugger / d. / bug checker

ANS:BREF:98

30.The ____ is thrown when an Array object is improperly indexed.

a. / NullReferenceException / c. / SqlException
b. / IndexOutOfRangeException / d. / ExternalException

ANS:BREF:99

31.To turn debugging on for the entire application, you must configure the ____

attribute in the compilation node of the Web.config file.

a. / debug / c. / customError
b. / Error / d. / system.Web

ANS:AREF:103

32.You can step through the application at defined points called ____.

a. / breakpoints / c. / hops
b. / stops / d. / endpoints

ANS:AREF:103

COMPLETION

1.The ______is the portion of a data packet that describes how and where to send the file.

ANS:header

REF:77

2.The ______object of the Page class allows you to retrieve any data sent by the browser, including the names and values of form fields and the server variables.

ANS:Request

REF:77

3.The ______provides a string that can be used to detect the browser version.

ANS:user agent

REF:77

4.With the ______property of the Page class, you can directly access the browser application’s name and version without the user agent.

ANS:Browser

REF:77

5.To retrieve the value of a field named CompanyName, you would enter ______.

ANS:Request.Form("CompanyName")

REF:78

6.If the value of the form method identified in the HTML Form element is Get, then the form results are HTML encoded and appended with a question mark to the URL requested as a single string called the ______.

ANS:QueryString

REF:78

7.The ______allows you to send data from one form to another

ANS:Cross-page posting

REF:78

8.The ______method allows you to send the entire contents of a text file to the Web page.

ANS:WriteFile

REF:79

9.Other than using Response.Redirect, to redirect the visitor to another page at you could use ______.

ANS:Server.Transfer("Page2. aspx",true)

REF:79

10.The ______, is a unique identifier that identifies each session

ANS:SessionID

REF:79

11.The business programming logic, such as the formulas to calculate interest rate, are implemented in components at a ______.

ANS:middle tier

REF:82|83

12.Making the application support, a larger number of visitors is called ______.

ANS:scaling

REF:83

13.The ______are groups of commonly used built-in classes stored in executable files.

ANS:base class libraries

REF:83

14.The base class libraries are organized into hierarchical logical groupings of code called ______.

ANS:namespaces

REF:83

15.______structures used conditional expressions to determine which block of code to execute.

ANS:Decision control

REF:83

16.An ______is a set of related, compartmentalized code that is based upon a class

ANS:object

REF:83

17.______is the process of declaring and initializing an object from a class.

ANS:Instantiation

REF:84

18.The source file for the class ends in .vb, and by default, is placed in a directory named ______

ANS:App_Code

REF:84

19.You can pass zero or more arguments, called ______, to a procedure or other type of programming structure

ANS:parameters

REF:85

20.You can use the ______statement to stop the subprocedure.

ANS:Exit Sub

REF:85

21.The subprocedures are executed in the order they are called by specifying the name of the subprocedure or using the keyword ______and passing any parameters required

ANS:Call

REF:85

22.An ______procedure is a type of subprocedure that is attached to an object with events

ANS:event

REF:86

23.The ______is the order that the Web Form is processed on the server and rendered in the browser

ANS:page lifecycle

REF:86

24.The ______event occurs immediately before the control hierarchy is rendered and sent to the browser.

ANS:Page_PreRender

REF:87

25.The______feature allows you to view the page controls, the order in which they are loaded, and the time it takes to load each control

ANS:Trace

REF:87

26.You can leave the function at any time by inserting the ______statement

ANS:Exit Function

REF:87

27.A ______method sets the value of a variable defined within an object and is often used to expose private variables that are defined within the class

ANS:Property

REF:88

28.With the ______class, you can create visual objects such as lines and shapes such as rectangles and ellipses, paint the background, include and scale existing images, build custom objects, and even insert charts into your web applications

ANS:Graphics

REF:89

29.The ______control is used as a container to store dynamically added Server controls

ANS:Placeholder

REF:92

30.______controls are often used to add client-side HTML and text to the page

ANS:Literal

REF:92

31.The HyperLink control is used to create an anchor tag that can link to another page or a target by using the ______property

ANS:ImageURL

REF:92

32.A ______expression is an expression that is evaluated by the program as true or false

ANS:conditional

REF:94

33.The ______class is the base class for all predefined exceptions

ANS:SystemException

REF:99

34.If the resource is received and returned, then a Status Code ______is returned to the browser in the header

ANS:200

REF:100

ESSAY

1.Why does the program not need to access the HTTP header directly? Explain.

ANS:

The System.Web.HttpRequest class is mapped directly to the Request property of the Page object. So, instead of using the server variables to retrieve the header data, you can use Page.Request.PropertyName or Request.PropertyName.

REF:77

2.What is the difference between the logical tier and physical architecture? Explain.

ANS:

The presentation tier contains the user interface. The Web Forms are used to display the data in a web page. The user interface is the presentation layer of the application. The business programming logic, such as the formulas to calculate interest rate, are implemented in components at a middle tier. It is useful to create the business components to isolate the programming logic so that changes within the visual layer would not impact the programming code. Assemblies contain the compiled code and can be stored on application servers or with the individual applications. The data tier often consists of one or more data servers such as SQL Server. Data can be stored in a variety of structures, such as a text file, an XML document, a database, or data server; this tier is also called the Data Access Layer (DAL).

REF:82

3.What are the four commonly intercepted page events in the page lifecycle? Explain what occurs during each event.

ANS:

The Page_Init event initializes the page framework hierarchy, creates all of the controls, deserializes the ViewState, and applies the previous settings to the controls. The Page_Load event loads any server controls into memory and occurs every time the page is requested. You can determine if the page has previously been loaded by using the Page.IsPostback property.The Page_PreRender event occurs immediately before the control hierarchy is rendered and sent to the browser. The browser sees only the rendered client controls, such as HTML and client-side script. When the Page_Unload event occurs, the page is removed from the server’s memory. You can use the Page_Unload event handler to close database connections, close files, and release any programming variables or objects.

REF:86