B.
TECH
COMPUTER SCIENCE ENGINEERING
Dr. A.P.J. Abdul Kalam Technical University
University, Uttar Pradesh
(AKTU)
SUBJECT – WEB TECHNOLOGY
UNIT 3
3- MOST EXPECTED
QUESTIONS AND ANSWERS
By Vishal Dhiman
Q. 1. What is JavaScript? How it works? What are the features of JavaScript?
Ans. JavaScript is the Programming Language for the Web.
JavaScript can update and change both HTML and CSS.
JavaScript can calculate, manipulate and validate data.
JavaScript is an open source language that anyone can use without purchasing a license
Working of JavaScript:
1. When the browser loads a web page, the HTML parser creates the DOM.
2. Whenever parser encounters JavaScript directive, it is handed over the JavaScript engine and loads the
external and inline code.
3. After HTML and CSS parsing is completed, JavaScript is executed in order they were found in web page
and DOM is updated and rendered by the browser.
JavaScript has several features:
1. Programming tool: JavaScript is a scripting language with very simple syntax.
2. Can produce dynamic text into an HTML page
3. Reaching to events: JavaScript code executes when something happens such as when page has finished
loading, when a user clicks on an HTML element.
4. Reading and writing HTML elements: JavaScript can read and change the content of an HTML element.
5. Validate data: JavaScript can be used to validate form data before it is submitted to a server, and thus
saves the server from extra processing.
.
Q. 2. What is the difference between Java and JavaScript ? Describe the strengths and weakness of
JavaScript.
Ans. Difference between Java and JavaScript :
Strengths/Advantages of JavaScript :
1. An interpreted language : JavaScript is an interpreted language, which requires no compilation steps.
2. Quick development : JavaScript does not require time consuming compilations, scripts can be developed
in a short period of time.
3. Performance : a. JavaScript can be written such that the HTML files are fairly compact and quite small.
b. It minimizes storage requirements on the web server and downloads time for the client.
4. Easy debugging and testing : Being an interpreted language, scripts in JavaScript are tested line by line
and the errors are also listed as they are encountered.
Q. 3. What are scripting languages and why JavaScript is used?
Ans. Scripting language:
1. A scripting language is a programming language designed for integrating and communicating with other
programming languages.
2. Some of the most widely used scripting languages are JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP.
JavaScript is used because:
a. It is executed on client side.
b. It saves bandwidth on web server.
c. It is written into an HTML page.
Q. 4. Explain the role of JavaScript to develop a web page.
Ans. Role of JavaScript:
1. It makes our website dynamic.
2. It makes our webpage interactive which means that it can respond to mouse clicks, double clicks, hover
and many other actions (called events).
3. It can also be used for modifying our html, content and styles, form validation.
4. JavaScript can interact with the website server to send and receive information to update UI in real-time.
Q. 5. Explain conditional statements used in JavaScript with example.
Ans. There are following conditional statement used in JavaScript :
1. If statement : If statement is used if we want to execute some code only if a specified condition is true.
Syntax :
if (condition)
{
code to be executed if condition is true
}
2. If...else statement : If...else statement is used when we do not confirm
about the condition that is true or not.
Syntax :
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
3. If...else if...else statement : We can use the if...else if...else statement
if we want to select one from many sets of lines with different condition.
Syntax :
if (condition1)
{
code to be executed if condition1 is true
}
else if (condition2)
{
code to be executed if condition2 is true
}
else
{
code to be executed if condition1 and condition2 are not true
}
Switch statement : If we want to select one of many blocks of code
then we use switch statement.
Syntax :
switch(n)
{
case 1 :
execute code block 1
break ;
case 2 :
execute code block 2
break ;
default ;
code to be executed if n is different from case 1 and 2
}
Q. 6. What is AJAX ? Explain the application of AJAX with the help of suitable examples.
AKTU 2015-16, Marks 10
OR
Discuss AJAX. Explain the application of AJAX with the help of suitable examples.
AKTU 2019-20, Marks 07
Ans. 1. AJAX (Asynchronous JavaScript and XML) is a set of web development techniques for creating better,
faster and more interactive web applications with the help of XML, HTML, CSS and JavaScript.
2. First a page is loaded. Next, the user performs some action such as filling out a form or clicking a link.
3. The user activity is then submitted to a server-side program for processing while the user waits until final
result is sent which reloads the entire page.
4. AJAX style applications use a significantly different model. Here user actions signal the server to fetch just
the data needed to update the page in response to the submitted actions.
5. This process generally happens asynchronously, thus it allows the user to perform other actions within
the browser while data is returned.
7. Asynchronous requests allow more than one thing to happen at the same time.
8. Only the relevant portion of the page is changed when we use AJAX, as shown in Fig.
Applications of AJAX are :
1. AJAX is used to change the text without reloading the web page.
2. AJAX is a technique used for creating fast and dynamic web pages.
3. AJAX contains div section which is used to display information returned from a server.
4. Major application of AJAX is in login forms where user can enter their login details directly on the original
page.
Q. 7. Explain TCP/IP client socket. Also, write the constructor and methods used to create a client socket.
Ans. 1. TCP/IP client sockets are used to implement bi-directional, point-to point, stream-based connections
between hosts on the Internet.
2. A socket can be used to connect Java I/O system to other programs that may reside either on the local
machine or on any other machine on the Internet.
3. The creation of a Socket object implicitly establishes a connection between the client and server.
4. Following are the two constructors used to create client socket :
a. Socket(String hostName, int port) : Creates a socket connecting the local host to the named host, port
and can throw an Unknown HostException or an IOException.
b. Socket(InetAddress ipAddress, int port) : Creates a socket using a pre-existing InetAddress object, a port
and can throw an IOException.
5. Following methods are used by TCP/IP client socket :
a. InetAddress getInetAddress() : Returns the InetAddress associated with the Socket object.
b. Int getPort() : Returns the remote port to which the Socket object is connected.
c. Int getLocalPort() : Returns the local port to which the Socket object is connected.
Q. 8. What is datagram ? Give its characteristics. Also, explain datagram socket.
Ans.
1. Datagram is a unit of transfer associated with networking.
2. Datagram is typically structured in header and payload section.
3. It provides a connectionless communication service across a packet-switched network.
Characteristics of datagram:
1. It is transmitted from source to destination without guarantee of delivery.
2. It provides a connectionless communication service.
Datagram socket :
1. It is a communication link used to send datagram between applications.
2. Datagram socket is a type of network socket which provide connectionless point for sending and receiving
packets.
3. Every packet sent from a datagram socket is individually routed and delivered.
4. Java DatagramSocket and DatagramPacket classes are used for connectionless socket programming.
5. A DatagramPacket is a message that can be sent or received through Datagram Socket.