Web Development Exam Questions: HTTP, XML, DOM
Web Development Exam Questions: HTTP, XML, DOM
Unit 1
1) What is HTTP? Explain its working along with request and response
example (5M)
HTTP, which stands for HyperText Transfer Protocol, is a protocol used to
access data on the World Wide Web (WWW). It can transfer data in various
forms, including plain text, hypertext, audio, and video. HTTP is known as
HyperText Transfer Protocol due to its efficiency in hypertext environments,
allowing for rapid jumps between documents. It is simpler than FTP, using only
one connection for transfers, and delivers messages immediately, unlike SMTP
which stores and forwards them.
Working of HTTP: HTTP operates as a request-response protocol, enabling
users to interact with web resources like HTML files by transmitting hypertext
messages between clients and servers. HTTP clients typically use
Transmission Control Protocol (TCP) connections for communication.
The HTTP transaction involves a client initiating a request message to the
server, and the server responding with a response message. HTTP messages
are of two types: request and response, both following the same format.
Request Message: This message is sent by the client and typically consists
of a request line, headers, and sometimes a body.
Response Message: This message is sent by the server to the client and
includes a status line, headers, and sometimes a body.
Date: Sat, 29 Oct 2009 [Link] GMT Server: Apache Last-Modified: Tue, 01 Dec 2009 [Link] GMT Etag:
Untitled 1
XML, which stands for Extensible Markup Language, is a text-based markup
language used for storing and transporting data.
How to prove an XML file is well-formed: To prove that an XML file, such as
[Link] , is well-formed, it must adhere to the following rules:
How to prove an XML file is valid: To prove that an XML file, such as
[Link] , is valid, it must be validated against a Document Type Definition
A DTD defines the legal building blocks of an XML document and its
attributes.
Untitled 2
This architecture provides a framework for most web applications on the
internet. It separates the business logic from the application logic and
database.
2. Application Tier
Also called the business logic layer.
Bridges the gap between the presentation layer and data layer.
3. Data Tier
Consists of persistent storage mechanisms (databases).
Advantages
1. Improved Data Integrity.
3. Improved security.
Untitled 3
6. Easier code maintenance and modification.
Disadvantages
1. More complex compared to 1-tier and 2-tier.
An XML DOM also provides an API that allows a programmer to add, edit,
move or remove nodes at any point in the tree, and to retrieve information.
Untitled 4
The HTML DOM is a standard object model and programming interface for
HTML.
It defines:
4. Form Control Elements: Form elements vary and can be checkboxes, text
areas, radio buttons, buttons, etc.
Untitled 5
Data-Centric → Stores and transports structured data.
Platform Independent → Works across different systems.
Self-Descriptive → Tags describe the data clearly.
Hierarchical Structure → Makes data easy to parse and manipulate.
Separation of Data & Presentation → Focuses only on data, not design.
Level 2 DOM: provides new functionalities such as mouse and user interface
events, CSS, Range, and Traversal.
Level 3 DOM: consists of all level 1 and 2 functionalities plus new specifications
like XPath, Load and Save, and Validation.
Untitled 6
<button onclick="getAdd()">Click To Add</button>
<p id="result"></p>
<script type="text/javascript">
function getAdd() {
var num1 = Number([Link]('val1').value);
var num2 = Number([Link]('val2').value);
var sum = num1 + num2;
5) Explain the working of DNS with the suitable diagrams. Clearly explain all
the steps involved in DNS resolution.
DNS (Domain Name System) is an application layer protocol that defines how
applications on different systems pass messages. It acts as a directory service
that maps hostnames on a network to their corresponding numerical IP
addresses. DNS translates human-friendly domain names into IP addresses,
making it easier for users to access hosts without remembering complex IP
addresses.
Working of DNS: DNS operates as a client/server network communication
protocol, where DNS clients send requests and DNS servers send responses.
1. When a user enters a web address or URL (e.g., [Link] ) into their
browser, the request is passed to a Domain Name Server (DNS).
Untitled 7
2. The DNS server holds a list of system names and their corresponding IP
addresses, converting the typed address into a numerical IP that identifies the
destination computer.
3. The browser, acting as a client, sends the request to the server using HTTP,
based on the IP address provided by the DNS server.
4. If the local DNS server does not have the IP address associated with the
hostname, it forwards the request to another DNS server. This process
involves querying root nameservers, then TLD (Top-Level Domain)
nameservers, and finally authoritative nameservers until the IP address is
found.
5. Once the IP address is obtained, it is sent back to the resolver, which then
completes the request over the internet protocol.
6. The server that hosts the website receives the request, gathers the
information about the requested document, and sends it back to the browser's
IP address.
7. The browser then gathers all the requested information and displays it on the
user's device screen in the form of web pages. This may involve the browser
requesting additional linked files, such as images, from the same server.
Unit 2
1) Write a Javascript to change the background color of the web page to red
color if button named “RED” is clicked and to green color if button named
“GREEN” is clicked. (5M)
<html>
<head>
<title>Hello Webpage</title>
<script type="text/javascript">
function changebg_red() {
[Link] = 'red';
}
function changebg_green() {
[Link] = 'green';
}
</script>
</head>
<body>
Untitled 8
<form>
<input type="button" value="RED" onclick="changebg_red()">
<input type="button" value="GREEN" onclick="changebg_green()">
</form>
</body>
</html>
<html>
<head>
<title>JavaScript form validation programs</title>
<script type="text/javascript">
function validateForm() {
var uname = [Link]["myform"]["username"].value;
var pword = [Link]["myform"]["password"].value;
var email = [Link]["myform"]["email"].value;
Untitled 9
alert("Please enter email address");
return false;
} else if ([Link]("@") == -1) {
alert("Email should have @ character!");
return false;
}
3) Write a Javascript to accept two numbers and display their sum using pop
up box. (5M)
<html>
<head>
<script type="text/javascript">
var num1 = parseInt(prompt("Enter First number "));
var num2 = parseInt(prompt("Enter Second number "));
var sum = num1 + num2;
alert("Sum = " + sum);
</script>
</head>
<body>
<h1>JavaScript Pop Up Box Example</h1>
<p>This page uses JavaScript to ask for two numbers and display their s
um in an alert box.</p>
Untitled 10
</body>
</html>
4) Differentiate ES5 and ES6. Give an example of the Anonymous and Arrow
function in ES6. (5M)
Differentiation between ES5 and ES6:
Untitled 11
Introduced the concept
of for...of loop to
The for loop is used to
Loops perform iteration over
iterate over elements.
the values of iterable
objects.
Example of Arrow Function in ES6: Arrow functions are a new feature in ES6
that allow for a shorter syntax compared to regular function expressions. They
are anonymous and do not require the function keyword.
A simpler example:
5) Write a Javascript to accept a number from the user and check if it is even
or odd (5M)
<html>
<head>
<script type="text/javascript">
var num = prompt("Enter a number ");
if (num % 2 == 0) {
alert("Number is Even = " + num);
} else {
Untitled 12
alert("Number is Odd = " + num);
}
</script>
</head>
<body>
<h1>JavaScript Even or Odd Check</h1>
<p>This page uses JavaScript to check if a number entered by the user i
s even or odd.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function changebgcolor() {
var a = [Link];
[Link] = [Link] == "red" ? "yell
ow" : "red";
// The original source changes color every 5000 milliseconds (5 sec
onds).
// To change it every 2 seconds as per the query, this value should
be 2000.
setTimeout(changebgcolor, 2000); // Changes background color ev
ery 2 seconds
}
</script>
</head>
<body onload="changebgcolor()">
<h1>Background Color Changer</h1>
<p>This page's background color will change automatically every 2 seco
nds.</p>
</body>
</html>
Untitled 13
7) Differentiate between ES5 and ES6. Describe the concepts of Arrow
Functions, classes and inheritance in JavaScript. (10M)
Concepts in JavaScript:
Arrow Functions: Arrow functions are a new feature introduced in ES6 that
provide a concise syntax for writing function expressions, eliminating the need
for the function keyword. They are anonymous functions (functions without a
name and not bound with an identifier).
Syntax: Arrow functions typically follow the syntax (parameters) => { function body
} .
Untitled 14
Context (this): One significant advantage is that the this context within
arrow functions is lexically or statically defined, meaning it inherits this
from the enclosing scope, unlike regular functions where this depends on
how the function is called.
Use Cases: Often used for callbacks and methods where the this context
needs to be preserved.
Instantiation: Objects are instantiated from classes using the new keyword.
◦ Single-level Inheritance: A derived class inherits from only one base class.
◦ Multiple Inheritance: (Note: The source states "Multiple Inheritance, a class
can be inherited from several classes. It is not supported in ES6.")
◦ Multi-level Inheritance: A derived class is created from another derived
class, forming a chain of inheritance.
Untitled 15
◦ Code Reusability: It allows derived classes to inherit behaviour and
properties, reducing repetitive code.
◦ Extensibility: Child classes can add new features while retaining those from
the parent.
◦ extends keyword: In ES6, the extends keyword is used to establish an
inheritance relationship between classes.
8) Write a JavaScript code for displaying a digital clock on a web page (5M)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Digital Clock</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<style>
:root{
--bg: #000000; /* full black background */
--card-bg: #ffffff; /* white card */
--text-dark: #111111; /* dark text for card */
--muted: #666666;
--accent: #ff7a18; /* warm accent for button */
--shadow: rgba(0,0,0,0.35);
}
Untitled 16
/* White card */
.clock {
background: var(--card-bg);
color: var(--text-dark);
padding:28px 36px;
border-radius:10px;
box-shadow: 0 12px 40px var(--shadow);
text-align:center;
width:360px;
max-width:92%;
border: 1px solid rgba(0,0,0,0.06);
}
.time {
font-size:54px;
font-weight:700;
letter-spacing:1px;
margin:0;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto
Mono", monospace;
}
.date {
margin-top:10px;
color: var(--muted);
font-size:15px;
}
.controls {
margin-top:14px;
display:flex;
justify-content:center;
gap:10px;
}
Untitled 17
appearance:none;
-webkit-appearance:none;
border: none;
background: var(--accent);
color: #fff;
padding:10px 14px;
border-radius:8px;
font-weight:600;
cursor:pointer;
box-shadow: 0 6px 18px rgba(255,122,24,0.18);
transition: transform 120ms ease, box-shadow 120ms ease, opacity 120
ms ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); opacity:0.95; }
.btn:focus { outline: 3px solid rgba(255,122,24,0.18); outline-offset:3px; }
@media (max-width:420px){
.time { font-size:44px; }
.clock { padding:18px; width:320px; }
}
</style>
</head>
<body>
<div class="clock" id="clock" role="region" aria-label="Digital clock">
<div class="time" id="time">--:--:--</div>
<div class="date" id="date">Loading...</div>
<div class="controls">
<button class="btn" id="toggleFormat">Use 24-hour</button>
Untitled 18
<!-- Example of another control if you want later:
<button class="btn btn-ghost" id="toggleTheme">Theme</button>
-->
</div>
</div>
<script>
const timeEl = [Link]('time');
const dateEl = [Link]('date');
const toggleBtn = [Link]('toggleFormat');
// state
let use24Hour = true;
let timerId = null;
function updateClock(){
const now = new Date();
let h = [Link]();
const m = [Link]();
const s = [Link]();
Untitled 19
// toggle button updates label and format
[Link]('click', () => {
use24Hour = !use24Hour;
[Link] = use24Hour ? 'Use 24-hour' : 'Use 12-hour';
updateClock(); // immediate reflect change
});
// Start clock
function startClock(){
if (timerId) clearInterval(timerId);
updateClock();
timerId = setInterval(updateClock, 1000);
}
startClock();
</script>
</body>
</html>
<html>
<head>
Untitled 20
<script type="text/javascript">
function changebgcolor() {
var a = [Link];
// This code toggles the background color between red and yellow.
[Link] = [Link] == "red" ? "yell
ow" : "red";
// The setTimeout function calls changebgcolor again after 5000 mil
liseconds (5 seconds).
setTimeout(changebgcolor, 5000);
}
</script>
</head>
<body onload="changebgcolor()">
<h1>Automatic Background Color Change</h1>
<p>The background color of this page will change automatically every 5
seconds.</p>
</body>
</html>
10) Write a JavaScript code to set a cookie on the user's computer. (5M)
The provided sources do not contain specific JavaScript code for setting a
cookie on the user's computer. While cookies are mentioned as a local storage
mechanism, no code example is given.
Unit 3
React
Untitled 21
that can change over time). Components are the primary building blocks of a
React application — instead of manipulating the DOM directly, you declare what
UI should look like for a given state and React takes care of updating the DOM.
This approach enforces separation of concerns in the UI layer: structure,
styling, and behavior for a particular piece of interface live together in a single
component, which improves maintainability and reusability.
Components come in two broad types:
you need lifecycle hooks or this based state management (legacy apps or
when studying lifecycle concepts).
Predictability: With one-way data flow (props down), it’s easier to reason
about how state changes affect the UI.
Props vs State:
Props are read-only inputs passed from parent to child. They make
components configurable and reusable.
Untitled 22
[Link]
[Link]
Short explanation of code: Car is a class component that reads brand from
props and renders a heading. [Link] mounts Car into the DOM element with id
root .
Untitled 23
How SPAs work (architecture):
On first load, the server delivers the static assets — one HTML file,
JavaScript bundles, and CSS.
JavaScript initializes the app, renders the initial UI, and sets up client-side
routing.
When the user navigates, the router intercepts link clicks and updates the
URL and displayed view purely in JavaScript.
API backend — exposes endpoints for data; the UI requests JSON instead
of full HTML pages.
Build tools — bundlers like Webpack, Vite, or tools from Create React App
to bundle and optimize assets.
Advantages (detailed):
Reduced Bandwidth Over Time: After initial load, only data (not full pages)
is transferred.
Initial load time: The JavaScript bundle can be large; must use code-
splitting and lazy loading to improve performance.
SEO & Social Sharing: Historically SPAs had poor SEO because content is
rendered client-side. Solutions: Server-Side Rendering (SSR), Static Site
Untitled 24
Generation (SSG), or hybrid approaches (e.g., [Link]) to pre-render
content for crawlers.
Browser History & Back button: Must be handled explicitly via router to
keep navigation predictable.
Examples: Gmail, Google Maps, many modern web apps (when built with
React, Angular, Vue as SPA front-ends).
constructor(props)
Purpose: derive state from props before render. Prefer avoiding this
unless necessary.
render()
Purpose: returns JSX describing the UI. Must be pure (no side-effects).
componentDidMount()
Purpose: called once after the component is inserted into the DOM.
Ideal place for AJAX calls, starting subscriptions, setting timers, or DOM
Untitled 25
measurements.
shouldComponentUpdate(nextProps, nextState)
render()
getSnapshotBeforeUpdate(prevProps, prevState)
Purpose: capture information from the DOM (e.g., scroll position) before
it is potentially changed by render. Value returned is passed to
componentDidUpdate .
componentWillUnmount()
Mounting:
constructor()
↓
render()
↓
componentDidMount()
Untitled 26
Updating (on state/props change):
getDerivedStateFromProps()
↓
shouldComponentUpdate()
↓ (if true)
render()
↓
getSnapshotBeforeUpdate()
↓
componentDidUpdate()
Unmounting:
componentWillUnmount()
Fetch data in componentDidMount so the initial render is fast and DOM exists
when you update state.
Untitled 27
1. State changes inside the component
If a parent re-renders, React will also call the child’s render by default.
This may occur even if the child’s props didn't change. Optimization
techniques (see below) can prevent unnecessary child renders.
5. forceUpdate()
Untitled 28
Keys in lists: correct key usage helps React identify items and avoid re-
rendering entire lists.
Immutable updates: by returning new objects for changed state, you help
shallow comparisons detect changes quickly.
// Parent:
<Child value={[Link].x} />
// If parent does: [Link]({ x: 10 }), Child will receive new prop and re-r
ender.
// Functional child
const Child = [Link](({ value }) => <div>{value}</div>);
// Child will skip re-render if `value` is shallowly equal to previous value.
Untitled 29