CS511 – Fundamentals of Web Development: Midterm Important Subjective (62 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS511 Course Page · CS511 MCQ Pack (135 MCQs)
-
Differentiate between the Internet and the World Wide Web.
Topic: Web & Internet Fundamentals • 3 marks marks
The Internet is the hardware part: it is a collection of computer networks connected through copper wires, fiber-optic cables or wireless connections. The World Wide Web (WWW), on the other hand, is the software part: it is a collection of web pages connected through hyperlinks and URLs. In short, the World Wide Web is only one of the services provided by the Internet; other services over the Internet include e-mail, chat and file transfer services.
-
What role did TCP/IP play in the growth of the Internet? What is a protocol?
Topic: Web & Internet Fundamentals • 3 marks marks
A protocol is the name given to a formal set of publicly available rules that manage data exchange between two points. In the early days there were many separate, disparate networks (such as ARPANET in 1969, X.25 in 1974 and USENET in 1979). To promote the growth and unification of these disparate networks, a suite of protocols - TCP/IP (Transmission Control Protocol/Internet Protocol) - was invented to unify them. Communication protocols allow any two computers to talk to one another so long as they implement the protocol. By 1981 the protocols for the Internet were published and ready for use, and new networks began to adopt the TCP/IP communication model.
-
What is a static website? Explain how a static website serves a page to a user.
Topic: Web & Internet Fundamentals • 3 marks marks
A static website consists only of HTML pages that look identical for all users at all times. A publisher publishes the web pages and periodically updates them; users can read the pages but cannot provide feedback. When a user requests a page (for example vacation.html), the server retrieves the files (the HTML file and images such as picture.jpg) from its hard drive, sends the HTML and then the image to the browser, and the browser displays the files.
-
Differentiate between a static website and a dynamic (server-side) website.
Topic: Web & Internet Fundamentals • 3 marks marks
A static website consists of ready-made HTML files that are identical for all users at all times; the server simply retrieves the stored files from its hard drive and sends them to the browser. In a dynamic server-side website, programs running on the web server generate the content dynamically at run time. These server-based programs read content from databases, interface with existing enterprise computer systems and communicate with financial institutions, and then output HTML that is sent back to the user's browser. Because the page content is created at run time by a program, it can vary from user to user.
-
Differentiate between Web 1.0, Web 2.0 and Web 3.0.
Topic: Web & Internet Fundamentals • 5 marks marks
Web 1.0: In the earliest days of the web, a webmaster (the person responsible for creating and supporting a website) would publish web pages and periodically update them. Users could read the pages but could not provide feedback. Content was generated by publishers/companies, and Web 1.0 included both static and dynamic websites. Web 2.0: Web 2.0 is mainly characterized by user-generated content (UGC) and dynamic websites. For users it means an interactive experience where users could contribute and consume web content, creating a more user-driven web experience (popular examples: Facebook, YouTube and Wikipedia). For developers it meant that programming logic, which previously existed only on the server, began to migrate to the browser, which required learning JavaScript and difficult techniques of asynchronous communication. Web 3.0: There is no standard consensus over Web 3.0, but it is argued that Web 3.0 will be the semantic web, mainly characterized by machine-understandable content. The semantic web adds context and meaning to web pages in the form of special markup, so that search engines and other data-mining agents can make sense of the content, dramatically improving the nature of search on the web.
-
Explain the client-server model of the web.
Topic: Client-Server Model, Servers & the Web Industry • 3 marks marks
The web is sometimes referred to as a client-server model of communications. In this model there are two types of actors: clients and servers. The server is a computer agent that is normally active 24/7, listening for requests from clients. A client is a computer agent that makes requests and receives responses from the server. The client sends a request to the server and the server returns a response; this is called the request-response loop.
-
Name the different types of servers used by a website and explain the working of each type.
Topic: Client-Server Model, Servers & the Web Industry • 5 marks marks
Most real-world websites are not served from a single server machine; the functionality of a website is split between several types of servers: 1. Web servers: A web server is a computer servicing HTTP requests, typically running web server software such as Apache or Microsoft IIS (Internet Information Services). 2. Application servers: A computer that hosts and executes web applications, which may be created in PHP, ASP.NET, Ruby on Rails, or some other web development technology. 3. Database servers: A computer devoted to running a Database Management System (DBMS), such as MySQL, Oracle, or MongoDB, that is being used by web applications. 4. Mail servers: A computer creating and satisfying mail requests, typically using the Simple Mail Transfer Protocol (SMTP). 5. Media servers: Also called streaming servers, these are dedicated to servicing requests for images and videos and may run special software that allows video content to be streamed to clients. 6. Authentication servers: These handle the most common security needs of web applications, and may interact with local networking resources such as LDAP (Lightweight Directory Access Protocol) or Active Directory. In smaller sites, these specialty servers are often the same machine as the web server.
-
What is a data center? What facilities does a typical data center contain?
Topic: Client-Server Model, Servers & the Web Industry • 3 marks marks
Server farms (clusters of machines used to distribute incoming requests, through load balancers, so that no single web or data server is overloaded) are typically housed in special facilities called data centers. A data center contains more than just computers and hard drives: sophisticated air conditioning systems, redundancy power systems using batteries and generators, specialized fire suppression systems, and security personnel are all part of a typical data center.
-
Describe the working of a router. What is a routing table and what is next-hop routing?
Topic: Client-Server Model, Servers & the Web Industry • 5 marks marks
The flow of Internet traffic or information is carried out mainly by routers. A router is a hardware device that forwards data packets from one network to another network. When the router receives a data packet, it examines the packet's destination address and then forwards it to another destination. A router uses a routing table to help determine where a packet should be sent; a routing table is a table of connections between target addresses and the destination (typically another router) to which the router can deliver the packet. In next-hop routing, the router only knows the address of the next step of the path to the destination; it leaves it to that next step to continue the routing process. The packet thus makes a variety of successive hops until it reaches its destination.
-
Briefly describe how the Internet connection reaches from a home to the ISP.
Topic: Client-Server Model, Servers & the Web Industry • 3 marks marks
The broadband modem, also called a cable modem or DSL (digital subscriber line) modem, is a bridge between the network hardware outside the house (typically controlled by a phone or cable company) and the network hardware inside the house; the wireless router is the most visible manifestation of the Internet in one's home. The various neighborhood broadband cables are aggregated and connected to fiber optic cable via fiber connection boxes. These fiber optic cables eventually make their way to an ISP's head-end, a facility that may contain a cable modem termination system (CMTS) in a cable system or a digital subscriber line access multiplexer (DSLAM) in a DSL-based system. This is a special type of very large router that connects and aggregates subscriber connections to the larger Internet. Different head-ends may connect directly to the wider Internet, or be connected to a master head-end, which provides the connection to the rest of the Internet.
-
Name the different job roles in a web development team and briefly describe the work of any four of them.
Topic: Client-Server Model, Servers & the Web Industry • 5 marks marks
Roles typically available in a web development company include: Hardware Architect/Network Architect/Systems Engineer, System Administrator, Database Administrator/Data Architect, Security Specialist, Developer/Programmer, Front-End Developer/UX Developer, Software Engineer, UX Designer/UI Designer/Information Architect, Tester/Quality Assurance, SEO Specialist, Content Strategist/Marketing Technologist, Project Manager/Product Manager, Business Analyst, and Full-stack Developer. Four of these roles are: 1. System Administrator: Once the system is built and wired to the network, system administrators get things up and running; they choose and install the network operating system and manage the shared operating system environments for other users. 2. Database Administrator (DBA): In larger companies there are many databases that need to be managed, secured and backed up. DBAs perform maintenance on the databases, manage access for user and software accounts, sometimes write triggers and advanced queries, and manage database indexes. 3. Security Specialist: Because security knowledge is complicated and ever changing, companies often outsource their security needs to specialists. They test for vulnerabilities, implement security best practices, and make updates and changes to programming code or hardware infrastructure to protect a site against well-known or newly emerging (zero-hour) threats. 4. Tester/Quality Assurance (QA): Testers are the people who try to identify flaws in software before it gets released. Many testers know how to program and might write automated tests as well as develop testing plans from requirements.
-
What is a full-stack developer?
Topic: Client-Server Model, Servers & the Web Industry • 2 marks marks
Rather than specializing in server-side development, or client-side user experience construction, or database administration, a full-stack developer ideally has competency and experience in all of these domains. Indeed, many companies even expect full-stack developers to be knowledgeable about various system administration tasks, such as setting up a web server and handling security issues.
-
Name the different types of web development companies and describe the working of any two of them.
Topic: Client-Server Model, Servers & the Web Industry • 5 marks marks
The main types of web development companies are: hosting companies, design companies, website solution companies, vertically integrated companies, start-up companies, and internal web development (an internal division of a company). 1. Hosting companies: These companies manage servers on your behalf. Hosting companies or data centers offer many employment opportunities, especially related to hardware, networking, and system administration roles. 2. Vertically integrated companies: These are increasingly becoming the one-stop shop for web development. They are called vertically integrated because they combine hosting, design, and application solutions into one company. This allows them to achieve economies of scale and appeal to nontechnical clients who can go there for all their web-related needs, large or small. (For comparison: design companies provide professional artistic and design services such as logos and branding, and may produce mockups in Photoshop which a web developer at another company turns into a website; website solution companies focus on the programming and deployment of websites for their clients.)
-
Name the four layers of the TCP/IP layered architecture and state the function of each layer.
Topic: Internet Protocols, DNS, URLs & HTTP • 5 marks marks
The TCP/IP Internet protocols were originally abstracted as a four-layer stack: 1. Link Layer: The lowest layer, responsible for both the physical transmission of data across media (both wired and wireless, in the form of raw bits, light waves etc.) and establishing logical links. It handles packet creation, transmission, reception, error detection, collisions and line sharing. MAC (media access control) addresses - unique 48- or 64-bit identifiers assigned to network hardware - are used at this layer. 2. Internet Layer: Also called the IP layer, it routes packets between communication partners across networks. It provides 'best effort' communication: it sends out a message to its destination, but expects no reply and provides no guarantee the message will arrive intact, or at all. It uses IP addresses, numeric codes that uniquely identify destinations on the Internet. 3. Transport Layer: It ensures transmissions arrive in order and without error. Data is broken into packets formatted according to TCP; each packet has a header with a sequence number so the receiver can put the message back in order, and each packet is acknowledged (ACK) back to the sender so a lost packet is retransmitted. 4. Application Layer: Application layer protocols implement process-to-process communication at a higher level of abstraction. Examples useful to web developers include HTTP (web communication), SSH (remote command-line connections), FTP (file transfer), POP/IMAP/SMTP (email) and DNS (resolving domain names to IP addresses).
-
Differentiate between TCP and UDP. When is UDP preferred over TCP?
Topic: Internet Protocols, DNS, URLs & HTTP • 3 marks marks
TCP (Transmission Control Protocol) is used at the transport layer when guaranteed delivery is required: the data is broken into packets, each packet carries a sequence number so the receiver can reorder the message, and each packet acknowledges its successful arrival back to the sender, so a lost packet (for which no ACK arrives) is retransmitted. This gives a guarantee that messages sent will arrive and will be in order. UDP (User Datagram Protocol) is used instead of TCP when we do not want guaranteed transmission of packets - for example a live multicast of a soccer game, where millions of subscribers are streaming and the broadcaster cannot afford to track and retransmit every lost packet; a small loss of data in the feed is acceptable. Other examples of UDP services include Voice over IP, many online games, and the Domain Name System (DNS).
-
What is the Domain Name System (DNS)? Why is it needed?
Topic: Internet Protocols, DNS, URLs & HTTP • 3 marks marks
DNS is one of the core systems that make an easy-to-use Internet possible (DNS is used for email as well). It is needed because users reference websites by names, while a browser eventually needs the numeric IP address of the website in order to request any resources from it. Without DNS, instead of typing google.com you would have to type its IP address, 216.58.216.78. DNS provides a mechanism for software to discover this numeric IP address: when you request a domain name, a computer called a domain name server returns the IP address for that domain, and with that IP address the browser can request a resource from the web server for that domain.
-
What are the types of top-level domains (TLDs)? Give examples of each type.
Topic: Internet Protocols, DNS, URLs & HTTP • 3 marks marks
The rightmost portion of a domain name is called the top-level domain. There are two broad categories, plus a third reserved for other use: 1. Generic top-level domains (gTLD): These include unrestricted TLDs such as .com, .net, .org and .info, and sponsored TLDs such as .gov, .mil and .edu, which can have requirements for ownership, so new second-level domains must have permission from the sponsor. From 2012, applications for new TLDs were also accepted, such as .apple, .google, .buy and .news. 2. Country code top-level domains (ccTLD): These are two-letter codes for countries, such as .us, .ca, .uk and .au; at the time of writing there were 252 codes registered, and they are under the control of the countries they represent.
-
Describe the process of address resolution in DNS.
Topic: Internet Protocols, DNS, URLs & HTTP • 5 marks marks
Address resolution is the process by which a browser discovers the IP address of a requested domain, and it works as follows: 1. The process starts at the user's computer. When a URL such as www.funwebdev.com is requested, the browser first checks whether it already has the IP address for the domain in its cache. 2. If not, the browser delegates the task to the DNS resolver, a software agent that is part of the operating system, which also keeps a cache of frequently requested domains. 3. Otherwise, the resolver asks a nearby (local) DNS server - for example a computer at your ISP or university - which keeps a more substantial cache of domain name/IP address pairs. 4. If the local DNS server does not have the address in its cache, it asks other DNS servers; the DNS has a great deal of redundancy built into it at both the local and the global level. 5. If the answer still cannot be found, the local DNS server must get it from the appropriate top-level domain (TLD) name server (for funwebdev.com this is .com). 6. If the local DNS server does not know the address of the TLD server, it asks a root name server. The DNS root name servers store the addresses of TLD name servers; IANA authorizes 13 root servers, which are mirrored and distributed around the world (over 500 root server machines). 7. The local DNS server then asks the TLD name server, which returns the address of the requested domain's own DNS server (second-level name server), because as part of domain registration the address of the domain's DNS servers is sent to the TLD name servers. 8. The local DNS server asks that name server and receives the correct IP address of the web server, stores it in its cache for future requests, and returns it to the resolver and finally to the browser, which can now send its request to the web server. If the IP address cannot be found, a failed response causes the browser to display an error message.
-
What are the components of a URL? Explain each component briefly.
Topic: Internet Protocols, DNS, URLs & HTTP • 3 marks marks
A URL (Uniform Resource Locator) has the following components: 1. Protocol: This part describes the protocol through which a web page is accessed. Most unsecured websites are accessed through the HTTP protocol, secured websites through HTTPS, and browsers also support other protocols such as FTP for accessing files. 2. Domain: The address of the website, consisting of top-level domain, country code top-level domain, second-level domain, third-level domain etc. (for example www.funwebdev.com). The Domain Name Server finds the IP address against this name. 3. Port: An optional part of the URL, usually not visible. HTTP servers usually listen at port 80. A colon is added after the domain name and then the integer port number is specified. 4. Path: The path of the file we want to access (for example index.php). When the path is not mentioned, default files like index.html or index.php are returned. 5. Query String: Information passed to the file, mostly used in dynamic websites. It is sent to the server in the form of key-value pairs; it starts from the delimiter '?' and multiple keys are separated using '&' (for example page=17). 6. Fragment: Used to request a specific portion of a web page. It is represented using the '#' symbol, and the browser automatically scrolls the website to it.
-
What information is contained in HTTP request and response headers?
Topic: Internet Protocols, DNS, URLs & HTTP • 3 marks marks
When a client requests to access a web page, a piece of information called the request header is sent to the server. It has different components like the method (GET, POST), the path the client wants to visit, and the file the client wants to access on the server. These headers are automatically generated by the browser and can also contain additional information such as the version of the protocol, the host, and the IP address. (The host matters because if multiple websites are hosted on a single web server, their IP address will remain the same.) Another important part of HTTP is the user agent, which contains information about the client's operating system and browser; a server can generate dynamic content on the basis of this information. When a web server receives a request, it sends back a response header and content against it. The response header can contain the response code, date and time, information about the server, and content length etc.
-
Write the meaning of the HTTP response codes 200, 301, 400, 404 and 500. What do the 200, 300, 400 and 500 series of codes represent?
Topic: Internet Protocols, DNS, URLs & HTTP • 2 marks marks
Different response codes are used to determine how a server handled a client's request. The 200 codes are for successful responses, the 300 codes are for redirection-related responses, the 400 codes are client errors, and the 500 codes are server errors. Examples: 200 means OK; 301 means Moved Permanently; 400 means Bad Request; 404 means Not Found; and 500 means Internal Server Error.
-
How does a web browser work when you request a web page? What is browser caching?
Topic: Internet Protocols, DNS, URLs & HTTP • 5 marks marks
When we request a web page, many processes run at the backend. We get its HTML contents first, which are in textual form. If that web page contains any images, videos, style sheets or scripts, all of these external files are fetched one by one: the browser requests and receives these files from the server, and one request may contain further multiple requests to get the web page content. When the browser gets all these contents, it renders and displays our page by using them. Different browsers use different rendering procedures according to the standards devised by the World Wide Web Consortium (W3C), so a web developer should test a website using different browsers. Browser caching: When we visit a website and fetch some images and files from it, they are stored in the browser cache. Next time, when we need that file from the same server, the file will be retrieved from the browser cache instead of the server, resulting in fast browsing. Caching can also be disabled to avoid caching, like done in banking websites.
-
What is an application stack? Explain the LAMP stack.
Topic: Web Servers, Application Stacks & Architecture • 3 marks marks
A web server follows a certain application stack. This application stack consists of an operating system, web server software, a database, and a scripting language for dynamic requests. The most commonly used application stack is LAMP, which contains the Linux operating system, Apache web server, MySQL database, and PHP scripting language; it is traditionally used for dynamic websites. There are other stacks as well, for example WAMP, WISA, and MEAN. Popular web server software includes Apache, Nginx and IIS; commonly used databases include relational databases like MySQL, PostgreSQL and SQLite, and document-based databases like MongoDB; and PHP is worldwide used as a scripting language, with ASP.NET, Python and Node.js also being used.
-
Explain the 3-tier architecture of a web-based system. What is the advantage of separating the presentation and business logic layers?
Topic: Web Servers, Application Stacks & Architecture • 3 marks marks
In the 3-tier architecture, the first tier is responsible for content display (the Presentation Layer), the second tier is the business logic for generating dynamic content, and the third tier is the database layer, which stores data and manages the database. (By comparison, in a 2-tier architecture there are only a client-side tier and a server-side tier; dividing the system into more tiers also eases the maintenance of a website.) The advantage of separating the presentation and business logic layers is that when we change the business logic for some users, we do not need to change the presentation layer necessarily.
-
What is the DOCTYPE declaration in HTML? Write its syntax.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 2 marks marks
The DOCTYPE tag is used to inform the web server and the browser that the document is an HTML document. It is written at the start of the document. Its syntax is: <!DOCTYPE html>.
-
Explain the head and body tags of an HTML document. What is placed inside each of them?
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 5 marks marks
An HTML document is divided into a head part and a body part. External files, the document title, and metadata about the document are mentioned in the 'head' tag. The head can contain, for example, the meta tag (which contains information about the coding details of the HTML contents), the link tag (used to link external style sheets to the HTML document) and the script tag (used to specify a script from an external file). The contents of the document - everything that is displayed on the page - are mentioned in the 'body' tag. Earlier, the parent 'html' tag was necessary, but this compulsion has been removed in HTML5; however, most developers still use this tag.
-
Differentiate between block-level elements and inline elements in HTML, with examples.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
Block-level elements disrupt the existing flow and take their own space: each block-level element is contained on its own line and begins with a line break, so without styling two block-level elements cannot exist on the same line. Block-level elements use the normal CSS box model, in that they have margins, paddings, background colors and borders. Examples are <p>, <div>, <h2>, <ul>, <hr>, <li> and <table>. Inline elements do not create their own space separately and do not disrupt the flow; they are displayed within lines. Normal text in an HTML document is inline, as are elements such as <a>, <br>, <em>, <img> and <span>.
-
What are the types of lists in HTML? Explain each type briefly.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
HTML provides three types of lists: 1. Unordered lists: Collections of items in no particular order. They are by default rendered by the browser as a bulleted list (although it is common in CSS to style them without bullets). Unordered lists have become the conventional way to mark up navigational menus. They use <li> items inside a <ul> container. 2. Ordered lists: Collections of items that have a set order. They are by default rendered by the browser as a numbered list, using <li> items inside an <ol> container. 3. Description lists: Collections of name and description/definition pairs, used for example in an FAQ list. The container is the <dl> element, which contains <dt> (the term or name to be described) and <dd> (which describes each term) pairs. A list within a list is called a nested list.
-
What is semantic HTML structuring? Write the advantages of using semantic markup.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 5 marks marks
HTML semantic structuring adds meaning to a web page rather than merely making it look pretty. A <p> tag, for example, denotes that the contained text is a paragraph, which is both semantic and presentational, whereas tags like <b> and <i> have no semantic value - they merely specify how the text should be formatted (bold or italic). Examples of semantic HTML tags include the header tags <h1> through <h6>, <blockquote>, <code> and <em>, and HTML5 elements such as <header>, <footer>, <nav>, <main>, <article> and <section>. Its advantages are: 1. Maintainability: Web pages with a lot of presentation markup are more difficult to edit and change than those with semantic markup, and maintaining and altering old code takes more time than writing new code. 2. Performance: Semantic web pages are typically quicker to author and faster to download. 3. Accessibility: If a website does not employ semantic markup, visiting it with speech (voice reading) software can be an extremely irritating experience for users with vision problems; many governments also require accessibility criteria such as the US Section 508 Accessibility Guidelines. 4. Search Engine Optimization: Search engine crawlers are, for many website owners, the most significant users of a website, and semantic markup gives these crawlers better instructions - it tells them what material on the site is most important.
-
What is relative referencing in HTML? Explain its types with examples.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
Whether we are constructing links with the <a> element, referencing images with the <img> element, or including external JavaScript or CSS files, we need to be able to successfully reference files within our site; this requires the syntax for so-called relative referencing. Its types are: 1. Same directory: <a href="example.html"> - the file is in the same folder. 2. Child directory: <a href="images/logo.gif"> - the file is in a sub-folder. 3. Grandchild/Descendant directory: <a href="css/images/background.gif">. 4. Parent/Ancestor directory: <a href="../about.html"> or <a href="../../about.html"> - move one or more levels up. 5. Sibling directory: <a href="../images/about.html"> - go up to the parent and then into another folder. 6. Root reference: <a href="/images/background.gif"> - referenced from the site root.
-
Explain the basic structure of an HTML table. What are the colspan and rowspan attributes used for?
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
A table in HTML is created using the <table> element and is used to represent information that exists in a two-dimensional grid, such as calendars, financial data and pricing tables. An HTML <table> contains any number of rows (<tr>), and each row contains any number of table data cells (<td>). Many tables contain headings in the first row; in HTML, header data is indicated by using the <th> element instead of <td>. The <caption> element can be used to define the table's title/header and must be the first child of the <table> element. If you want a given cell to cover several columns or rows, you can do so by using the colspan or rowspan attributes: colspan spans a cell across multiple columns, and rowspan spans it across multiple rows. For accessible tables, tables should be used for data, not layout.
-
How do HTML forms work? What is a query string?
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
Forms provide the user with an alternative way to interact with a web server; before forms, clicking hyperlinks was the only mechanism available to the user for communicating with the server. The process begins with a request for an HTML page that contains some type of form on it - something as complex as a user registration form or as simple as a search box. After the user fills out the form, the form data is submitted back to the server, typically via a submit button (although through JavaScript it is possible to submit form data using some other mechanism). The browser packages the user's data input into something called a query string. A query string is a series of name=value pairs separated by ampersands (the & character).
-
Differentiate between the GET and POST methods of form submission.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
The method attribute of a form specifies how the query string data will be transmitted from the browser to the server. The difference between GET and POST resides in where the browser locates the user's form input in the subsequent HTTP request: with GET, the browser locates the data in the URL of the request; with POST, the form data is located in the HTTP header after the HTTP variables. GET: The data can be clearly seen in the address bar, which may be an advantage during development but a disadvantage in production. The data remains in browser history and cache, and can be bookmarked (each of these can be an advantage or a disadvantage - for example a security risk on public computers). There is a limit on the number of characters in the form data returned. POST: The data can contain binary data; the data is hidden from the user; and submitted data is not stored in cache, history, or bookmarks.
-
Name the five categories of web development tools and explain any two of them.
Topic: Web Development Tools • 5 marks marks
Web development tools are divided into five categories: (1) WYSIWYG editors, (2) Code editors, (3) Full IDEs, (4) Cloud-based environments, and (5) Code playgrounds. 1. WYSIWYG editors: These tools provide a user experience similar to that of a word processor (What-You-See-Is-What-You-Get). Their benefit is that you don't require much (if any) HTML knowledge. However, they are never fully WYSIWYG and frequently have trouble previewing increasingly complex CSS, so they almost always have to give users a typical HTML view as well. Adobe Dreamweaver and Adobe Muse are two prominent editors of this genre. 2. Full IDEs: Integrated Development Environments provide a fuller featured programming experience. They not only provide most of the functionality of code editors, but also typically provide extra capabilities such as comprehensive help files, build tools, multiple-language support, and integration with other enterprise tools such as databases. Examples include Eclipse, NetBeans and Visual Studio. This extra power comes at a price: these complicated IDEs typically have a more substantial learning curve and can often have steep hardware requirements. (The other categories: code editors such as Atom, Notepad++, Sublime Text and Visual Studio Code focus on viewing and editing text files with color coding, hints and tag completion; cloud-based environments such as CodeAnywhere and Cloud9 let you develop, test and host online without installing tools, but require an Internet connection; code playgrounds such as CodePen, JSFiddle and CSS Deck are used to experiment with, demonstrate and share smaller snippets of code.)
-
What is CSS? Write any four benefits of using CSS.
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
In current web development best practices, HTML should not describe the formatting or presentation of documents; that presentation task is best performed using Cascading Style Sheets (CSS). CSS is a W3C standard for describing the appearance of HTML elements; with CSS we can assign font properties, colors, sizes, borders, background images, and even position elements on the page. Its benefits include: 1. Improved control over formatting: The degree of formatting control in CSS is significantly better than that provided in HTML; CSS gives web authors fine-grained control over the appearance of their web content. 2. Improved site maintainability: All formatting can be centralized into one CSS file, or a small handful of them, so site-wide visual modifications can be made by changing a single file. 3. Improved accessibility: By keeping presentation out of the HTML, screen readers and other accessibility tools work better, providing an enriched experience for those reliant on accessibility tools. 4. Improved page-download speed: A site built using a centralized set of CSS files will be quicker to download because each individual HTML file contains less style information and markup, and thus is smaller. (CSS also provides improved output flexibility: a page can be adapted for different output media, an approach often referred to as responsive design.)
-
Explain the three locations where CSS style rules can be placed. Which location is preferred and why?
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
CSS style rules can be placed in three locations: 1. Inline styles: Style rules placed within an HTML element via the style attribute. An inline style only affects the element it is defined within and overrides any other style definitions for the properties used. No selector is necessary. Using inline styles is generally discouraged since they increase bandwidth and decrease maintainability, because presentation and content are intermixed; they are, however, handy for quickly testing a style change. 2. Embedded style sheet: Also called internal styles, these are style rules placed within the <style> element inside the <head> element of an HTML document. They are better than inline styles, but since each HTML document has its own <style> element, it is more difficult to consistently style multiple documents. 3. External style sheet: Style rules placed in an external text file with the .css extension. This is by far the most common place to locate style rules because it provides the best maintainability: when you make a change to an external style sheet, all HTML documents that reference it automatically use the updated version, and the browser can cache the external style sheet, which improves the performance of the site as well.
-
Explain the three basic types of CSS selectors with examples.
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
When defining CSS rules, a selector is used to tell the browser which elements will be affected by the property values. The three basic selector types are: 1. Element selectors: These select all instances of a given HTML element (for example, p { ... } selects all paragraphs). All elements can be selected by using the universal element selector, the * (asterisk) character. A group of elements can be selected by separating the different element names with commas, which reduces the size and complexity of CSS files by combining multiple identical rules into a single rule. 2. Class selectors: A class selector allows you to simultaneously target different HTML elements regardless of their position in the document tree. If a series of HTML elements have been labeled with the same class attribute value, they can be targeted using a class selector, which takes the form: a period (.) followed by the class name, e.g. .note { ... }. 3. Id selectors: An id selector allows you to target a specific element by its id attribute regardless of its type or position. It takes the form: a pound/hash (#) followed by the id name, e.g. #header { ... }.
-
What is the CSS box model? Name its parts. Differentiate between content-box and border-box sizing.
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
In CSS, all HTML elements exist within an element box, and in order to become proficient with CSS one must become familiar with this element box (the box model). The box of an element consists of its content, padding, border and margin: the background color or image of an element fills the element out to its border. Box sizing can work in two ways: 1. Content-box: The width/height are applied to the contents only; borders and padding are counted separately, and margins are also counted separately. 2. Border-box: The width/height include the border and padding; margins are still counted separately.
-
What does the 'Cascade' in CSS mean? Explain its three principles.
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
The 'Cascade' in CSS refers to how conflicting rules are handled. CSS uses the following cascade principles to deal with conflicts: 1. Inheritance: Many (but not all) CSS properties affect not only the element itself but its descendants as well. Font, color, list and text properties are inheritable, while layout, sizing, border, background and spacing properties are not inheritable. For example, text inside other elements will inherit the Arial font and red color set on <body>, but not its thick green border or 100px margin. 2. Specificity: Specificity is how the browser determines which style rule takes precedence when more than one style rule could be applied to the same element. The more specific the selector, the more it takes precedence (i.e., overrides the previous definition). 3. Location: When inheritance and specificity cannot determine style precedence, the principle of location is used: when rules have the same specificity, the latest are given more weight. For instance, an inline style will override one defined in an external or embedded style sheet, and an embedded style will override an equally specific rule in an external author style sheet if it appears after the external sheet's <link> element.
-
Differentiate between raster and vector images.
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
Images we see on a screen are made of many small squares of colored light called pixels arranged in a two-dimensional grid. In a raster image (also called a bitmap image), the smaller components are pixels: the image is broken down into a two-dimensional grid of colored squares, and each colored square uses a number that represents its color value. A raster image has a set number of pixels, so dramatically increasing or decreasing its size can dramatically affect its quality. A vector image is not composed of pixels but instead is composed of objects such as lines, circles, Bezier curves, and polygons, so it does not lose quality when enlarged or reduced.
-
Compare the JPEG, GIF and PNG image formats for the web.
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
1. JPEG: JPEG (Joint Photographic Experts Group) or JPG is a 24-bit, true-color file format that is ideal for photographic images. It uses a sophisticated compression scheme that can dramatically reduce the file size of the image, and it is the ideal format for photographs and other continuous-tone images such as paintings and grayscale images. 2. GIF: The GIF (Graphic Interchange Format) file was the first image format supported by the earliest web browsers. Unlike the 24-bit JPEG format, GIF is an 8-bit or less format, meaning that it can contain no more than 256 colors. GIF files use a much simpler compression system that is lossless, which means that no pixel information is lost. 3. PNG: The PNG (Portable Network Graphics) format is a more recent format. Its main features are lossless compression; 8-bit (or 1-bit, 2-bit and 4-bit) indexed color as well as full 24-bit true color; and from 1 to 8 bits of transparency. For normal photographs, JPEG is generally still a better choice because the file size will be smaller than using PNG. (A fourth format, SVG - Scalable Vector Graphics - is a vector format whose graphics do not lose quality when enlarged or reduced.)
-
Differentiate between a fixed layout and a liquid layout in CSS.
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
In a fixed layout, the basic width of the design is set by the designer, typically corresponding to an 'ideal' width based on a 'typical' monitor resolution. Fixed layouts are created using pixel units, typically with the entire content within a <div> container (often named 'container', 'main' or 'wrapper') whose width property has been set to some width. The advantage of a fixed layout is that it is easier to produce and generally has a predictable visual result. Its drawbacks are that for larger screens there may be an excessive amount of blank space to the left and/or right of the content, and when the browser window shrinks below the fixed width, the user will have to horizontally scroll to see all the content. In a liquid layout (also called a fluid layout), widths are not specified using pixels but percentage values. Its obvious advantage is that it adapts to different browser sizes, so there is neither wasted white space nor any need for horizontal scrolling.
-
What is responsive design? Write its four key components.
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
In a responsive design, the page 'responds' to changes in the browser size that go beyond the width scaling of a liquid layout. One of the problems of a liquid layout is that images and horizontal navigation elements tend to take up a fixed size, and when the browser window shrinks to the size of a mobile browser, liquid layouts can become unusable. In a responsive layout, images will be scaled down and navigation elements will be replaced as the browser shrinks. There are four key components that make responsive design work: 1. Liquid layouts. 2. Scaling images to the viewport size. 3. Setting viewports via the <meta> tag. 4. Customizing the CSS for different viewports using media queries.
-
What are CSS media queries? Name the device properties a media query can check.
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
A media query is a way to apply style rules based on the medium that is displaying the file. You can use these queries to look at the capabilities of the device, and then define CSS rules to target that device; they are one of the key components of responsive design. (Media queries are not supported by Internet Explorer 8 and earlier.) The properties a media query can check include: width (width of the viewport), height (height of the viewport), device-width (width of the device), device-height (height of the device), orientation (whether the device is portrait or landscape), and color (the number of bits per color).
-
What is the difference between hiding an element with the display property and with the visibility property?
Topic: Image Formats, Layout & Responsive Design • 2 marks marks
There are two different ways to hide elements in CSS. The display property takes an item out of the flow: it is as if the element no longer exists. The visibility property just hides the element, but the space for that element remains.
-
What is the float property in CSS? What is the clear property used for?
Topic: Image Formats, Layout & Responsive Design • 3 marks marks
It is possible to displace an element out of its position in the normal flow via the CSS float property. An element can be floated to the left or floated to the right: when an item is floated, it is moved all the way to the far left or far right of its containing block and the rest of the content is 're-flowed' around the floated element. One of the more common usages of floats is to place multiple items side by side on the same line. You can stop elements from flowing around a floated element by using the clear property. Its values are: left (the left-hand edge of the element cannot be adjacent to another element), right (the right-hand edge cannot be adjacent to another element), both (both edges cannot be adjacent to another element), and none (the element can be adjacent to other elements).
-
What is Bootstrap? What are the three ways to get Bootstrap, and how many columns does its grid system use?
Topic: Bootstrap • 3 marks marks
Bootstrap is a CSS framework - a pre-created set of CSS classes or other software tools that make it easier to use and work with CSS. Bootstrap has two parts: CSS and JavaScript. There are three main ways to get Bootstrap: (1) through a Content Delivery Network (CDN), (2) from a web server/local machine, and (3) through package managers. To use Bootstrap, a page requires certain tags: <!DOCTYPE html>, <meta charset="utf-8"> and the viewport meta tag <meta name="viewport" content="width=device-width, initial-scale=1">. Grid systems make it easier to create multicolumn layouts; Bootstrap uses a 12-column grid (the 960 framework uses a 12- or 16-column grid and Blueprint a 24-column grid). The grid is constructed using <div> elements with classes defined by the framework, and in Bootstrap content must be placed within the <div class="row"> row container.
-
What are the three ways to include JavaScript in a web page? Explain each briefly.
Topic: JavaScript Fundamentals • 3 marks marks
1. Inline JavaScript: This refers to the practice of including JavaScript code directly within certain HTML attributes, for example <input type="button" onclick="alert('Are you sure?');" /> or <a href="JavaScript:OpenWindow();">. 2. Embedded JavaScript: This refers to the practice of placing JavaScript code within a <script> element in the page, for example <script type="text/javascript"> alert("Hello World!"); </script>. 3. External JavaScript: The code is placed in external files, which typically contain function definitions, data definitions, and other blocks of JavaScript code. JavaScript external files have the extension .js, and are included using a script tag with a src attribute, for example <script type="text/JavaScript" src="greeting.js"></script> in the <head>.
-
Why is JavaScript called a dynamically typed language? How is a variable declared in JavaScript?
Topic: JavaScript Fundamentals • 3 marks marks
In languages like C, C++ and Java, variables are statically typed, but JavaScript decides the type of a variable at run time; such variables are called dynamically typed (Python variables are also dynamically typed). This simplifies variable declarations, so that we do not require the familiar type fields like int, char and String. Instead, to declare a variable x, we use the var keyword, the name, and a semicolon. JavaScript has two types of data types: primitive data types, in which the exact value of the variable is stored (e.g. Boolean, number and string), and reference data types (objects), in which the address of the object is stored in the variable.
-
Write the three mechanisms used to view output in JavaScript.
Topic: JavaScript Fundamentals • 2 marks marks
In JavaScript we have three mechanisms to view the output: 1. alert(): The alert() function makes the browser show a pop-up to the user, with whatever is passed being the message displayed, e.g. alert("Good Morning");. During debugging and testing we may use the alert function. 2. console.log(): It is a very good way to debug your application; the output appears in the browser console (which can be opened with Ctrl+Shift+I). 3. document.write(): This method writes a string of text to a document stream opened by document; whatever we write with document.write will become part of the HTML page.
-
What are the two ways to create an array in JavaScript? Write the common features of JavaScript arrays.
Topic: JavaScript Fundamentals • 3 marks marks
There are two main ways to define an array in JavaScript: 1. Object literal notation: It is a simple form of creating arrays. The values we want to store in the array are written in square brackets and separated with commas, e.g. var greetings = ["Good Morning", "Good Afternoon"]; 2. Array constructor: In this way the 'new' keyword is used and comma-separated values are written in parentheses, e.g. var greetings = new Array("Good Morning", "Good Afternoon"); Common features of arrays in JavaScript are: the index starts from ZERO; [] is used to access a particular element; .length is used to give the length of the array; .push() adds a new element/item to an array; .pop() removes the last element from the array; and concat is a method used to concatenate two or more arrays.
-
Name the types of loops in JavaScript and explain each briefly.
Topic: JavaScript Fundamentals • 3 marks marks
Loops are used for repetitive execution of statements. JavaScript provides the following loops: 1. While loop: The most basic loop; it loops until the condition is not met, e.g. while (i < 10) { ... i++; }. 2. Do-while loop: The do...while statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once. 3. For loop: A for loop combines the common components of a loop - initialization, condition, and post-loop operation - into one statement. It begins with the for keyword and has the components placed between ( ) brackets, semicolon (;) separated, e.g. for (var i = 0; i < 10; i++) { ... }. 4. ForEach loop: This loop is used with an array in JavaScript, e.g. fruits.forEach(myFunction);
-
What are anonymous functions and arrow functions in JavaScript?
Topic: JavaScript Functions, Scope, Errors & Prototypes • 3 marks marks
Functions in JavaScript are defined using the function keyword followed by the name of the function, e.g. function square(number) { return number * number; }. JavaScript also supports anonymous functions: an anonymous function has no name and must be assigned to a variable, e.g. var showMessage = function () { alert("Hello World!"); }; which is then called as showMessage();. An arrow function expression is a compact alternative to a traditional function expression, with a shorter syntax. To convert a normal anonymous function into an arrow function, remove the word 'function' and place an arrow (=>) between the argument and the opening body bracket, e.g. (a) => { return a + 100; }.
-
What is a callback function in JavaScript?
Topic: JavaScript Functions, Scope, Errors & Prototypes • 2 marks marks
JavaScript supports callback functions. In JavaScript, you can pass a function as an argument to another function; the function that is passed as an argument inside of another function is called a callback function.
-
Explain function scope in JavaScript. Can an outer function access the variables of its inner (nested) function?
Topic: JavaScript Functions, Scope, Errors & Prototypes • 3 marks marks
In JavaScript, the scope can be considered as a box. The biggest scope is called the global scope, implying that anything put inside this area can be accessible from any program's location; anything declared/put outside of the function body is recognized as global. Functions can also be defined inside other functions (nested functions); the nested function is in the scope of the outer function. The inner function can access the variables and parameters of the outer function, but the outer function cannot access the variables defined inside the inner function. A function therefore acts like a one-way window: for example, an inner() function can use variable a defined in outer(), but outer() cannot use variable b defined in inner().
-
How are exceptions handled in JavaScript? Explain the try, catch and finally blocks, and how a programmer can throw an exception.
Topic: JavaScript Functions, Scope, Errors & Prototypes • 5 marks marks
Errors that occur at run time are called exceptions. They might result in unexpected behavior, and if the exceptions are not properly handled the logic can terminate abruptly, so handling exceptions avoids unexpected termination. In JavaScript, exceptions are handled using try/catch: - The statements expected to generate an exception or exceptions are put in the try block. - Exception handling (the remedy of the exception) is done in the catch block, which takes a parameter (e) where e is the exception, e.g. try { var A = new Array(-5); } catch (e) { console.log(e); }. - The finally block is executed regardless of whether a try block is executed or not. A programmer can also generate (throw) an exception using the throw statement, which is used when no built-in exception exists for a scenario - for example, if a user's age taken from a form must be between 0 and 150, an 'InvalidAge' exception can be thrown when the value is greater than 150 or less than 0. Where multiple types of exceptions are expected, the instanceof keyword can be used in the catch block to identify the specific type of error. Built-in exceptions include TypeError (for example, attempting to access an undefined property of a variable), RangeError (for example, new Array(-5), where the array size is a negative integer), and ReferenceError (for example, accessing a function's local variable from outside the function).
-
What is a prototype in JavaScript? Why are prototypes used instead of defining methods inside a constructor function?
Topic: JavaScript Functions, Scope, Errors & Prototypes • 3 marks marks
If methods are defined inside a constructor function, a new function (object) is created for each new object instance: for example, with a Die constructor that defines randomRoll inside it, creating 100 or 100,000 Die objects would redefine each method that many times, which wastes memory and can impact client execution times and browser performance. Prototypes solve this problem. A prototype attribute is given (inherited) by every function object, and it is initially an empty object. The prototype properties and methods are defined once for all instances of an object created with the new keyword from a constructor function: for example, Die.prototype.randomRoll = function() { ... }; defines the method only once, and since all instances of Die share the same prototype object, the function declaration happens one time and is shared with all instances. In addition, prototypes allow you to extend existing objects (including built-in objects) by adding methods to their prototypes, e.g. adding a countChars() method to String.prototype makes it available to all strings.
-
What is the Document Object Model (DOM)? What types of nodes/objects does it contain?
Topic: The Document Object Model (DOM) • 3 marks marks
Any HTML document can be represented in the form of a tree called the Document Object Model (DOM). The DOM is available as a data structure in JavaScript: when an HTML document is represented as a tree, the tree is a data structure that JavaScript can access, and once it is accessible in JavaScript, it becomes feasible to manipulate it. The DOM thus helps in accessing and manipulating HTML elements through JavaScript. 'Document' is the primary variable used to access a DOM tree via JavaScript; besides the document, each element (such as <html>, <head>, <body>, <title>, <h1>) becomes a node. When a tree is built in memory, everything in it becomes a node, whether it is an element, text, spaces or a new line character. Nodes at the same hierarchical level are called sibling nodes, and a subnode of a node is its child node while the node above it is the parent node. The DOM-related data types are: Document (the root document, representing the whole document), Node (every object in the HTML document - elements, attributes, text, etc.), NodeList (a collection/array of nodes), Element (an HTML element or node), and Attribute (an element's attribute).
-
Write the methods used to access (select) DOM elements in JavaScript.
Topic: The Document Object Model (DOM) • 3 marks marks
The document object is used to access the DOM tree, and there are several ways to do so: Classic methods: - getElementById(): Each element has a unique ID, and this method returns a single node object/element, e.g. var node = document.getElementById("latest"); - getElementsByTagName(): Returns a node list of all elements with the given tag name, e.g. document.getElementsByTagName("div") retrieves all of a document's div elements. - getElementsByClassName(): Returns a node list of all elements that use the given class, e.g. document.getElementsByClassName("comment"). Newer methods (query selectors): For selection purposes, a CSS selector is passed to the query selector. - querySelector(): The first match will be returned by this function, and it returns a node. - querySelectorAll(): This function is used to access multiple elements and returns a node list of all elements matching the selector, e.g. querySelectorAll("nav ul a:link").
-
How can JavaScript modify the content and style of a DOM element? Give examples.
Topic: The Document Object Model (DOM) • 3 marks marks
Prior to making any changes, the element must first be accessed, for example with querySelector() or getElementById(). After that: 1. Changing content: The innerHTML property is used to change an element's content. For example, node.innerHTML = "foo<em> bar</em>"; makes that HTML the content of the element at run time. Note that innerHTML is a property, not a function, so a value is assigned to it rather than calling it. 2. Changing styles directly: Modifying the styles associated with a specific element can be accomplished by altering the style property of that element, e.g. node.style.backgroundColor = "#FFFF00"; node.style.borderWidth = "3px";. 3. Changing classes: It is generally preferable to change the appearance of an element using the className or classList properties, because it allows the styles to be created outside the code (in CSS) and thus be more accessible to designers. For example, node.className = "grey"; applies a predefined class, and node.classList.toggle("hide") toggles a class like an on/off switch - if the class is set it is removed, otherwise it is added. From any node, its relative nodes can also be accessed through family relation properties such as parentNode, previousSibling, nextSibling, firstChild and lastChild.
-
Differentiate between an HTML element and a block element.
Topic: HTML: Structure, Tags, Lists, Tables & Forms • 3 marks marks
An HTML element is any tag-based structure in HTML, such as <div>, <p> or <a>; it includes both block-level and inline types. A block element is one specific type of HTML element: it always starts on a new line, stretches to the full width of its container and forces a line break after it. Examples of block elements are <div>, <h1> and <p>, whereas elements such as <span> and <a> are inline elements, not block elements.
-
What are CSS preprocessors? Name the popular CSS preprocessors and state the features they add to CSS.
Topic: CSS: Syntax, Selectors & the Cascade • 3 marks marks
CSS preprocessors are tools that extend CSS with features such as variables, functions and inheritance; code written in the preprocessed language is converted (compiled) into normal CSS that the browser can use. The popular CSS preprocessors are: Sass, the most popular one, which uses .scss files; LESS (Leaner CSS), which is often used with Node.js; and Stylus, which has a minimal syntax and is also used in Node.js environments.