Predicted Questions – Web Development (3151606) – Summer 2025
UNIT 1 – INTRODUCTION
1. Explain HTTP Request and Response with example.
Introduction
HTTP (Hypertext Transfer Protocol) is the communication protocol of the Web.
It works on a client–server model, where the client (browser) sends an HTTP Request and the server
sends an HTTP Response.
A) HTTP Request
An HTTP Request is sent by the browser to ask for a resource such as a webpage, image, CSS, JSON,
etc.
Structure of HTTP Request
1. Request Line
Contains method, resource path, and protocol.
Example:
GET /[Link] HTTP/1.1
2. Request Headers
Additional information sent to server:
• Host: domain name
• User-Agent: browser details
• Accept: content type
• Cookie: session data
• Authorization: login token
3. Request Body
Used for POST, PUT, PATCH.
Contains form data or JSON.
Example:
username=bhumi&password=123
B) HTTP Response
A response is sent by server back to the client after processing the request.
Structure of HTTP Response
1. Status Line
Indicates the result:
• 200 OK
• 404 Not Found
• 500 Server Error
Example:
HTTP/1.1 200 OK
2. Response Headers
Examples:
• Content-Type: text/html
• Content-Length: 1024
• Set-Cookie: session nid=10
3. Response Body
Contains the actual data such as HTML, JSON, CSS, image.
Example:
<html><body>Welcome Bhumi</body></html>
C) Complete Example
Request
GET /[Link] HTTP/1.1
Host: [Link]
Response
HTTP/1.1 200 OK
Content-Type: text/html
<html>
<body>Welcome to GTU Web Development</body>
</html>
Conclusion
HTTP request–response cycle forms the backbone of communication between browsers and servers.
2. Discuss the architecture of a Web Browser.
A Web Browser is a software application used to open and display web pages.
Popular browsers are Chrome, Firefox, Edge, Safari.
Browser Architecture Components
1. User Interface (UI)
Visible part of browser:
• Address bar
• Back/Forward buttons
• Tabs
• Refresh/Stop buttons
2. Browser Engine
Acts as a link between UI and Rendering Engine.
Manages actions such as reload, stop page, etc.
3. Rendering Engine
Responsible for parsing HTML, CSS and displaying the webpage.
Examples:
• Chrome → Blink
• Firefox → Gecko
Tasks:
• Build DOM tree
• Build CSSOM
• Render on screen
4. JavaScript Engine
Executes JavaScript code inside web pages.
Examples:
• Chrome → V8
• Firefox → SpiderMonkey
5. Networking Layer
Handles:
• HTTP/HTTPS requests
• Responses
• Caching
• Cookies
Supports protocols like: DNS, TCP/IP, SSL.
6. UI Backend
Draws basic widgets:
Scroll bars, windows, dialog boxes.
7. Data Storage
Stores:
• Cache
• Cookies
• LocalStorage
• SessionStorage
• IndexedDB
Improves performance and offline support.
D
A
User Interface T
A
P
E
Browser engine R
S
I
S
T
Rendering engine
A
N
C
E
Networking Javascript interpreter UI Backend
3. What is CORS? Explain with example.
Definition
CORS (Cross-Origin Resource Sharing) is a browser security feature that controls how web pages
from one domain can request resources from another domain.
Why CORS is Required?
Browsers block requests made from:
[Link] → [Link]
This prevents:
• Unauthorized API access
• Session hijacking
• Data leakage
How CORS Works?
The server being requested must allow cross-origin access by including a specific header:
Important CORS Headers
1. Access-Control-Allow-Origin
2. Access-Control-Allow-Headers
3. Access-Control-Allow-Methods
Example Scenario
Website:
[Link]
wants data from:
[Link]
Server must respond with:
Access-Control-Allow-Origin: [Link]
Or allow all:
Access-Control-Allow-Origin: *
Code Example
[Link] Server Example
[Link]("Access-Control-Allow-Origin", "*");
Without CORS Header → Error
Browser blocks request and shows:
CORS Policy: No 'Access-Control-Allow-Origin' header present
4. What is Web Security? Explain major security risks.
Definition
Web Security refers to the techniques used to protect web applications from cyber attacks and
unauthorized access.
Goal:
• Confidentiality
• Integrity
• Availability
Major Security Risks
1. SQL Injection
Attacker inserts SQL commands through input fields.
Example:
' OR '1'='1
Can access database without permission.
2. Cross-Site Scripting (XSS)
Malicious JavaScript is injected into a webpage.
Used to steal:
• Cookies
• Sessions
• User data
3. Cross-Site Request Forgery (CSRF)
Attacker tricks user into performing unintended actions (like sending money).
4. Broken Authentication
Weak login systems → password leak → unauthorized access.
5. Insecure Direct Object Reference (IDOR)
Attacker manipulates URL:
/profile?id=101 → /profile?id=102
Can access someone else's account.
6. Phishing Attacks
Fake websites/emails to steal login credentials.
7. Server Misconfiguration
Examples:
• Default admin credentials
• Open ports
• Missing SSL
5. What is SEO? Explain its process.
Definition
SEO (Search Engine Optimization) is the process of improving the visibility of a website in search
engine results (Google, Bing).
SEO Process Steps
1. Keyword Research
Finding the terms users search for.
2. On-Page SEO
Optimizing elements inside the website:
• Meta title
• Meta description
• Header tags
• Keyword placement
• Image ALT text
• Internal linking
3. Technical SEO
Improving website structure:
• XML sitemap
• [Link]
• HTTPS
• Fast loading
• Mobile-friendly design
4. Off-Page SEO
External ranking factors:
• Backlinks from high-authority websites
• Social media links
• Brand mentions
5. Content Optimization
Creating high-quality, keyword-rich content.
6. Monitoring Results
Using:
• Google Analytics
• Google Search Console
Improves ranking over time
6. Explain HTTP methods and headers.
HTTP METHODS
HTTP Methods define what action the client wants the server to perform on a resource.
Below are the most important methods (GTU asks these repeatedly):
1) GET Method
Used to retrieve data from the server.
• Data sent in URL
• No request body
• Safe and idempotent
Example
Request
GET /products HTTP/1.1
Host: [Link]
Response
HTTP/1.1 200 OK
Content-Type: application/json
2) POST Method
Used to send data to the server (form submission).
• Data sent in body
• Used for login, registration
Example
Request
POST /login HTTP/1.1
Host: [Link]
Content-Type: application/x-www-form-urlencoded
username=bhumi&password=12345
3) PUT Method
Used to update entire resource on the server.
Example
PUT /user/101 HTTP/1.1
Content-Type: application/json
"name": "Bhumi",
"email": "bhumi@[Link]"
4) PATCH Method
Used to update only part of a resource.
Example
PATCH /user/101 HTTP/1.1
Content-Type: application/json
"email": "newemail@[Link]"
5) DELETE Method
Used to delete a resource.
Example
DELETE /user/101 HTTP/1.1
6) HEAD Method
Same as GET but no response body.
Used to:
• Check resource existence
• Get metadata (content length, type)
Example
HEAD /[Link] HTTP/1.1
7) OPTIONS Method
Used to check:
• Allowed methods
• CORS permissions
Example
Response
Allow: GET, POST, PUT, DELETE
Access-Control-Allow-Origin: *
HTTP HEADERS
Headers provide extra information with every request and response.
A) REQUEST HEADERS
1) Host
Specifies target domain.
Example:
Host: [Link]
2) User-Agent
Browser or device information.
Example:
User-Agent: Mozilla/5.0
3) Accept
Indicates what type of data client accepts.
Example:
Accept: text/html, application/json
4) Authorization
Used to send tokens or credentials.
Example:
Authorization: Bearer abc123token
5) Cookie
Sends stored cookies to the server.
Example:
Cookie: sessionid=5566
B) RESPONSE HEADERS
1) Content-Type
Tells the type of data returned by server.
Example:
Content-Type: application/json
2) Set-Cookie
Server creates cookie on browser.
Example:
Set-Cookie: userid=101; Path=/; HttpOnly
3) Server
Shows backend server software.
Example:
Server: Apache/2.4.1
4) Content-Length
Size of response body.
Example:
Content-Length: 2456
5) Access-Control-Allow-Origin
Used for CORS.
Example:
Access-Control-Allow-Origin: *
Complete Example (Request + Response)
Request
GET /home HTTP/1.1
Host: [Link]
User-Agent: Chrome
Accept: text/html
Response
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 150
<html>
<body>Welcome Bhumi!</body>
</html>
7. Explain WWW and its working.
UNIT 2 – HTML & CSS
8. Create an HTML form for student registration using various form controls.
9. Explain different types of CSS with examples.
Types of CSS
CSS (Cascading Style Sheets) can be applied to HTML documents in three different ways:
1. Inline CSS
Inline CSS is written inside the HTML tag using the style attribute.
Features
• Highest priority.
• Used for applying style to a single specific element.
• Not recommended for large websites (difficult to maintain).
Example
<p style="color: blue; font-size: 20px;">This is an inline styled paragraph.</p>
2. Internal CSS (Embedded CSS)
Internal CSS is written inside the <style> tag in the head section of the HTML file.
Features
• Styles apply to the whole page (only that page).
• Better managed than inline CSS.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
text-align: center;
p{
font-size: 18px;
</style>
</head>
<body>
<h1>Internal CSS Example</h1>
<p>This paragraph uses internal CSS.</p>
</body>
</html>
3. External CSS
External CSS is written in a separate .css file and linked using the <link> tag in <head>.
Features
• Best for large websites.
• Single CSS file can style multiple HTML pages.
• Easy to maintain and update.
Example
HTML File
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h1>External CSS Example</h1>
<p>This paragraph uses external CSS.</p>
</body>
</html>
[Link] File
h1 {
color: purple;
text-align: center;
p{
font-size: 18px;
color: darkgray;
}
Summary Table
Type of CSS Where Written Scope Priority Use Case
Inline CSS Inside HTML tag Single element Highest Quick fixes, small changes
Internal CSS <style> tag in <head> Single page Medium Page-specific CSS
External CSS Separate .css file Multiple pages Lowest Large projects, reusable styling
10. What is CSS Box Model? Explain with diagram.
CSS Box Model
The CSS Box Model is a fundamental concept in web design that describes how every HTML element
is treated as a rectangular box.
This box consists of four layers:
1. Content – The actual text or image inside the element.
2. Padding – Space between the content and the border.
3. Border – The line surrounding the padding and content.
4. Margin – Space outside the border that separates the element from others.
The box model determines how width, height, and spacing of elements are calculated in CSS.
Box Model Layers (Inside → Outside)
+-------------------------------+
| Margin |
| +-----------------------+ |
| | Border | |
| | +---------------+ | |
| | | Padding | | |
| | | +---------+ | | |
| | | | Content | | | |
| | | +---------+ | | |
| | +---------------+ | |
| +-----------------------+ |
+-------------------------------+
Explanation with Example
Consider this CSS:
div {
width: 200px;
padding: 20px;
border: 5px solid black;
margin: 15px;
Total Width Calculation
Total width = content width + padding + border + margin
= 200 + (20 + 20) + (5 + 5) + (15 + 15)
= 280px
Total Height Calculation
(Follows the same formula)
Short Notes (for exam)
• CSS Box Model defines how elements are structured and displayed.
• It includes Content → Padding → Border → Margin.
• Helps in controlling layout, spacing, and alignment.
• Used to calculate the real space an element occupies on the page.
11. Explain pseudo-class selectors in CSS.
Pseudo-Class Selectors in CSS
A pseudo-class in CSS is a keyword added to a selector that defines a special state of an element.
It is used to style elements based on their state, position, or user interaction, without adding extra
classes or JavaScript.
Pseudo-classes always start with a colon (:).
Common Pseudo-Class Selectors
1. :hover
Applied when the mouse pointer is over an element.
Example:
button:hover {
background-color: blue;
color: white;
2. :active
Applied when an element is being clicked.
Example:
a:active {
color: red;
3. :focus
Applied when an element (like an input box) is focused.
Example:
input:focus {
border: 2px solid green;
4. :visited
Styles a link after it has been clicked.
Example:
a:visited {
color: purple;
5. :first-child
Selects an element that is the first child of its parent.
Example:
p:first-child {
font-weight: bold;
6. :last-child
Selects the last child of its parent.
Example:
li:last-child {
color: blue;
7. :nth-child(n)
Selects an element based on its position.
Example:
tr:nth-child(2) {
background-color: yellow;
}
8. :invalid
Matches form fields with invalid input entered in them.
<style>
input:invalid {
border: 2px solid red;
</style>
Output:
12. Explain types of lists in HTML with example.
Types of Lists in HTML
HTML provides three types of lists to display items in an organized manner:
1. Ordered List (<ol>)
2. Unordered List (<ul>)
3. Description List (<dl>)
1. Ordered List (<ol>)
An ordered list displays items in a numbered or sequenced format.
Each item is written using the <li> tag.
Default numbering: 1, 2, 3, …
Example
<ol>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ol>
Types of numbering (type attribute):
• type="1" → 1, 2, 3
• type="A" → A, B, C
• type="a" → a, b, c
• type="I" → I, II, III
• type="i" → i, ii, iii
Example:
<ol type="A">
<li>Apple</li>
<li>Mango</li>
</ol>
2. Unordered List (<ul>)
An unordered list displays items with bullets (●) instead of numbers.
Example
<ul>
<li>Dog</li>
<li>Cat</li>
<li>Rabbit</li>
</ul>
Bullet styles (type attribute):
• type="disc" → ● (default)
• type="circle" → ○
• type="square" → ■
Example:
<ul type="square">
<li>Red</li>
<li>Blue</li>
</ul>
3. Description List (<dl>)
A description list is used to display terms and their descriptions, like dictionaries or FAQs.
• <dt> → Definition Term
• <dd> → Definition Description
Example
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Summary Table
List Type Tag Used Purpose Example
Ordered List <ol> + <li> Numbered items Steps, rankings
Unordered List <ul> + <li> Bulleted items Categories, menus
Description List <dl>, <dt>, <dd> Term–description pairs Glossaries, FAQs
13. Create an HTML Time Table using table tag.
<!DOCTYPE html>
<html>
<head>
<title>College Time Table</title>
<style>
table {
border-collapse: collapse;
width: 70%;
margin: auto;
th, td {
border: 1px solid black;
padding: 10px;
text-align: center;
th {
background-color: lightgray;
</style>
</head>
<body>
<h2 style="text-align:center;">Weekly Time Table</h2>
<table>
<tr>
<th>Day</th>
<th>9:00 - 10:00</th>
<th>10:00 - 11:00</th>
<th>11:00 - 12:00</th>
<th>12:00 - 1:00</th>
<th>2:00 - 3:00</th>
<th>3:00 - 4:00</th>
</tr>
<tr>
<td>Monday</td>
<td>Maths</td>
<td>English</td>
<td>Physics</td>
<td>Break</td>
<td>Computer</td>
<td>Sports</td>
</tr>
<tr>
<td>Tuesday</td>
<td>Biology</td>
<td>Maths</td>
<td>Chemistry</td>
<td>Break</td>
<td>English</td>
<td>Library</td>
</tr>
<tr>
<td>Wednesday</td>
<td>Physics</td>
<td>Computer</td>
<td>Maths</td>
<td>Break</td>
<td>Chemistry</td>
<td>Yoga</td>
</tr>
<tr>
<td>Thursday</td>
<td>English</td>
<td>Biology</td>
<td>Physics</td>
<td>Break</td>
<td>Maths</td>
<td>Computer</td>
</tr>
<tr>
<td>Friday</td>
<td>Chemistry</td>
<td>Physics</td>
<td>English</td>
<td>Break</td>
<td>Biology</td>
<td>Sports</td>
</tr>
</table>
</body>
</html>
14. Explain Internal CSS & apply styles.
What is Internal CSS?
Internal CSS (also called Embedded CSS) is a method of adding CSS styles inside the <style> tag
within the <head> section of an HTML document.
It is used when:
• You want to apply CSS to a single webpage.
• You do not want an external stylesheet.
• You need better style control than inline CSS.
Syntax of Internal CSS
<head>
<style>
/* CSS rules here */
</style>
</head>
Example: Internal CSS with Applied Styles
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS Example</title>
<style>
h1 {
color: blue;
text-align: center;
font-family: Arial;
p{
font-size: 18px;
color: green;
.box {
width: 200px;
height: 100px;
background-color: lightgray;
border: 2px solid black;
padding: 10px;
</style>
</head>
<body>
<h1>Welcome to Internal CSS Demo</h1>
<p>This paragraph is styled using internal CSS.</p>
<div class="box">This is a styled box.</div>
</body>
</html>
Output Explanation (Text-Based Preview)
Welcome to Internal CSS Demo
This paragraph is styled using internal CSS.
+-----------------------------------+
| This is a styled box. |
| (light gray background, |
| black border, padding) |
+-----------------------------------+
• Heading appears blue, centered, and with Arial font.
• Paragraph appears green with 18px size.
• Box appears with light gray background, border, and padding.
15. Explain padding, margin, borders, backgrounds in CSS.
1. Padding in CSS
Definition
Padding is the space between the content of an element and its border.
Syntax
padding: 20px;
Types
• padding-top
• padding-right
• padding-bottom
• padding-left
Example
div {
padding: 20px;
2. Margin in CSS
Definition
Margin is the space outside the border of an element.
It creates space between elements.
Syntax
margin: 15px;
Types
• margin-top
• margin-right
• margin-bottom
• margin-left
Example
div {
margin: 30px;
}
3. Border in CSS
Definition
Border is the line around the padding and content of an element.
Syntax
border: 2px solid black;
Border Properties
• border-width
• border-style
• border-color
Border Styles
• solid
• dotted
• dashed
• double
• groove
• ridge
• inset
• outset
Example
div {
border: 2px dashed blue;
4. Background in CSS
Definition
Background is used to set the background color, image, or gradient of an element.
Common Properties
• background-color
• background-image
• background-repeat
• background-size
• background-position
Examples
Background color
body {
background-color: lightyellow;
Background image
div {
background-image: url("[Link]");
background-size: cover;
background-repeat: no-repeat;
5. Combined Example
<style>
.box {
padding: 20px; /* space inside */
margin: 30px; /* space outside */
border: 3px solid green; /* border */
background-color: lightblue; /* background */
</style>
<div class="box">
This is a styled box.
</div>
16. Explain Bootstrap for CSS.
Bootstrap for CSS
Bootstrap is a popular open-source CSS framework used to create responsive, mobile-first, and
modern-looking websites quickly.
It provides a collection of pre-designed CSS classes, components, and layouts that help developers
build web pages without writing CSS from scratch.
Originally developed by Twitter, Bootstrap is now the most widely used CSS UI framework.
Key Features of Bootstrap
1. Responsive Grid System
Bootstrap uses a 12-column grid that automatically adjusts layout for mobile, tablet, and desktop
screens.
Example:
<div class="row">
<div class="col-md-6">Column 1</div>
<div class="col-md-6">Column 2</div>
</div>
2. Predefined CSS Classes
Bootstrap comes with ready-made classes for:
• Buttons
• Tables
• Forms
• Images
• Alerts
• Cards
• Navbars
Example:
<button class="btn btn-primary">Click Me</button>
3. Mobile-First Design
Bootstrap is built to work first for smaller screens, then scale up for larger devices.
4. Ready-Made Components
Components include:
• Navigation Bar
• Dropdown Menu
• Carousel Slider
• Modal Popup
• Progress Bars
• Tooltips
Example:
<div class="alert alert-success">Success Message!</div>
5. Utility Classes
Small classes for spacing, colors, borders, text, etc.
Examples:
<p class="text-center text-danger">Error!</p>
<div class="mt-3 p-2 border"></div>
6. Easy Integration
Bootstrap can be added using:
• CDN link
• Local files
• NPM packages
CDN example:
<link rel="stylesheet"
href="[Link]
Advantages of Bootstrap
✔ Fast and efficient development
✔ Responsive web design becomes easy
✔ Large collection of UI components
✔ Consistent design across all browsers
✔ Huge community support
Conclusion (Exam Friendly)
“Bootstrap is a powerful CSS framework that simplifies web development by providing a responsive
grid system, ready-made styles, UI components, and utility classes. It helps developers create
modern, mobile-friendly websites quickly without writing extensive CSS.”
UNIT 3 – JAVASCRIPT
17. Write JavaScript to validate an email using Regular Expression.
18. Explain DOM. How to access HTML elements using DOM?
What is DOM? (Document Object Model)
DOM (Document Object Model) is a programming interface for HTML and XML documents.
It represents the webpage as a tree structure where every part of the page (elements, attributes,
text) becomes an object.
Key Points
• Browser converts HTML → DOM Tree.
• JavaScript can use DOM to read, modify, add, or delete HTML elements.
• DOM makes the webpage dynamic and interactive.
DOM Tree (Diagram)
Every tag becomes a node/object in the DOM tree.
How to Access HTML Elements using DOM
JavaScript provides several methods to access HTML elements.
1. getElementById()
Finds an element using its id.
Example:
HTML:
<p id="msg">Hello</p>
JS:
var x = [Link]("msg");
2. getElementsByClassName()
Finds elements using class name (returns a list/collection).
Example:
var items = [Link]("box");
3. getElementsByTagName()
Finds elements by tag name such as <p>, <div>, <h1>.
Example:
var allPara = [Link]("p");
4. querySelector()
Returns the first matching CSS selector element.
Example:
var x = [Link](".box");
5. querySelectorAll()
Returns all elements matching a CSS selector.
Example:
var items = [Link]("[Link]");
Example Program: Access & Change HTML Element
<!DOCTYPE html>
<html>
<body>
<p id="text">Welcome</p>
<script>
var p = [Link]("text");
[Link] = "blue"; // Change color
[Link] = "Hello DOM!"; // Change content
</script>
</body>
</html>
Summary (Exam Friendly)
• DOM is a tree-like representation of an HTML document.
• It allows JavaScript to access and modify webpage elements.
• Common DOM access methods include:
✔ getElementById()
✔ getElementsByClassName()
✔ getElementsByTagName()
✔ querySelector()
✔ querySelectorAll()
19. Explain alert, prompt, and confirm with examples.
1. alert()
Definition
alert() displays a message box with an OK button.
It is used to show information or warnings to the user.
Syntax
alert("Message");
Example
alert("Welcome to JavaScript!");
Output:
A pop-up window appears with the message "Welcome to JavaScript!" and an OK button.
2. prompt()
Definition
prompt() displays a dialog box that asks the user to enter some input.
It has:
• A text box
• OK and Cancel buttons
Syntax
prompt("Message", "Default value");
Example
var name = prompt("Enter your name:");
alert("Hello " + name);
Output:
1. User sees a box: "Enter your name:"
2. User types a name
3. Another alert appears: "Hello (name)"
If user presses Cancel, the value becomes null.
3. confirm()
Definition
confirm() displays a dialog box asking the user to accept or reject something.
It has:
• OK (returns true)
• Cancel (returns false)
Syntax
confirm("Are you sure?");
Example
var choice = confirm("Do you want to delete this file?");
if (choice) {
alert("File deleted!");
} else {
alert("Action cancelled.");
Output:
If user clicks OK → "File deleted!"
If user clicks Cancel → "Action cancelled."
Summary Table
Function Purpose Buttons Returns
alert() Display a simple message OK Nothing
prompt() Get input from user OK / Cancel String / null
confirm() Ask user for confirmation OK / Cancel true / false
20. Write JS function to find maximum of three numbers.
21. Explain callback function in JavaScript with example.
Step 1: What is a Callback Function?
A callback function is simply:
A function that you pass to another function
So that the other function can call it later
JavaScript treats functions like values, so you can:
• store them in variables
• pass them as arguments
• return them from other functions
This makes callbacks possible.
Step 2: Why Do We Need Callbacks?
JavaScript runs code line by line, but some operations take time, such as:
• Waiting for a timer
• Loading data from a server
• Reading a file
• Waiting for a user to click a button
Callbacks help JavaScript say:
“Do this task, and when you're done… call this function.”
This is how JavaScript handles asynchronous behavior.
Step 3: First, a Simple Callback Example
function greet(name, afterGreeting) {
[Link]("Hello " + name);
afterGreeting();
function finish() {
[Link]("This is the callback function.");
greet("Bhumi", finish);
What happens here?
1. greet() runs
2. It prints "Hello Bhumi"
3. It then calls afterGreeting() → which is actually finish()
4. Output:
Hello Bhumi
This is the callback function.
Step 4: Callback With Anonymous Function
You can pass a function without a name:
greet("Bhumi", function() {
[Link]("Callback executed.");
});
This is very common in real JavaScript code.
Step 5: Callback in Asynchronous Code (Important!)
Let’s look at setTimeout() which runs code after a delay:
function work(message, callback) {
[Link]("Starting work...");
setTimeout(function() {
[Link](message);
callback(); // callback runs AFTER timeout
}, 2000);
work("Task completed!", function() {
[Link]("Callback executed after async task.");
});
Output:
Starting work...
(2 seconds pause)
Task completed!
Callback executed after async task.
This shows why callbacks are important—they help run code after a task that takes time.
Step 6: Real-Life Example (Easy Understanding)
Imagine:
• You order food → Main function
• Wait for it → Async operation
• After you get food → Callback function executes
The restaurant does not stop working while preparing your food.
Similarly, JavaScript doesn’t stop—it continues running other code.
22. Write JS to display prime numbers between 1–100.
23. Explain event handling in JavaScript.
What is Event Handling in JavaScript?
Event handling in JavaScript means detecting user actions (events) and responding to them with
functions (event handlers).
An event is any activity that happens in a webpage such as:
• Clicking a button
• Moving the mouse
• Typing in a textbox
• Submitting a form
• Loading the webpage
JavaScript allows us to capture these events and run code when the event occurs.
Common JavaScript Events
Event When it Occurs
onclick user clicks an element
onmouseover mouse pointer moves over an element
onmouseout mouse leaves an element
onkeyup key is released
Event When it Occurs
onkeydown key is pressed
onload page finished loading
onsubmit form is submitted
Ways to Handle Events in JavaScript
JavaScript provides three main ways to handle events:
1. Inline Event Handling (Inside HTML Tag)
<button onclick="showMessage()">Click Me</button>
<script>
function showMessage() {
alert("Button clicked!");
</script>
24. Explain types of JavaScript.
Types of JavaScript
In Web Development, “Types of JavaScript” usually refers to the ways JavaScript is used or included
in a webpage.
There are three main types:
1. Inline JavaScript
JavaScript code written inside an HTML tag using event attributes like onclick, onmouseover, etc.
Example
<button onclick="alert('Hello!')">Click Me</button>
• Easy to write
• Not suitable for large programs
2. Internal JavaScript
JavaScript code written inside the <script> tag within the HTML file itself, usually in the <head> or
<body>.
Example
<!DOCTYPE html>
<html>
<head>
<script>
function greet() {
alert("Welcome to JS");
</script>
</head>
<body>
<button onclick="greet()">Greet</button>
</body>
</html>
• Good for small/medium scripts
• Keeps JS and HTML together in one file
3. External JavaScript
JavaScript code written in a separate .js file and linked using the <script src=""> tag.
Example
HTML File
<script src="[Link]"></script>
[Link]
function hello() {
alert("This is External JavaScript!");
• Best practice
• Recommended for large projects
• Easy to maintain and reuse
Summary Table
Type Where it is written Example Best for
Inline JS Inside an HTML tag <button onclick=""> Very small tasks
Internal JS Inside <script> inside HTML <script>…</script> Medium projects
External JS Separate .js file <script src=""> Large websites
UNIT 4 – PHP BASICS
25. Explain PHP arrays with example.
PHP Arrays (With Description)
An array in PHP is a special data structure that allows you to store multiple values in a single
variable.
Each value in an array is stored with a key, which can be numeric or a string.
PHP supports three main types of arrays, each used for different purposes.
1. Indexed Array
Description
• Indexed arrays use numeric keys (0, 1, 2, …).
• Used when you want to store a list of items in order.
• PHP automatically assigns index numbers starting from 0.
Example
<?php
$colors = array("Red", "Green", "Blue");
// Accessing elements
echo $colors[0]; // Red
echo $colors[1]; // Green
echo $colors[2]; // Blue
?>
Output
Red
Green
Blue
2. Associative Array
Description
• Associative arrays use string keys instead of numbers.
• Useful when you want to store data in key–value format.
• Makes the array easier to understand and access.
Example
<?php
$age = array(
"Riya" => 20,
"Amit" => 22,
"Bhumi" => 19
);
echo "Amit's age is " . $age["Amit"];
?>
Output
Amit's age is 22
3. Multidimensional Array
Description
• Contains one or more arrays inside another array.
• Used for representing tables, records, or complex data.
• Accessed using multiple indexes.
Example
<?php
$students = array(
array("Riya", 20, "BCA"),
array("Amit", 22, "BSc"),
array("Bhumi", 19, "BBA")
);
// Accessing data
echo $students[0][0]; // Riya
echo $students[1][2]; // BSc
?>
Output
Riya
BSc
26. Explain browser detection in PHP with example.
Browser Detection in PHP
Browser detection means identifying which web browser (Chrome, Firefox, Safari, Edge, etc.) a user
is using to visit your website.
PHP can detect the browser on the server side by reading the User-Agent string sent by the browser.
PHP provides a built-in global variable:
$_SERVER['HTTP_USER_AGENT']
This variable contains information about:
• Browser name
• Browser version
• Operating system
• Device details
Why Browser Detection is Used?
Browser detection is useful for:
• Displaying browser-specific content
• Handling compatibility issues
• Redirecting mobile/desktop users
• Logging visitor browser information
Example 1: Display User Browser Information
<?php
$user_browser = $_SERVER['HTTP_USER_AGENT'];
echo "Your Browser Information: " . $user_browser;
?>
Output Example
Your Browser Information: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36
This is the browser’s User-Agent string.
Example 3: Using get_browser() Function (Advanced Method)
PHP also provides a function named get_browser(), but it requires a special configuration
([Link]), so it's less used.
<?php
$browser = get_browser(null, true);
print_r($browser);
?>
This gives detailed information such as:
• Browser name
• Version
• Platform
• JS support
• Cookies support
27. PHP program to store registration form data in MySQL (CRUD).
28. Write PHP code to find leap year.
29. Explain REST API creation using PHP.
REST API in PHP (Short 5–7 Mark Theory Answer)
REST (Representational State Transfer) is an architectural style used to build web services that
communicate over HTTP. A REST API treats data as resources which can be accessed using different
HTTP methods:
• GET – Read data
• POST – Insert new data
• PUT/PATCH – Update existing data
• DELETE – Remove data
In PHP, a REST API is created by writing PHP scripts that receive HTTP requests, process input,
interact with a database, and return output in JSON format.
To create a REST API in PHP, we use $_SERVER['REQUEST_METHOD'] to detect the request type.
For example:
• if ($_SERVER['REQUEST_METHOD'] == 'GET') → fetch data
• if ($_SERVER['REQUEST_METHOD'] == 'POST') → add data
• if ($_SERVER['REQUEST_METHOD'] == 'PUT') → update data
• if ($_SERVER['REQUEST_METHOD'] == 'DELETE') → delete data
Basic Steps to Create REST API in PHP
1. Create Database & Table (for real project – optional in exam)
2. Create a PHP file, e.g., [Link]
3. Check HTTP method using $_SERVER['REQUEST_METHOD']
4. Perform action based on method (GET/POST/PUT/DELETE)
5. Return data as JSON using json_encode()
30. Explain PHP string handling functions with examples.
PHP String Handling Functions (With Examples)
PHP provides many built-in functions to work with strings such as searching, replacing, converting
case, splitting, counting length, etc.
Below are the most important string functions commonly asked in exams.
1. strlen() – Find Length of String
Description:
Returns the number of characters in a string.
Example
<?php
$str = "Hello World";
echo strlen($str);
?>
Output:
11
2. strtoupper() – Convert to Uppercase
Description:
Converts all characters to uppercase.
Example
<?php
echo strtoupper("hello php");
?>
Output:
HELLO PHP
3. strtolower() – Convert to Lowercase
Description:
Converts all characters to lowercase.
Example
<?php
echo strtolower("WELCOME");
?>
Output:
welcome
4. substr() – Extract Part of a String
Description:
Extracts a portion of a string.
Example
<?php
echo substr("Hello World", 0, 5);
?>
Output:
Hello
5. str_replace() – Replace Characters
Description:
Replaces a word or character with another.
Example
<?php
echo str_replace("World", "PHP", "Hello World");
?>
Output:
Hello PHP
31. Explain file upload in PHP.
File Upload in PHP
PHP provides built-in support to upload files from an HTML form to the server.
File uploading is mainly done using:
• HTML <form enctype="multipart/form-data">
• PHP superglobal $_FILES
• PHP function move_uploaded_file()
Steps for File Upload
1. Create an HTML form
• Must use POST method
• Must use enctype="multipart/form-data"
• Must use <input type="file">
2. Handle uploaded file in PHP
• PHP stores uploaded file info in $_FILES array
• Temporary file is created in server
• Use move_uploaded_file() to save file permanently
Important $_FILES Elements
Key Description
$_FILES['file']['name'] Original filename
$_FILES['file']['type'] File type (image/jpeg etc.)
$_FILES['file']['size'] File size
$_FILES['file']['tmp_name'] Temporary storage path
$_FILES['file']['error'] Error status
Simple File Upload Example (HTML + PHP)
32. What is exception handling in PHP? Explain.
What is Exception Handling in PHP?
Exception handling in PHP is a mechanism used to handle runtime errors in a controlled manner.
Instead of stopping the program when an error occurs, PHP allows you to:
• Detect the error
• Catch the error
• Display a custom message
• Continue the script safely
PHP uses:
• try
• throw
• catch
• (optional) finally
to handle exceptions.
Why Exception Handling is Needed?
Without exception handling:
• Program stops immediately when an error occurs
• User sees an error message
• Program becomes unreliable
With exception handling:
• Program continues running
• Custom error messages
• Cleaner and safer code
Keywords Used in PHP Exception Handling
Keyword Meaning
try Code that may generate an exception
throw Throws an exception manually
catch Handles the thrown exception
finally Code that runs always (optional)
UNIT 5 – SESSION MANAGEMENT
33. Differentiate between Cookie and Session.
Cookie Session
Stored on client-side (browser). Stored on server-side.
Data is saved in the user’s computer. Data is stored in server memory.
Less secure (user can modify/view cookies). More secure (user cannot access session data).
Can store only small amounts of data (4KB). Can store larger amounts of data.
Slower because browser sends cookies in
Faster because only session ID is sent.
every request.
Session data is destroyed when the browser is closed
Cookie remains until it expires or is deleted.
or session ends.
Used for long-term storage (e.g., remember
Used for short-term storage (e.g., login validation).
me).
Created using setcookie() function. Created using session_start() function.
Stored in text files on the browser. Stored on server in temporary files or memory.
Not suitable for sensitive data. Suitable for sensitive and secure data.
34. Define Hidden Fields and Query Strings.
Hidden Fields
Definition:
Hidden fields are form elements in HTML that store data without showing it to the user.
They are used to pass information from one page to another silently, through an HTML form.
Hidden fields use:
<input type="hidden" name="username" value="Bhumi">
Uses:
• Storing user ID
• Passing data during form submission
• Maintaining state (page navigation)
• Shopping cart data
Important Points:
• Not visible to the user
• Can be viewed/modified using browser inspection
• Used in post-back forms
Query Strings
Definition:
A query string is a way to pass data through the URL using the ? and & symbols.
It is visible in the browser’s address bar.
Example URL:
[Link]/[Link]?name=Riya&age=20
• name=Riya
• age=20
PHP reads query strings using:
$_GET['name'];
$_GET['age'];
Uses:
• Passing small data between pages
• Search keywords
• Page filters (category=mobile)
• Pagination (page=2)
Important Points:
• Visible to user
• Less secure
• Limited length
• Works only with GET method
Short Difference
Hidden Field Query String
Data passed using a hidden form input Data passed in the browser URL
Not visible to the user Visible in address bar
Hidden Field Query String
Uses POST method Uses GET method
More secure than query strings Less secure
Not suitable for bookmarking Allows bookmarking
35. Need of session management.
Why Session Management is Needed?
1. Maintain User State
Since HTTP does not remember users, sessions help keep track of:
• Login status
• User identity
• Preferences
Example: Once a user logs in, session keeps them logged in across pages.
2. Store Temporary Data
Sessions store small data temporarily while the user is active.
Example:
• Shopping cart
• Answers in online exam
• Selected items in a form
3. Enhance Security
Session data is stored on the server, making it safer than cookies.
Used for:
• Authenticating users
• Preventing unauthorized access
• Secure transactions
4. Personalization
Session tracks:
• Theme selected
• Language preference
• Items viewed
Used for customizing user experience.
5. Track User Interaction
Useful in:
• Shopping websites
• Banking systems
• Portals and dashboards
It ensures every page request belongs to the same user.
Exam-Friendly Definition
“Session management is required because HTTP is stateless. It helps maintain user information
across multiple webpage requests, stores temporary data securely on the server, and allows
features like login systems, shopping carts, and personalized user experiences.”
36. How hidden fields maintain session? Explain.
How Hidden Fields Maintain Session
HTTP is a stateless protocol, meaning it does not remember any user information between page
requests.
To maintain user state across multiple pages, we can use Hidden Fields.
A hidden field is an HTML form element that stores data without showing it to the user:
<input type="hidden" name="userid" value="101">
When the form is submitted, this data is automatically sent to the next page.
How It Maintains Session
✔ 1. Hidden fields store user information temporarily
Data such as:
• User ID
• Username
• Selected values
• Session tokens
is stored in hidden fields.
✔ 2. Data travels from one page to another
When the form is submitted, hidden field values are sent using POST method.
Example submission:
userid = 101
The next page retrieves it using:
$user = $_POST['userid'];
✔ 3. Every page gets the same user data
Each page includes the hidden field again, passing data forward:
<input type="hidden" name="userid" value="<?php echo $user; ?>">
Thus, the user’s identity is preserved across multiple pages, similar to a session.
Example (Simple Flow)
Page 1: [Link]
<form action="[Link]" method="post">
<input type="text" name="name">
<input type="hidden" name="userid" value="101">
<input type="submit">
</form>
Page 2: [Link]
<?php
$uid = $_POST['userid'];
echo "Welcome User ID: " . $uid;
?>
The value 101 is passed silently, maintaining the user’s session.
Advantages of Using Hidden Fields for Session
• Works even when cookies are disabled
• Simple to implement
• Good for wizard forms (multi-step forms)
Limitations
• User can view/modify the value using browser tools → not secure
• Works only with POST forms
• Cannot maintain session if user does not submit a form
Exam-Friendly Definition
“Hidden fields maintain session by storing user data inside invisible form fields and sending the
data from one page to another through form submission. Each request passes the hidden values
forward, allowing the application to remember the user without using cookies or server-side
sessions.”
UNIT 6 – DATABASE CONNECTIVITY
37. Write PHP program for database connectivity and CRUD operations.
38. Write PHP code to insert, update, delete data from MySQL.
39. REST API in PHP to fetch user details as JSON.
UNIT 7 – JQUERY / AJAX
40. Explain AJAX with advantages and limitations.
What is AJAX?
AJAX (Asynchronous JavaScript and XML) is a web development technique used to send and receive
data from the server without reloading the entire webpage.
AJAX allows a webpage to update only a part of the page, making web applications:
• Faster
• More interactive
• More user-friendly
AJAX uses a combination of:
• JavaScript → to send request
• XMLHttpRequest / fetch API → to communicate with server
• Server-side languages (PHP, etc.) → to process request
• JSON or XML → to exchange data
How AJAX Works (Simple Explanation)
1. User performs an action (e.g., typing, clicking a button).
2. JavaScript creates an AJAX request.
3. Request goes to the server in the background.
4. Server processes it and sends back data.
5. JavaScript updates part of the page without refreshing.
Simple AJAX Example
JavaScript:
var xhttp = new XMLHttpRequest();
[Link] = function() {
[Link]("result").innerHTML = [Link];
[Link]("GET", "[Link]", true);
[Link]();
HTML:
<button onclick="loadData()">Load Data</button>
<div id="result"></div>
PHP ([Link]):
echo "Hello from server!";
This updates only the <div> content, not the entire page.
Advantages of AJAX
1. No full page reload
Only required data is updated → improves speed.
2. Faster response
Less data transferred, quicker interactions.
3. Better user experience
Feels like desktop apps (smooth interaction).
4. Reduces server load
Only small requests are sent.
5. Asynchronous processing
User can continue using the page while data loads.
6. Partial page updates
Useful for:
• Search suggestions
• Live form validation
• Live chat
• Auto-refresh dashboards
Limitations of AJAX
1. Depends on JavaScript
If JS is disabled in browser → AJAX won’t work.
2. Not SEO-friendly
Search engines may not read content loaded via AJAX.
3. Security issues
AJAX applications are vulnerable to:
• XSS
• CSRF
• Data exposure
4. Browser compatibility issues
Older browsers may not support modern AJAX features.
5. Difficult debugging
Asynchronous nature makes it harder to trace errors.
6. Cannot update browser URL
Content changes without URL changes (unless using history API).
Exam-Friendly Definition
“AJAX stands for Asynchronous JavaScript and XML. It is a technique used to send and receive data
from the server without reloading the entire page. AJAX improves performance, speed, and user
experience by updating only specific parts of a webpage.”
41. Explain benefits of jQuery.
Benefits of jQuery
jQuery is a lightweight, fast, and easy-to-use JavaScript library that simplifies client-side scripting.
Its main purpose is to make JavaScript coding simpler and shorter.
Below are the major benefits:
1. Simplifies JavaScript Coding
jQuery reduces long JavaScript code into just a few lines.
Example:
// JavaScript
[Link]("box").[Link] = "none";
// jQuery
$("#box").hide();
2. Cross-Browser Compatibility
jQuery works the same in all major browsers:
• Chrome
• Firefox
• Safari
• Edge
• Opera
So developers do not worry about browser issues.
3. Built-in Effects and Animations
jQuery provides ready-made effects:
• hide()
• show()
• fadeIn()
• fadeOut()
• slideUp()
• slideDown()
These make UI interactive easily.
4. Easy DOM Manipulation
jQuery makes selecting and changing HTML elements very easy.
Examples:
$("#title").text("Hello");
$(".box").css("color", "red");
5. Simplifies AJAX Calls
AJAX requests become very simple using jQuery.
Example:
$.get("[Link]", function(response){
$("#result").html(response);
});
6. Large Library of Plugins
Thousands of free jQuery plugins exist for:
• Image sliders
• Form validation
• Animation
• Data tables
• UI components
Developers can add powerful features quickly.
7. Lightweight and Fast
The jQuery library file is small and loads quickly.
It improves website performance.
8. Chainable Functions
Multiple functions can be applied in a single line.
Example:
$("#box").slideDown().css("color", "blue").fadeOut();
9. Easy Event Handling
Events like click, keypress, hover are very easy.
Example:
$("#btn").click(function(){
alert("Button clicked!");
});
10. Easy Learning Curve
jQuery is simple, short, and beginner-friendly.
Even non-experts can learn and use it quickly.
Exam-Friendly Summary
“jQuery is a fast and lightweight JavaScript library that simplifies DOM manipulation, event
handling, effects, animations, and AJAX. It offers cross-browser compatibility, a large plugin library,
easy coding syntax, and improved website performance.”
42. Create an image slider using jQuery.
43. Create dropdown using jQuery.
44. Using jQuery validate a form.
45. Explain difference between AJAX and jQuery.
AJAX jQuery
AJAX stands for Asynchronous JavaScript and XML. jQuery is a JavaScript library.
AJAX is a technique used to send and receive data jQuery provides easy methods, including
without reloading the page. simplified AJAX functions.
Pure AJAX requires more code (XMLHttpRequest
jQuery reduces AJAX code to very few lines.
object).
Written using JavaScript syntax + jQuery
Written using JavaScript only.
functions.
Harder to write and manage. Easier, shorter, and more readable.
AJAX example: [Link]("GET", "[Link]", jQuery example: $.get("[Link]",
true); function(data){ });
Has DOM manipulation, events, animations,
No animations, effects, selectors.
selectors, plus AJAX.
Create a registration form using JavaScript on one click of the button. Make use of at least following
functions: createElement(), appendChild(), setAttribute(). gave easy, short and understanding for 7
marks in gtu
Using java script create a simple calculator for addition, subtraction, multiplication and division
operation. Gave easy and understanding and short for 4 marks in gtu
ChatGPT said:
Here is a short, easy, and perfect 4-marks GTU answer for a JavaScript simple calculator (Add,
Subtract, Multiply, Divide).
JavaScript Simple Calculator (4 Marks)
Create your resume using HTML (Suggested sections of resume are Personal Information, Educational
Information, Professional Skills, Experience, Achievements, Hobbies), Experiment with text, colors,
link and other html tags that you studied.
PREDICTED QUESTIONS FOR SUMMER 2025
(Based on last 8 GTU papers)
3 MARK QUESTIONS (Very High Chances)
Unit 1 – Basics
1. Explain HTTP Request and Response.
2. What is CORS?
3. What is SEO?
4. Explain web security.
5. Discuss basic structure of HTML.
Unit 2 – HTML & CSS
6. What are the types of CSS?
7. What is Internal CSS?
8. Explain padding and margin.
9. What are HTML lists?
Unit 3 – JavaScript
10. Explain alert, prompt, and confirm boxes.
11. What is a callback function?
12. Define JSON with example.
13. What is DOM?
Unit 4 – PHP
14. What are PHP arrays?
15. What is browser detection in PHP?
16. What is exception handling?
17. Define GET and POST.
Unit 5 / 7
18. What is AJAX?
19. What is jQuery?
20. What are cookies?
4 MARK QUESTIONS (Most Repeated in GTU)
Unit 1
1. Draw and explain architecture of a web browser.
2. Explain HTTP methods and headers.
Unit 2 – HTML & CSS
3. Explain list properties in CSS with examples.
4. Explain pseudo-class selectors with examples.
5. Explain CSS variables.
6. Explain Bootstrap framework.
Unit 3 – JavaScript
7. Different types of JavaScript.
8. Event handling in JavaScript.
9. Explain JavaScript regular expressions.
10. Explain callback & function as argument in JS.
Unit 4 – PHP
11. Explain any four PHP array functions.
12. Explain string handling functions in PHP.
13. Explain file upload process in PHP.
14. Explain OOP concepts in PHP (Constructor, Objects).
Unit 5 – Session & State
15. Differentiate cookie and session.
16. Explain query string and hidden field.
Unit 7 – jQuery / AJAX
17. List benefits of jQuery.
18. Explain limitations of AJAX.
19. How does jQuery plugin work?
7 MARK QUESTIONS (MOST LIKELY)
These 10 questions appear every single year in GTU papers.
HTML / CSS (Unit 2)
1. Create an HTML form for student/employer registration with all HTML controls.
2. Create a timetable using table tag (with CSS formatting).
3. Explain CSS Box Model with diagram and code example.
4. Explain CSS selectors (ID, class, attribute, pseudo-class) with examples.
JavaScript (Unit 3)
5. Write JavaScript to validate email using Regular Expression.
6. Write JS function to find maximum of three values entered by user.
7. Write JS to display all prime numbers between 1 to 100.
8. Explain DOM and show different ways to access HTML elements using DOM.
PHP + Database (Unit 4 + 6)
9. Write PHP program for database connectivity and CRUD operations.
10. Create PHP REST API to display user details from database in JSON format.
jQuery / AJAX (Unit 7)
11. Create an image slider using jQuery.
12. Validate a registration form using jQuery.
13. Explain AJAX and jQuery with proper example.
BONUS: MOST LIKELY 3 QUESTIONS (SUPER IMPORTANT)
These have 95% chance of appearing:
• HTML Form + CSS styling
• JavaScript validation (email/prime/DOM)
• PHP CRUD / PHP + MySQL connectivity