0% found this document useful (0 votes)
8 views32 pages

WP Passing Package

This document is a model paper consisting of three parts: Part A with short answer questions on topics like IP addresses, web servers, MIME, PHP, and exception handling; Part B with detailed questions on JavaScript execution environment, PHP programming, operators, and the Document Object Model (DOM); and Part C covering advanced topics such as element access in JavaScript, XML, XML namespaces, and Document Type Definitions (DTD). Each part includes specific questions with corresponding answers that provide foundational knowledge in web development and programming concepts.

Uploaded by

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

WP Passing Package

This document is a model paper consisting of three parts: Part A with short answer questions on topics like IP addresses, web servers, MIME, PHP, and exception handling; Part B with detailed questions on JavaScript execution environment, PHP programming, operators, and the Document Object Model (DOM); and Part C covering advanced topics such as element access in JavaScript, XML, XML namespaces, and Document Type Definitions (DTD). Each part includes specific questions with corresponding answers that provide foundational knowledge in web development and programming concepts.

Uploaded by

kkabhinav01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Model Paper -1

Part - A
I – Answer any 4 questions. Each question carries 2 marks. 4x2=8

1. What is IP address?

Ans: Every machine on the internet has a unique identifying number called an IP address. The IP stands for
Internet Protocol, which is the language that computers used to communicate over the internet. Eg: IP
address looks like 216.27.61.136

2. What is a Web Server ? Give Examples

Ans: A web server is a computer that stores, processes, and delivers website files to web browsers. A web
server is a computer system capable of delivering web content to end users over the Internet via a web
browser. A web server is software that runs on the web site hosting Server computer. Its main purpose is to
serve web pages; which means it waits for requests from web browsers (also known as clients) and
responds by sending the required data back.
Eg: Apache Web Server, IIS, NGINX, Oracle.

3. What is MIME?

Ans: MIME or Multipurpose Internet Mail Extensions is a specification that helps different software system
communication with each other over the internet. It does this by specifying the types of being
exchanged ,such as text, images ,audio ,video and application programmes .This is important because
different types of files required different method of interpretation and display. A MIME type is comprised as
: primary_type/subtype Ex: text/html.

4. Mention any two Keyboard Events.

Ans: i) keypress ii) keyup

5. What is PHP? Write its Structure.

Ans: PHP (Hypertext Preprocessor) is a widely-used open-source server-side scripting language designed
for web development but also used as a general-purpose programming language. It is especially suited for
creating dynamic web pages and can be embedded into HTML.
PHP scripts are enclosed within <?php and ?> tags. The structure includes the opening and closing tags,
with PHP code residing between them.
6. What is Exception Handling?

Ans: Exception handling is a programming technique used to handle errors and unexpected situations that
may occur during the execution of a program. The purpose of exception handling is to provide a way to
gracefully handle errors and prevent the program from crashing or producing incorrect results. The
exceptional situations often referred to as exceptions or errors. This can include things like division by zero,
file not found, or database connection failures. Exception handling helps ensure that program continues to
run smoothly even when unexpected issues arise.

Part - B

II – Answer any 4 questions. Each question carries 5 marks. 4 x 5 = 20


7. Explain the different parts of JavaScript Execution Environment.

Ans: The JavaScript execution environment refers to the environment in which JavaScript code is executed. In web
programming, the JavaScript execution environment is typically the client's browser. The window object and
document object are two important objects in JavaScript Execution Environment.

i) The window object and the document object together provide a powerful set of tools for creating dynamic and
interactive web pages using JavaScript.

The browser provides a global object called the window object, which represents the browser window and
provides access to various properties and methods. The window object is the top-level object in the
JavaScript hierarchy and is used to interact with the browser and the user's computer.

ii) The document object is another important object in the JavaScript execution environment. It represents the web
page that is currently loaded in the browser window and provides access to the various elements on the page, such as
forms, buttons, and text boxes. The document object is a property of the window object and can be accessed using the
window.document property.
8. Write a PHP program to find Fibonacci Series

Ans:

<?php
Function fib($n){
$f1= 0; $f2= 1;
echo$f1.” ”.$f2.” ”;
for($i-2;$i<=n;$i++) {
$f3=$f1+$f2;
cho$f3.” “;
}
}
fib(10);
?>
9. Explain any 3 operators in PHP

Ans: PHP Arithmetic Operators: The arithmetic operators are used to perform common
arithmetical operations, such as addition, subtraction, multiplication etc. Here's a
complete list of PHP's arithmetic operators:
Operator Description Example Result
+ Addition $x + $y Sum of $x and $y

- Subtraction $x - $y Difference of $x and $y.


* Multiplication $x * $y Product of $x and $y.

/ Division $x / $y Quotient of $x and $y

% Modulus $x % $y Remainder of $x divided by $y

PHP Assignment Operators: The assignment operators are used to assign values to variables.
Operator Description Example Is The Same As

= Assign $x = $y $x = $y
+= Add and assign $x += $y $x = $x + $y

-= Subtract and assign $x -= $y $x = $x - $y

*= Multiply and assign $x *= $y $x = $x * $y


Divide and assign quotient $x /= $y $x = $x /
/=
$y
Divide and assign modulus $x %= $y $x = $x %
%= $y

PHP Comparison Operators: The comparison operators are used to compare two values in a Boolean
fashion.
Operator Name Example Result

== Equal $x == $y True if $x is equal to $y


=== Identical
$x === $y True if $x is equal to $y, and

they are of the same type

!= Not equal $x != $y True if $x is not equal to $y

<> Not equal $x <> $y True if $x is not equal to $y


!== Not identical $x !== $y
True if $x is not equal to $y, or they
are not of the same type

< Less than $x < $y True if $x is less than $y

> Greater than $x > $y True if $x is greater than $y


>= Greater than or $x >= $y True if $x is greater than or equal to $y
equal to

Less than or
<= equal to $x <= $y True if $x is less than or equal to $y

10. Explain the DOM in detail.


Ans: The Document Object Model (DOM) is an application programming interface (API) for XHTML documents.
The DOM represents a document as a hierarchical tree of nodes, allowing developers to add, remove and modify
individual parts of web page. The DOM allows a developer to access the document via a common set of objects,
properties, methods, events and to alter the contents of the web page dynamically using scripts.
Levels of DOM:
1. DOM 0: All browsers have a Document Object Model, which gives you access to various parts of the document.
The Level 0 DOM is the oldest of them. It was implemented in Netscape 2 and 3 and still works in all java script
browsers. It gives easy access to forms and their elements, images and links.
2. DOM 1: The initial DOM standard, known as DOM Level 1, was recommended by W3C in 1998. DOM Level 1
provided a complete model for an entire HTML or XML document, including means to change any portion of the
document.
3. DOM 2: Level 2 is complete and many of the properties, methods, and events have been implemented by today’s
browsers. It has sections that add specifications for events and style sheets to the specification for core and HTML
specific properties and events.
4. DOM 3: Level 3 archived recommendation status in 2004. It is intended to resolve a lot of the complications that
still exists in the event model in Level 2 of the standard and adds support for XML features such as content models
and being able to save the DOM as an XML document. Only few browsers support some features of Level 3.
Example of DOM:
<!DOCTYPE HTML>
<html>
<head> <title>About DOM</title> </head>
<body> The truth about DOM. </body>
</html>
Tree representation of DOM:

11. Explain Arrays in PHP.

Ans: ARRAYS

Array is used to store multiple values of same type in single variable. An array is a special variable, which
can hold more than one value at a time.
CREATE AN ARRAY IN PHP
In PHP, the array() function is used to create an array.
Syntax:$var= array( );
TYPES OF ARRAY IN PHP
There are three types of array in PHP, which are given below.

1. Indexed arrays - Arrays with a numeric index


2. Associative arrays - Arrays with named keys
3. Multidimensional arrays - Arrays containing one or more arrays
1. Indexed Arrays
The index can be assigned automatically (index always starts at 0).
Example
<?php
$student = array("Harry", "Varsha", "Gaurav");
echo "Class 10th Students " . $student[0] . ", " . $student[1] . "
and " . $student[2] . ".";
?>
Output: Class 10th Students Harry, Varsha and Gaurav
Find Length of an Array in PHP
Using count() function you can find length of an array in php.
Example <?php
$student = array("Harry", "Varsha", "Gaurav"); echo "Length of Array: ";
echo count($student);
?>
Output: Length of Array: 3
Arrays using for Loop
Example <?php
$student = array("Harry", "Varsha", "Gaurav");
$arrlength = count($student); for($i = 0; $i < $arrlength;
$i++)
{
echo $student[$i];
echo "<br>";
}
?>
Output: Harry
Varsha
Gaurav

2. Associative Arrays in PHP


In this type of array; arrays use named keys that you assign to them.
Syntax
$age = array("Harry"=>"10", "Varsha"=>"20", "Gaurav"=>"30");
or
$age['Harry'] = "10";
$age['Varsha'] = "20";
$age['Gaurav'] = "30";

3. Multidimensional Arrays in PHP


A multidimensional array is an array containing one or more arrays.
For a two-dimensional array you need two indices to select an element
Example <?php
$student = array( array("Harry",300,11), array("Varsha",400,10),
array("Gaurav",200,8), array("Hitesh",220,8));

echo $student[0][0].": ".$student[0][2].".<br>"; Marks: ".$student[0][1].", Class:


Marks: ".$student[1][1].", Class:
echo $student[1][0].": ".$student[1][2].".<br>";

Marks: ".$student[2][1].", Class:


echo $student[2][0].": ".$student[2][2].".<br>";

echo$student[3][0].":".$student[3][2].".<br>";
Marks: ".$student[3][1].", Class:
?>
Output: Harry: Marks: 300 Class: 11
Varsha: Marks: 400 Class: 10
Gaurav: Marks: 200 Class: 8
Hitesh: Marks: 220 Class: 8

12. What is a Cookie? How a Cookie is created?

Ans: COOKIES: A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you
can both create and retrieve cookie values.
OR
PHP cookie is a small piece of information which is stored at client browser. It is used to recognize the user.
OR
Cookies are text files stored on the client computer and they are kept of use tracking purpose
Create Cookies With PHP A cookie is created with the setcookie() function.
Syntax ssetcookie ( string name [, string value [, int expire [, string path [, string domain [, bool
secure]]]]] )
Parameter Description
 name The name to set the cookie variable to and hence
the name to access it with
 value The value of the current cookie
 expire When a cookie will expire (in the form of a Unix
timestamp)
 path The directory where the cookie will be available for
use
 domain The domain at which the cookie will be available

 secure Whether a cookie can be read on a non-SSL enable


Script
setcookie($cookie_name, $cookie_value, time() + (86400*30));
<?php
setcookie("username", "John Carter", time()+30*24*60*60); ?>
Part - C
III – Answer any 4 questions. Each question carries 8 marks. 4 x 8 = 32

13. Explain the different ways of Element access in JavaScript.

Ans: The different ways of element access in java script are:

1.Using forms and elements array of document object: This is the original way (DOM 0) to access the elements using
forms and elements array of document object.

Syntax: document.forms[number].elements[number]
Example: <script type=”text/javascript”>
function function1(){
var Name = document.forms[0].elements[0].value;
var Age = document.forms[0].elements[1].value;
var Phone = document.forms[0].elements[2].value;
}
</script>
2.Using form names: It’s better to use the names of the forms and elements. In XHTML, we have to give a name to
each form and each element.

Example: <form name=”firstForm”>


<input type=”text”name=”NameText”/>
<input type=”text”name=”AgeText”/>
<input type=”text”name=”PhoneText”/>
<input type=”submit”name=”myButton”/>
</form>
 And it can access by these elements by
Document.firstForm.NameText
Document.firstForm.AgeText
Document.firstForm.PhoneText
Document.firstForm.myButton1
3.Using getElementById() method: By combining the XHTML id attribute with the getElementById() method of the
document object, it is easier to get a handle on any XHTML object. This method takes the id of an XHTML element
as its argument and returns a reference to that element.

Example: <form name=”firstForm”>


<input type=”text”id=”NameText”/>
<input type=”text”id=”AgeText”/>
<input type=”text”id=”PhoneText”/>
<input type=”submit”id=”myButton”/>
</form>
 And it can access by:

var name_element=document.getElementById(“NameText”);
var age_element=document.getElementById(“AgeText”);
var phone_element=document.getElementById(“PhoneText”);
var submit_element=document.getElementById(“myButton1”);
14. What is XML? Explain XML Namespaces.
Ans: The eXtensible Markup Language is a text document used mainly for distributing the data on internet between
different applications. It9s a structured document for storing and transporting the data, mainly used for the
interchanging the data on internet.

In XML, a namespace is used to prevent any conflicts with element names. Because XML allows to create our own
element names, there’s always the possibility of naming an element exactly the same as one in another XML
document, this is possible when they never use both documents together.

 We can create a name conflict by creating a namespace for the XML document. To use XML namespace, elements
are given qualified names. These qualified names consists of two parts:

1.The local part is the same as the names we have been given elements.

2.The namespace prefix specifies to which namespace this name belongs.

Ex: <bk:books xmlns:bk=”http://www.mysite.com”/>

Where, xmlns stands for XML Namespace.

bk is the namespace prefix.

http:// www.mysite.com is the URL of the namespace.

Example:

<?xml version=”1.0”encoding=”UTF-8”?>
<!DOCTYPE books SYSTEM “bookrules dtd”>
<bk:books xmlns:bk=”http://www.musite.com”>
<bk:book type=”programming”>
<bk:title>Web programming</bk:title>
<bk:author>Srikanth.S</bk:author>
</bk:book>
</bk:books>
15. Explain DTD and Types of DTD

Ans: 1.What is DTD? Explain internal DTD and external DTD. A DTD is a Document Type Definition. A DTD
defines the structure and the legal elements and attributes of an XML document.
1.Internal DTD: An internal DTD is the DTD is defined between the square brackets within the XML documents.
RULES:
1. The document type declaration must be written in between the XML declaration and the root element.
2. Keyword DOCTYPE must be followed by the root element.
3. Keyword DOCTYPE must be in upper case.
Example:
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tom</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
2.External DTD: An external DTD is nothing different from internal DTD except that defining DTD in an external
file. It can be use with more than one XML document.
Example:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tom</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
14. Explain DOM tree Traversal and Modification.

Ans:

DOM Tree Modification refers to the process of adding, modifying, or deleting elements and content from the DOM
tree structure of a document. This is an important aspect of web development, as it allows developers to dynamically
update the content of a web page in response to user actions or other events.
15. Explain Positioning of Elements in JavaScript

Ans: Defining Position Property


The general syntax of defining the 'position' property in CSS is:

Syntax
selector { position: value; }

position: static | relative | absolute| fixed

The Default value is: static

Here, selector' is the HTML element to which the 'position' property is being applied, and
'value' is one of the four possible values: 'static', 'relative', 'absolute', or 'fixed'. The 'position'
property is used to specify the type of positioning method used for an HTML element.
Types of Positioning

The position property indicates that an element is to be positioned, and specifies which positioning
method should be used.

1 Static Positioning:

• This is the default value. Elements are positioned according to the normal flow of the document.
• The top, right, bottom, and left properties have no effect on statically positioned elements.
• A statically positioned element is placed in the document flow as it would normally appear.
• Normal paragraphs and divs are static by default and stack as they appear in the HTML
2 Relative Positioning:

• An element with position: relative; is first laid out just like a static element.
• A relatively positioned element is positioned relative to its normal position in the document flow
 It can then be shifted from its normal position using top, right, bottom, and left properties.
• Other content will not adjust to fill the space left by the element when it moves.
• The distinctive behaviour of relative positioning is that the space the element would have
occupied in the normal flow is preserved.
• For example, If we want to move a button slightly to the right from where it would normally be,
we could use position: relative; left: 20px;
3 Absolute Positioning:

• The absolute position in CSS is a powerful property that allows for precise placement of an
element within a webpage, independent of the normal flow of document content.
• When an element is given position: absolute;, it is taken out of the normal document flow.
• This means it no longer affects the positioning of other elements in the document. These other
elements behave as if the absolutely positioned element doesn't exist.
• The final position of an absolutely positioned element is relative to its closest ancestor element
that has a position other than static. If no such ancestor exists, it defaults to positioning relative to
the <html> element (essentially, the entire page).
4 Fixed Positioning:

• The top, right, bottom, and left properties are used to position the element.
• Fixed elements are removed from the document flow and positioned relative to the browser
window rather than another element in the document.
• Example: A "back to top" button can be made with position: fixed; bottom: 20px; right: 20px; so it
hovers at the bottom right of the screen, even when scrolling.

17. Explain XML Schema

Ans: An XML Schema describes the structure of an XML document. The XML Schema language is also referred to
as XML Schema Definition (XSD). The purpose of an XML Schema is to define the legal building blocks of an XML
document.

1. The elements and attributes that can appear in a document.


2. The number of (and order of) child elements.
3. Data types for elements and attributes.
4. Default and fixed values for elements and attributes.
The following is a high-level overview of schema types:

1.Elements can be simple or complex type.


2.Simple type elements can only contain text. They cannot have child element or attributes.
3.All the built-in types are simple types.
4.Schema developers can derive simple types by restricting another simple type.
5.Simple types can be atomic or non-atomic.
6.Complex-type elements can contain child elements and attributes as well as text.
7.By default, complex-type elements have complex content, meaning that they have child elements.
8.Complex-type elements can be limited to having simple content, meaning they only contain text. They are different
from simple type elements in that they have attributes.
9. Complex types can be limited to having no content, meaning they are empty, but they have attributes.
10.Complex types may have mixed content-a combination of text and child elements.
Simple-type:
Simple-type elements have no children or attributes. For example, the Name element below is a
simple-type element; whereas the Person and HomePage elements are not. A simple-type element is
defined using the type attribute in Scheme Definition.

• Data types that are already defined in XML schema specification and ready to use in schema to declare
elements and attributes are known as built-in data types. XML Schema provides many built-in data types.

*primitive data:
1 Boolean 2. String 3.Decimal 4. Float
*Built in derived data:
1.Token 3.language 4.Name 5.Entity
*Data derived from decimal primitive data:
1.Integer 2.Non positive integer 3.Negetive integer 4.Int
Example: In the below code, we have used xs:string for FirstName and LastName, xs:integer for Age,
xs:date for DOB, and xs:float for Percentage. They are not explicitly defined as simple type elements.
Instead, the type is defined with the type attribute. Because the value (string, integer,date, and float) is a
simple type, the elements themselves are simple-type elements.

•A complex-type element can be empty, contain simple content such as a string, or can contain complex
content such as a sequence of elements. It is not necessary to explicitly declare that a simple-type element
is a simple type, but it is necessary to specify that a complex-type element is a complex type.

• Content Models: Content models are used to indicate the structure and order in which child elements can
appear within their parent element. Content models are made up of model groups.

The three types of model groups are listed below.


1. xs:sequence - the elements must appear in the order specified.
2. xs:all - the elements must appear, but order is not important.
3. xs:choice - only one of the elements can appear.
> xs:sequence: The following sample shows the syntax for declaring a complex-type element as a sequence,
meaning that the elements must show up in the order they are declared.
> xs:all : The following sample shows the syntax for declaring a complex-type element as a conjunction.
> xs:choice: The following sample shows the syntax for declaring a complex-type element as a choice.

18. Explain the different types of Loops in PHP

Ans: A loop is a way of executing lines of code repeatedly. If we want to print "Hello" on the screen 100
times then we can either use echo statement 100 times or we can put one echo statement in a loop that runs
100 times which takes very minimum number of lines of code.
Executing set of statements repeatedly is called iteration or loop. The iterative statements are also
called as looping statements or repetitive statements. In programming specifically, iterative
statements are referred to as sequence of statements or code repeatedly executed until a specific
condition is true. The main looping constructs in PHP are:
1. while loop
2. do...while loop
3. for loop
4. foreach loop
While Statement
The while loop in PHP is used to repeatedly execute a block of code as long as a specified
condition is true. It tests the condition before executing the loop body. It's used for iterative
tasks where the number of iterations isn't known beforehand. It's written just like an if
statement, except that it uses the while keyword.
Eg:
<?php
$ch=’a’;
while($ch<=’’) {
echo $ch;
$ch++;
}
?>
Do-while Statement
The do-while loop in PHP is a control structure that executes a block of code at least once
before checking a condition at the end of the loop. It differs from the while loop in that it
guarantees the execution of the loop body at least once, regardless of the condition. This means
that the loop body always executes at least once, even if the expression is always false.
Example: <?php
$count=1; do {
echo "Count is: 11 . $count . "<br>";
$count++;
}
while ($count <=5) ;
?>
For Loop Statement
A for loop is a repetition control structure that allows to efficiently write a loop that needs to be
executed a specific number of times. A for loop is useful when we know how many times a
task is to be repeated. The for statement contains the initialization expression, test expression
and update expression in one line thereby providing a shorter, easy to debug structure of
looping.
Example: <?php
for ($i = 1; $i <= 5; $i++) {
echo "Number” . $i . "<br>";
}
?>
Foreach Loop Statement
The foreach loop in PHP is a control structure specifically designed for iterating over arrays
and objects. It provides a simple way to traverse through each element in an array or each
property of an object without the need for counters or more complex syntax. It is particularly
useful when we need to process each element of an array or object without knowing the size or
structure of the data in advance.
Example: <?php
$numbers = [1, 2,3, 4, 5];
foreach ($numbers as $number)
{
echo $number "<br>";
}
?>
Model Paper -2
Part - A
I – Answer any 4 questions. Each question carries 2 marks. 4x2=8

1. What is Web Browser? Give Examples.

Ans: A web browser is a software application used to locate and display web pages. It is able to retrieve,
find, view, and send information over the internet.

Web browsers are:


1. Internet Explorer
2. Netscape Navigator
3. Opera
4. Google Chrome
5. Mozilla Firefox
6. Safari
2. Define URL? Mention its Parts.

Ans: Uniform Resource Locator or URL is a fancy name for address. It contains information about where a
file is and what a browser should do while it. Each file on the Internet has a unique URL.

Parts of URL :- scheme://hostname:port/path-and-file-name

3. Mention any two Mouse Events

Ans:
 mousedown
 mouseup
 mouseover
 mousemove
 mouseouy
 click
4. What is DNS?
Ans: Domain Name System is a database system that translates a computers fully qualified domain name
into an IP address. The DNS is used to resolve human readable hostnames into machine readable IP address.
DNS also provides other information about domain names such as mail services.

5. . Define DHTML?

Ans: DHTML stands for Dynamic Hyper Text Markup Language. DHTML is not a language or a web
standard. DHTML is a term used to describe the technologies used to make web pages dynamic and
interactive.

6. What is For-Each loop in PHP

Ans: A for loop is a repetition control structure that allows to efficiently write a loop that needs to be
executed a specific number of times. A for loop is useful when we know how many times a task is to be
repeated. The for statement contains the initialization expression, test expression and update expression in
one line thereby providing a shorter, easy to debug structure of looping

Part - B

II – Answer any 4 questions. Each question carries 5 marks. 4 x 5 = 20

7. Write Short note on WWW.

Ans:

The World Wide Web often referred to as the "WWW" or simply the "Web" is a system of interconnected

documents and other resources linked by hyperlinks and URLS (Uniform Resource Locators) that are

accessed over the Internet. Sir Tim Berners-Lee, a British computer scientist, invented the World Wide Web

(WWW) in 1989 while working at CERN

The World Wide Web is a service that runs on the Internet. It's a collection of documents and resources that

are accessed over the Internet. The other services that run on the Internet apart from the Web include email,

chat services, and file transfer protocols.

In simple terms, WWW or the Web is a collection of websites or web pages stored in web servers and

accessed using web browsers through the internet. The websites contain text pages, digital images, audios,

videos, etc. Users can access the content of these sites from any part of the world over the internet using

their devices such as computers, laptops, cell phones, etc.


The WWW along with internet enables the retrieval and display of text and media. The World Wide Web.
Or 'Web' is a part of the Internet. The Web is viewed through web browser software such as Google chrome,
Internet Explorer, Mozilla Firefox etc. Using browsers one can access the digital libraries containing
innumerable articles, journals, e-books, news, tutorials stored in the form of web pages on computers
around the world called web servers. Today thousands of web pages/websites are added to the WWW every
hour.
8. Explain DTD
Ans: Refer MQP 1 Q 15
9. Explain the difference between echo and print command.

Ans:

Echo Print
It is a language construct . It is a function like a construct.
It does not require parentheses . It requires parentheses.
It does not have return value. It allows returns the value 1.
It is faster than print . It is slightly slower than echo
It can output multiple values separated by comma. It can only out put a single expression.
It can be used as a part of more complex It cannot be used as a part of more complex
expression. expression.
Syntax: echo value1,value2,…..value_n; Syntax: print(value)

10. Write a PHP program to display the Prime Numbers.


Ans: <?php
function isPrime($num) {
if ($num <= 1) return false;
for ($i = 2; $i <= sqrt($num); $i++) {
if ($num % $i == 0) {
return false; } }
return true;
}
$n=10;
echo "Prime numbers are:\n";
for ($num = 2; $num <= $n; $num++) {
if (isPrime($num)) {
echo $num . "\n"; } }
?>
11. Explain the Date & Time functions in PHP

Ans:
12. Define a Cookie? Explain the process of creating a cookie with an example.

Ans: Refer MQP 1 Q 12

Part - C
III – Answer any 4 questions. Each question carries 8 marks. 4 x 8 = 32

13. Explain DOM2 Event Model in Detail

Ans: The DOM 2 event model is a standard for handling events in web browsers. It is an improvement over
the original DOM event model, which had some limitations and inconsistencies. The DOM 2 event model
defines a standard set of event types and provides a way to register event listeners for those events. It also
introduces the concept of event propagation, which allows events to be handled at different levels of the
document hierarchy. The DOM 2 event model is supported by most modern web browsers and is widely
used in web development.

While the DOM 0 model is still widely supported and used, the DOM 2 model introduces a more modular
and flexible way to manage events, with better support for a wider range of event types and interactions.

Key Features of the DOM 2 Event Model

1. Standard Event Types: The DOM 2 event model defines a standard set of event types, such as click,
mouseover, and keydown. This makes it easier for developers to write cross-browser code that works
consistently across different platforms.
2. Event Listeners: The DOM 2 event model provides a way to register event listeners for specific events.
This allows developers to write code that responds to user actions, such as clicking a button or typing in a
text field.
3. Event Propagation: The DOM 2 event model introduces the concept of event propagation, which allows
events to be handled at different levels of the document hierarchy. This means that an event can be handled
by an element's parent, grandparent, or even higher up in the document tree.
4. Event Object: The DOM 2 event model provides an event object that contains information about the
event, such as the target element, the type of event, and any data associated with the event.
There are two types of event propagation: bubbling and capturing.

1. Capturing: When an event occurs on an element, it is first handled by the top-level element (ie, the
document object), and then it "captures" the event as it propagates down the DOM hierarchy to the
element that triggered the event. Capturing is less common than bubbling and is not supported by all
browsers.
Example: Let's say that the document contains a <div> which contains a <p> which contains an
<img>. Further, let's say we have added an event listener to all of them. When a user clicks on the
image, a mouseclick event occurs. Even though the user clicked the image, the image doesn't get the
event first. Instead, the event listener attached to the document grabs the event first and processes it.
(That is, it captures the event before it gets to its intended target <img>.) The event is then passed
down to the <div>'s event listener. The event then goes to the <p>, and finally to the <img>. That is,
all of the clicked-on object's "ancestors" higher up in the document capture the event for processing
before sending it down the chain to its intended target.
2. Bubbling: Bubbling is the most common type of event propagation. When an event occurs on an
element, it is first handled by that element, and then it "bubbles up" to its parent element, and then to
its parent's parent, and so on, until it reaches the top of the DOM hierarchy (i.e., the document
object).
Example: We have an <img> inside a <p>, which is inside a <div>, which is inside the document.
When a user clicks the image, this time the events rise like a bubble in a glass of water. The click's
original target, the <img>, gets to see the event first and it processes, and then passes it upwards to
the <p> for further processing, which passes it on to the <div>, which finally passes it up to the
document for processing.

14. Explain the different ways of registering an Event.

Ans:
1. Using "on" Attribute in HTML: This app he first approach for registering event handlers in
HTML is to use the "one attributed this approach is simple and straightforward, where we can specify
the name of the event and the name of the function that will be called when the event occurs.
However, this approach has some limitations, especially for larger projects, as it can be difficult to
manage and debug code that uses this approach.
Example:
<html>
<head>
<title>Event Handling Example</title>
<style>
#message {
font-size: 20px;
margin-top: 20px;}
</style>
</head>
<body>
<h1>Event Handling Using "on" Attributes</h1>
<button onclick="changeText()">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
function changeText() {
document.getElementById("message").innerText = "You clicked the button!";
alert("Button was clicked!"); }
</script>
</body>
</html>
In this example, "changeText()" is the name of the function that will be executed when the button is
clicked.
2. Using DOM Event Handlers: The second approach is to use the "addEventListener" method in
JavaScript. This approach is more flexible and powerful than using the "on" attribute in HTML. It
allows to register multiple event handlers for the same event, remove event handlers, and more.
Example: <html >
<head>
<title>Event Handling with DOM Event Handlers</title>
<style>
#message {
font-size: 20px;
margin-top: 20px; }
</style>
</head>
<body>
<h1>Event Handling Using DOM Event Handlers</h1>
<button id="myButton">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
const button = document.getElementById("myButton");
const message = document.getElementById("message");
function changeText() {
message.innerText = "You clicked the button!";
alert("Button was clicked!"); }
button.addEventListener("click", changeText);
</script>
</body>
</html>
In this example, "myButton" is the ID of the button element, and "changeText" is the name of the function
that will be executed when the button is clicked
3. Using Event Handler Properties: This method involves assigning a function to the event handler
property of an HTML element. The event handler could also be registered by the assignment to the
associated event property on the button object as shown below, For example, to add a click event
handler to a button element, you can use the following code:
Example: <html >
<head>
<title>Event Handling with Event Handler Properties</title>
<style>
#message {
font-size: 20px;
margin-top: 20px; }
</style>
</head>
<body>
<h1>Event Handling Using Event Handler Properties</h1>
<button id="myButton">Click Me!</button>
<p id="message">This is the original text.</p>
<script>
const button = document.getElementById("myButton");
const message = document.getElementById("message");
button.onclick = function() {
message.innerText = "You clicked the button!";
alert("Button was clicked!"); };
</script>
</body>
</html>
In this example, "myButton" is the ID of the button element, and "function" is the name of the
function that will be executed when the button is clicked.

15. Explain the different IF statements in PHP

Ans: Conditional Statements in PHP


Sometimes when you write code, you want to perform different actions for different decisions. You
can use conditional statements in your code to do this. The conditional statements are the set of
commands used to perform different actions based on different conditions.
• PHP if statement allows conditional execution of code. It is executed if condition is true. The If
statement is used to executes the block of code exist inside the if statement only if the specified
condition is true.
Syntax:
if (condition)
{
//code to be executed
}
You might have a script that checks if Boolean value is true or false, if variable contains number or
string value, if an object is empty or populated, etc. The condition can be anything you choose, and
you can combine conditions together to make for actions that are more complicated.

Eg: Write a program to find the smaller of two numbers?

• Compound If Statements: You may also compound the statements using elseif to have multiple
conditions tested in sequence. You should use this construction if you want to select one of many sets
of lines to execute.

<?php
$num1 = 12;
$num2 = 15; $num3=20; if ( ( $num1 <$num2) && ($num2<$num3) )
{ echo “$num1 is 12, $num2 is 15 and $num3 is 20"; } ?>
• PHP if-else statement is executed whether condition is true or false. If-else statement is slightly
different from if statement. It executes one block of code if the specified condition is true and another
block of code if the condition is false. The syntax if-else statement is:

if (condition)

{ statements_1 } else

{ statements_2 }

• PHP if...elseif...else Statement is a special statement used to combine multiple if?.else statements. So, we
can check multiple conditions using this statement.The if...elseif...else statement executes different codes
for more than two conditions. The syntax:

if (condition1) {
//code to be executed if condition1 is true
} elseif (condition2) {
//code to be executed if condition2 is true
} elseif (condition3) {
//code to be executed if condition3 is true
....
} else {
//code to be executed if all given conditions are false
}

• The Nested if contains the if block inside another if block. Here, the inner if statement executes only
when specified condition in outer if statement is true. The syntax for the Nested if is:

if (condition) {
//code to be executed if condition is true if (condition) {
//code to be executed if condition is true }
else{
//code to be executed if condition is false
}}

• Switch statements work the same as if statements. However, the difference is that they can check for
multiple values. Of course you do the same with multiple if..else statements, but this is not always the
best approach. A switch statement allows a program to evaluate an expression and attempt to match
the expression’s value to a case label. If a match is found, the program executes the associated
statement. One can use the switch statement to select one of many blocks of code to be executed.
Syntax:

Switch (expression)
{
Case label1: code to be executed if expression = label1; break;
Case label2: code to be executed if expression = label2; break;
default: Code to be executed if expression is different from both label1
and label2; }
16. Explain Looping statements in PHP

Ans: Refer MQP 1 Q 18

17. What is an Exception? Explain Exception Handling.

Ans: Exception Handling


Exception handling is a programming technique used to handle errors and unexpected situations that may
occur during the execution of a program. The purpose of exception handling is to provide a way to
gracefully handle errors and prevent the program from crashing or producing incorrect results. The
exceptional situations often referred to as exceptions or errors. This can include things like division by zero,
file not found, or database connection failures. Exception handling helps ensure that program continues to
run smoothly even when unexpected issues arise.
The primary purposes of exception handling are:
Error Handling: To manage errors robustly without terminating the program abruptly.
Control Flow: To ensure the program continues to run or fails gracefully when an exception Occurs.
Maintainability: To make the code easier to manage and debug by centralizing error handling.
Reliability: To enhance the reliability of the software by preventing unexpected crashes or behaviours.
Exception Handling Using try, catch and finally blocks in PHP. exception handling is implemented using
the 'try', 'catch', and 'finally' blocks.
1. try Block:
This block contains the code that may throw an exception. If an exception occurs within the try
block, PHP will immediately exit the try block and jump to the corresponding catch block to handle
the exception. If no exceptions occur, the code within the try block continues to execute as normal.
Example try Block
try {
// Code that may throw an exception
$result = 100; // Division by zero will trigger an exception
} catch (Exception $e) {
// Code to handle the exception
echo "An exception occurred: ", $e-
>getMessage();\ }
Explanation
In this example, the try block contains code that attempts to perform a division by zero, which will
throw an exception. If an exception is thrown, the program will immediately exit the try block and
move to the catch block to handle the exception.

2. catch Block:
This block is used to handle the exception that was thrown in the 'try' block. It contains code that is
executed when an exception is caught. The 'catch' block specifies the type of exception that it can
handle and if the caught exception matches the specified type, the code in the 'catch" block is executed.
We can catch specific types of exceptions by specifying the exception type in the parentheses after
catch.

Example catch Block


try {
// Code that may throw an exception
$result = 10 / 0; // Division by zero will trigger an exception
} catch (DivisionByZeroError $e) { // Code to
handle division by zero exception echo
"Division by zero error: ". $e->getMessage();
} catch (Exception $e) {
// Code to handle other exceptions
echo "An exception occurred: ". Se->getMessage();
}
Explanation
In this example, we catch a specific DivisionByZeroError exception and provide a different response
than catching a general Exception. Catch blocks are executed sequentially, and the first one that
matches the exception type is executed.
3. finally Block:
This block is optional and is used to specify code that should be executed regardless of whether an
exception was thrown or caught. The code in the 'finally' block is executed after the 'try' and 'catch'
blocks have finished executing. This block is often used for cleanup operations, such as closing database
connections or releasing resources like file closing etc.
Example: finally Block
try {
// Code that may throw an exception
$file fopen("example.txt", "r");
} catch (Exception $e) {
// Handle the exception
echo "Error opening file: ", $e->getMessage();
} finally {
// Code that runs regardless of an
exception if ($file) ( fclose($file);
echo "Attempted to open the file.";
}
Explanation
This example attempts to open a file, catches any exceptions related to file opening, and
ensures that the file is closed whether an exception occurs or not.

18. Explain XML Schema

Ans: Refer MQP 1 Q 17


V Semester B.C.A. Degree Examination, February/March - 2024
SECTION-A
Answer any Four questions. Each question carries 2 marks.
1. Define web Browser.
Ans: Refer MQP 2 Q 1
2.What is MIME?
Ans: Refer MQP 1 Q 3
3.List any two mouse events.
Ans: Refer MQP 2 Q 3
4.Define XML.
Ans: Refer MQP 1 Q 14
5.Write the basic structure of PHP.
Ans: Refer MQP 1 Q 5
6.Write the syntax of for each loop.
Ans: Refer MQP 2 Q 6
SECTION-B
Answer any Four questions. Each questions carries 5 marks.
7.Explain Navigator object.
Ans: Navigator object
 The navigator object contains information about the browser.
 The navigator object is a property of the window object.
 The navigator object is accessed with:
 window.navigator or just navigator:
8. Write the difference between print and echo commands.

Ans: Refer MQP 2 Q 9

9.Write a simple program in PHP for generating Fibonacci series.

Ans: Refer MQP 1 Q 8

10. Write a note on operators in PHP.

Ans: Refer MQP 1 Q 9

11. Explain the date () function in PHP with an example.

Ans: Refer MQP 2 Q 11

12. What is cookie? How to create cookies in PHP?

Ans: Refer MQP 1 Q 12

SECTION-C

Write any Four questions. Each question carries 8 marks.

13. What are the different ways of accessing elements in Javascript. Explain with an example.

Ans: Refer MQP 1 Q 13

14. Explain the properties and methods used for DOM tree traversal and modification.

Ans: Refer MQP 1 Q 14

15. Briefly explain XML namespace.

Ans: Refer MQP 1 Q 14

16. Explain loop statements in PHP with examples.

Ans: Refer MQP 1 Q 18

17. What are the types of arrays in PHP? Explain.

Ans: Refer MQP 1 Q 11


18. Explain exception handling in PHP with an example.

Ans: Refer MQP 2 Q 17

V BCA – Web Programming Model Questions

Short Answer

1. DOM
Ans: Refer MQP 1 Q 10

2. HTML VS XML.
Ans:

3. Dynamic documents in web development

Ans: Dynamic Content in web development refers to the ability to change the content of
HTML on a web page dynamically using JavaScript. This can involve updating text, images,
or other content in response to user interactions, data changes, or other events without
requiring reload. The concept of dynamic content is important as it allows web developers to
create more user and Responsive user interfaces. By updating content dynamically, web
pages can provide real feedback, display live data, and adapt to user input, resulting in a more
engaging and personalize user experience.
4. Data type supported in PHP

Ans: PHP is a dynamically-typed language, which means that the data type of a variable is
determined at runtime based on the value assigned to it. For example, if we assign a string to
a variable, and later assign an integer, PHP will handle the conversion automatically.
Example: $name = "Srikanth"; // This is a string variable
$name 40; // This is an integer variable
PHP variables are loosely typed, which means that they can hold different types of data, and
their type can change during the execution of a program. For example, a variable that Initially
holds a string value can later be assigned a numeric value.
5.Namepace

Ans: Refer MQP 1 Q 14

6.URL

Ans: Refer MQP 2 Q 2

7. Any Two mouse events.

Ans: Refer MQP 2 Q 3

8. Define Internet.

Ans: The Internet is also known as the INTERconnected NETwork is a wide area network
(WAN) that connects millions of computing devices (also called hosts or end-systems) across
the world. It emerged as a promising technology for providing widespread access to millions
of private, public, academic, business, and government networks. It is linked by an extensive
range of electronic, wireless, and optical networking technologies. The Internet enables
communication between different types of networks and devices.
9.echo() vs print()

Ans: Refer MQP 2 Q 9

10.Operator precedence.

Ans: We know that an expression is a combination of operands, operators and constants


(values). Now, consider this simple expression, echo (7 + 10) Output: 17
Since there is just one operation to be performed, its output is straightforward. But, such
calculations can get complex when 2 or more operators are involved in an expression. Let's
consider another expression, echo (10+20+30) Output: 60
Long Answer

1.Event handling in Javascript.

Ans: Refer MQP 2 Q 14

2.Definition of Cookie. Creation and deletion of a cookie.

Ans: Refer MQP 1 Q 12

3.Date and Time functions.


Ans: Refer MQP 2 Q 11

4.Various methods to access HTML form element using JavaScript

Ans: Refer MQP 1 Q 13

5.Different types of arrays in PHP with examples

Ans: Refer MQP 1 Q 11

6.Any five string handling functions in PHP with examples.

Ans:

STRING FUNCTIONSIN PHP

PHP have lots of predefined function which is used to perform


operation with string some functions are:

strlen(): strlen() function returns the length of a string. Example

<?php

echo strlen("Hello world!"); ?>

Output: 12

strrev(): strrev() function is used to revers


any string. Example

<?php

echo strrev("Hello world!");

?>

Output: !dlrow olleH

strtolower(): strtolower() function is used to convert uppercase


latter into lowercase latter.

Example

<?php

$str="Hello friends i am HITESH";

$str=strtolower($str);
echo$str; ?>

Output: hello friends i am hitesh

strtoupper(): PHP strtoupper() function is used to convert lowercase


latter into uppercase latter.

Example
<?php
$str="Hello friends i AM Hitesh";
$str=strtoupper($str);
echo
$str; ?>
Output: HELLO FRIENDS I AM HITESH

rtrim(): Removes whitespace or other characters from the right side of a


string

Syntax: rtrim(string,charlist)
<?php
$str = "Hello World!"; echo $str . "<br>";
echo rtrim($str,"World!");
?>
Output: Hello World!
Hello

7.Break and Continue in PHP.

Ans:

Break:
The PHP break keyword is used to terminate the execution of a loop prematurely. The
break statement is placed inside the statement block. It gives you full control and
whenever you want to exit from the loop you can come out. After coming out of a
loop immediate statement to the loop will be executed.
Example: In the following example condition test becomes true when the counter value
reaches 3 and loop terminates.
<?php
$i-0;
while( $i < 10) {
$i++;
if( $i == 3 )
break;}
echo ("Loop stopped at i = $i" ); ?>

Continue:
The PHP continue keyword is used to halt the current iteration of a loop but it does not
terminate the loop. Just like the break statement the continue statement is placed inside
the statement block containing he code that the loop executes, preceded by a
conditional test. For the pass encountering continue statement, rest of the loop code is
skipped and next pass starts.
Example: In the following example loop prints the value of array but for which
condition becomes true it just skip the code and next value is printed.
<?php
$array = array( 1, 2, 3, 4, 5);
foreach( $array as $value ){
if( $value == 3 ) continue;
echo "Value is $value <br/>";}?>
Output: Value is 1 Value is 2 Value is 4 Value is 5

8. Program to implement keyboard events.


Ans:
<html>
<head>
<title>Keyboard Events Example</title>
<style>
#output {
font-size: 20px;
margin-top: 20px; }
</style>
</head>
<body>
<h1>Keyboard Events Example</h1>
<p>Press any key on your keyboard:</p>
<p id="output">You pressed: </p>
<script>
const output = document.getElementById("output");
document.addEventListener("keydown", function(event) {
output.innerText = "You pressed: " + event.key; });
document.addEventListener("keyup", function(event) {
console.log("Key released: " + event.key); });
</script>
</body>
</html>
9.Exceptional handling in PHP.

Ans: Refer MQP 2 Q 17

You might also like