Gurgaon: World College of Technology & Management
Gurgaon: World College of Technology & Management
Subject:
Web Development
Class:
Q.1.
Solution:
AO
Object Oriented Programming or OOP is the technique to create programs based on the real
world. Unlike procedural programming, here in the OOP programming model programs are
organized around objects and data rather than actions and logic. Objects represent some
concepts or things and like any other objects in the real Objects in programming language have
certain behavior, properties, type, and identity. In OOP based language the principal aim is to
find out the objects to manipulate and their relation between each other. OOP offers greater
flexibility and compatibility and is popular in developing larger application. Another important
work in OOP is to classify objects into different types according to their properties and behavior.
So OOP based software application development includes the analysis of the problem,
preparing a solution, coding and finally its maintenance.
TM
Java is a object oriented programming and to understand the functionality of OOP in Java, we
first need to understand several fundamentals related to objects. These include class, method,
inheritance, encapsulation, abstraction, polymorphism etc.
W
C
Class - It is the central point of OOP and that contains data and codes with behavior. In Java
everything happens within class and it describes a set of objects with common behavior. The
class definition describes all the properties, behavior, and identity of objects present within that
class. As far as types of classes are concerned, there are predefined classes in languages like
C++ and Pascal. But in Java one can define his/her own types with data and code.
Object - Objects are the basic unit of object orientation with behavior, identity. As we mentioned
above, these are part of a class but are not the same. An object is expressed by the variable
and methods within the objects. Again these variables and methods are distinguished from each
other as instant variables, instant methods and class variable and class methods.
Methods - We know that a class can define both attributes and behaviors. Again attributes are
defined by variables and behaviors are represented by methods. In other words, methods define
the abilities of an object.
Inheritance - This is the mechanism of organizing and structuring software program. Though
objects are distinguished from each other by some additional features but there are objects that
share certain things common. In object oriented programming classes can inherit some
common behavior and state from others. Inheritance in OOP allows to define a general class
and later to organize some other classes simply adding some details with the old class
definition. This saves work as the special class inherits all the properties of the old general class
and as a programmer you only require the new features. This helps in a better data analysis,
accurate coding and reduces development time.
Abstraction - The process of abstraction in Java is used to hide certain details and only show
the essential features of the object. In other words, it deals with the outside view of an object
(interface).
AO
Q.2.
W
C
TM
Polymorphism - It describes the ability of the object in belonging to different types with specific
behavior of each type. So by using this, one object can be treated like another and in this way it
can create and define multiple level of interface. Here the programmers need not have to know
the exact type of object in advance and this is being implemented at runtime.
Solution:
Method overloading:
In Java it is possible to define two or more methods within the same class that share the
same name, as long as their parameter declarations are different. When this is the case,
the methods are said to be overloaded, and the process is referred to as method
overloading. Method overloading is one of the ways that Java implements
polymorphism.
Demonstrate method overloading.
class OverloadDemo {
AO
void test() {
System.out.println("No parameters");
}
// Overload test for one integer parameter.
void test(int a) {
System.out.println("a: " + a);
}
// Overload test for two integer parameters.
void test(int a, int b) {
System.out.println("a and b: " + a + " " + b);
}
// overload test for a double parameter
double test(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
W
C
TM
class Overload {
public static void main(String args[]) {
OverloadDemo ob = new OverloadDemo();
double result;
// call all versions of test()
ob.test();
ob.test(10);
ob.test(10, 20);
result = ob.test(123.2);
System.out.println("Result of ob.test(123.2): " + result);
}
}
Constructors:
A constructor is a special method that is used to initialize a newly created object and is called
just after the memory is allocated for the object
It can be used to initialize the objects ,to required ,or default valuesat the time of object creation
It is not mandatory for the coder to write a constructor for the class.
In order to create a Constructor observe the following rules
1) It has the same name as the class
2) It should not return a value not even void
class Demo{
int value1;
int value2;
Demo(){
value1 = 10;
value2 = 20;
System.out.println("Inside Constructor");
}
AO
}
}
Q.3.
W
C
d1.display();
TM
Solution:
The inheritance allows subclasses to inherit allproperties (variables and methods) of their parent
classes. The different forms of inheritance are:
Single inheritance (only one super class)
Multiple inheritance (several super classes)
Hierarchical inheritance (one super class, many sub classes)
Multi-Level inheritance (derived from a derived class)
AO
int y;
int get(int p, int q){
void Show(){
System.out.println(x);
}
class B extends A{
W
C
void Showb(){
TM
System.out.println("B");
}
}
class C extends B{
void display(){
System.out.println("C");
}
public static void main(String args[]){
A a = new A();
a.get(5,6);
a.Show();
}
}
Q.4.
What is java interface? Can we achieve multiple inheritance with the help of interface?
Explain with suitable example.
Solution:
AO
In the Java programming language, an interface is a reference type, similar to a class, that can
contain only constants, method signatures, and nested types. There are no method bodies.
Interfaces cannot be instantiatedthey can only beimplemented by classes or extended by
other interfaces.
Multiple Inheritance
The mechanism of inheriting the features of more than one base class into a single class is
known as multiple inheritance. Java does not support multiple inheritance but the multiple
inheritance can be achieved by using the interface.
TM
W
C
interface Area
{
float compute(float x, float y);
}
}
}
class InterfaceArea
{
public static void main(String args[])
{
Rectangle rect = new Rectangle();
Triangle tri = new Triangle();
Area area;
area = rect;
System.out.println("Area Of Rectangle = "+ area.compute(1,2));
Solution:
U
G
TM
Q.5.
AO
area = tri;
System.out.println("Area Of Triangle = "+ area.compute(10,2));
}
}
W
C
a) packages: A package allows a developer to group classes (and interfaces) together. These
classes will all be related in some way they might all be to do with a specific application or
perform a specific set of tasks.
package battleships
class GameBoard{
}
Every class with the above package statement at the top will now be part of the Battleships
package.
In a Java source file, the package that this file's class or classes belong to is specified
with the package keyword. This keyword is usually the first keyword in source file.
package java.awt.event;
AO
In the multithreading concept, several multiple lightweight processes are run in a single
process/task or program by a single processor. For Example, When you use a word
processor you perform a many different tasks such as printing, spell checking and so on.
Multithreaded software treats each process as a separate program.
W
C
TM
In Java, the Java Virtual Machine (JVM) allows an application to have multiple threads of
execution running concurrently. It allows a program to be more responsible to the user. When a
program contains multiple threads then the CPU can switch between the two threads to execute
them at the same time.
For example, look at the diagram shown as:
In this diagram, two threads are being executed having more than one task. The task of each
thread is switched to the task of another thread.
Advantages of multithreading over multitasking :
Q.6.
Solution:
AO
A Java applet is an applet delivered to users in the form of Java bytecode. Java applets can run
in a Web browser using a Java Virtual Machine (JVM), or in Sun's AppletViewer, a stand-alone
tool for testing applets. Java applets were introduced in the first version of the Java language in
1995, and are written in programming languages that compile to Java bytecode, usually in Java.
Applet runs in the browser and its lifecycle method are called by JVM when it is loaded and
destroyed. Here are the lifecycle methods of an Applet:
Q.7.
W
C
TM
destroy(): This method is called only once in the life cycle of the applet when applet is
destroyed.
Solution:
</form>
The following elements can make up the user-inputting portion of a form:
input field
text a simple text box that allows input of a single line of text (an
alternative, password, is used for security purposes, in which the characters typed in are
invisible or replaced by symbols such as *)
reset a reset button that, when activated, tells the browser to restore the values
to their initial values.
submit a button that tells the browser to take action on the form (typically to
send it to a server)
textarea much like the text input field except a textarea allows for multiple rows of data
to be shown and entered
select a drop-down list that displays a list of items a user can select from
Q.7.
AO
TM
The <meta> tag provides metadata about the HTML document. Metadata will not be displayed
on the page, but will be machine parsable.
W
C
Meta elements are typically used to specify page description, keywords, author of the
document, last modified, and other metadata.
The <meta> tag always goes inside the head element.
The metadata can be used by browsers (how to display content or reload page), search engines
(keywords), or other web services.
<meta name="keywords" content="HTML, CSS, XML" />
Semantic HTML is the use of HTML markup to reinforce the semantics, or meaning, of the
information in webpages rather than merely to define its presentation (look). Semantic HTML is
processed by regular web browsers as well as by many other user agents. CSS is used to
suggest its presentation to human users.
Semantic HTML or semantic markup is HTML that introduces meaning to the web page rather
than just presentation.
Abbreviation
<blockquote>
Long quotation
<dfn>
Definition
<address>
<code>
Code reference
<del>
Deleted text
<ins>
Inserted text
What do you mean by style sheet? Explain internal style specification within HTML.
AO
Q.8.
<abbr>
Solution:
Style sheets represent a major breakthrough for Web page designers, expanding their ability to
improve the appearance of their pages. In the scientific environments in which the Web was
conceived, people are more concerned with the content of their documents than the
presentation.
TM
The purpose of style sheets is to separate the content of the HTML documents from their style.
This makes control over the style much easier and group efforts easier since content of an
entire set of HTML pages can be easily controlled using one or more style sheets.
W
C
<html>
<head>
<title>Example Style Settings</title>
</head>
<style type="text/css">
Body
</style>
Internal Style Sheet
An internal style sheet is a section on an HTML page that contains style definitions. Internal
style sheets are defined by using the <style> tag within the <head> area of the document. Here
is an example of an internal style sheet:
<html>
<head>
AO
Q.9.
Solution:
TM
W
C
Every web page resides inside a browser window which can be considered as an object.
A Document object represents the HTML document that is displayed in that window. The
Document object has various properties that refer to other objects which allow access to and
modification of document content.
The way that document content is accessed and modified is called the Document Object Model,
or DOM. The Objects are organized in a hierarchy. This hierarchical structure applies to the
organization of objects in a Web document.
Window object: Top of the hierarchy. It is the outmost element of the object hierarchy.
Document object: Each HTML document that gets loaded into a window becomes a
document object. The document contains the content of the page.
Form object: Everything enclosed in the <form>...</form> tags sets the form object.
Form control elements: The form object contains all the elements defined for that object
such as text fields, buttons, radio buttons, and checkboxes.
U
G
TM
AO
W
C
a) Output in javaScript
JavaScript is special from other languages because it can accept input and produce
output on the basis of that input in the same page. That mean, you don't have to go to
other page or refreash the page to see the output.
Functions to show output
1)window.alert():
2)window.status()
3)document.write()
1)window.alert(): This function show the message in a small messagebox . The
messagebox contains the string and an "OK"button on it. If the user presses the "OK"
button the messagebox dissapears. The message to be displayed has to be passed as
parameter window.alert() .
Code example :
<html>
<body>
<script language="Javascript">
window.alert ("Hello");
</script>
</body>
</html>
2)window.status(): This function show the message in statusbar . The message to be displayed
has to be passed as parameter window.status() .
Code example :
W
C
TM
<html>
<body>
<script language="Javascript">
document.write( "Welcome to JavaScript");
document.close();
</script >
</body>
</html>
AO
<html>
<body>
<script language="Javascript">
window.status ="Welcome to JavaScript";
</script >
</body>
</html>
3)document.write(): This function print a string in the current page. The message to be
displayed has to be passed as parameter document.write() .
Code example :
1.
2.
3.
4.
5.
6.
A mouse click
A web page or an image loading
Mousing over a hot spot on the web page
Selecting an input field in an HTML form
Submitting an HTML form
A keystroke
Event Handlers:
Use this to invoke JavaScript upon clicking (a link, or form boxes)
onload:
Use this to invoke JavaScript after the page or an image has finished loading.
onmouseover:
onmouseout:
Use this to invoke JavaScript if the mouse goes pass some link
onunload:
Use this to invoke JavaScript right after someone leaves this page.
AO
onclick:
The onLoad and onUnload events are triggered when the user enters or leaves the page.
The onLoad event is often used to check the visitor's browser type and browser version, and
load the proper version of the web page based on the information.
W
C
TM
Both the onLoad and onUnload events are also often used to deal with cookies that should be
set when a user enters or leaves a page. For example, you could have a popup asking for the
user's name upon his first arrival to your page. The name is then stored in a cookie. Next time
the visitor arrives at your page, you could have another popup saying something like: "Welcome
John Doe!".
onFocus, onBlur and onChange
The onFocus, onBlur and onChange events are often used in combination with validation of
form fields.Below is an example of how to use the onChange event. The checkEmail() function
will be called whenever the user changes the content of the field:
<input type="text" size="30" id="email" onchange="checkEmail()">
onSubmit
The onSubmit event is used to validate ALL form fields before submitting it.
Below is an example of how to use the onSubmit event. The checkForm() function will be called
when the user clicks the submit button in the form. If the field values are not accepted, the
submit should be cancelled. The function checkForm() returns either true or false. If it returns
true the form will be submitted, otherwise the submit will be cancelled:
<form method="post" action="xxx.htm" onsubmit="return checkForm()">
onMouseOver
The onmouseover event can be used to trigger a function when the user mouses over an HTML
element:
AO
<head>
</head>
TM
<body>
</script>
</head>
<body>
W
C
<script type="text/javascript">
Q.12. What is server side programming? Explain in brief Common gateway interface.
Solution:
Server-side scripting is a web server technology in which a user's request is verified by running
a script directly on the web server to generate dynamic web pages. It is usually used to provide
interactive web sites that interface to databases or other data stores.
CGI
W
C
TM
AO
Though it is technically feasible to implement almost any business logic using client side
programs, logically or functionally it carries no ground when it comes to enterprise applications
(e.g. banking, air ticketing, e-shopping etc.). To further explain, going by the client side
programming logic; a bank having 10,000 customers would mean that each customer should
have a copy of the program(s) in his or her PC which translates to 10,000 programs! In addition,
there are issues like security, resource pooling, concurrent access and manipulations to the
database which simply cannot be handled by client side programs. The answer to most of the
issues cited above is ? ?Server Side Programming?. Figure-1 illustrates Server side
architecture in the simplest terms.
When you are dealing with Web pages, you will often hear people talk about CGI or CGI scripts
without ever explaining exactly what that is. Essentially, CGI is the connection (or interface)
between a form on a Web page and the Web server.
Web pages cannot interact directly with the reader. In fact, until JavaScript came along, Web
pages had no way of interpreting reader reaction except through interaction with the server they
were running on. This interaction is done through scripts and programs that use common
gateway interface to create interactive programs on your Web pages.
GET -- the data are passed within the query string of the URL.
POST -- the data are sent as a message body that follows the request message sent by the
client to the server. This is more complex than GET, but allows for more complex data.
Q.13. Explain Active server pages and its advantages.
Solution:
Abbreviated as ASP, a specification for a dynamically created Web page with
a.ASP extension that utilizes ActiveX scripting -- usually VB Script or Jscriptcode. When
a browser requests an ASP, the Web server generates a page with HTML code and sends it
back to the browser. So ASPs are similar to CGIscripts, but they enable Visual Basic
programmers to work with familiar tools
AO
Solution:
//Form processing using javascript
<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
<TITLE>Test Input</TITLE>
TM
}
</SCRIPT>
</HEAD>
W
C
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
</FORM>
</BODY>
</HTML>
//Form processing using VBScript
<HTML>
<HEAD>
<TITLE>Date/Time Example</TITLE>
</HEAD>
<BODY>
<CENTER>
AO
</FORM>
Sub btnTime_OnClick
TM
frmMyForm.timeinfo.value = Now
<SCRIPT LANGUAGE="vbscript">
End Sub
</SCRIPT>
</BODY>
W
C
frmMyForm.timeinfo.value = Now
</HTML>
Pronounced ver-mal, and short for Virtual Reality Modeling Language, VRML is a specification
for displaying 3-dimensional objects on the World Wide Web. You can think of it as the 3-D
equivalent of HTML. Files written in VRML have a.wrl extension (short for world). To view these
files, you need a VRMLbrowser or a VRML plug-in to a Web browser.
VRML produces a hyperspace (or a world), a 3-dimensional space that appears on your display
screen. And you can figuratively move within this space. That is, as you press keys to turn left,
right, up or down, or go forwards or backwards, the images on your screen will change to give
the impression that you are moving through a real space.
VRML 1.0
This is the first generation of VRML.
AO
It describes the foundations of a world including geometry, lighting, color, texture and linking.
Platform independence
Extensibility
TM
VRML 2.0
W
C
If you have used shell scripts or awk or sed or similar (Unix) utilities for various purposes, you
will find that you can normally use Perl for those and many other purposes, and the code tends
to be more compact. And if you haven't used such utilities but have started thinking you might
have need for them, then perhaps what you really need to learn is Perl instead of all kinds of
futilities.
Perl is implemented as an interpreted (not compiled) language. Thus, the execution of a Perl
script tends to use more CPU time than a corresponding C program, for instance. On the other
hand, computers tend to get faster and faster, and writing something in Perl instead of C tends
to save your time.
AO
Solution:
Java Applets
TM
Java's primary contribution to the Web, however, has been in the form of Java applets, which
are self-contained, mini-executable programs. These programs, named with the .class suffix,
can be placed right on the web page, like a graphic.
W
C
Java Servlets
When compared to the Common Gateway Interface (CGI) and proprietary server
extensions such as Netscape Server API (NSAPI) or Microsofts Internet Services API
(ISAPI), servlets provide a better abstraction of the Hypertext Transfer Protocol (HTTP)
request-response paradigm. In addition, servlets have all the advantages of the Java
programming language, including platform independence. Java servlet based
applications can be deployed on any web server with built-in (in-process) or connectorbased (out-of-process) servlet engines, irrespective of the operating system and the
hardware platform. This is one of the reasons for servlets gaining wide acceptance over
the past one year.
TM
AO
W
C
Solution:
Cookies are small amounts of data stored by the web browser. They allow you to store
particular information about a user and retrieve it every time they visit your pages. Each user
has their own unique set of cookies.
Cookies are typically used by web servers to perform functions such as tracking your visits to
websites, enabling you to log in to sites, and storing your shopping cart. However we don't need
fancy web server programming to use cookies. We can use them in JavaScript, too!
How Cookies work
A Cookies is nothing but a small text file thats stored in your browser. It contains some data:
var x = document.cookie;
AO
domain=domain; secure";
Description
name=value
username=matt
expires=date
expires=
13/06/2003 00:00:00
path=/tutorials/
W
C
TM
Property
path=path
domain=domain
Example
domain=elated.com
Q.18. Give a brief description of Microsoft .net technology and discuss how it is better than
other technologies?
AO
Solution:
TM
W
C
A Microsoft operating system platform that incorporates applications, a suite of tools and
services and a change in the infrastructure of the company's Web strategy.
There are four main principles of .NET from the perspective of the user:
It erases the boundaries between applications and the Internet. Instead of interacting
with an application or a single Web site, .NET will connect the user to an array of computers and
services that will exchange and combine objects and data.
Software will be rented as a hosted service over the Internet instead of purchased on a
store shelf. Essentially, the Internet will be housing all your applications and data.
Users will have access to their information on the Internet from any device, anytime,
anywhere.
There will be new ways to interact with application data, such as speech and handwriting
recognition.
Reasons Why dotNET Is Better Than Java
1- In .NET you have a choice of languages to code with (C#,VB.NET, Java,Boo,Python e.t.c),
producing the same type of compiled code but in Java one is limited to the java
language..
2, NET prgrams run at native speed while java is interpreted which makes java slower.Although
java has Just In Time compilation but it stills run slower. With .NET you are not limited to
JIT but have the option AOT or ahead of time compilation if you want to eliminate startup
delays.
3. Calling native code in java is not a very clean process. You need to generate some stub files
which makes the whole process cumbersome and dirty. In .NET you just declare that
you are calling a native function from a specified library and just start calling it.
4. .NET languages are richer than Java. They have object oriented feature that are absent in
java e.g properties,delegates,generics.
5. Java GUI programs look alien on the host operating system. Even if you use the OS's theme
you still notice that the java widgets look out of place.
AO
6. Many programs that would have been difficult to develop with java have been developed with
.NET things like compilers (Mono's C# and VB.NET) 3D game engines (unity game
engine) etc.
W
C
TM
7. You can code on the .NET platform using Java but you cannot code on Java platform using
any of the .NET languages.
A system of Internet servers that support specially formatted documents. The documents are
formatted in a markup language called HTML (HyperText Markup Language) that supports links
to other documents, as well asgraphics, audio, and video files. This means you can jump from
one document to another simply by clicking on hot spots. Not all Internet servers are part of the
World Wide Web.
There are several applications called Web browsers that make it easy toaccess the World Wide
Web; Two of the most popular being Firefox andMicrosoft's Internet Explorer.
The Internet
The Internet, on the technological level, consists of the wires, cables, machines, and networking
software which connects millions of computers around the world. This complex infrastructure of
computer networks is the pavement of the "Information Superhighway" that allows web
browsers to communicate with servers, request, send, and receive information from around the
world, regardless of global location.
Information Servers
Information servers run on computers connected to the Internet all over the world. Information
servers are processes (executing computer software) which dish out information as requested
from users connected to the same network (in the case of the WWW, the public Internet). The
most common information types of servers on the Internet today are:
AO
Extensible Markup Language (XML) is a set of rules for encoding documents in machinereadable form. It is defined in the XML 1.0 Specification produced by the W3C, and several
other related specifications, all gratis open standards
W
C
TM
The design goals of XML emphasize simplicity, generality, and usability over the Internet.[6] It is
a textual data format with strong support via Unicode for the languages of the world. Although
the design of XML focuses on documents, it is widely used for the representation of arbitrary
data structures, for example in web services.
XHTML (eXtensible HyperText Markup Language) is a family of XML markup languages that
mirror or extend versions of the widely-used Hypertext Markup Language (HTML), the language
in which web pages are written. XHTML is an application of XML, a more restrictive subset of
SGML. Because XHTML documents need to be well-formed, they can be parsed using standard
XML parsers unlike HTML, which requires a lenient HTML-specific parser.
The World Wide Web Consortium (W3C) is an international community where Member
organizations, a full-time staff, and the public work together to develop Web standards