0% found this document useful (0 votes)
62 views11 pages

IT8501 Model QP Answers

The document provides information about a Web Technology class, including questions and answers about HTML, JavaScript, Java, and JavaScript objects. It contains 6 multiple choice questions in Part A worth 2 marks each, and 2 long answer questions in Part B worth 12 marks each. Question 7(a)(i) asks to write a JavaScript program to delete a property from an object and print the object before and after. 7(a)(ii) asks to write a program to search for a date string within a string. Part B also provides short notes on various JavaScript built-in objects like Math, String, Date, and their methods.

Uploaded by

hari suresh
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)
62 views11 pages

IT8501 Model QP Answers

The document provides information about a Web Technology class, including questions and answers about HTML, JavaScript, Java, and JavaScript objects. It contains 6 multiple choice questions in Part A worth 2 marks each, and 2 long answer questions in Part B worth 12 marks each. Question 7(a)(i) asks to write a JavaScript program to delete a property from an object and print the object before and after. 7(a)(ii) asks to write a program to search for a date string within a string. Part B also provides short notes on various JavaScript built-in objects like Math, String, Date, and their methods.

Uploaded by

hari suresh
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
You are on page 1/ 11

www.AUNewsBlog.

net

B.Tech INFORMATION TECHNOLOGY


IT8501 – WEB Technology

SEM. & CLASS : 05 & III IT DATE: 26.07.2018


DURATION : 1 Hr & 30 Mins MAX. MARKS: 50
ANSWER ALL QUESTIONS
PART A - (6 X 2 = 12 marks)

1. How a scripting language differs from HTML?


HTML Scripting
Language to create web pages Helps to create dynamic web pages
It is presentation language - delivers the Helps for interactions and processing a
images and text for the user logic
2. How to create a new browser window in Javascript?
WinObj=window.open(“url”,”name”,”features”)
WinObj - store the new windowobject
URL – What to be loaded in the window
Name - window name
List of Optional Features
3. What is the significance of, and reason for, wrapping the entire content of a JavaScript source file
in a function block?
This is an increasingly common practice, employed by many popular JavaScript libraries (jQuery,
Node.js, etc.). This technique creates a closure around the entire contents of the file which,
perhaps most importantly, creates a private namespace and thereby helps avoid potential name
clashes between different JavaScript modules and libraries.
4. Write the syntax for declaring a two dimensional array in Java.
type var-name[ ] [ ]=new type [ ] [ ];
For eg:
int twoD[][] = new int[4][5];
5. Write a Java code to find the Fibonacci series of a given number
class FibonacciExample1{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);
for(i=2;i<count;++i)
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
} }}

IT6503 / Internal Assessment -1 Answer Key Page 1 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

6. Compare and contrast final, finalize and finally


Final Finally Finalise
Keyword Block Method
Apply restrictions as follows Important code to execute Used to perform clean up just
Class – cannot be inherited irrespective of whether before object is garbage
Method – cannot be overidden exception is handled or not collected.
Variable – cannot be changed

PART B - (2 X 12 = 24 marks)
7. a)(i) Write a Javascript program to delete the rollno property from the following object. Also print
the object before and after deleting the property
Sample object: var student = {name:”Santhosh Ravy”, class:”VI”,rollno:29};
Solution
<!DOCTYPE html>
Output:
<html>
Before deleting : Santhosh Rayy VI
<head>
29 After deleting : Santhosh Rayy VI
<title>Delete a property from an object</title>
</head>
<body>
<script language= "JavaScript">
var Student = {
name: " Santhosh Ravy ",
class: "VI",
rollno: 29,
};
var txt = "";
for (x in Student) {
txt += Student[x] + " ";
}
document.write("Before deleting : " + txt);
delete Student.rollno;
var txt1 = "";
for (x in Student) {
txt1 += Student[x] + " ";
}
document.write("after delete : " + txt1);
</script>
</body>
</html>
(ii)Write a Javascript program to search a date (MM/DD/YYYY) within a string
Solution
!DOCTYPE html>
Output
<html>
truefalsetrue
<head>
<meta charset="utf-8">
<title>JavaScript function to check whether a given value is date string or not.</title>

IT6503 / Internal Assessment -1 Answer Key Page 2 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

</head>
<body>
<script>
function is_dateString(str)
{
regexp = /^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/(?:[0-9]{2})?[0-9]{2}$/;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
document.write(is_dateString("01/01/2015"));
document.write(is_dateString("32/30/2015"));
document.write(is_dateString("02/12/2015"));
</script>
</body>
</html>
OR
b)(i) Write short notes on JavaScript built-in objects
Object
Objects encapsulate data (attributes) and methods (behavior); the data and methods of an object
are tied together intimately. Objects have the property of information hiding. Programs
communicate with objects through well-defined interfaces. Normally, implementation details of
objects are hidden within the objects themselves.
Objects in Javascript are:
 Math
 String
 Date
 Boolean and number
 Window
 Document
Math Object
The Math object’s methods allow the programmer to perform many common mathematical
calculations. Few of it methods are:
Method Description Example
abs( x ) absolute value of x abs( 7.2 ) is 7.2
abs( 0.0 ) is 0.0
abs( -5.6 ) is 5.6
ceil( x ) rounds x to the smallest integer not less ceil( 9.2 ) is 10.0
than x ceil( -9.8 ) is -9.0
cos( x ) trigonometric cosine of x (x in radians) cos( 0.0 ) is 1.0
exp( x ) exponential method ex exp( 1.0 ) is 2.71828
exp( 2.0 ) is 7.38906
IT6503 / Internal Assessment -1 Answer Key Page 3 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

floor( x ) rounds x to the largest integer not floor( 9.2 ) is 9.0


greater than x floor( -9.8 ) is -10.0
log( x ) natural logarithm of x (base e) log( 2.718282 ) is 1.0
max( x, y ) larger value of x and y max( 2.3, 12.7 ) is 12.7
max( -2.3, -12.7 ) is -2.3
String Object
A string is a series of characters treated as a single unit. A string may include letters, digits and
various special characters, such as +, -, *, /, $ and others. JavaScript supports the set of characters
called Unicode that represents a large portion of the world’s commercially viable languages. Few of
it methods are:
Method Description
charAt( index ) Returns a string containing the character at the specified index. If there is no
character at the index, charAt returns an empty string. The first character is
located at index 0.
charCodeAt( index ) Returns the Unicode value of the character at the specified index. If there is no
character at the index, charCodeAt returns NaN (Not a Number).
concat( string ) Concatenates its argument to the end of the string that invokes the method.
The string invoking this method is not modified; instead a new String is
returned. This method is the same as adding two strings with the string
concatenation operator + (e.g., s1.concat( s2 ) is the same as s1 + s2).
fromCharCode( Converts a list of Unicode values into a string containing the corresponding
value1, value2, ) characters.
indexOf( Searches for the first occurrence of substring starting from position index in the
substring, index ) string that invokes the method. The method returns the starting index of
substring in the source string or –1 if substring is not found. If the index
argument is not provided, the method begins searching from index 0 in the
source string.
lastIndexOf( Searches for the last occurrence of substring starting from position index and
substring, index ) searching toward the beginning of the string that invokes the method. The
method returns the starting index of substring in the source string or –1 if
substring is not found. If the index argument is not provided, the method begins
searching from the end of the source string.
Date Object
Provides methods for date and time manipulations
Few of it methods are:
Method Description
getDate() Returns a number from 1 to 31 representing the day of the month in local time or
getUTCDate() UTC, respectively.
getDay() Returns a number from 0 (Sunday) to 6 (Saturday) representing the day of the
getUTCDay() week in local time or UTC, respectively.
getFullYear() Returns the year as a four-digit number in local time or UTC, respectively.
getUTCFullYear()
getHours() Returns a number from 0 to 23 representing hours since midnight in local time or
getUTCHours() UTC, respectively.
Boolean and Number Objects

IT6503 / Internal Assessment -1 Answer Key Page 4 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

Object wrappers for boolean true/false values and numbers


Method Description
toString() Returns the string “true” if the value of the Boolean object is true; otherwise, returns the
string “false.”
valueOf() Returns the value true if the Boolean object is true; otherwise, returns false.

Document Object
Manipulate document that is currently visible in the browser window
Method or Property Description
write( string ) Writes the string to the XHTML document as XHTML code.

writeln( string ) Writes the string to the XHTML document as XHTML code and adds a
newline character at the end.
document.cookie This property is a string containing the values of all the cookies stored on
the user’s computer for the current document. See Section 12.9, Using
Cookies.
document.lastModified This property is the date and time that this document was last modified.

Window Object
Provides methods for manipulating browser window
• Opening New Windows with JavaScript
– The JavaScript command to create a new browser window is
WinObj=window.open(“url”,”name”,”features”)
• The following are the components of the window.open() statement:
– The WinObj variable is used to store the new windowobject. You can access methods and properties
of the new object by using this name.
– The first parameter of the window.open() method is a URL, which will be loaded into the new
window. If it’s left blank, no web page will be loaded. In this case, you could use JavaScript to fill
the window with content.
– .The second parameter specifies a window name (here, WindowName). This is assigned to the
window object’s name property and is used to refer to the window.
– The third parameter is a list of optional features, separated by commas. You can customize the new
window by choosing whether to include the toolbar, status line, and other features. This enables
you to create a variety of “floating” windows, which might look nothing like a typical browser
window
• Setting the Features of a Pop-up Window
– The feature list obeys the following syntax:
“feature1=value1, feature2=value2…featureN=valueN”
• The window.close() method closes a window.
• Browsers don’t normally allow you to close the main browser window without the user’s
permission; this method’s main purpose is for closing windows you have created.
• For example, this statement closes a window called updatewindow: updatewindow.close();
Moving and Resizing Window
• window.moveTo() moves the window to a new position. The parameters specify the x (column) and
y (row) position.
• window.moveBy() moves the window relative to its current position. The x and y parameters can be
positive or negative, and are added to the current values to reach the new position.
• window.resizeTo() resizes the window to the width and height specified as parameters.
IT6503 / Internal Assessment -1 Answer Key Page 5 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

• window.resizeBy() resizes the window relative to its current size. The parameters are used to modify
the current width and height
(ii) Differentiate Client side scripting and server side scripting with suitable example
Server Side Scripting Client Side Scripting

Executes the server side scripting that Executes the client side scripting that resides
produces the page to be sent to the browser. at the user’s computer
Send out a page but it does not execute client- Execute client-side scripts.
side scripts.
Connect to the databases that reside on the Cannot be used to connect to the databases
web server on the web server
Access the file system residing at the web can’t access the file system that resides at the
server web server
Cannot be blocked by the user Can be blocked by the user
Response is comparatively slower Response is comparatively Faster

8. a) Elaborate the inheritance and their types in Java with example coding
Inheritance
One object acquires all the properties and behaviors of parent object.
Helps for code reusability
Runtime polymorphism can be achieved
Syntax
class subclass-name extends superclass-name {
// body of class
}

IT6503 / Internal Assessment -1 Answer Key Page 6 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

Example: Multi level Inheritance


Consider the following program. In it, the subclass BoxWeight is used as a superclass to create the
subclass called Shipment. Shipment inherits all of the traits of BoxWeight and Box, and adds a field
called cost, which holds the cost of shipping such a parcel.
// Extend BoxWeight to include shipping costs.
// Start with Box.
class Box {
private double width;
private double height;
private double depth;
// construct clone of an object
Box(Box ob) { // pass object to constructor
width = ob.width;
height = ob.height;
depth = ob.depth;
}
// constructor used when all dimensions specified
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
// constructor used when no dimensions specified
Box() {
width = -1; // use -1 to indicate
height = -1; // an uninitialized
depth = -1; // box
}
// constructor used when cube is created
Box(double len) {
width = height = depth = len;
}
// compute and return volume
double volume() {
return width * height * depth;
}
}
// Add weight.
class BoxWeight extends Box {
double weight; // weight of box
// construct clone of an object
BoxWeight(BoxWeight ob) { // pass object to constructor
super(ob);
weight = ob.weight;
}
// constructor when all parameters are specified
BoxWeight(double w, double h, double d, double m) {
super(w, h, d); // call superclass constructor
IT6503 / Internal Assessment -1 Answer Key Page 7 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

weight = m;
}
// default constructor
BoxWeight() {
super();
weight = -1;
}
// constructor used when cube is created
BoxWeight(double len, double m) {
super(len);
weight = m;
}
}
// Add shipping costs.
class Shipment extends BoxWeight {
double cost;
// construct clone of an object
Shipment(Shipment ob) { // pass object to constructor
super(ob);
cost = ob.cost;
}
// constructor when all parameters are specified
Shipment(double w, double h, double d,
double m, double c) {
super(w, h, d, m); // call superclass constructor
cost = c;
}
// default constructor
Shipment() {
super();
cost = -1;
}
// constructor used when cube is created
Shipment(double len, double m, double c) {
super(len, m);
cost = c;
}
}
class DemoShipment {
public static void main(String args[]) {
Shipment shipment1 = new Shipment(10, 20, 15, 10, 3.41);
Shipment shipment2 = new Shipment(2, 3, 4, 0.76, 1.28);
double vol;
vol = shipment1.volume();
System.out.println("Volume of shipment1 is " + vol);
System.out.println("Weight of shipment1 is "+ shipment1.weight);
System.out.println("Shipping cost: $" + shipment1.cost);
System.out.println();
IT6503 / Internal Assessment -1 Answer Key Page 8 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

vol = shipment2.volume();
System.out.println("Volume of shipment2 is " + vol);
System.out.println("Weight of shipment2 is "+ shipment2.weight);
System.out.println("Shipping cost: $" + shipment2.cost);
}
}
OR
b) Give a detailed description for creation of package in Java with an example
Package is a group of similar types of classes, interfaces and sub-packages
General form
package pkg;
package pkg1[.pkg2[.pkg3]];
Advantages
 categorize the classes and interfaces so that they can be easily maintained.
 provides access protection.
 removes naming collision.
Example
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}
 Compile: javac -d directory javafilename
 Run: java pkgname. javafilename
There are three ways to access the package from outside the package.
 import package.*;
 import package.classname;
 fully qualified name.
Example
package MyPack;
class Balance {
String name;
double bal;
Balance(String n, double b) {
name = n;
bal = b;
}
void show() {
if(bal<0)
System.out.print("--> ");
System.out.println(name + ": $" + bal);
}
}
class AccountBalance {
public static void main(String args[]) {
Balance current[] = new Balance[3];

IT6503 / Internal Assessment -1 Answer Key Page 9 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

current[0] = new Balance("K. J. Fielding", 123.23);


current[1] = new Balance("Will Tell", 157.02);
current[2] = new Balance("Tom Jackson", -12.33);
for(int i=0; i<3; i++) current[i].show();
}
}
PART C ( 1 X 14 = 14 marks)
9. a) (i) Write a script that inputs three integers from the user and displays the sum, average,
product, smallest and largest of the numbers in an alert dialog.
<html >
<head>
<title> sum, average, product, smallest and largest of the numbers </title>
<script type = "text/javascript">
<!--
var firstNumber; //first number entered by user
var secondNumber; //second number entered by user
var thirdNumber; //third number entered by user
var number1; //first number
var number2; //second number
var number3; //third number
var sum; //sum of the 3 numbers entered
var average; //average of the 3 numbers entered
var product; //product of the 3 numbers entered
var small; //smallest number of the 3
var large; //largest number of the 3
//read in first number from the user
firstNumber = window.prompt( "Enter first integer" );
//read in second number from the user
secondNumber = window.prompt( "Enter second integer" );
//read in third number from the user
thirdNumber = window.prompt( "Enter third integer" );
//convert numbers from strings to integers
number1 = parseInt( firstNumber );
number2 = parseInt( secondNumber );
number3 = parseInt( thirdNumber );
sum = number1 + number2 + number3; //add the numbers
product = number1 * number2 * number3; //multiply the numbers
average = (number1 + number2 + number3) / 3; //average of the 3 numbers
if ((number1 <= number2) && (number1 <= number3))
{small = number1
}
if ((number2 <= number1) && (number2 <= number3))
{small = number2
}
if ((number3 <= number1) && (number3 <= number2))
{small = number3
}
if ((number1 >= number2) && (number1 >= number3))
IT6503 / Internal Assessment -1 Answer Key Page 10 of 11

www.AUNewsBlog.net
www.AUNewsBlog.net

{large = number1
}
if ((number2 >= number1) && (number2 >= number3))
{large = number2
}
if ((number3 >= number1) && (number3 >= number2))
{large = number3
}
//display the results
window.alert( "The sum is " + sum + "\nThe product is " + product + "\nThe average is
" + average + "\nThe smallest number is " + small + "\nThe largest number is " + large);
//-->
</script>
</head>
<body></body>
</html>
(ii) Write javascript statements to accomplish each of the following tasks:
a) Declare variables sum and x.
var sum, x;
b) Assign 1 to variable x.
x=1;
c)Assign 0 to variable sum.
sum=0
d) Add variable x to variable sum, and assign the result to variable sum.
sum=sum+x;
e) Print "The sum is: ", followed by the value of variable sum
document.writeln( "<h1>The sum is " + sum + "</h1>" );

IT6503 / Internal Assessment -1 Answer Key Page 11 of 11

www.AUNewsBlog.net

You might also like