COMP721 Quiz 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/63

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

64 Terms

1
New cards

Which one of these techniques for maintaining state information is client side and which is server side?

- Hidden form fields

- Query strings

- Cookies

- HTML5 local storage (JavaScript)

- PHP Sessions

Client Side:

- Hidden form fields

- Query strings

- Cookies

- HTML5 local storage (JavaScript)

Server Side:

- PHP Sessions

2
New cards

How do you create hidden form fields?

Using "hidden" type attribute in element:

3
New cards

How do you pass information from 1 webpage to another with a query string?

Add "?" after the URL followed by "name=value" pairs separated by "&"

4
New cards

What are 2 types of cookies and their definitions?

- Temporary cookies remain available only for the current browser session

- Persistent cookies remain available beyond the current browser session and are storedin a text file on a client computer

5
New cards

Syntax for creating cookies?

setcookie(name, value, expires, path, domain, secure)

6
New cards

Where must cookies be sent?

Before any HTML elements or other output are sent from the server

7
New cards

How to specify a cookie expiration time?

Use time() function and offset (in seconds) for the "expires" argument

setcookie("firstName", "Don", time()+3600);

Default value of "expires" is 0, which means it is available for only the current browser session

8
New cards

How does "path" argument in setcookie() work? What argument do you provide to allow any page? What is the default value?

Determines the availability of a cookie to other web pages on a server. (e.g. /marketing/)

- To allow any page, provide "/"

- Default value is the directory the cookie is set in

9
New cards

How does "domain" argument in setcookie() work?

Used to share cookies across multiple servers in the same domain:

- Includes all sub-domains

- Cookies cannot be shared outside of a domain

10
New cards

How does "secure" argument in setcookie() work? What is the default value?

Indicates that a cookie can only be transmitted over asecure HTTPS connection:

- Values are either true or false

- Default value is false

11
New cards

How do you read cookies?

Using the $_COOKIE superglobal associative array

12
New cards

How do you delete cookies?

Set expiration time that is in the past

13
New cards

What are 2 types of HTML5 Local Storage?

sessionStorage - temporary

localStorage - persistent

14
New cards

Where is PHP session state information stored?

In the $_SESSION superglobal as an associative array

15
New cards

How to set the lifetime of a PHP session? (What method do you use?)

session_set_cookie_params(3600); (sets to 1 hour)

16
New cards

How to delete PHP session variables?

unset($_SESSION['name'])

17
New cards

How to delete an entire PHP session?

session_destroy()

18
New cards

How do you provide redirection after manipulating PHP session variables? What’s the syntax?

header("location:URL")

19
New cards

What is the member selection notation in PHP classes (What do you use to access methods and properties of a PHP class?)

"->" symbol

20
New cards

How to define, detect and check if an object is instantiated from a given class in JS?

- Define: "class" keyword

- Detect: get_class() function

- Check instance: instance_of() function

21
New cards

Syntax for constructor function in PHP?

class BankAccount {
	private $accountNumber;
	private $customerName;
	private $balance;
	function __construct() {
		$this->accountNumber = 0;
		$this->balance = 0;
		$this->customerName = "";
	}
}

22
New cards

What is serialization in PHP and how do you serialize objects?

  • Serialization refers to the process of converting an object into a string that can be stored.

  • To serialize an object, pass an object name to the serialize() function:

    • $savedAccount = serialize($checking);

  • You can also do the opposite (converting serialized string back to an object with unserialize())

23
New cards

What does Ajax, DOM, and JSON stand for?

Asynchronous JavaScript and XML

Document Object Model

JavaScript Object Notation

24
New cards

What are the 2 ways to implement the Ajax Model?

- fetch(): fetch-then-catch code pattern. Using JS object Promise

- XMLHttpRequest Object: var xhr = new XMLHttpRequest()

25
New cards

What is the basic flow of asynchronous interation with Ajax?

User does something (clicks a button) -> event handler (onClick() calls the JS function, which creates an XHR object or fetch() -> Retrieves the data (communication with server / PHP file) with xhr.open or fetch() -> PHP echoes the result -> Does something (place text in innerHTML) | defines the function onreadystatechange then xhr.send()

26
New cards

How do you check if XHR communication has finished?

if (xhr.readyState == 4 && xhr.status == 200)

27
New cards

How do you write JS code in HTML file? How do you refer to a JS file externally?

- using script tags:"

<script type="text/javascript">...</script>

To link to external file, simply add a “src” attribute:

<script type="text/javascript" src="xhr.js"></script>

28
New cards

Difference between var and let in JS?

let has block scope

var are available throughout the entire function

29
New cards

How to define multi-line strings in JS?

use backticks

30
New cards

What does this code return?

function add1(n) {
   return n+1;
}

function demo(f, p) {
   return f(p);
}

alert(demo(add1, 1));

Alerts 2 to the screen.

demo() is a function that takes in a function as an argument and a value. it calls add1() function with an argument "1"

31
New cards

Syntax for arrow functions?

const sum = (x, y) => x + y;

<p>const sum = (x, y) =&gt; x + y;</p>
32
New cards

JSON syntax?

var person = {"name": 'Chuck', // String

"age": 29, // Integer

"college" : true, // Boolean

"offices" : [ '3350DMC', '3437NQ' ], // Array

"skills" : { // Object

"fortran": 10,

"C": 10,

"C++": 5,

"python" : 7

}

};

“name” : “value”,

Remember that array definition uses square brackets

33
New cards

What are these browser objects (Browser Object Model (BOM)) and what do they stand for?

window

history

location

navigator

screen

document

- window: top level object in the BOM hierarchy

- history: keep track of pages the user visits

- location: contains the URL of the page

- navigator: contains information about the browser (e.g. name and version)

- screen: provides information about display characteristics

- document: belongs to both BOM and DOM

34
New cards

Explain these Window Object Properties:

closed

document

history

length

location

name

opener

outerheight

pageXOffset

parent

self

top

- closed: Returns whether or not a window has been closed

- document: See Document object in DOM

- history: visited URLs

- length: Sets or returns the number of frames in the window

- location: URLs

- name: Sets or returns the name of the window

- opener: Returns a reference to the window that created the window

- outerheight: Sets or returns the outer height of a window

- pageXOffset: Sets or returns the X position of the current page in relation to the upper left corner of a window's display area

- parent: Returns the parent window

- self: Returns a reference to the current window

- top: Returns the topmost ancestor window

<p>- closed: Returns whether or not a window has been closed</p><p>- document: See Document object in DOM</p><p>- history: visited URLs</p><p>- length: Sets or returns the number of frames in the window</p><p>- location: URLs</p><p>- name: Sets or returns the name of the window</p><p>- opener: Returns a reference to the window that created the window</p><p>- outerheight: Sets or returns the outer height of a window</p><p>- pageXOffset: Sets or returns the X position of the current page in relation to the upper left corner of a window's display area</p><p>- parent: Returns the parent window</p><p>- self: Returns a reference to the current window</p><p>- top: Returns the topmost ancestor window</p>
35
New cards

Explain these Window Object Methods:

alert()

blur()

close()

confirm()

createPopup()

focus()

moveBy()

moveTo()

open()

print()

prompt()

setTimeout()

- alert() Displays an alert box with a message and an OK button

- blur() Removes focus from the current window

- close() Closes the current window

- confirm() Displays a dialog box with a message and an OK and a Cancel button

- createPopup() Creates a pop-up window

- focus() Sets focus to the current window

- moveBy() Moves a window relative to its current position

- moveTo() Moves a window to the specified position

- open() Opens a new browser window

- print() Prints the contents of the current window

- prompt() Displays a dialog box that prompts the user for input

- setTimeout() Evaluates an expression after a specified number of milliseconds

<p>- alert() Displays an alert box with a message and an OK button</p><p>- blur() Removes focus from the current window</p><p>- close() Closes the current window</p><p>- confirm() Displays a dialog box with a message and an OK and a Cancel button</p><p>- createPopup() Creates a pop-up window</p><p>- focus() Sets focus to the current window</p><p>- moveBy() Moves a window relative to its current position</p><p>- moveTo() Moves a window to the specified position</p><p>- open() Opens a new browser window</p><p>- print() Prints the contents of the current window</p><p>- prompt() Displays a dialog box that prompts the user for input</p><p>- setTimeout() Evaluates an expression after a specified number of milliseconds</p><p></p>
36
New cards

What are the 5 ways to define an object in JS?

- "constructor" function:

var Car = function() {
	this.wheels = 4; // specifies a property "wheels"
	this.start = function() {
	alert("Vroom!");
   }; // defines a method called "start"
};

var myVW = new Car(); // declares a new Car object
myVW.start();
alert(myVW.wheels);

- "Object" constructor:

// Creates a single object, no class
var member = new Object();
// Add properties
member.name = "Donald Duck";
member.email = "dd@gmail.com";
member.isRegistered = true;
// Define methods as named functions
function showMe() {
alert("I'm here!");
}
member.present = showMe;
// Define methods as anonymous functions
member.present = function() { alert("I'm here!"); }

- Object prototype

// Create the prototype function
function Member(name, emaddr, reg) {
	this.name = name;
	this.email = emaddr;
	this.isRegistered = reg;
}

// Define methods via prototype
Member.prototype.present = function () {
alert("I'm here! ");
};
// Define properties with default values
Member.prototype.isActive = true;
m5 = new Member();
m5.isActive = false;

- object literal / JSON (preferred):

var member = {
name: "Donald Duck",
email: "dd@gmail.com",
isRegistered: true,
present: function () { alert("I'm here!"); }
};

- Class keyword (preferred):

class Member {
	constructor(name, emaddr, reg) {
		this.name = name;
		this.email = emaddr;
		this.isRegistered = reg;
	}
	present() {
		alert("I'm here!");
	}
}
var member = new Member("Donald Duck", "dd@gmail.com", true);

37
New cards

Structure of a Document Object Model?

Element → Attribute / Text

<p>Element → Attribute / Text</p>
38
New cards

Map the Element type to node type (number) in DOM.

  • Element

  • Attribute

  • Text

  • Comment

  • Document

knowt flashcard image
39
New cards

What are the 2 JS event models? Explain them.

Event capturing (default)

  • An event fires from the least-specific target to the most-specific target.

  • E.g. mouseover fires parent element (div) firs

Event Bubbling

  • An event fires from the most-specific target to the lease-specific target.

  • mouseover fires inner element (p) first

The screenshot shows the W3C DOM event registration style.

<p>Event capturing (default)</p><ul><li><p>An event fires from the least-specific target to the most-specific target.</p></li><li><p>E.g. mouseover fires parent element (div) firs</p></li></ul><p></p><p>Event Bubbling</p><ul><li><p>An event fires from the most-specific target to the lease-specific target.</p></li><li><p>mouseover fires inner element (p) first</p></li></ul><p></p><p>The screenshot shows the W3C DOM event registration style.</p>
40
New cards

XML syntax?

remember XML declaration:
<?xml version="1.0" encoding="UTF-8"?>

tags are case sensitive

<p>remember XML declaration:<br><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code></p><p>tags are case sensitive</p>
41
New cards

What is PCDATA?

parsed-character data. PCDATA is any “well-formed” text string, most text strings are “well-formed” except those that contain symbols reserved for XML, such as <, >, &

42
New cards

What are some common entity references in XML? what is the syntax?

Start with “&”, End with “;”

<p>Start with “&amp;”, End with “;”</p>
43
New cards

what are CDATA sections? can CDATA sections be empty?

Character Data (CDATA) sections indicate entire regions that should not be parsed. E.g. when we want to include some HTML as string and not XML markup.

CDATA sections cannot be empty

<p>Character Data (CDATA) sections indicate entire regions that should not be parsed. E.g. when we want to include some HTML as string and not XML markup. </p><p></p><p>CDATA sections cannot be empty</p>
44
New cards

Structure of XML document?

An optional prolog:

  • XML declaration

  • Miscellaneous statements or comments

  • Document type declaration

A body / root element

An optional epilog – seldom used

45
New cards

Some notable well-formedness rules in XML?

  • One root element must contain all other elements

  • Attribute values must be in double or single quotes

    • E.g <book settext="no">

  • Element names may only begin with letters, underscores, or “:” and the remaining characters may only be alphanumeric, “_”, “-”, “:”, or “.”

  • Markup characters (e.g. <, >, &) do not appear directly in parsed content

    • <eqn>1 &lt; 3</eqn> for showing “1 < 3”

46
New cards

What is XML DTD? What’s the syntax?

  • Document Type Definition (DTD) is a formalisation of what the data should look like.

  • Used to validate XML documents

    • What type of data can be contained in an element

    • What elements must be included

    • Order of elements

  • Kinda similar to regex

<ul><li><p>Document Type Definition (DTD) is a formalisation of what the data should look like.</p></li><li><p>Used to validate XML documents </p><ul><li><p>What type of data can be contained in an element </p></li><li><p>What elements must be included </p></li><li><p>Order of elements </p></li></ul></li><li><p>Kinda similar to regex</p></li></ul><p></p>
47
New cards

How do you create XML and JSON responses in PHP?

  • XML:

    • Create a structured XML Document:

      • new DomDocument()

    • Append children as required

      • createElement()

      • appendChild()

    • Generate the text: saveXML()

  • JSON

    • Create the data

    • json_encode()

      • use JSON_PRETTY_PRINT will indent it nicely

<ul><li><p>XML: </p><ul><li><p>Create a structured XML Document: </p><ul><li><p><code>new DomDocument()</code></p></li></ul></li><li><p>Append children as required</p><ul><li><p><code>createElement()</code></p></li><li><p><code>appendChild()</code></p></li></ul></li><li><p>Generate the text: <code>saveXML()</code></p></li></ul></li><li><p>JSON</p><ul><li><p>Create the data</p></li><li><p><code>json_encode()</code></p><ul><li><p>use <code>JSON_PRETTY_PRINT</code> will indent it nicely</p></li></ul></li></ul></li></ul><p></p>
48
New cards

What are the different XHR readyStates? (5 of them)

knowt flashcard image
49
New cards

What are some Angular Key Features?

  • Written in TypeScript

  • Two-way data binding (NgModel)

    • The value of an HTML Form input element is “bound” to the property of an object

  • MVC architecture (“separation of concerns”)

    • Model, View, Controller

<ul><li><p>Written in TypeScript</p></li><li><p>Two-way data binding (NgModel)</p><ul><li><p>The value of an HTML Form input element is “bound” to the property of an object</p></li></ul></li><li><p>MVC architecture (“separation of concerns”)</p><ul><li><p>Model, View, Controller</p></li></ul></li></ul><p></p>
50
New cards

What are some common Angular directives? Syntax for using them?

  • NgModel for form control

    • <input [(ngModel)]="hero.name" placeholder="name">

  • NgIf for conditional logic

    • <div *ngIf="hero"> (displays if “hero” is defined)

  • NgFor for iteration

    • <li *ngFor="let hero of heroes">

  • NgClass for CSS classes

51
New cards

How do you launch an Angular application?

ng serve --open

52
New cards

What are some Angular components?

  • app.component.ts

    • The component class code, written in TypeScript

  • app.component.html

    • The component template, written in HTML

  • app.component.css

    • The component's private CSS styles

  • app.component.spec.ts

    • Unit tests for the component, written in TypeScript

53
New cards

What is interpolation in Angular? What is the syntax?

When you bind Class Variables to HTML Content. Change in one place apply to the other. Syntax is double curly braces:

export class AppComponent {
	title = 'my-angular-app';
}

Bind in HTML:

<h1>Hello, {{ title }}</h1>

54
New cards

What does the Input package do in Angular? Whats the syntax?

allows us to get properties as inputs:

export class HeroDetailComponent {
	@Input() hero?: Hero;

}

55
New cards

What is server side rendering? What is hydration?

  • SSR: A process that involves rendering pages on the server, resulting in initial HTML content which contains initial page state.

  • Hydration: The process that restores the SSR application on the client

56
New cards

What does REST and SOAP stand for? how do they work

  • REST: Representational State Transfer

    • Uses HTTP methods to communicate intent

    • Send the endpoint + parameters

    • Receive JSON data

  • SOAP: Simple Object Access Protocol

    • A SOAP XML document is used for request/response

    • The <SOAP:Envelope> element specifies several namespaces for the XML Schema, instance and SOAP

      • contains a <SOAP:Header> element (optional) and a <SOAP:Body> element

    • All the details about the request (method, parameters, content) are contained within <SOAP:Body>

57
New cards

Common characteristics of web services?

Accessible over the Web

Communicate using platform-independent and language-neutral protocols

Provide an interface that can be called from another program

Registered and located through a Web Service Registry

Support loosely coupled connections between systems

Promote componentization of common functions

Ease the web programming effort

58
New cards

Difference between SOAP vs RESTful Web Services?

knowt flashcard image
59
New cards

Map HTTP methods with CRUD operations

  • POST – Create

  • GET – Retrieve

  • PUT – Update

    • PATCH – partial update

  • DELETE – delete

<ul><li><p>POST – Create</p></li><li><p>GET – Retrieve</p></li><li><p>PUT – Update</p><ul><li><p>PATCH – partial update</p></li></ul></li><li><p>DELETE – delete</p></li></ul><p></p>
60
New cards

What is the 4 step process of a web service?

knowt flashcard image
61
New cards

What is the same origin policy in web services?

API must be called from the same origin.

Two pages have the same origin if the protocol (https), port (default 80), and host (domain) are the same 

<p>API must be called from the same origin.</p><p><span>Two pages have the same origin if the protocol (https), port (default 80), and host (domain) are the same&nbsp;</span></p>
62
New cards

What is a solution to the same origin policy?

Create an “appliation proxy”, a proxy page on the server since the same origin policy only applies to client side, not the server side.

Call the page on the server → relay the call to the external web server

However, application servers can still be subject to firewalls

<p>Create an “appliation proxy”, a proxy page on the server since the same origin policy only applies to client side, not the server side. </p><p>Call the page on the server → relay the call to the external web server</p><p>However, application servers can still be subject to firewalls</p>
63
New cards

What is Curl?

  • Curl is a multi-protocol file transfer library

  • Library that allows you to connect and communicate to many different types of servers with many different types of protocols

64
New cards

What is Routing in RESTful API design?

  • Routing refers to how an application’s endpoints (URIs) respond to client requests

  • A route associate an URI/URL with one or more functions defined in the backend

  • Mapping the URL and method to a function