COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts

Size: px
Start display at page:

Download "COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts"

Transcription

1 COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

2 Contents 1 (User-defined) Objects Object Literals Object Constructors Prototype Property Public and Private Static Variables Inheritance Classes as Syntactic Sugar 2 Pre-defined Objects String Date 3 Further Reading Ullrich Hustadt COMP519 Web Programming L14 1

3 Object Literals (User-defined) Objects Literals JavaScript is an object-oriented language, but one without classes Instead of defining a class, we can simply state an object literal { property1 : value1, property2 : value2,... where property1, property2,... are variable names and value1, value2,... are values (expressions) var person1 = { age : (30 + 2), gender : male, name : { first : Bob, last : Smith, interests : [ music, skiing ], hello : function () { return Hi! I\ m + this. name. first +. ; person1. age --> 32 // dot notation person1 [ gender ] --> male // bracket notation person1. name. first --> Bob person1 [ name ][ last ] --> Smith Ullrich Hustadt COMP519 Web Programming L14 2

4 Object Literals (User-defined) Objects Literals var person1 = {... name : { first : Bob, last : Smith, hello : function () { return Hi! I\ m + this. name. first +. ; person1. hello () --> "Hi! I m Bob." Every part of a JavaScript program is executed in a particular execution context Every execution context offers a keyword this as a way of referring to itself In person1.hello() the execution context of hello() is person1 this.name.first is person1.name.first Ullrich Hustadt COMP519 Web Programming L14 3

5 Object Literals (User-defined) Objects Literals var person1 = { name : { first : Bob, last : Smith, greet : function () { return Hi! I\ m + name. first +., full1 : this. name. first + " " + this. name.last, full2 : name. first + " " + name. last ; person1. greet () --> "Hi! I m undefined." person1. full1 --> " undefined undefined " person1. full2 --> " undefined undefined " In person1.greet() the execution context of greet() is person1 but name.first does not refer to person1.name.first In the (construction of the) object literal itself, this does not refer to person1 but its execution context (the window object) none of name.first, name.last, this.name.first, and this.name.last refers to properties of this object literal Ullrich Hustadt COMP519 Web Programming L14 4

6 Object Constructors (User-defined) Objects Constructors JavaScript is an object-oriented language, but one without classes Instead of defining a class, we can define a function that acts as object constructor variables declared inside the function will be instance variables of the object each object will have its own copy of these variables it is possible to make such variables private or public inner functions will be methods of the object it is possible to make such functions/methods private or public private variables/methods can only be accessed inside the function public variables/methods can be accessed outside the function Whenever an object constructor is called, prefixed with the keyword new, then a new object is created the function is executed with the keyword this bound to that object Ullrich Hustadt COMP519 Web Programming L14 5

7 (User-defined) Objects Objects: Definition and Use Constructors function SomeObj () { instvar2 = B // private variable var instvar3 = C // private variable this. instvar1 = A // public variable this. method1 = function () { // public method // use of a public variable, e.g. instvar1, must be preceded by this return m1[ + this. instvar1 + ] + method3 () this. method2 = function () { // public method // calls of a public method, e.g. method1, must be preceded by this return m2[ + this. method1 () + ] method3 = function () { // private method return m3[ + instvar2 + ] + method4 () var method4 = function () { // private method return m4[ + instvar3 + ] obj = new SomeObj () // creates a new object obj. instvar1 --> "A" obj. instvar2 --> undefined obj. instvar3 --> undefined obj. method1 () --> "m1[a] m3[b] m4[c]" obj. method2 () --> "m2[m1[a] m3[b] m4[c ]]" obj. method3 () --> error obj. method4 () --> error Ullrich Hustadt COMP519 Web Programming L14 6

8 (User-defined) Objects Objects: Definition and Use Constructors function SomeObj () { this. instvar1 = A // public variable instvar2 = B // private variable var instvar3 = C // private variable this. method1 = function () {... // public method this. method2 = function () {... // public method method3 = function () {... // private method var method4 = function () {... // private method Note that all of instvar1 to instvar3, method1 to method4 are instance variables (properties, members) of SomeObj The only difference is that instvar1 to instvar3 store strings while method1 to method4 store functions every object stores its own copy of the methods Ullrich Hustadt COMP519 Web Programming L14 7

9 (User-defined) Objects Objects: Prototype Property Prototype All functions have a prototype property that can hold shared object properties and methods objects do not store their own copies of these properties and methods but only store references to a single copy function SomeObj () { this. instvar1 = A // public variable instvar2 = B // private variable var instvar3 = C // private variable SomeObj. prototype. method1 = function () {... // public SomeObj. prototype. method2 = function () {... // public method3 = function () {... // private method var method4 = function () {... // private method Note: prototype properties and methods are always public! Ullrich Hustadt COMP519 Web Programming L14 8

10 (User-defined) Objects Objects: Prototype Property Prototype The prototype property can be modified on-the-fly all already existing objects gain new properties / methods manipulation of properties / methods associated with the prototype property needs to be done with care function SomeObj () {... obj1 = new SomeObj () obj2 = new SomeObj () document. writeln ( obj1. instvar4 ) // undefined document. writeln ( obj2. instvar4 ) // undefined SomeObj. prototype. instvar4 = A document. writeln ( obj1. instvar4 ) // A document. writeln ( obj2. instvar4 ) // A SomeObj. prototype. instvar4 = B document. writeln ( obj1. instvar4 ) // B document. writeln ( obj2. instvar4 ) // B obj1. instvar4 = C // creates a new instance variable for obj1 SomeObj. prototype. instvar4 = D document. writeln ( obj1. instvar4 ) // C!! document. writeln ( obj2. instvar4 ) // D!! Ullrich Hustadt COMP519 Web Programming L14 9

11 (User-defined) Objects Objects: Prototype Property Prototype The prototype property can be modified on-the-fly all already existing objects gain new properties / methods manipulation of properties / methods associated with the prototype property needs to be done with care function SomeObj () {... obj1 = new SomeObj () obj2 = new SomeObj () SomeObj. prototype. instvar5 = E SomeObj. prototype. setinstvar5 = function ( arg ) { this. instvar5 = arg obj1. setinstvar5 ( E ) obj2. setinstvar5 ( F ) document. writeln ( obj1. instvar5 ) // E!! document. writeln ( obj2. instvar5 ) // F!! Ullrich Hustadt COMP519 Web Programming L14 10

12 (User-defined) Objects Static Class Variables and Class Methods Function properties can be used to emulate Java s class variables (static variables shared among instances) and class methods function Circle ( radius ) { this.r = radius // class variable - property of the Circle constructor function Circle. PI = // instance method Circle. prototype. area = function () { return Circle. PI * this.r * this.r; // class method - property of the Circle constructor function Circle. max = function (a,b) { if (a.r > b.r) { return a else { return b c1 = new Circle (1.0) // create an instance of the Circle class c1.r = 2.2; // set the r instance variable c1_area = c1. area (); // invoke the area () instance method x = Math. exp ( Circle. PI) // use the PI class variable in a computation c2 = new Circle (1.2) // create another Circle instance bigger = Circle. max (c1, c2) // use the max () class method Ullrich Hustadt COMP519 Web Programming L14 11

13 Private Static Variables (User-defined) Objects Static In order to create private static variables shared between objects we can use a self-executing anonymous function var Person = ( function () { var population = 0 // private static class variable return function ( value ) { // constructor population ++ var name = value // private instance variable this. setname = function ( value ) { name = value this. getname = function () { return name this. getpop = function () { return population ()) person1 = new Person ( Peter ) person2 = new Person ( James ) person1. getname () --> Peter person2. getname () --> James person1. name --> undefined Person. population person1. population --> undefined person1. getpop () --> 2 person1. setname ( David ) person1. getname () --> David Ullrich Hustadt COMP519 Web Programming L14 12

14 for/in-loop (User-defined) Objects The for/in-loop allows us to go through the properties of an object Static for ( var in object ) { statements Within the loop we can use object[var] to access the value of the property var var person1 = { age : 32, gender : male, name : Bob Smith for ( prop in person1 ) { document. writeln ( person1 [ + prop + ] has value + person1 [ prop ]+ <br > ); person1 [ gender ] has value male <br > person1 [ name ] has value Bob Smith <br > person1 [ age ] has value 32 <br > Ullrich Hustadt COMP519 Web Programming L14 13

15 Inheritance (User-defined) Objects Inheritance The prototype property can also be used to establish an inheritance relationship between objects function Rectangle ( width, height ) { this. width = width this. height = height this. type = Rectangle this. area = function () { return this. width * this. height function Square ( length ) { this. width = this. height = length ; this. type = Square // Square inherits from Rectangle Square. prototype = new Rectangle (); var sq1 = new Square (5); document. writeln (" The area of sq1 is " + sq1. area () ); The area of sq1 is 25 Ullrich Hustadt COMP519 Web Programming L14 14

16 (User-defined) Objects Classes as Syntactic Sugar Classes ECMAScript 2015 introduced classes as syntactic sugar for prototype-based objects class Rectangle { constructor ( width, height ) { this. width = width this. height = height this. type = Rectangle get area () { return this. width * this. height class Square extends Rectangle { constructor ( length ) { super ( length, length ) this. type = Square var sq1 = new Square (5) document. writeln (" The area of sq1 is " + sq1. area ) // not sq1. area ()! Ullrich Hustadt COMP519 Web Programming L14 15

17 Pre-defined Objects Pre-defined Objects: String String JavaScript has a collection of pre-defined objects, including Array, String, Date A String object encapsulates values of the primitive datatype string Properties of a String object include length the number of characters in the string Methods of a String object include charat(index) the character at position index (counting from 0) substring(start,end) returns the part of a string between positions start (inclusive) and end (exclusive) touppercase() returns a copy of a string with all letters in uppercase tolowercase() returns a copy of a string with all letters in lowercase Ullrich Hustadt COMP519 Web Programming L14 16

18 Pre-defined Objects String Pre-defined Objects: String and RegExp JavaScript supports (Perl-like) regular expressions and the String objects have methods that use regular expressions: search(regexp) matches regexp with a string and returns the start position of the first match if found, -1 if not match(regexp) without g modifier returns the matching groups for the first match or if no match is found returns null with g modifier returns an array containing all the matches for the whole expression replace(regexp,replacement) replaces matches for regexp with replacement, and returns the resulting string name1 = Dave Shield. replace (/(\ w +)\ s(\w+)/, "$2, $1 ") regexp = new RegExp ("(\\ w +)\\ s (\\ w +)") name2 = Ken Chan. replace ( regexp, "$2, $1 ") Ullrich Hustadt COMP519 Web Programming L14 17

19 Pre-defined Objects Pre-defined Objects: Date Date The Date object can be used to access the (local) date and time The Date object supports various constructors new Date() current date and time new Date(milliseconds) set date to milliseconds since 1 Januar 1970 new Date(dateString) set date according to datestring new Date(year, month, day, hours, min, sec, msec) Methods provided by Date include tostring() returns a string representation of the Date object getfullyear() returns a four digit string representation of the (current) year parse() parses a date string and returns the number of milliseconds since midnight of 1 January 1970 Ullrich Hustadt COMP519 Web Programming L14 18

20 Revision Revision and Further Reading Read Chapter 20: The JavaScript Language: Objects of S. Schafer: Web Standards Programmer s Reference. Wiley Publishing, Harold Cohen Library S29 or E-book Read Chapter 5: Reference Types: The Object Type Chapter 6: Object-Oriented Programming Chapter 7: Anonymous Functions of N. C. Zakas: Professional JavaScript for Web developers. Wrox Press, Harold Cohen Library Z21 or E-book Ullrich Hustadt COMP519 Web Programming L14 19

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts COMP519 Web Programming Lecture 21: Python (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Functions

More information

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts COMP519 Web Programming Lecture 20: Python (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 4 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Control

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts

COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts COMP284 Scripting Languages Lecture 6: Perl (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

COMP284 Scripting Languages Lecture 13: PHP (Part 5) Handouts

COMP284 Scripting Languages Lecture 13: PHP (Part 5) Handouts COMP284 Scripting Languages Lecture 13: PHP (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript Lecture 3: The Basics of JavaScript Wendy Liu CSC309F Fall 2007 Background Origin and facts 1 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static content How

More information

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Symbols. accessor properties, attributes, creating, adding properties, 8 anonymous functions, 20, 80

Symbols. accessor properties, attributes, creating, adding properties, 8 anonymous functions, 20, 80 Index Symbols { } (braces) for function contents, 18 and object properties, 9 == (double equals operator), 5 === (triple equals operator), 5 [ ] (square brackets) for array literals, 10 for property access,

More information

Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies. JavaScript Part I Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

COMP519 Web Programming Lecture 7: Cascading Style Sheets: Part 3 Handouts

COMP519 Web Programming Lecture 7: Cascading Style Sheets: Part 3 Handouts COMP519 Web Programming Lecture 7: Cascading Style Sheets: Part 3 Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University

More information

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications JavaScript Started as a simple script in a Web page that is interpreted and run by the browser Supported by most modern browsers Allows dynamic update of a web page More generally, allows running an arbitrary

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. Preface p. xiii Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. 5 Client-Side JavaScript: Executable Content

More information

JavaScript: Sort of a Big Deal,

JavaScript: Sort of a Big Deal, : Sort of a Big Deal, But Sort of Quirky... March 20, 2017 Lisp in C s Clothing (Crockford, 2001) Dynamically Typed: no static type annotations or type checks. C-Like Syntax: curly-braces, for, semicolons,

More information

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology JavaScript: the language of browser interactions Claudia Hauff TI1506: Web and Database Technology ti1506-ewi@tudelft.nl Densest Web lecture of this course. Coding takes time. Be friendly with Codecademy

More information

Web Application Development

Web Application Development Web Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie JavaScript JAVASCRIPT FUNDAMENTALS Agenda

More information

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2012

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2012 CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2012 Name: This exam consists of 6 problems on the following 7 pages. You may use your two-sided hand-written 8 ½ x 11 note sheet during the exam.

More information

Using JavaScript in Viedoc

Using JavaScript in Viedoc Using JavaScript in Viedoc 1 Expressions An expression in Viedoc is a JavaScript function body written in ECMAScript 5.1 standards http://www.ecmainternational.org/ecma-262/5.1 http://www.w3schools.com/js/js_syntax.asp

More information

COMP519: Web Programming Lecture 4: HTML (Part 3)

COMP519: Web Programming Lecture 4: HTML (Part 3) COMP519: Web Programming Lecture 4: HTML (Part 3) Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents 1 HTML

More information

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts

COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts COMP284 Scripting Languages Lecture 2: Perl (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects JavaScript CAC Noida is an ISO 9001:2015 certified training center with professional experience that dates back to 2005. The vision is to provide professional education merging corporate culture globally

More information

3 The Building Blocks: Data Types, Literals, and Variables

3 The Building Blocks: Data Types, Literals, and Variables chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

More information

COMP284 Scripting Languages Lecture 9: PHP (Part 1) Handouts

COMP284 Scripting Languages Lecture 9: PHP (Part 1) Handouts COMP284 Scripting Languages Lecture 9: PHP (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Such JavaScript Very Wow

Such JavaScript Very Wow Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016 JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written

More information

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore 560 100 WEB PROGRAMMING Solution Set II Section A 1. This function evaluates a string as javascript statement or expression

More information

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every

More information

COMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts

COMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts COMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Ch. 5: JavaScript An Object-Based Language Ch. 6: Programming the Browser Review Data Types & Variables Data Types Numeric String Boolean Variables Declaring

More information

Node.js Training JavaScript. Richard richardrodger.com

Node.js Training JavaScript. Richard richardrodger.com Node.js Training JavaScript Richard Rodger @rjrodger richardrodger.com richard.rodger@nearform.com A New Look at JavaScript Embracing JavaScript JavaScript Data Structures JavaScript Functions Functional

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

7. C++ Class and Object

7. C++ Class and Object 7. C++ Class and Object 7.1 Class: The classes are the most important feature of C++ that leads to Object Oriented programming. Class is a user defined data type, which holds its own data members and member

More information

JAVASCRIPT - OBJECTS OVERVIEW

JAVASCRIPT - OBJECTS OVERVIEW JAVASCRIPT - OBJECTS OVERVIEW http://www.tutorialspoint.com/javascript/javascript_objects.htm Copyright tutorialspoint.com JavaScript is an Object Oriented Programming OOP language. A programming language

More information

Object-Oriented Programming Concepts

Object-Oriented Programming Concepts Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified

More information

Variables and Typing

Variables and Typing Variables and Typing Christopher M. Harden Contents 1 The basic workflow 2 2 Variables 3 2.1 Declaring a variable........................ 3 2.2 Assigning to a variable...................... 4 2.3 Other

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Lecture 36: Cloning Last time: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Today: 1. Project #7 assigned 2. equals reconsidered 3. Copying and cloning 4. Composition 11/27/2006

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

"Hello" " This " + "is String " + "concatenation"

Hello  This  + is String  + concatenation Strings About Strings Strings are objects, but there is a special syntax for writing String literals: "Hello" Strings, unlike most other objects, have a defined operation (as opposed to a method): " This

More information

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Handout 7. Defining Classes part 1. Instance variables and instance methods. Handout 7 CS180 Programming Fundamentals Spring 15 Page 1 of 8 Handout 7 Defining Classes part 1. Instance variables and instance methods. In Object Oriented programming, applications are comprised from

More information

More on JavaScript Functions

More on JavaScript Functions More on JavaScript Functions Nesting Function Definitions Function definitions can be nested. function hypotenuse(a, b) function square(x) return x * x; return Math.sqrt(square(a) + square(b));

More information

Lesson 9: Custom JavaScript Objects

Lesson 9: Custom JavaScript Objects Lesson 9: Custom JavaScript Objects Objectives Create a custom JavaScript object Define properties and methods of custom objects Create new object instances Create client-side arrays using custom objects

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Topics. Class Basics and Benefits Creating Objects.NET Architecture and Base Class Libraries 3-2

Topics. Class Basics and Benefits Creating Objects.NET Architecture and Base Class Libraries 3-2 Classes & Objects Topics Class Basics and Benefits Creating Objects.NET Architecture and Base Class Libraries 3-2 Object-Oriented Programming Classes combine data and the methods (code) to manipulate the

More information

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an

More information

Object-Oriented Programming Concepts

Object-Oriented Programming Concepts Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are

More information

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3: PROGRAMMING ASSIGNMENT 3: Read Savitch: Chapter 7 Programming: You will have 5 files all should be located in a dir. named PA3: ShapeP3.java PointP3.java CircleP3.java RectangleP3.java TriangleP3.java

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Using JavaScript in Viedoc

Using JavaScript in Viedoc Using JavaScript in Viedoc 1 Introduction In Viedoc Designer, JavaScript can be used to provide a lot more flexibility when working with the study design, by: setting Visibility conditions (for items,

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished

More information

CPS 109 Lab 2 Alexander Ferworn Updated Fall 05. Ryerson University. School of Computer Science CPS109. Lab 2

CPS 109 Lab 2 Alexander Ferworn Updated Fall 05. Ryerson University. School of Computer Science CPS109. Lab 2 Ryerson University Chapter 2: Using Objects Lab Exercises School of Computer Science CPS109 Lab 2 Objects, Classes and Methods 1. The String class provides methods that you can apply to String objects.

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

CSCE 120: Learning To Code

CSCE 120: Learning To Code CSCE 120: Learning To Code Manipulating Data I Introduction This module is designed to get you started working with data by understanding and using variables and data types in JavaScript. It will also

More information

COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts

COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University

More information

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems CIS 110 Introduction To Computer Programming October 5th, 2011 Exam 1 Review problems Scores: 1 2 3 4 5 6 Total (100 max) CIS 110 Exam 1 Instructions You have 50 minutes to finish this exam. Time will

More information

Today. Continue our very basic intro to JavaScript. Lambda calculus

Today. Continue our very basic intro to JavaScript. Lambda calculus JavaScript (cont) Today Continue our very basic intro to JavaScript Lambda calculus Last lecture recap JavaScript was designed in 10 days Lots of unsatisfactory parts (in retrospect); many due due to the

More information

Chapter 3 Classes. Activity The class as a file drawer of methods. Activity Referencing static methods

Chapter 3 Classes. Activity The class as a file drawer of methods. Activity Referencing static methods Chapter 3 Classes Lesson page 3-1. Classes Activity 3-1-1 The class as a file drawer of methods Question 1. The form of a class definition is: public class {

More information

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 2

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 2 COMP 111 Introduction to Computer Science and Object-Oriented Programming Programming A program solves a problem or provides a service Useful programs apply to many instances of a problem First use for

More information

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

JavaScript: Objects, Methods, Prototypes

JavaScript: Objects, Methods, Prototypes JavaScript: Objects, Methods, Prototypes Computer Science and Engineering College of Engineering The Ohio State University Lecture 22 What is an Object? Property: a key/value pair (aka "name"/value) Object:

More information

Identifiers and Variables

Identifiers and Variables Identifiers and Variables Lecture 4 Based on Slides of Dr. Norazah Yusof 1 Identifiers All the Java components classes, variables, and methods need names. In Java these names are called identifiers, and,

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant

More information

Week 6: Review. Java is Case Sensitive

Week 6: Review. Java is Case Sensitive Week 6: Review Java Language Elements: special characters, reserved keywords, variables, operators & expressions, syntax, objects, scoping, Robot world 7 will be used on the midterm. Java is Case Sensitive

More information

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to Object-Oriented Programming. Reusing Software Objects

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to Object-Oriented Programming. Reusing Software Objects Objectives JavaScript, Sixth Edition When you complete this chapter, you will be able to: Explain basic concepts related to object-oriented programming Use the Date, Number, and Math objects Define your

More information

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information

JavaScript Basics. The Big Picture

JavaScript Basics. The Big Picture JavaScript Basics At this point, you should have reached a certain comfort level with typing and running JavaScript code assuming, of course, that someone has already written it for you This handout aims

More information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Perl Library Functions

Perl Library Functions Perl Library Functions Perl has literally hundreds of functions for all kinds of purposes: file manipulation, database access, network programming, etc. etc. It has an especially rich collection of functions

More information

Functions and Objects

Functions and Objects Functions and Objects Christopher M. Harden Contents 1 Arrays 2 1.1 Defining arrays.......................... 2 1.2 Array length............................ 3 1.3 Multi-dimensional arrays.....................

More information

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17 PIC 40A Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers 04/24/17 Copyright 2011 Jukka Virtanen UCLA 1 Objects in JS In C++ we have classes, in JS we have OBJECTS.

More information

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective- UNIT -II Style Sheets: CSS-Introduction to Cascading Style Sheets-Features- Core Syntax-Style Sheets and HTML Style Rle Cascading and Inheritance-Text Properties-Box Model Normal Flow Box Layout- Beyond

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Chapter 8 Objects and Classes 1 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections, loops, methods, and arrays. However, these Java

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill CSCI 136 Data Structures & Advanced Programming Lecture 3 Fall 2018 Instructors: Bill & Bill Administrative Details Lab today in TCL 217a (and 216) Lab is due by 11pm Sunday Lab 1 design doc is due at

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

CS/ENGRD 2110 SPRING Lecture 5: Local vars; Inside-out rule; constructors

CS/ENGRD 2110 SPRING Lecture 5: Local vars; Inside-out rule; constructors 1 CS/ENGRD 2110 SPRING 2017 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 Announcements 2 1. Writing tests to check that the code works when the precondition

More information

Lesson:9 Working with Array and String

Lesson:9 Working with Array and String Introduction to Array: Lesson:9 Working with Array and String An Array is a variable representing a collection of homogeneous type of elements. Arrays are useful to represent vector, matrix and other multi-dimensional

More information

UMBC CMSC 331 Final Exam

UMBC CMSC 331 Final Exam UMBC CMSC 331 Final Exam Name: UMBC Username: You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy

More information

JScript Reference. Contents

JScript Reference. Contents JScript Reference Contents Exploring the JScript Language JScript Example Altium Designer and Borland Delphi Run Time Libraries Server Processes JScript Source Files PRJSCR, JS and DFM files About JScript

More information

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors 1 CS/ENGRD 2110 FALL 2016 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 References to text and JavaSummary.pptx 2 Local variable: variable declared in a method

More information

Programming in the Large II: Objects and Classes (Part 1)

Programming in the Large II: Objects and Classes (Part 1) Programming in the Large II: Objects and Classes (Part 1) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : An interface defines the list of fields

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information