0% found this document useful (0 votes)
7 views25 pages

Untitled Document

The document provides a comprehensive overview of web communication, HTML, CSS, JavaScript, and Java Servlets. It covers definitions, syntax, and examples related to client-server architecture, HTML tags, CSS properties, JavaScript functionalities, and servlet lifecycle. Key concepts include the use of semantic elements, the importance of validation, and the differences between various programming languages and methods.

Uploaded by

sec23cs159
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

Untitled Document

The document provides a comprehensive overview of web communication, HTML, CSS, JavaScript, and Java Servlets. It covers definitions, syntax, and examples related to client-server architecture, HTML tags, CSS properties, JavaScript functionalities, and servlet lifecycle. Key concepts include the use of semantic elements, the importance of validation, and the differences between various programming languages and methods.

Uploaded by

sec23cs159
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

✅ CO1

1. Define a client and a server in web communication.

In web communication, a client is a device or software application (such as a web


browser) that sends a request to access web resources like webpages, images, or
data. A server is a powerful computer that stores these resources and responds to
client requests by delivering the requested content. The interaction between the
client (request) and the server (response) forms the basis of the web’s client–server
architecture.

2. Write the HTML tag to insert an image.

The <img> tag is used to insert an image in HTML.​


Example: <img src="[Link]" alt="Sample Image">​
The src attribute specifies the image path and alt gives alternative text.

3. Which tag is used to create a table row in HTML?

The <tr> tag is used to define a row inside an HTML table. It groups one
horizontal set of table cells.

4. List any two types of CSS style sheets.

●​ Inline style sheet – styles written inside the HTML tag.


●​ Internal style sheet – styles placed within <style> inside <head>.
●​ External style sheet – styles written in a separate .css file. (any two)

5. State the purpose of the <header> element in HTML5.

The <header> element represents the introductory section of a webpage or a


section. It commonly contains headings, navigation menus, logos, and introductory
content. It improves the semantic structure of the webpage.
6. Name two semantic elements in HTML5.

Examples include: <article>, <section>, <nav>, <footer>, <aside>

7. Which CSS property is used to apply text color?

The color property is used to change the color of text in CSS.​


Example: color: blue;

8. Write the HTML5 tag used for embedding video.

The <video> tag is used to embed a video in HTML5.

9. Which attribute is used to make an element draggable in HTML5?

The draggable="true" attribute makes an element draggable.

10. Name two CSS3 properties used for creating animations.

●​ @keyframes, animation-name, animation-duration

11. Differentiate between inline CSS and external CSS.

Inline CSS is written inside the HTML element using the style attribute. It affects
only that particular element but increases code clutter.

External CSS is written in a separate .css file and linked using <link>. It promotes
clean structure and allows global styling across multiple webpages.

12. Explain the importance of semantic elements in HTML5.

Semantic elements add meaning to webpage structure. Tags like <header>, <nav>,
and <article> help browsers, search engines, and screen readers understand the
purpose of each section. They improve SEO, accessibility, and maintainability by
clearly defining the content’s role.
13. What is the role of rule cascading in CSS3?

Cascading determines which CSS rule is applied when multiple rules target the
same element. It follows three principles: specificity (priority of selectors),
importance (!important rules), and source order (later rules override earlier). This
ensures predictable and consistent styling.

14. Distinguish between <ul> and <ol> lists in HTML.

<ul> creates an unordered list with bullet points.​


<ol> creates an ordered list with automatic numbering or lettering.​
Both use <li> to define list items.

15. Why is inheritance important in CSS styling?

Inheritance allows certain properties (like font-family, color) to automatically flow


from parent elements to their children. This reduces repetition, saves time, and
ensures consistent styling across the webpage.

16. Explain the use of the <section> tag in HTML5.

The <section> element divides a webpage into thematic blocks such as chapters,
topics, or grouped content. It improves readability and provides meaningful
grouping for search engines and assistive technologies.

17. What is the purpose of border-image in CSS3?

The border-image property allows you to use an image instead of a traditional


border. The image can be sliced, stretched, or repeated around the element,
enabling attractive and customizable visual borders.

18. Differentiate between transitions and animations in CSS3.

Transitions allow smooth changes between two states, typically triggered by an


event like hover.​
Animations use keyframes to create multi-step, automatic movement or effects
without user actions. Animations are more flexible and complex than transitions.
19. Why is the World Wide Web called a client-server system?

Because browsers (clients) request web pages, and servers respond by sending
those pages over the internet. The communication always follows a request →
response model, which is the core of the WWW architecture.

20. Explain how the background-image property works in CSS3.

The background-image property sets an image as the background of an element. It


can be customized using:

●​ background-size (cover, contain)


●​ background-repeat (repeat, no-repeat)
●​ background-position (center, top)

This allows flexible and visually appealing layout designs.

21. Construct a simple HTML table with 2 rows and 3 columns.


<table border="1">
<tr>
<td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td>D</td><td>E</td><td>F</td>
</tr>
</table>

22. Develop an HTML code to insert an image with alternate text.


<img src="[Link]" alt="Flower Image">

23. Apply inline CSS to change the background color of a paragraph.


<p style="background-color: lightblue;">
This is a paragraph.
</p>
24. Develop an HTML5 form with text, password, and submit input elements.
<form>
Name: <input type="text"><br>
Password: <input type="password"><br>
<input type="submit" value="Login">
</form>

25. Construct HTML code to include an audio file with play controls.
<audio controls>
<source src="music.mp3" type="audio/mpeg">
</audio>

26. Apply CSS3 to transform a box by rotating it 45 degrees.


<div class="box"></div>
<style>
.box {
width: 100px;
height: 100px;
background: red;
transform: rotate(45deg);
}
</style>

27. Construct HTML code using <header>, <nav>, and semantic tags.
<header>
<h1>My Webpage</h1>
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
</nav>
<article>
<p>Welcome to my website!</p></article>
28. Develop a simple button with hover transition effects.
<button class="btn">Click Me</button>
<style>
.btn {
padding: 10px;
background: blue;
color: white;
transition: background 0.3s;
}
.btn:hover {
background: darkblue;
}
</style>

29. Develop a small CSS3 animation that moves a div from left to right.
<div class="move"></div>

<style>
.move {
width: 50px; height: 50px;
background: red;
animation: slide 3s infinite;
}
@keyframes slide {
from { margin-left: 0; }
to { margin-left: 200px; }
}
</style>
30. Experiment with the <video> tag to embed and control video playback in a
webpage.

The <video> tag allows embedding videos directly without plugins. It supports
controls such as play, pause, volume, fullscreen, and also multiple formats for
browser compatibility.

Example:

<h3>Video Example</h3>

<video width="400" controls>


<source src="movie.mp4" type="video/mp4">
<source src="[Link]" type="video/ogg">
Your browser does not support the video tag.
</video>

✅ CO2
1. Define JavaScript.

JavaScript is a lightweight, object-based scripting language used primarily to add


interactivity and dynamic behavior to webpages. It runs inside the browser,
allowing developers to manipulate HTML, CSS, respond to user actions, validate
inputs, and build interactive web applications.

2. What does DOM stand for?

DOM stands for Document Object Model. It represents the webpage structure as
a tree of objects, enabling JavaScript to access and modify HTML elements
dynamically.

3. Name any two JavaScript built-in objects.

Examples: Math, Date, String, Array, Object


4. Expand JSON.

JSON stands for JavaScript Object Notation, is a lightweight, human-readable


text format for data interchange that is used by web applications, APIs, and
configuration files. It represents data as a collection of key-value pairs (objects) or
an ordered list of values (arrays) and is independent of any specific programming
language.

5. Which symbol is used for single-line comments in JavaScript?

The double slash // is used for single-line comments.

6. List two event handling attributes in JavaScript.

onclick, onmouseover, onkeydown, onload (any two)

7. Name any two JavaScript dialog box functions.

alert(), confirm(), prompt()

8. State the purpose of regular expressions in JavaScript.

Regular expressions are patterns used to match, search, and validate strings. They
help in tasks like email validation, password checking, and finding specific text
patterns.

9. Explain array creation in JavaScript with examples.

Arrays store multiple values in a single variable. They can be created in two ways:

Literal method:

let nums = [10, 20, 30];

Using constructor:

let nums = new Array(10, 20, 30);


10. Explain the three types of Popup Box.

1.​ alert() – Displays a message with an OK button.


2.​ confirm() – Displays OK/Cancel and returns true/false based on user choice.
3.​ prompt() – Accepts input from the user via a text box.

11. Difference between HTML and DHTML.

HTML DHTML

HTML stands for HyperText Markup DHTML stands for Dynamic HTML.
Language.

Used to create static webpages where Used to create dynamic webpages with
content does not change on its own. interactive and real-time updates.

Cannot change content or style Uses JavaScript + CSS + DOM to


automatically after loading the page. modify content without reloading.

Limited user interaction and no Supports animations, effects, form


movement/animation. validation, and live updates.

Acts only as a page structure/markup Acts as a combination of HTML, CSS,


language. JavaScript, and DOM.

12. Differentiate between JavaScript and Java.

Java is a compiled, object-oriented programming language used to build


large-scale applications. It runs on the Java Virtual Machine (JVM) after
compilation into bytecode. JavaScript, on the other hand, is an interpreted
scripting language executed directly inside the browser, mainly used to add
interactivity, dynamic behavior, and event handling to webpages.
13. Explain the role of the DOM in JavaScript.

DOM allows JavaScript to access and manipulate HTML elements. Using DOM,
we can change content, modify styles, handle events, and dynamically update
webpage structure.

14. How does exception handling improve program reliability?

Exception handling prevents a program from crashing when errors occur. The
try–catch block identifies errors and provides alternative actions, ensuring smooth
and safe execution.

15. Describe the importance of validation in JavaScript.

Validation ensures that user inputs are correct and meaningful before processing. It
prevents errors, enhances data accuracy, improves security, and increases the
reliability of web forms.

16. Compare alert() and prompt() with examples.

alert() only displays a message:

alert("Hello!");

prompt() displays a message and takes user input:

let name = prompt("Enter your name:");

17. Explain the significance of built-in objects in JavaScript.

Built-in objects like Math, Date, Array provide ready-made functions, reducing
coding effort. They help perform tasks like calculations, storing collections, and
handling dates easily.
18. Describe the use of HTTP requests in JavaScript.

HTTP requests allow JavaScript to communicate with a server. They help fetch
data, send form details, load dynamic content, and build interactive applications
using AJAX.

19. How does DHTML differ from normal HTML?

Normal HTML displays static content. DHTML uses JavaScript + CSS + DOM to
update page content dynamically without reloading the page.

20. Explain the use of the Math object with an example.

The Math object provides mathematical functions.​


Example: let x = [Link](25); // Gives 5

21. Why is JSON widely used for data exchange?

JSON is lightweight, easy to read, and language-independent. It can be quickly


parsed by browsers and APIs, making it ideal for web data transfer.

22. Write a Java program to print “Good Day” using IF-ELSE.


public class Main {
public static void main(String[] args) {
if(true) {
[Link]("Good Day");
} else {
[Link]("Hello");
}
}
}

23. Write JavaScript code to display the current date.


[Link](new Date());
24. Program: Add 2 numbers using prompt box.
let a = Number(prompt("Enter first number:"));
let b = Number(prompt("Enter second number:"));
alert("Sum = " + (a + b));

25. Write the syntax for declaring an array in JavaScript.


let arr = [item1, item2, item3];

26. Construct a JSON object with keys name and age.


let person = { "name": "Anjali", "age": 20 };

27. Write a JavaScript snippet to handle an onclick event.


<button onclick="show()">Click</button>
<script>
function show() {
alert("Button Clicked!");
}
</script>

28. Construct a JavaScript regex to validate an email.


let emailPattern = /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;

29. Write a try-catch block to handle division by zero.


try {
let x = 10 / 0;
if(!isFinite(x)) throw "Division by zero";
}
catch(e) {
alert(e);
}

30. Show how to change the text of a paragraph using DOM.


[Link]("p1").innerHTML = "New Text";
31. Write JavaScript code to validate if a number is positive.
let n = Number(prompt("Enter a number:"));
if(n > 0) alert("Positive");
else alert("Not Positive");

32. Demonstrate form validation using JavaScript.


function validate() {
let x = [Link]("name").value;
if(x == "") {
alert("Name required");
return false;
}
return true;
}

33. Program to send a GET request using XMLHttpRequest.


let x = new XMLHttpRequest();
[Link]("GET", "[Link]", true);
[Link]();

34. Construct a JavaScript array and print its first element.


let arr = ["apple", "banana", "cherry"];
[Link](arr[0]);

✅ CO3
1. What is a Java Servlet?

A Java Servlet is a server-side program that extends the capabilities of a web


server. It processes client requests, generates dynamic responses, and is commonly
used to handle form data, sessions, and dynamic web content.
2. List the phases of the servlet life cycle.

The servlet life cycle consists of three phases: initialization (init()), request
handling (service()), and destruction (destroy()).

3. Differentiate between GET and POST methods in servlets.

GET Method POST Method

Sends data appended in the URL. Sends data inside the request body.

Less secure because data is visible in More secure because data is not visible
the URL. in the URL.

Limited amount of data can be sent. Large amount of data can be sent.

Used mainly for fetching data. Used mainly for submitting form data
safely.

4. What is a session in web applications?

A session is a mechanism used to store user-specific data on the server across


multiple requests. It helps track users as they navigate different pages of a web
application.

5. What is a stateful and stateless protocol?

A stateful protocol remembers previous interactions, while a stateless protocol


does not retain any information between requests. HTTP is stateless, meaning each
request is treated independently unless mechanisms like sessions or cookies are
used.
6. Differentiate GenericServlet and HttpServlet.

GenericServlet HttpServlet

Protocol-independent. Designed specifically for HTTP


protocol.

Only has service() method. Provides doGet(), doPost(), etc.

Cannot directly handle HTTP Simplifies handling of GET/POST


methods. requests.

Used for any type of service. Used mainly for web applications.

7. What are the features of servlet?

Servlets are efficient, portable, scalable, secure, and platform-independent. They


support multithreading, are faster than CGI, and integrate easily with Java
technologies.

8. List the methods of servlet interface.

The main methods are init(), service(), and destroy(), which control the servlet’s
lifetime.

9. Define JDBC driver.

A JDBC driver is a software component that enables Java applications to


communicate with a database using the JDBC API.

10. Define JDBC.

JDBC (Java Database Connectivity) is an API used to connect Java programs with
relational databases, execute SQL queries, and retrieve results.
11. State the advantages of servlet over CGI.

Servlets are faster, platform-independent, multithreaded, memory-efficient, and


easier to maintain compared to CGI because they use a single process to handle
multiple requests.

12. Define JSP.

JSP (JavaServer Pages) is a server-side technology used to create dynamic web


pages by embedding Java code inside HTML using special tags.

13. List out the advantages of JSP.

JSP allows easy separation of presentation and logic, supports dynamic content
generation, reduces Java code inside HTML, and integrates well with servlets and
JavaBeans.

14. What are the types of directive tags?

JSP supports three directives: page, include, and taglib.

15. Distinguish between Servlet and JSP.

Servlet JSP

Written entirely in Java. Written mainly in HTML with Java embedded.

Better for business logic. Better for presentation/UI.

Harder to design visually. Easier for designers to update UI.

Compiled first, then executed. Translated into a servlet internally and then
executed.
16. Explain the role of the service() method in servlet life cycle.

The service() method processes incoming requests and determines whether to


invoke doGet(), doPost(), or other HTTP methods. It is the core method
responsible for handling client interactions.

17. Why is the POST method considered more secure than GET for form
data?

POST sends data in the request body, making it invisible in the URL and less likely
to be logged or cached. This prevents sensitive information from being exposed in
browser history or network logs.

18. Explain how HttpSession helps in maintaining state across requests.

HttpSession stores user-specific data on the server, allowing information such as


username or preferences to persist across multiple page requests even though
HTTP is stateless.

19. How do cookies differ from sessions?

Cookies Sessions

Stored on client browser. Stored on server side.

Less secure because user can More secure as data stays on server.
view/modify them.

Suitable for small data (max 4 KB). Suitable for larger user-related data.

Data persists even after browser restart Ends when session expires or browser
(if persistent). closes.
20. Explain the basic steps in establishing a JDBC connection.

1.​ Load the JDBC driver.


2.​ Establish a connection using DriverManager.
3.​ Create a Statement object.
4.​ Execute SQL queries.
5.​ Process the results.
6.​ Close the connection.

21. Why is JSTL preferred over writing Java code directly inside JSP pages?

JSTL improves readability and avoids mixing Java code with HTML. It offers
ready-made tags for loops, conditions, formatting, and database access, making
JSP cleaner and easier to maintain.

22. Explain the use of <jsp:include> tag in JSP.

<jsp:include> inserts another JSP or HTML page at request time. It helps reuse
headers, footers, menus, and common UI components across multiple pages.

23. Write the code snippet of doGet() method to display “Hello Servlet”.
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("Hello Servlet");
}

24. Design a simple HTML form with POST and explain how servlet processes
it.
<form action="login" method="POST">
Name: <input type="text" name="uname">
<input type="submit">
</form>
25. Write Java code to create a session and store a username.
HttpSession session = [Link]();
[Link]("user", "Anjali");

26. How would you delete a cookie in a servlet program?


Cookie c = new Cookie("username", "");
[Link](0);
[Link](c);

27. Write a JDBC code snippet to connect to a MySQL database.


[Link]("[Link]");
Connection con = [Link](
"jdbc:mysql://localhost:3306/mydb","root","password");

28. Use <c:forEach> JSTL tag to display a list of names.


<c:forEach var="name" items="${names}">
${name}<br>
</c:forEach>

29. Create a JSP code snippet for a login form.


<form action="[Link]" method="POST">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Login">
</form>
✅CO4
1. Define PHP and its features.

PHP (Hypertext Preprocessor) is a popular server-side scripting language used to


create dynamic and interactive web pages. It runs on the server and generates
HTML that is sent to the browser. PHP is easy to learn, platform-independent, and
works well with databases like MySQL.​
Features include:

●​ Supports server-side scripting and dynamic content.


●​ Built-in support for databases such as MySQL.
●​ Easy integration with HTML, CSS, and JavaScript.
●​ Supports sessions, cookies, file handling, and form processing.

2. List the data types used in PHP.

PHP supports several flexible data types that allow handling different kinds of
values. The commonly used types are:

●​ Integer – whole numbers


●​ Float/Double – decimal numbers
●​ String – sequence of characters
●​ Boolean – true or false
●​ Array – collection of values
●​ Object – user-defined classes
●​ NULL – no value assigned
●​ Resource – external resources like file handle

3. Write a simple PHP Script.


<?php
echo "Hello, this is my first PHP script!";
?>

This script displays a message on the webpage using the echo statement.
4. State cookie. Give example in PHP.

A cookie is a small piece of data stored in the user’s browser to remember


information like login status or preferences. PHP sends cookies to the browser
using setcookie().​
Example: setcookie("username", "Anjali", time() + 3600);

This stores the value "Anjali" for one hour.

5. List the rules for creating variables in PHP.

PHP variable rules:

●​ Must begin with a $ symbol.


●​ Must start with a letter or underscore (not a number).
●​ Cannot contain spaces or special characters.
●​ PHP variable names are case-sensitive.

6. Name any four built-in functions in PHP.

Examples of commonly used built-in functions:

●​ strlen() → Finds string length


●​ count() → Counts elements in an array
●​ sqrt() → Computes square root
●​ var_dump() → Displays variable details

7. How do you declare and initialize an array in PHP?

Arrays store multiple values in a single variable.​


Example using array() syntax:

$colors = array("Red", "Green", "Blue");

Or using short syntax:

$colors = ["Red", "Green", "Blue"];


8. Explain built-in functions in PHP.

Built-in functions are predefined functions provided by PHP to perform frequently


required operations. They reduce the need to write code from scratch. Examples
include:

●​ String functions like strlen(), strtoupper()


●​ Array functions like count(), sort()
●​ Math functions like abs(), pow()
●​ Date functions like date()​
They help improve productivity and simplify development.

9. Illustrate variables and data types in PHP

Variables in PHP start with $ and store data of various types. Examples:

$name = "Anjali"; // String


$age = 20; // Integer
$price = 99.50; // Float
$isStudent = true; // Boolean
$marks = [80, 90, 95]; // Array

These types help handle different values in a program.

10. Write a PHP script to compute the sum and average of N numbers.
<?php
$nums = [10, 20, 30, 40];
$sum = array_sum($nums);
$avg = $sum / count($nums);

echo "Sum = $sum<br>";


echo "Average = $avg";
?>
11. Difference between echo() & print().

echo() print()

Can output multiple values at once. Can output only one value at a time.

Slightly faster than print(). Slightly slower because it returns a


value.

Does not return a value. Returns 1, so it can be used in


expressions.

Commonly preferred for displaying Used when a return value is needed.


output.

12. How will you embed the PHP code in HTML?

PHP code is inserted inside HTML using <?php … ?> tags.

<html>
<body>
<h3>Welcome!</h3>
<?php
echo "This is PHP inside HTML";
?>
</body>
</html>

13. Explain the use of preg_match in PHP.

preg_match() checks whether a string matches a given regular expression pattern.​


It is widely used for validations like email, phone number, and password rules.​
Example:

preg_match("/[0-9]/", "abc123"); // returns 1


14. Demonstrate the concept of regular expression in PHP.

Regular expressions help match patterns in text.​


Example:

$pattern = "/^[A-Za-z0-9]+$/";
if(preg_match($pattern, "Hello123")) {
echo "Valid";
}

This checks whether the string has only letters and numbers.

15. Describe the usage of asort() and ksort() functions in PHP.

asort() sorts an associative array based on values, keeping keys intact. ksort() sorts
the same kind of array based on keys. Both functions help maintain relationships
between keys and values.

16. State the use of foreach function in PHP.

foreach is used to loop through arrays easily. It automatically accesses each array
element.​
Example:

foreach($names as $n) {
echo $n;
}

17. Infer when superglobal arrays in PHP should be used. Which array stores
POST data?

Superglobals are built-in arrays available everywhere in PHP. They store request
data, server information, and session values. Examples include: $_GET, $_POST,
$_SESSION, $_COOKIE. The HTML form POST data is stored in $_POST.

18. List out the advantages of PHP.


PHP is easy to learn, open-source, platform-independent, and efficient for
server-side programming. It supports database connectivity, handles forms,
sessions, and integrates smoothly with HTML and CSS. Its large community and
built-in libraries make development faster.

19. Write the use of isset() and unset() functions.

isset() checks whether a variable is declared and not NULL. unset() removes a
variable from memory.​
Example: isset($x); unset($x);

20. Difference between preg_match() and preg_replace().

preg_match() preg_replace()

Checks if a pattern exists in a Replaces matched patterns with


string. new text.

Returns 1 (found) or 0 (not Returns the modified string.


found).

Used for validation. Used for formatting or editing text.

Does not modify the original Produces an updated string.


string.

21. Apply a for loop in PHP to display numbers from 1 to 10.


for($i = 1; $i <= 10; $i++) {
echo $i . " ";
}
22. Demonstrate how preg_match() checks if a string contains digits.
$str = "Hello123";
if(preg_match("/\d/", $str)) {
echo "Contains digits";
}

You might also like