Unit 3 WT
Unit 3 WT
1 Java script: Introduction, documents, forms, To include JavaScript in HTML document, you must
statements, functions, Objects enclose it inside <Script>…</Script> tag, you must set
type attribute of script tag to text/JavaScript. You can write
script anywhere within HTML document but it is
Scripting
preferable to write it inside <Head> … </Head> tags.
JavaScript is an object-based scripting language which is
lightweight and cross-platform. Example:
javaScript is an object-oriented language that allows
< HTML>
creation of interactive Web Pages. JavaScript allows user
<HEAD>
entries, which are loaded into an HTML form to be
processed as required. This empowers a web site to return <TITLE>Home Page</TITLE> <SCRIPT type =
site information according to a user’s requests. “text/javascript”>
JavaScript is not a compiled language, but it is a translated // JavaScript Statements…
</SCRIPT>
language. The JavaScript Translator (embedded in the
browser) is responsible for translating the JavaScript code </HEAD>
for the web browser. <BODY> </BODY>
JavaScript is a dynamic programming language for </HTML>
computers. It is a lightweight component of web pages
whose implementations allow client-side scripts to Features of JavaScript
communicate with users and create dynamic pages. It's an There are following features of JavaScript:
object-oriented programming language that can be
interpreted. 1. All popular web browsers support JavaScript as
JavaScript is a lightweight, cross-platform object-based they provide built-in execution environments.
scripting language. 2. JavaScript follows the syntax and structure of the
JavaScript is a translated language, not a compiled C programming language. Thus, it is a structured
language. The JavaScript Translator (which is built into programming language.
the browser) is in charge of translating JavaScript code for 3. JavaScript is a weakly typed language, where
web browsers. certain types are implicitly cast (depending on the
JavaScript (js) is a lightweight object-oriented operation).
programming language that is used to script webpages by a 4. JavaScript is an object-oriented programming
number of websites. When applied to an HTML document, language that uses prototypes rather than using
it is an interpreted, full-featured programming language classes for inheritance.
that enables dynamic interactivity on websites. 5. It is a light-weighted and interpreted language.
6. It is a case-sensitive language.
It was first released in 1995 to enable users to add 7. JavaScript is supportable in several operating
programs to webpages in the Netscape Navigator browser. systems including, Windows, macOS, etc.
Since then, all other graphical web browsers have followed 8. It provides good control to the users over the web
it. Users can use JavaScript to create modern web browsers.
applications that communicate directly without having to
reload the page every time. Js is used on a typical website Application of JavaScript
to include various ways of interactivity and simplicity. JavaScript is used to create interactive websites. It is
mainly used for:
Steps for writing and executing JavaScript
o Client-side validation,
1) Write HTML And script code into source document
o Dynamic drop-down menus,
in a text editor o Displaying date and time,
2) Save the source document file o Displaying pop-up windows and dialog boxes
3) Open any browser and open source document in (like an alert dialog box, confirm dialog box and
browser and view output prompt dialog box),
Please note that, if you made any change in your source
o Displaying clocks etc.
document then you must save it then refresh browser to
view the changes.
● XML (often used as the format for transferring data) Until an IP packet is sent over the network, it contains two
main components: a header and a payload.
String toString( ) : Returns a string that lists the host Socket (String hostname1, int port1)
name and the IP address for convenience.
Where hostname1 is a string style variable referring to the
destination address, and port1 is the destination address's
port number. In the event of an error, this method will
throw the UnknownHostException or IOException
exceptions.
A TCP/IP client socket connects two computers on a Example: Client Side Code
network in a secure, bi-directional, stream-based link. An import java.net.*;
instance of the Socket class is used to implement the client import java.io.*;
socket. Its aim is to establish a connection to the server and class clientsock
initiate protocol exchanges. {
public static void main (String args []) throws
TCP/IP sockets are used to create stable, bidirectional, IOException
permanent, point-to-point, stream-based connections {
between Internet hosts. A socket connects Java's I/O System.out.println("sending request to server....");
device to other programs running on the local computer or Socket client=new Socket ("127.0.0.1",1235);
on some other machine connected to the Internet. System.out.println("successfully connected");
BufferedReader br1=new BufferedReader
In Java, there are two types of TCP sockets. The first is for (new InputStreamReader (System.in));
servers, and the second is for clients. The ServerSocket PrintStream ps=new
class is intended to function as a "listener," meaning it will PrintStream(client.getOutputStream());
Using the getInputStream () method of the For server applications, Java has a separate socket class
URLConnection class, we may show all of the data from a that must be used. The ServerSocket class is used to build
webpage. The getInputStream () method returns all of the servers that listen on published ports for connections from
data in the stream that can be read and displayed for the local or remote client programs. Server Sockets are not the
given URL. same as regular Sockets.
public static void main (String [] args) { Three of its constructors are as follows:
try {
URL url=new
URL("http://www.javatpoint.com/java-tutorial");
URLConnection urlcon=url.openConnection();
Fig 4: constructor
InputStream stream=urlcon.getInputStream();
Accept () is a blocking method on ServerSocket that waits
int i; for a client to initiate communication before returning with
a regular Socket that can be used to communicate with the
while((i=stream.read())! =-1) { client.
System.out.print((char)i); 10 Datagram
DatagramSocket
DatagramSocket defines four public constructors. They are
shown here: DatagramSocket () throws SocketException