Describe the Three-Tier Architecture of a Web Application
Answer:
The three-tier architecture divides a web application into three layers:
1. Presentation Tier: This is the user interface, usually a web browser or mobile app, where
users interact with the system. It displays information and sends user requests to the server.
2. Logic Tier (Application Tier): This layer processes the user requests. It contains the business
logic, rules, and decision-making part of the application.
3. Data Tier: This layer is responsible for data storage and management. It consists of databases
where data is saved and retrieved.
This architecture improves performance, security, and allows easier maintenance and scalability.
3. What is the Use of the <textarea> Tag in HTML?
Answer:
The <textarea> tag in HTML is used to create a multi-line text input area within a web form. Unlike
the <input> tag which accepts only single-line input, <textarea> allows users to write longer text such
as comments, feedback, or messages. It supports attributes like rows and columns to control the size
of the text box.
4. Write the Basic Syntax to Create a Table in HTML
Answer:
The basic syntax for creating a table in HTML is:
html
CopyEdit
<table>
<tr> <!-- Table Row -->
<th>Header1</th> <!-- Table Header -->
<th>Header2</th>
</tr>
<tr>
<td>Data1</td> <!-- Table Data -->
<td>Data2</td>
</tr>
</table>
<table> tag defines the table.
<tr> defines a table row.
<th> defines header cells (bold and centered).
<td> defines data cells.
This structure allows you to display data in rows and columns.
5. Explain the Purpose of document.getElementById() in JavaScript
Answer:
document.getElementById() is a JavaScript method used to select an HTML element by its unique id
attribute. Once selected, you can read or change the element’s content, style, or attributes. It helps
in dynamic interaction with the web page, such as updating text, showing or hiding elements, or
handling events.
Example:
javascript
CopyEdit
document.getElementById("demo").innerHTML = "Hello World!";
6. Differentiate Between HTTP and HTTPS
Answer:
Feature HTTP HTTPS
Full Form HyperText Transfer Protocol HyperText Transfer Protocol Secure
Security Not secure Secure with encryption (SSL/TLS)
Port 80 443
Data Encryption No encryption Encrypts data for privacy
Use Case General web browsing Secure transactions (banking, login)
Speed Faster (less overhead) Slightly slower (due to encryption)
HTTPS is more secure because it encrypts data between the browser and server, protecting against
eavesdropping and tampering.
7. Define JDBC and Write Basic JDBC Connection Code
Answer:
JDBC (Java Database Connectivity) is an API in Java that lets Java programs connect and interact with
databases. It allows sending SQL commands and retrieving results.
Basic JDBC Connection Code:
java
CopyEdit
import java.sql.*;
public class ConnectDB {
public static void main(String[] args) {
try {
// Load MySQL driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Connect to database
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root",
"password");
System.out.println("Connection successful!");
// Close connection
con.close();
} catch (Exception e) {
System.out.println(e);
8. Explain SMTP and HTTP Protocols
Answer:
SMTP (Simple Mail Transfer Protocol):
SMTP is used for sending emails from client to server or between mail servers. It handles the
email transfer and delivery.
HTTP (Hypertext Transfer Protocol):
HTTP is used for transferring web pages and resources from web servers to browsers. It
allows users to view websites.
Both are protocols that define rules for communication but are used for different purposes: SMTP for
email, HTTP for web pages.
9. Create an HTML Form with a Dropdown, Textarea, and Submit Button
Answer:
html
CopyEdit
<form>
<label for="color">Choose a color:</label>
<select id="color" name="color">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select><br><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4" cols="30"></textarea><br><br>
<input type="submit" value="Submit">
</form>
This form has:
Dropdown to select color
Multi-line textarea for message
Submit button to send data
10. Write an HTML + JS Code to Show an Alert on Button Click
Answer:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>Alert Example</title>
</head>
<body>
<button onclick="showAlert()">Click me</button>
<script>
function showAlert() {
alert("Button clicked!");
</script>
</body>
</html>
When the button is clicked, the showAlert() function runs and shows an alert message.
Web Architecture
Web architecture is the overall design and structure of a web-based system that explains how
different components interact to deliver web content and services. It defines the flow of data
and communication between the user’s device (client), web servers, and databases.
Key Components of Web Architecture:
1. Client (User Agent):
This is usually a web browser or mobile app that sends requests to the web server and
displays the received web pages to the user.
2. Web Server:
The server receives requests from clients, processes them, and sends back responses
(like HTML pages, images, or data). It handles the logic for serving web content.
3. Database Server:
This stores the data used by web applications, such as user information, product
details, or posts. The web server communicates with the database server to retrieve or
store data.
4. Protocols:
Communication between clients and servers happens using standard protocols like
HTTP (Hypertext Transfer Protocol), which defines how requests and responses
are formatted.
Types of Web Architecture:
Single-tier: Client and server are on the same machine (rare).
Two-tier: Client and server communicate directly.
Three-tier: Adds a middle layer (application server) to separate user interface,
business logic, and data storage. This is common in modern web apps
. Explain the Architecture of the World Wide Web
Answer:
The World Wide Web (WWW) is a system that allows users to access and share information over the
internet. Its architecture is mainly client-server based.
Client (Browser): Users use web browsers (like Chrome, Firefox) to request web pages by
entering URLs.
Web Server: The server hosts websites and responds to client requests by sending HTML
pages and resources.
HTTP Protocol: Communication between client and server happens through the HTTP
protocol which defines the format for requests and responses.
Resources: Web pages include HTML, CSS, JavaScript files, images, videos, and more.
URL: Each resource on the web is identified by a unique Uniform Resource Locator (URL).
Web Application Server (optional): For dynamic websites, the server runs applications to
generate pages dynamically, often accessing databases.
The architecture ensures that clients request data and servers respond, making the web a flexible,
scalable information system.
2. Describe the HTTP Request-Response Cycle with GET and POST Methods
Answer:
The HTTP request-response cycle is the process where a client (browser) sends a request to a server,
and the server sends back a response.
GET Method:
o Used to request data from a server.
o The request includes parameters in the URL (query string).
o Data is visible in the URL and limited in length.
o Example: Loading a webpage or fetching data.
POST Method:
o Used to send data to the server to create/update resources.
o Data is sent in the request body, not visible in the URL.
o Used for forms, uploading files, etc.
Cycle Steps:
1. Client sends HTTP request (GET or POST) to the server.
2. Server processes the request.
3. Server sends an HTTP response with status code and data.
4. Client receives response and renders content.
3. Discuss the Pull and Push Communication Mechanisms on the Web
Answer:
Pull Mechanism:
o The client requests data from the server when needed.
o Example: Refreshing a webpage or clicking a link to get updated content.
o It is user-initiated and happens intermittently.
Push Mechanism:
o The server sends data to the client without the client requesting it each time.
o Example: Notifications, live chat updates, or real-time feeds.
o It provides instant updates without user action.
Both mechanisms help in delivering content effectively: pull for user control and push for real-time
updates.
4. Explain the CSS Box Model with a Diagram and Describe Each Component
Answer:
The CSS Box Model is a box that wraps around HTML elements, defining their size and spacing.
sql
CopyEdit
+-----------------------+
| Margin | ← Space outside the border, clears area around the element.
| +-----------------+ |
| | Border | ← Edge around padding and content.
| | +-----------+ | |
| | | Padding | | ← Space between content and border.
| | | +-----+ | | |
| | | |Content| | | ← Actual content of the element (text, images).
| | | +-----+ | | |
| | +-----------+ | |
| +-----------------+ |
+-----------------------+
Content: Text or images inside the element.
Padding: Space between content and border.
Border: Surrounds padding and content.
Margin: Space outside the border, separates element from others.
5. Create an HTML Page Styled with CSS for a Navigation Bar with Hover Effects
Answer:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
.navbar {
background-color: #333;
overflow: hidden;
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
.navbar a:hover {
background-color: #ddd;
color: black;
</style>
</head>
<body>
<div class="navbar">
<a href="#home">Home</a>
<a href="#services">Services</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
</body>
</html>
Write a JavaScript Event Handler Example Using a Button Click
Answer:
JavaScript event handlers run code when an event happens, like clicking a button.
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>Button Click Example</title>
</head>
<body>
<button id="myButton">Click Me!</button>
<script>
// Get button element by ID
const button = document.getElementById('myButton');
// Add click event listener
button.addEventListener('click', function() {
alert('Button was clicked!');
});
</script>
</body>
</html>
Explanation:
When the user clicks the button, an alert box appears saying "Button was clicked!".
This shows how event handlers listen for user actions and run JavaScript code.
7. Compare and Contrast Callbacks, Promises, and Async/Await in JavaScript
Feature Callbacks Promises Async/Await
Functions passed as Objects representing future Syntax built on promises to
Definition arguments to be completion or failure of an write async code like
executed later async operation synchronous code
Nested functions; can Uses async keyword and await
Syntax .then(), .catch() for chaining
cause "callback hell" inside functions
Error Harder to manage;
.catch() handles errors clearly Use try-catch blocks for errors
Handling error passed in callback
Can get complex and
Readability Easier than callbacks Most readable and clean code
hard to read
Older code and simple Modern async code, best for
Use Case Modern async tasks, chaining
async complex flows
8. Explain CRUD Operations Using JDBC with Examples
CRUD = Create, Read, Update, Delete - basic database operations.
java
CopyEdit
// Import JDBC packages
import java.sql.*;
public class JDBCExample {
public static void main(String[] args) throws Exception {
// 1. Load driver and connect
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user",
"password");
Statement stmt = con.createStatement();
// 2. Create - Insert data
stmt.executeUpdate("INSERT INTO students VALUES (1, 'John')");
// 3. Read - Select data
ResultSet rs = stmt.executeQuery("SELECT * FROM students");
while(rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
// 4. Update - Modify data
stmt.executeUpdate("UPDATE students SET name='Johnny' WHERE id=1");
// 5. Delete - Remove data
stmt.executeUpdate("DELETE FROM students WHERE id=1");
con.close();
}
}
Explanation:
This Java code connects to a MySQL database and performs all four CRUD operations.
9. Compare HTTP, HTTPS, and SMTP Protocols in Terms of Functionality and Security
Protocol Purpose Port Security Use Case
HTTP Transfer web pages 80 No encryption Browsing websites
Secure version of Secure web browsing,
HTTPS 443 Uses SSL/TLS for encryption
HTTP payments
Can use SSL/TLS for
SMTP Sending emails 25, 465 Email sending
security
HTTP is not secure; data is sent as plain text.
HTTPS encrypts data to protect privacy and prevent tampering.
SMTP handles sending emails, may use security extensions for safe email transfer.
10. Write a Node.js Express Application to Create a Server that Listens on Port 3000
javascript
CopyEdit
// Import express module
const express = require('express');
const app = express();
// Define a route handler for GET /
app.get('/', (req, res) => {
res.send('Hello, World!');
});
// Start the server and listen on port 3000
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Explanation:
This code creates a simple web server using Express.
When a user visits http://localhost:3000, they see "Hello, World!".
The server listens for connections on port 3000.
11. Explain the Structure and Purpose of an HTML Document. Describe <html>, <head>, and
<body> Tags
Answer:
An HTML document is a structured text file that browsers use to display web pages. It has three main
parts:
<html> tag:
The root element that contains the entire HTML document.
<head> tag:
Contains metadata about the document like title, links to stylesheets, scripts, and other
information not shown directly on the page.
<body> tag:
Contains the visible content of the page, such as text, images, links, and other elements the
user interacts with.
Basic structure:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Welcome to my website</h1>
<p>This is some content.</p>
</body>
</html>
Purpose:
The structure organizes content so browsers understand how to display the page.
The <head> controls important settings and resources, while <body> holds everything visible
12. Design a Student Registration Form Using HTML
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>Student Registration Form</title>
</head>
<body>
<h2>Student Registration</h2>
<form action="/submit" method="post">
<label for="fullname">Full Name:</label><br>
<input type="text" id="fullname" name="fullname" required><br><br>
<label for="rollno">Roll No:</label><br>
<input type="text" id="rollno" name="rollno" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="dob">Date of Birth:</label><br>
<input type="date" id="dob" name="dob" required><br><br>
<label for="department">Department:</label><br>
<select id="department" name="department" required>
<option value="">Select</option>
<option value="IT">Information Technology</option>
<option value="CSE">Computer Science</option>
<option value="ECE">Electronics</option>
</select><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
Explanation:
<form> tag defines the form and method/action attributes specify how and where data is
sent.
Input fields like text, email, date, and dropdown (select) collect user data.
Labels describe each field for clarity.
13. Describe Five Commonly Used HTML Tags with Purpose and Syntax
Tag Purpose Syntax Example
<p> Defines a paragraph <p>This is a paragraph.</p>
<a> Creates a hyperlink to another page <a href="https://example.com">Link</a>
<img> Displays an image <img src="image.jpg" alt="Description">
<div> Container for grouping elements <div>Content here</div>
<h1> to <h6> Headings, <h1> is the largest <h1>Heading 1</h1>
14. List and Explain Five Different Input Types in HTML Forms with Examples
Input Type Purpose Example
text Single line text input <input type="text" name="name">
email Input for email addresses <input type="email" name="email">
password Password field (hidden text) <input type="password" name="pass">
date Select date from calendar <input type="date" name="dob">
checkbox Select multiple options <input type="checkbox" name="agree">
15. Write an HTML Table with 3 Rows and 3 Columns and Explain Tags
html
CopyEdit
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>22</td>
<td>Delhi</td>
</tr>
<tr>
<td>Bob</td>
<td>24</td>
<td>Mumbai</td>
</tr>
</table>
Explanation:
<table> defines the table container.
<tr> defines a table row.
<th> defines a header cell (bold & centered).
<td> defines a data cell (normal text).
border="1" adds a simple border to the table.
16. Explain the Interaction Between Web Servers and Web Browsers in the Client-Server Model
Answer:
A web browser (client) requests web pages or resources by sending an HTTP request to a
web server.
The web server processes the request, fetches the requested data (like HTML, images,
scripts), and sends an HTTP response back to the browser.
The browser receives this response, interprets the data, and displays the web page to the
user.
This request-response cycle continues as the user interacts with the website.
Summary:
Client initiates requests.
Server responds with requested resources.
Communication happens over HTTP/HTTPS protocols.
17. Describe How DNS Resolves Domain Names to IP Addresses with an Example
Answer:
DNS (Domain Name System) translates easy-to-remember domain names (like
www.google.com) into IP addresses (like 142.250.190.4) which computers use to
communicate.
When a user types a URL, the browser sends a DNS query to a DNS resolver.
The resolver checks if it has the IP cached; if not, it queries root DNS servers → Top-Level
Domain (TLD) servers → Authoritative DNS servers until it finds the IP.
The IP address is returned to the browser, which then connects to the web server using that
IP.
Example:
Typing www.example.com in browser triggers DNS lookup → finds IP → browser connects to server
at that IP.
Short Note on Web Servers, SMTP, and DNS Protocols
Web Servers:
Web servers store and deliver web pages to users over the internet.
When a browser sends a request (HTTP/HTTPS), the web server processes it and sends back
the requested page or resource.
Examples: Apache, Nginx, Microsoft IIS.
SMTP (Simple Mail Transfer Protocol):
SMTP is used for sending emails across networks.
It handles the sending and forwarding of emails between mail servers and from client to
server.
Works on port 25 and is mainly for outgoing mail.
DNS (Domain Name System):
DNS translates domain names (like google.com) into IP addresses that computers use to
locate servers.
It works like the internet’s phonebook, making navigation easier.
DNS uses UDP port 53 for queries.
19. Concept and Use of DOM Manipulation Using JavaScript with Example
DOM (Document Object Model):
DOM represents the structure of an HTML document as a tree of objects (nodes).
JavaScript can access and change these objects to update content, style, or structure
dynamically.
Use:
Change text or images without reloading the page.
Add or remove HTML elements.
React to user actions like clicks or input.
Example:
html
CopyEdit
<p id="greeting">Hello!</p>
<button onclick="changeText()">Click me</button>
<script>
function changeText() {
document.getElementById('greeting').innerText = "Welcome to my website!";
</script>
When the button is clicked, the paragraph text changes.
20. Create a Web Page Using JavaScript That Displays a Welcome Message When a Button Is
Clicked
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>Welcome Message</title>
</head>
<body>
<button onclick="showMessage()">Click Here</button>
<p id="message"></p>
<script>
function showMessage() {
document.getElementById('message').innerText = "Welcome to our website!";
</script>
</body>
</html>
Explanation:
A button triggers the showMessage() function on click.
The function changes the paragraph’s text to show the welcome message.
This uses simple DOM manipulation in JavaScript.