Web programming
[End-sem 2024-25]
1. Explain the structure of an HTML document with a neat diagram.
Ans :-
1. HTML is used to create web pages.
2. Every HTML file starts with <!DOCTYPE html>.
3. The main tag is <html>.
4. Inside <html>, there are <head> and <body>.
5. <head> has meta info, title, and links to CSS/JS.
6. <title> sets the name in the browser tab.
7. <body> has all the visible content.
8. You can put headings, text, images, and links in <body>.
9. Tags are written in pairs: opening and closing.
10. Tags can be nested inside each other.
11. Indent your code to make it neat.
12. HTML is not case-sensitive.
13. Comments can be added with <!-- comment -->.
14. The structure helps browsers show the page correctly.
15. Diagram:
xml
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Welcome</h1>
<p>This is a paragraph.</p>
</body>
</html>
2. Explain the concept and uses of semantic tags in HTML5. Provide
examples.
Ans :-
1. Semantic tags show the meaning of each part.
2. They make code easy to read.
3. Help search engines understand the page.
4. <header> is for the top part (logo, title).
5. <nav> is for menus or navigation links.
6. <main> is for the main content.
7. <section> is for different sections.
8. <article> is for blog posts or news stories.
9. <aside> is for side content (ads, tips).
10. <footer> is for the bottom part (copyright).
11. <figure> is for images or charts.
12. <figcaption> is for the caption of a figure.
13. Semantic tags are better than just using <div>.
14. They help people using screen readers.
15. Example:
xml
<header>My Blog</header>
<nav>Home | About</nav>
<main>
<article>
<h2>Post Title</h2>
<p>Post content...</p>
</article>
</main>
<footer>© 2025 My Blog</footer>
3. Discuss various types of lists in HTML with examples and appropriate
tables.
Ans :-
1. Lists help organize items.
2. Ordered List (<ol>): Numbered list.
3. Unordered List (<ul>): Bulleted list.
4. Definition List (<dl>): Terms and meanings.
5. <li> is for each item in <ol> and <ul>.
6. <dt> is the term, <dd> is the meaning in <dl>.
7. Lists can be nested (lists inside lists).
8. Ordered lists are for steps or instructions.
9. Unordered lists are for menus or features.
10. Definition lists are for glossaries.
11. Lists are easy to style with CSS.
12. Lists make info easy to read.
13. Lists can be vertical or horizontal.
14. Lists help with navigation bars.
15. Table and Example:
Type Tag Example
Ordered <ol> 1. Apple 2. Banana
Unordered <ul> - Apple - Banana
Definition <dl> HTML: Markup Language
xml
<ol>
<li>Step 1</li>
<li>Step 2</li>
</ol>
<ul>
<li>Item A</li>
<li>Item B</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
</dl>
4. Explain different types of CSS (Inline, Internal, External) with syntax and
examples.
Ans :-
1. CSS styles your web page.
2. Inline CSS: Style inside the HTML tag.
3. Internal CSS: Style in a <style> tag in <head>.
4. External CSS: Style in a separate file.
5. Inline CSS is for quick, small changes.
6. Internal CSS is for one page only.
7. External CSS is best for many pages.
8. Inline CSS uses the style attribute.
9. Internal CSS uses <style>.
10. External CSS uses <link rel="stylesheet" href="style.css">.
11. Inline CSS is strongest.
12. External CSS keeps code cleaner.
13. CSS can change color, size, and layout.
14. You can use all three types together.
15. Example:
xml
<p style="color: red;">Inline CSS</p>
<style>
p { color: blue; }
</style>
<link rel="stylesheet" href="style.css">
5. What is the Box Model in CSS? Explain with diagram and code
example.
Ans :-
1. Every element is a box.
2. The box has four parts.
3. Content: The text or image.
4. Padding: Space around the content.
5. Border: Line around the padding.
6. Margin: Space outside the border.
7. Margin separates elements.
8. Padding adds space inside the box.
9. Borders can be colored and styled.
10. You can set top, right, bottom, left separately.
11. Box model helps with layouts.
12. You can use box-sizing to include padding/border in width.
13. Helps make responsive designs.
14. Easy to control spacing.
15. Diagram and Code:
Text:
[Margin]
[Border]
[Padding]
[Content]
css
div {
margin: 10px;
border: 2px solid black;
padding: 20px;
width: 200px;
}
6. Differentiate between ID and Class selectors with examples.
Ans :-
1. ID is unique, used for one element.
2. Class can be used for many elements.
3. ID uses # in CSS.
4. Class uses . in CSS.
5. IDs are for special items.
6. Classes are for groups.
7. IDs are used in JavaScript.
8. Classes are for styling.
9. Only one element can have each ID.
10. Many elements can share a class.
11. IDs are stronger in CSS.
12. Use class for repeated styles.
13. Use ID for unique things like banners.
14. IDs help with page links.
15. Example:
xml
<div id="header">Header</div>
<div class="menu">Menu 1</div>
<div class="menu">Menu 2</div>
css
#header { color: red; }
.menu { color: blue; }
7. Explain JavaScript variable scoping (var, let, const) with examples and
comparison table.
Ans :-
1. Variables store data.
2. var is function-scoped.
3. let is block-scoped.
4. const is block-scoped and cannot change.
5. var can be used anywhere in the function.
6. let and const work only inside {}.
7. var can be redeclared.
8. let cannot be redeclared in the same block.
9. const cannot be redeclared or changed.
10. Use let for changing values.
11. Use const for fixed values.
12. var is old, not used much now.
13. Use meaningful names for variables.
14. Helps avoid bugs.
15. Table and Example:
Keyword Scope Redeclare Reassign
var Function Yes Yes
let Block No Yes
const Block No No
js
var x = 10;
let y = 20;
const z = 30;
8. Differentiate between synchronous and asynchronous JavaScript with
examples.
Ans :-
1. Synchronous: Runs one line at a time.
2. Waits for each step to finish.
3. Easy to understand.
4. Can be slow if something takes time.
5. Asynchronous: Can run in the background.
6. Does not wait for slow tasks.
7. Good for loading data or waiting for clicks.
8. Uses callbacks, promises, or async/await.
9. Makes pages faster.
10. Used for network requests.
11. Used for timers.
12. Stops the page from freezing.
13. Used in modern web apps.
14. Can be tricky to debug.
15. Example:
js
// Synchronous
alert("Hello");
console.log("World");
// Asynchronous
setTimeout(() => { console.log("World"); }, 1000);
console.log("Hello");
9. Explain DOM manipulation with examples and diagram.
Ans :-
1. DOM means Document Object Model.
2. It is a tree of all HTML elements.
3. JavaScript can change the DOM.
4. Use getElementById to select elements.
5. Use innerHTML to change content.
6. Use .style to change CSS.
7. Can add new elements.
8. Can remove elements.
9. Can change attributes like src or href.
10. Makes pages interactive.
11. Used for form validation.
12. Used for dynamic menus.
13. Used for animations.
14. Updates happen instantly.
15. Diagram and Example:
text
<body>
<div id="demo">Text</div>
</body>
js
document.getElementById("demo").innerHTML = "Hello!";
10.What are JavaScript events? Explain event handling with examples.
Ans :-
1. Events are actions like clicks or key presses.
2. Event handling means running code when an event happens.
3. Use onclick in HTML.
4. Use addEventListener in JavaScript.
5. Common events: click, mouseover, keydown, submit.
6. Makes pages interactive.
7. Can show messages on click.
8. Can change colors on hover.
9. Can check forms before submitting.
10. Can load new data without refreshing.
11. Can stop default actions.
12. Can add many handlers to one element.
13. Used in games and apps.
14. Helps with user experience.
15. Example:
xml
<button onclick="alert('Clicked!')">Click Me</button>
js
document.getElementById("btn").addEventListener("click", function() {
alert("Clicked!");
});
11.Explain JSON and its uses in JavaScript with examples.
Ans :-
1. JSON means JavaScript Object Notation.
2. It is a way to store and send data.
3. Looks like a JavaScript object.
4. Used to send data from server to browser.
5. Easy to read and write.
6. Uses key-value pairs.
7. Can store arrays and objects.
8. Used in APIs and web services.
9. JSON.stringify() turns object into JSON string.
10. JSON.parse() turns JSON string into object.
11. Used for saving data in browser.
12. Used in AJAX requests.
13. Fast and lightweight.
14. Used in almost every web app.
15. Example:
js
let obj = { name: "John", age: 25 };
let jsonString = JSON.stringify(obj);
let newObj = JSON.parse(jsonString);
12.Explain error handling (try-catch-finally) in JavaScript with example.
Ans :-
1. Errors can happen in code.
2. try block is for code that might fail.
3. catch runs if there is an error.
4. finally always runs, error or not.
5. Stops the program from crashing.
6. Makes debugging easier.
7. Can show friendly error messages.
8. Can log errors for fixing.
9. catch gets details about the error.
10. finally is good for cleanup.
11. Used in network requests.
12. Used in file operations.
13. Can nest try-catch blocks.
14. Good for safe coding.
15. Example:
js
try {
let x = y + 1; // y is not defined
} catch (error) {
alert("Error happened!");
} finally {
alert("Done!");
}
13.Explain OOP principles (Inheritance, Encapsulation, Polymorphism,
Abstraction) with diagrams.
Ans :-
1. OOP means Object-Oriented Programming.
2. Uses objects and classes.
3. Inheritance: Child gets features from parent.
4. Encapsulation: Hides data, uses methods to access.
5. Polymorphism: Same method, different behavior.
6. Abstraction: Shows only important details.
7. Makes code reusable.
8. Makes code easy to manage.
9. Helps in big projects.
10. Classes are blueprints for objects.
11. Objects have properties and methods.
12. Reduces code duplication.
13. Makes programs modular.
14. Encourages organized code.
15. Diagram and Example:
text
Animal (Parent)
|
Dog (Child)
java
class Animal {}
class Dog extends Animal {}
14.What is JDBC? Explain steps to connect Java with database using JDBC
with diagram.
Ans :-
1. DBC means Java Database Connectivity.
2. Lets Java talk to databases.
3. Used for storing and getting data.
4. Works with many databases.
5. Steps:
1. Import JDBC package.
2. Load JDBC driver.
3. Connect to database.
4. Create a statement.
5. Run SQL queries.
6. Get results.
7. Close connection.
6. Needs database URL, username, password.
7. Can do SELECT, INSERT, UPDATE, DELETE.
8. Returns data as ResultSet.
9. Can handle errors.
10. Used in big applications.
11. JDBC drivers are different for each database.
12. Can use PreparedStatement for safety.
13. Supports transactions.
14. Makes dynamic apps.
15. Diagram and Example:
text
Java Program -> JDBC Driver -> Database
java
Connection con = DriverManager.getConnection(url, user, pass);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM table");
15.Explain Java Collections framework with examples and diagrams.
Ans :-
1. Collections store groups of items.
2. Main types: List, Set, Map.
3. List: Ordered, allows repeats (e.g., ArrayList).
4. Set: No repeats (e.g., HashSet).
5. Map: Key-value pairs (e.g., HashMap).
6. Collections are flexible in size.
7. Part of java.util package.
8. Can hold any type of object.
9. Use generics for type safety.
10. Can sort and search data.
11. Can be made thread-safe.
12. Has helper methods (Collections class).
13. Used in almost all Java programs.
14. Makes data handling easy.
15. Diagram and Example:
text
Collection
|-- List
|-- Set
|-- Map
java
List<String> list = new ArrayList<>();
Set<Integer> set = new HashSet<>();
Map<Integer, String> map = new HashMap<>();
16.Explain the concept of packages and access specifiers in Java with
examples.
Ans :-
1. Package: Group of related classes.
2. Organizes code.
3. Avoids name conflicts.
4. Makes code reusable.
5. Use import to use packages.
6. Access Specifiers: Control who can use classes or methods.
7. Four types: public, private, protected, default.
8. public: Anyone can use.
9. private: Only in same class.
10. protected: Same package and subclasses.
11. default: Only in same package.
12. Good for security.
13. Helps in big projects.
14. Makes code modular.
15. Example:
java
package mypack;
public class MyClass {}
17.Explain serialization and deserialization in Java with code example.
Ans :-
1. Serialization: Change object to bytes.
2. Used to save object to file or send over network.
3. Deserialization: Change bytes back to object.
4. Class must use Serializable interface.
5. Saves object state.
6. Good for sending objects between computers.
7. Not all objects can be serialized.
8. Use transient to skip fields.
9. Can handle errors in process.
10. Used in caching and sessions.
11. Java uses ObjectOutputStream and ObjectInputStream.
12. Can encrypt data for safety.
13. Good for deep copying.
14. Used in distributed systems.
15. Example:
java
// Serialization
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("file"));
out.writeObject(obj);
// Deserialization
ObjectInputStream in = new ObjectInputStream(new FileInputStream("file"));
MyClass obj = (MyClass) in.readObject();