PROGRAMMING LANGUAGES VB.NET XML JavaScript. Visual Basic.NET evolved from BASIC (Beginner’s ALL...

49
PROGRAMMING LANGUAGES VB.NET XML JavaScript

Transcript of PROGRAMMING LANGUAGES VB.NET XML JavaScript. Visual Basic.NET evolved from BASIC (Beginner’s ALL...

PROGRAMMING LANGUAGESVB.NET XML JavaScript

Visual Basic.NET• evolved from BASIC (Beginner’s ALL Purpose

Symbolic Instruction Code)

• developed in the mid-1960’s

• by Prof. John Kemeny and Thomas Kurtz

Visual Basic.NET• event driven

• visual programming language

• an object-oriented programming language

designed

by Microsoft

Visual Basic.NET• Encapsulation

• Allows your program to treat objects as black boxes

• Polymorphism• One object can have different forms depending on

the situation

• Reuse• By using containment and delegation

READABILITY• Simplicity and Orthogonality

AddHandler Auto CBool

AndAlso ByVal CDec

Double End Event

Implements Integer Like

Next NotOverridable Optional

RaiseEvent RemoveHandler Set

Then AddressOf Ansi

CByte CDbl CLng

Dim Each Enum

GoTo Imports Interface

MyClass Not Object

Property ReadOnly Resume

Structure Throw Alias

Case CChar Char

Declare DirectCast Else

READABILITY• Control Structure

If/then Do Loop/Until

If/Then/Else     Do Loop/While

Case While

Do While/Loop For/Next

   Do Until/Loop For Each/Next

READABILITY• Data Types and Structure

Type Size in Bits

Boolean 16Char 16Byte 8Date 64

Decimal 128

Short 16Integer 32

Long 64

Single 32

Double 64Object 32

String 0-2000000000

READABILITY• Syntax Design

• uses special words in forming compound statements primarily in control constructs (such as If/Then/Else)

WRITABILITY• Simplicity and Orthogonality• Control Structure Dim firstname = "Phil“ If firstname = "Bill" Then MsgBox "firstname is Bill" Else MsgBox "firstname is not Bill“ End If

WRITABILITY• Data Types and Structure• Syntax Design

Dim value As Integer = Integer.Parse(Console.ReadLine()) Select Case value Case 1 Console.WriteLine("You typed one") MsgBox("You typed one") Case 2 Console.WriteLine("You typed two") MsgBox("You typed two") Case 5 Console.WriteLine("You typed five") MsgBox("You typed five") Case Else Console.WriteLine("You typed something else") MsgBox("You typed somethinig else") End Select

WRITABILITY• Abstraction

Public MaximumSpeed as _ Integer

Public ModelName as StringPublic Sub Accelerate()

'Some code to make the car goEnd SubPublic Sub Stop()

'Some code to make the car stopEnd Sub

WRITABILITY• Expressivity

RELIABILITY• Type Checking• Exception Handling• Restricted Aliasing

COST• Migrating from any other language to Visual

Basic .NET could cost companies on the order of $43,000 per developer, research from the Gartner Group

PORTABILITY• can only be compiled and run through the .NET

framework which only runs on windows

XML• eXtensible Markup Language• Markup: a text-based notation for describing data• A widely supported open technology for

describing data• The standard format for data exchanged between

applications over the Internet.• permits document authors to create markup for

virtually any type of information

XML• NOT replace HTML• Foundation for several next-generation Web

technologies• XHTML, RSS (Blogs), Ajax, Web Services

• can be used to create entirely new markup languages that describe specific types of data,

including mathematical formulas, chemical molecular structures, music and recipes.

• describes data in a way that human beings can understand and computers can process.

XML• http://www.w3schools.com/xml/xml_validator.asp

XML Parser in the Browser• When a user loads an XML document in a browser,

a parser parses the document, and the browser uses a style sheet to format the data for display

XML Elements• The root element of an XML document encompasses all its other elements• XML element names can be of any length and can

contain letters, digits, underscores, hyphens and periods

• XML element names must begin with either a letter or an underscore, and they should not begin with “xml” in any combination of uppercase and lowercase letters, as this is reserved for use in the XML standards

DOCUMENT TYPE DEFINITIONS• DTDs and schemas specify documents’ element types

and attributes, and their relationships to one another• DTDs and schemas enable an XML parser to verify

whether an XML document is valid (i.e., its elements contain the proper attributes and appear in the proper sequence)

• In a DTD, an ELEMENT element type declaration defines the rules for an element. An ATTLIST attribute-list declaration defines attributes for a particular element

NAMESPACES• XML namespaces provide a means for document

authors to prevent naming collisions• Each namespace prefix is bound to a uniform resource identifier (URI) that uniquely identifies the

namespace• We declare a default namespace using keyword xmlns

with a URI (Uniform Resource Identifier) as its value

W3C XML SCHEMA DOCUMENTS• which to define your XML document structure and

limitations.• XML schemas provide a set of basic types, such as

integer, byte, string and floating point numbers.• XML schemas provide an Object Oriented approach.• The author of an XML schema can use basic types,

along with various operators and modifiers, to create complex types of their own.

XSL AND XSLT• XSL is a style sheet language for XML documents.• XSL is more than a style sheet language. XSL consists

of two parts:• XSLT – a language for transforming XML documents• XPath – a language for navigating in XML documents

• XSL style sheets can be connected directly to an XML document by adding an xml:stylesheet processing instruction to the XML document

READBILITY• XML is the first language that makes documents

both human-readable and computer-manipulable• It is the language of the intelligent document, a

step ahead of conventional methods of document representation that rely on format rather than structure

WRITABILITY• XML declaration: identifies the version of XML

used.• XML tags are case sensitive.• Each start tag must have a matching end tag.• Using a white space character in a XML element

name is an error.• XML element names should be meaningful to

humans and should not use abbreviations.

WELL FORMED vs. VALID XML• Well-formed XML documents

• Matching start tag and end tag

• Valid XML documents• One that has been tested against a set of rules• These rules are specified as either DTD or XML

schema files

RELIABILITY• XML provides a common syntax for messaging

systems for the exchange of information between applications.

• If everyone uses the same syntax it makes writing these systems much faster and more reliable.

PORTABILITY• XML is an open standard, there is a wide selection

of tools for implementing it• XML can be used on a wide variety of platforms

and interpreted with a wide variety of tools.

COST• enables a nonprogrammer to do things that would

have previously required extensive knowledge of scripting languages or thousands of dollars worth of custom software

• text-based, so anybody can create an XML document with even the most primitive text processing tools.

JavaScript• Scripting language which is used to enhance the

functionality and appearance of web pages.• All major web browsers contain JavaScript interpreters, which process the commands written in JavaScript.

JavaScript• JavaScript allows for interactivity• Browser/page manipulation

• Reacting to user actions

• A type of programming language• Easy to learn• Developed by Netscape

• Standardized by European Computer Manufacturers Association (ECMA)

• www.ecma-international.org/publications/standards/ECMA-262.HTM

How JavaScript works• Embedded within HTML page

• View source

• Executes on client• Fast, no connection needed once loaded

• Simple programming statements combined with HTML tags

• Interpreted (not compiled)• No special tools required

JavaScript compared to Java

JavaScript Java

Interpreted (not compiled) by client. Compiled bytecodes downloaded from server, executed on client.

Object-based. No distinction between types of objects. Inheritance is through the prototype mechanism and properties and methods can be added to any object dynamically.

Object-oriented. Objects are divided into classes and instances with all inheritance through the class hierarchy. Classes and instances cannot have properties or methods added dynamically.

Code integrated with, and embedded in, HTML.

Applets distinct from HTML (accessed from HTML pages).

Variable data types not declared (loose typing).

Variable data types must be declared (strong typing).

Dynamic binding. Object references checked at runtime.

Static binding. Object references must exist at compile-time.

JavaScript• Often, JavaScripts appear in the <head> section

of the HTML document. The browser interprets the contents of the <head> section first

• The <script> tag indicates to the browser that the text that follows is part of a script. Attribute type specifies the scripting language used in the script—such as text/javascript

CONTROL STRUCTURES• Sequential execution

• Statements execute in the order they are written• Transfer of control

• Next statement to execute may not be the next one in sequence

• Three control structures• Sequence structure• Selection structure

• if• if…else• switch

• Repetition structure• while• do…while• for• for…in

JavaScript Keywordsbreak case catch continue default

delete do else finally for

function if in instanceof new

return switch this throw try

typeof var void while with

Keywords that are reserved but not currently used by JavaScript

abstract boolean byte char class

const debugger double enum export

extends final float goto implements

import int interface long native

package private protected public short

static super synchronized

throws transient

volatile

JavaScript Statements<html><head><title>My Page</title></head><body><script language="JavaScript">

document.write('This is my first JavaScript Page');

</script></body></html> Note the symbol for

line continuation

JavaScript Statements<html><head><title>My Page</title></head><body><script language="JavaScript">

document.write('<h1>This is my first JavaScript Page</h1>');

</script></body></html>

HTML writteninside JavaScript

JavaScript Statements<html><head><title>My Page</title></head><body><p><br /><a href="myfile.html"onMouseover="window.alert('Hello');">My Page</A></p></body></html>

JavaScript writteninside HTML

An Event

CHARACTERISTICS• Dynamically typed• Standard operator precedence• Overloaded operators• Reserved words

CHARACTERISTICS• Strings are very common data types• Rich set of methods available• Arrays have dynamic length• Array elements have dynamic type• Arrays are passed by reference• Array elements are passed by value

EXAMPLES• Division with / is not integer division• Modulus (%) is not an integer operator• 5 / 2 yields 2.5• 5.1 / 2.1 yields 2.4285714285714284 • 5 % 2 yields 1• 5.1 % 2.1 yields 0.8999999999999995

WRITABILITY• Browser contains a complete set of objects that allow script programmers to access and manipulate every element of an HTML document• Every statement should end with a semicolon

(also known as the statement terminator), although none is required by JavaScript

• JavaScript is case sensitive• Not using the proper uppercase and lowercase

letters is a syntax error

WRITABILITY• A variable name can be any valid identifier consisting of letters, digits, underscores ( _ ) and dollar signs ($) that does not begin with a digit and is not a reserved JavaScript keyword.• JavaScript does not require variables to have a type before they can be used in a script• A variable in JavaScript can contain a value of any data type, and in many situations, JavaScript automatically converts between values of different types for you• JavaScript is referred to as a loosely typed language

WRITABILITY• Comments in JavaScript

• <script> // a single line comment

/* amultilinecomment*/

</script>

RELIABILITY• From a core language standpoint, it is a reliable

language for small applications.• From a browser implementation standpoint, it is

not so reliable because different browsers behave differently.

• Garbage Collection• JavaScript knows when a program no longer needs a

variable or object• Automatically cleans up the memory

PORTABILITY• As long as there is support for it, Javascript will

work on all browsers and all Operating Systems• window.navigator

• Has information about the current browser• Properties include

• appName (Netscape or Microsoft Internet Explorer)• appVersion• userAgent• appCodeName (not useful)• platform (operating system)• language (e.g., en or fr)

COST• JavaScript is free and open-source