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

Size: px
Start display at page:

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

Transcription

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)

2 AGENDA 9. Introduction to Objects 10. Advanced Objects 11. Functions 12. Advanced Functions

3 Introduction to Objects 9.

4 9.1 OVERVIEW OF OBJECTS 129 Object is fundamental type in JavaScript: Object is a composite value: it aggregates multiple values (primitive values or other objects) and allows you to store and retrieve those values by name Object is an unordered collection of properties, each of which has a name and a value (String to Value mapping) (Also known as hash, hashtable, dictionary object, associative array) JavaScript object inherits the properties and methods of another object, known as its prototype ( prototypal inheritance ) JavaScript objects are dynamic properties can be added and deleted Objects are mutable and are manipulated by reference rather than by value: Variable x refers to an object, and code var y = x; is executed Variable y holds a reference to the same object, not a copy of that object Modifications made to the object through y are also visible through x Most common things to do with objects are create them and to set, query, delete, test, and enumerate their properties

5 9.1 OVERVIEW OF OBJECTS 130 Besides name and value, properties have attributes: Besides its properties, objects have attributes: Some terms to distinguish among three broad categories of JavaScript objects: Own versus inherited properties:

6 9.2 CREATING OBJECTS ways to create objects: Creating Objects with Object Literals Easiest way to create an object is to include an object literal in your JavaScript code :

7 9.2 CREATING OBJECTS 132 Reserved words may be used as property names by using quotes not recommended An object literal is an expression that creates and initializes a new and distinct object each time it is evaluated: A single object literal can create many new objects if it appears within the body of a loop in a function that is called repeatedly

8 9.2 CREATING OBJECTS 133 Creating Objects with new new operator creates and initializes a new object new keyword must be followed by a function invocation Function used in this way is called a constructor and serves to initialize a newly created object

9 9.2 CREATING OBJECTS 134 Prototypes Every JavaScript object has a second JavaScript object (or null, but this is rare) associated with it known as a prototype, and the first object inherits properties from the prototype All objects created by object literals have the same prototype object Object.prototype Object.prototype has no prototype (top of the chain) All of the built-in constructors (and most user-defined constructors) have a prototype that inherits from Object.prototype

10 9.2 CREATING OBJECTS 135 Creating Objects with Object.create() Object.create() has two arguments: First argument is the prototype of that object Optional second argument describes the properties of the new object Object.create() is a static function (not a method invoked on individual objects), simply pass the desired prototype object You can pass null to create a new object that does not have a prototype If you want to create an ordinary empty object ( object returned by {} or new Object()), pass Object.prototype

11 9.3 GETTING AND SETTING PROPERTIES 136 To obtain the value of a property, use the dot (.) or square bracket ([]) operators. = Name of property as identifier [] = Name of property as string To create or set a property: Use a dot or square brackets as you would to query the property Use the property access expression on left-hand side of an assignment expression Identifier following the dot operator cannot be a reserved word if property name is a reserved word must use [] notation

12 9.3 GETTING AND SETTING PROPERTIES 137 Objects as Associative Arrays These two expressions have the same value: First syntax is similar to accessing static property/struct/object in Java/C Second syntax (square brackets) looks like array access, but to an array indexed by strings rather than by numbers associative array In other languages (C, C++, Java) an object can have only a fixed number of properties, and names must be defined in advance In JavaScript, this rule does not apply can create any number of properties at run-time. notation uses name of property as an identifier typed literally into your JavaScript program [] notation uses property expressed as string string datatype can be manipulated and created at run-time!

13 9.3 GETTING AND SETTING PROPERTIES 138

14 9.3 GETTING AND SETTING PROPERTIES 139 Property Access Errors It is not an error to query a property that does not exist: If the property x is not found as an own property or an inherited property of o, the property access expression o.x evaluates to undefined It is an error to query a property of an object that does not exist Do not write expressions where you do not know whether an object exists To safe guard, test for the existence of object first

15 9.3 GETTING AND SETTING PROPERTIES 140 Setting a property on null or undefined also causes a TypeError: Other attempts may also fail, for example a read-only property But no error is thrown, they fail silently In ECMAScript 5 (strict mode) any failed attempt to set a property throws a TypeError exception An attempt to set a property p of an object o fails in these circumstances:

16 9.4 DELETING PROPERTIES 141 delete operator removes a property from an object Its single operand should be a property access expression delete does not operate on the value of the property but on the property itself delete operator only deletes own properties, not inherited ones Certain properties of built-in objects and the global object are nonconfigurable and hence cannot be deleted

17 9.5. TESTING PROPERTIES 142 JavaScript objects can be thought of as sets of properties, and it is often useful to be able to test for membership in the set: in operator (own and inherited properties) hasownproperty() method (own property only)

18 9.5. TESTING PROPERTIES 143 propertyisenumerable() method (own and enumerable property) querying the property (in most cases this is sufficient) One thing in operator can do compared to simple property access technique shown above: Distinguish between properties that do not exist and properties that do exist but have been set to undefined

19 9.6 ENUMERATING PROPERTIES 144 Usually done with the for/in loop, although ECMAScript 5 provides two handy alternatives (see next slide) for/in loop runs the body of the loop once for each enumerable property (own or inherited) of the specified object, assigning the name of the property to the loop variable

20 9.6 ENUMERATING PROPERTIES 145 Built-in methods that objects inherit are not enumerable, but properties that you add are enumerable Some utility libraries add new methods (or other properties) to Object.prototypes o that they are inherited by, and available to, all objects To filter out those methods or properties: Two new ECMAScript5 methods:

21 Advanced Objects 10.

22 10.1 PROPERTY GETTERS AND SETTERS 146 Object property consists of name, value, and set of attributes ECMAScript5 defines getter and setter methods (accessor methods) for value When querying an accessor property, JavaScript invokes the getter method (passing no arguments) When setting the value of an accessor property, JavaScript invokes the setter method, passing the value of the right-hand side of the assignment Accessor properties are defined as one or two functions whose name is the same as the property name, and with the function keyword replaced with get and/or set

23 10.1 PROPERTY GETTERS AND SETTERS 147 Reasons to use accessor properties: Sanity checking of property writes (validation) Returning different values on each property read

24 10.2 PROPERTY ATTRIBUTES 148 Property attributes specify whether they can be written, enumerated, and configured (only in ECMAScript 5) Important to JavaScript library authors: For this section consider the value also as an attribute: Property has a name and four attributes: Accessor property: get (Data value), set (Writable), enumerable, configurable Property descriptor represents those 4 attributes To obtain the property descriptor for a named property of a specified object, call Object.getOwnPropertyDescriptor() Object.getOwnPropertyDescriptor() only works for own properties Query inherited properties explicitly traverse prototype chain

25 10.2 PROPERTY ATTRIBUTES 149 To set the attributes of a property, or to create a new property: Property descriptor you pass to Object.defineProperty() does not have to include all four attributes: Modify or create multiple properties: Object.defineProperties(): First argument: Property to be modified Second argument: Object of names of properties and values

26 10.3 OBJECT ATTRIBUTES 150 Every object has three attributes: Prototype Attribute Object s prototype attribute specifies the object from which it inherits properties Prototype attribute is set when an object is created Query the prototype of any object by passing that object to Object.getPrototypeOf() To determine whether one object is the prototype of (or is part of the prototype chain of) another object, use the isprototypeof() method

27 10.3 OBJECT ATTRIBUTES 151 Class Attribute Object s class attribute is a string that provides information about the type of the object Neither ECMAScript 3 nor ECMAScript 5 provide any way to set this attribute Only an indirect technique for querying it: Default tostring() method (inherited from Object.prototype) returns a string of the form: [object class] Obtain the class of an object, you can invoke this tostring() method on it, and extract the eighth through the second-to-last characters of the returned string Tricky part is that many objects inherit other, more useful tostring() methods, and to invoke the correct version of tostring(), we must do so indirectly, using the Function.call() method

28 10.3 OBJECT ATTRIBUTES 152 Extensible Attribute Extensible attribute of an object specifies whether new properties can be added to the object or not ECMAScript 5, all built-in and user-defined objects are extensible unless they have been converted to be nonextensible, and the extensibility of host objects is implementation defined To query the extensible attribute: Object.isExtensible() To make an object non-extensible: Object.preventExtensions() If properties added to prototype of a nonextensible object nonextensible object will inherit those new properties To lock down an object, use Object.seal(): new properties cannot be added to the object, and existing properties cannot be deleted or configured To completely lock down, use Object.freeze(): all of the object s own data properties are read-only

29 10.4 SERIALIZING OBJECTS 153 Object serialization is the process of converting an object s state to a string from which it can later be restored ECMAScript 5 provides two native functions: JSON = JavaScript Object Notation:

30 10.5 OBJECT METHODS 154 All JavaScript objects (except those explicitly created without a prototype) inherit properties from Object.prototype (primarly methods)

31 Functions 11.

32 11 FUNCTIONS 155 Function is a block of JavaScript code that is defined once but may be executed, or invoked, any number of times Function definition may include a list of identifiers, known as parameters, that work as local variables for the body of the function Function invocation provide values (arguments) for the function s parameters If a function is assigned into a property of an object method In JavaScript, functions are objects and can be programmatically manipulated JavaScript function definitions can be nested within other functions, and they have access to any variables that are in scope where they are defined

33 11.1 DEFINING FUNCTIONS 156 Functions can be used in two fundamentally different ways: These two forms can be used interchangeably, however, function definition expressions are more useful: In either form a function is comprised of:

34 11.1 DEFINING FUNCTIONS 157

35 11.1 DEFINING FUNCTIONS 158 Function Names Any legal JavaScript identifier can be a function name Function names are often verbs or phrases that begin with verbs It is a common convention to begin function names with a lowercase letter. Use _ or CamelCase if multiple words Functions that are supposed to be internal or hidden (and not part of a public API) are sometimes given names that begin with an underscore

36 11.1 DEFINING FUNCTIONS 159 Function Hoisting Function declaration statements are hoisted to the top of the enclosing script or the enclosing function This is not true for functions defined as expressions: To invoke a function, you must be able to refer to it Cannot refer to a function defined as an expression until it is assigned to a variable Represents the same behavior as with variables

37 11.1 DEFINING FUNCTIONS 160

38 11.1 DEFINING FUNCTIONS 161 Return Statement Return statement causes the function to stop executing and to return the value of its expression (if any) to the caller Return statement often appears at the end of the function, but does not have to be Return statement can be also used without an expression returns undefined Most functions compute something and return a value to the caller, but there are exceptions:

39 11.1 DEFINING FUNCTIONS 162 Nested Function Functions can be nested within other functions: Scoping Rules: Can access the parameters and variables of the function (or functions) they are nested within Function statements are not true statements because they have some limitations: Can only appear in global code Cannot appear inside of loops, conditionals, or try/catch/finally or with statements

40 11.2 EXECUTING FUNCTIONS 163 JavaScript functions can be invoked in four ways: Function Invocation An invocation expression consists of: Function expression that evaluates to a function object Followed by an open parenthesis comma-separated list of zero or more argument expressions Closed by a close parenthesis

41 11.2 EXECUTING FUNCTIONS 164 Each argument expression is evaluated, and the resulting values become the arguments to the function For regular function invocation, return value of function becomes the value of the invocation expression

42 11.2 EXECUTING FUNCTIONS 165 Method Invocation Method is nothing more than a JavaScript function that is stored in a property of an object: Method name m_func defines a function func in object obj To invoke: obj.m_func() or with arguments obj.m_func(x,y) Arguments and return value of a method invocation are handled exactly as described above for regular function invocation Method invocations differ from function invocations in one important way Invocation context: Property access expressions consist of two parts: an object (in this case obj) and a property name (m_func) Method invocation expression like above, the object obj becomes the invocation context, and the function body can refer to that object by using the keyword this

43 11.2 EXECUTING FUNCTIONS 166 Method invocation can use [] or. access notation Method invocations may also involve more complex property access expressions Methods and the this keyword are central to the object-oriented programming paradigm Any function that is used as a method is effectively passed an implicit argument the object through which it is invoked Hypothetical functions invoked in these two lines of code may perform exactly the same operation on object objrect: Method-invocation syntax in the first line more clearly indicates the idea that it is the object objrect that is the primary focus of the operation

44 11.2 EXECUTING FUNCTIONS 167 Constructor Invocation Constructor invocation is preceded by the keyword new Constructor invocations differ from regular function and method invocations in their handling of arguments, invocation context, and return value With parameters, same as usual, but without parameters you can omit parentheses Constructor functions do not normally use the return keyword perform only initialization for the object Indirect Invocation JavaScript functions are objects they have methods Two methods, call() and apply(), invoke the function indirectly: Call() method uses its own argument list as arguments to the function Apply() method expects an array of values to be used as arguments

45 Advanced Functions 12.

46 12.1 FUNCTION ARGUMENTS AND PARAMETERS 168 JavaScript function definitions do not specify an expected type for the function parameters, and function invocations do not do any type checking on the argument values you pass JavaScript function invocations do not even check the number of arguments being passed!! Optional Parameters When function is invoked with fewer arguments than declared parameters, the additional parameters are set to the undefined value It is often useful to write functions so that some arguments are optional and may be omitted when the function is invoked

47 12.1 FUNCTION ARGUMENTS AND PARAMETERS 169 Arguments Object The identifier arguments refers to the Arguments object for an invocation of a function The Arguments object is an array-like object that allows the argument values passed to the function to be retrieved by number, rather than by name f(x) invoked as f(3,8): access first parameter using x or arguments[0], second parameter only with arguments[1] arguments has a length property indicating number of parameters Functions that can accept any number of arguments are called variadic functions, variable arity functions, or varargs functions

48 12.1 FUNCTION ARGUMENTS AND PARAMETERS 170 arguments is an object and not an array! It happens to have some numbered properties When a function is defined having named parameters, the name of the parameter and the arguments object point to the same variable! Changing the value of one of them changes the value of the other If arguments object were an array, this behavior would not true!

49 12.2 FUNCTION AS VALUES 171 Function definition and invocation are syntactic features of JavaScript and of most other programming languages In JavaScript, however, functions are not only syntax but also values, which means they can be assigned to variables, stored in the properties of objects or the elements of arrays, passed as arguments to functions, and so on. This definition creates a new function object and assigns it to the variable function_name: Name of function is really immaterial It is just the name of a variable that refers to the function object Function can be assigned to another variable ->still work the same way Functions can also be assigned to object properties rather than variables, in this case they are called methods Functions can also be contained in arrays and called as such using argument values stored in the same array

50 12.3 FUNCTION AS PROPERTIES 172 Functions are data values, they can be created with the Function( ) constructor sure signs that functions are actually represented by a type of JavaScript object: the Function object Since functions are objects, they have properties and methods, just like the String and Date objects Function s length property stores number of defined function arguments through the callee property of the function, which is also implemented through the arguments object: When a function needs a static variable whose value persists across invocations, it is often convenient to use a property of the function, instead of cluttering up the namespace by defining a global variable

51 12.4 FUNCTION AS NAMESPACES 173 No concept of namespace and by default variables are global When using 3 rd party plugins, how to avoid variable name collisions? Variable Scope: Variables declared in a function are local Variables outside function boundaries are global No block scope! Use functions as temporary namespaces to declare local variables without polluting global space

52 12.4 FUNCTION AS NAMESPACES 174 Solution is to place code into a function and then invoke the function (do not forget!): Only defines one global variable, the function mymodule Everything is local inside function Rewrite as an unnamed expression: Take note of the open/close parentheses after curly braces! For larger code bases having many functions, wrap entire application code into one global object Demo examples shows 3 functions wrapped into an object:

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

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

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

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

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

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

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

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material. Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA2442 Introduction to JavaScript Objectives This intensive training course

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

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

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

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

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

Haskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.

Haskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G. Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

CGS 3066: Spring 2015 JavaScript Reference

CGS 3066: Spring 2015 JavaScript Reference CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within

More information

Compiler Errors. Flash CS4 Professional ActionScript 3.0 Language Reference. 1 of 18 9/6/2010 9:40 PM

Compiler Errors. Flash CS4 Professional ActionScript 3.0 Language Reference. 1 of 18 9/6/2010 9:40 PM 1 of 18 9/6/2010 9:40 PM Flash CS4 Professional ActionScript 3.0 Language Reference Language Reference only Compiler Errors Home All Packages All Classes Language Elements Index Appendixes Conventions

More information

CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

JavaScript Functions, Objects and Array

JavaScript Functions, Objects and Array JavaScript Functions, Objects and Array Defining a Function A definition starts with the word function. A name follows that must start with a letter or underscore, followed by any number of letters, digits,

More information

Javascript Arrays, Object & Functions

Javascript Arrays, Object & Functions Javascript Arrays, Object & Functions Agenda Creating & Using Arrays Creating & Using Objects Creating & Using Functions 2 Creating & Using Arrays Arrays are a type of object that are ordered by the index

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

COLOGO A Graph Language Reference Manual

COLOGO A Graph Language Reference Manual COLOGO A Graph Language Reference Manual Advisor: Stephen A. Edwards Shen Wang (sw2613@columbia.edu) Lixing Dong (ld2505@columbia.edu) Siyuan Lu (sl3352@columbia.edu) Chao Song (cs2994@columbia.edu) Zhou

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

YAGL: Yet Another Graphing Language Language Reference Manual

YAGL: Yet Another Graphing Language Language Reference Manual YAGL: Yet Another Graphing Language Language Reference Manual Edgar Aroutiounian, Jeff Barg, Robert Cohen July 23, 2014 Abstract YAGL is a programming language for generating graphs in SVG format from

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

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013 CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Winter 2013 Ruby logistics Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework Ruby logistics CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Autumn 2018 Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage

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 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Overview of the Ruby Language. By Ron Haley

Overview of the Ruby Language. By Ron Haley Overview of the Ruby Language By Ron Haley Outline Ruby About Ruby Installation Basics Ruby Conventions Arrays and Hashes Symbols Control Structures Regular Expressions Class vs. Module Blocks, Procs,

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

La Mesa Language Reference Manual COMS 4115: Programming Languages and Translators Professor Stephen Edwards

La Mesa Language Reference Manual COMS 4115: Programming Languages and Translators Professor Stephen Edwards La Mesa Language Reference Manual COMS 4115: Programming Languages and Translators Professor Stephen Edwards Michael Vitrano Matt Jesuele Charles Williamson Jared Pochtar 1. Introduction La Mesa is a language

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

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

RAQUEL s Relational Operators

RAQUEL s Relational Operators Contents RAQUEL s Relational Operators Introduction 2 General Principles 2 Operator Parameters 3 Ordinary & High-Level Operators 3 Operator Valency 4 Default Tuples 5 The Relational Algebra Operators in

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Fundamentals of Programming Session 25

Fundamentals of Programming Session 25 Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

GAWK Language Reference Manual

GAWK Language Reference Manual GAWK Language Reference Manual Albert Cui, Karen Nan, Mei-Vern Then, & Michael Raimi So good, you re gonna GAWK. 1.0 Introduction This manual describes the GAWK language and is meant to be used as a reliable

More information

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

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts 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

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

iwiki Documentation Release 1.0 jch

iwiki Documentation Release 1.0 jch iwiki Documentation Release 1.0 jch January 31, 2014 Contents i ii Contents: Contents 1 2 Contents CHAPTER 1 Python 1.1 Python Core 1.1.1 Strings 1.1.2 Functions Argument Lists *args tuple/list **kwargs

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

JavaScript Lecture 1

JavaScript Lecture 1 JavaScript Lecture 1 Waterford Institute of Technology May 17, 2016 John Fitzgerald Waterford Institute of Technology, JavaScriptLecture 1 1/31 Javascript Extent of this course A condensed basic JavaScript

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

S206E Lecture 19, 5/24/2016, Python an overview

S206E Lecture 19, 5/24/2016, Python an overview S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

This document defines the ActionScript 3.0 language, which is designed to be forward- compatible with the next edition of ECMAScript (ECMA-262).

This document defines the ActionScript 3.0 language, which is designed to be forward- compatible with the next edition of ECMAScript (ECMA-262). ActionScript 3.0 Language Specification This document defines the ActionScript 3.0 language, which is designed to be forward- compatible with the next edition of ECMAScript (ECMA-262). This document is

More information

CSE 341, Autumn 2015, Ruby Introduction Summary

CSE 341, Autumn 2015, Ruby Introduction Summary CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful

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 Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

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

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW Prepared by: Dr. Abdallah Mohamed, AOU-KW 1 1. Introduction 2. Objects and classes 3. Information hiding 4. Constructors 5. Some examples of Java classes 6. Inheritance revisited 7. The class hierarchy

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

JavaScript Patterns O'REILLY* S toy an Stefanov. Sebastopol. Cambridge. Tokyo. Beijing. Farnham K8ln

JavaScript Patterns O'REILLY* S toy an Stefanov. Sebastopol. Cambridge. Tokyo. Beijing. Farnham K8ln JavaScript Patterns S toy an Stefanov O'REILLY* Beijing Cambridge Farnham K8ln Sebastopol Tokyo Table of Contents Preface xiii 1. Introduction 1 Patterns 1 JavaScript: Concepts 3 Object-Oriented 3 No Classes

More information

Generating Continuation Passing Style Code for the Co-op Language

Generating Continuation Passing Style Code for the Co-op Language Generating Continuation Passing Style Code for the Co-op Language Mark Laarakkers University of Twente Faculty: Computer Science Chair: Software engineering Graduation committee: dr.ing. C.M. Bockisch

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

CPS122 Lecture: Defining a Class

CPS122 Lecture: Defining a Class Objectives: CPS122 Lecture: Defining a Class last revised January 14, 2016 1. To introduce structure of a Java class 2. To introduce the different kinds of Java variables (instance, class, parameter, local)

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

The format for declaring function templates with type parameters

The format for declaring function templates with type parameters UNIT 3 Function and class templates - Exception handling try-catch-throw paradigm exception specification terminate and Unexpected functions Uncaught exception. Templates Function templates Function templates

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Language Reference Manual

Language Reference Manual Espresso Language Reference Manual 10.06.2016 Rohit Gunurath, rg2997 Somdeep Dey, sd2988 Jianfeng Qian, jq2252 Oliver Willens, oyw2103 1 Table of Contents Table of Contents 1 Overview 3 Types 4 Primitive

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

SPARK-PL: Introduction

SPARK-PL: Introduction Alexey Solovyev Abstract All basic elements of SPARK-PL are introduced. Table of Contents 1. Introduction to SPARK-PL... 1 2. Alphabet of SPARK-PL... 3 3. Types and variables... 3 4. SPARK-PL basic commands...

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Chapter 3 Data Types and Variables

Chapter 3 Data Types and Variables Chapter 3 Data Types and Variables Adapted from JavaScript: The Complete Reference 2 nd Edition by Thomas Powell & Fritz Schneider 2004 Thomas Powell, Fritz Schneider, McGraw-Hill Jargon Review Variable

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

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

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

More information

Introduction to Java & Fundamental Data Types

Introduction to Java & Fundamental Data Types Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

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 8 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information