0% found this document useful (0 votes)
77 views60 pages

WT U3 One shot Notes(Edushine Classes)

AKTU WT

Uploaded by

iamvansh22
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)
77 views60 pages

WT U3 One shot Notes(Edushine Classes)

AKTU WT

Uploaded by

iamvansh22
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/ 60

Web Technology (BCS502)

Unit-3 Scripting & Networking

Edushine Classes

Follow Us
Free Notes Available on : https://telegram.me/rrsimtclasses
https://telegram.me/rrsimtclasses/
Web Technology (BCS502)

Introduction :
• Javascript is a dynamic computer programming language.
• It is lightweight and most commonly used as a part of web pages, whose
implementations allow client-side script to interact with the user and
make dynamic pages.
• It is an interpreted programming language with object-oriented
capabilities.
• Java Script was developed by Netscape in 1995.
• JavaScript was first known as LiveScript, but Netscape changed its name
to JavaScript.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

JavaScript has three parts.


 Core: It includes Operators, Expressions, Statements, and Subprogram.
 Client Side: It is a collection of objects using which one can control
over the browser.
 Server Side: It is a collection of objects using which one can access the
database on the server.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 JavaScript – Syntax :
• JavaScript can be implemented using JavaScript statements that
are placed within the <script> ... </script> tags.
• You can place the <script> tags, containing your JavaScript, anywhere
within your web page, but it is normally recommended that you should
keep it within the <head> tags.
Syntax - <script language="javascript" type="text/javascript" src="MyPage.js">
JavaScript code • Language – This attribute specifies what
<script> </script> scripting language you are using. Typically, its
JavaScript code value will be "javascript."
</script> • Type – This attribute is what is now
recommended to indicate the scripting
language in use, and its value should be set
to "text/javascript."

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

Client – Side Validation –


Client-side validation is a process where the web browser checks the
data entered by a user in a form before sending it to the server. This
validation happens on the user's device (the "client") using HTML and
JavaScript. It helps ensure that the data entered is correct and
complete, making the user's experience smoother.
Why Use Client-Side Validation?
• Immediate Feedback: Users get instant responses if they make a
mistake (e.g., missing required fields).
• Reduces Server Load: Errors are caught before data is sent to the
server, saving resources.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

• Improves User Experience: Quick error messages help users corr ect
issues without waiting for a server response.
Common Types of Client-Side Validation –
1. Required Field Validation: Ensures that certain fields are not left empty.
html
Eg - <input type="text" required>
2. Data Type Validation: Checks if the entered data matches the expected type (e.g.,
numbers for age).
html
Eg - <input type="number">
3. Length Validation: Ensures the input is within a specific length range.
Html Eg - <input type="text" minlength="5" maxlength="10">

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

4. Pattern Matching: Uses regular expressions to ensure the input follows a


specific format (e.g., email).
html
Eg - <input type="email">
5. Range Validation: Ensures that numbers are within a certain range.
html
<input type="number" min="1" max="100">

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

<form onsubmit="return validateForm()" name="myForm">


<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<input type="submit" value="Submit">
</form>

onsubmit="return validateForm()": Calls the JavaScript function before form


submission.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

function validateForm() {
let email = document.forms["myForm"]["email"].value;
if (email == "") {
alert("Email must be filled out");
return false;
The function checks if the email field is
}
empty and shows an alert if it is.
}

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 What is Scripting Language –


Scripting languages are like tools that help you write small
programs (scripts) to automate tasks. They are easy to learn and
don't need to be changed into a special format before running
(interpreted).
Examples of Scripting Languages
• JavaScript: Makes websites interactive.
• Python: Good for making websites, automating things, and working with data.
• PHP: Used to create websites on the server side.
• Ruby: Helps build web applications.
• Perl: Used for managing and processing text.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Conditional Statement in JavaScript –


Conditional statements in JavaScript are used to make decisions in your
code. They allow you to execute different parts of your code based on
certain conditions (true or false). Think of it as making choices depending
on the situation.
Types of Conditional Statements
1. if Statement: Runs a block of code if a condition is true.
2. else Statement: Runs a block of code if the if condition is false.
3. else if Statement: Tests another condition if the first one is false.
4. switch Statement: Chooses between many blocks of code based on different
values.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
Example –
1. If Statement –
let age = 18;
If age is 18 or more, it prints "You are an adult."
if (age >= 18) {
console.log("You are an adult.");
}
2. If – else Statement –
let age = 16;
If age is less than 18, it prints "You are a minor."
if (age >= 18) {
console.log("You are an adult.");
} else {console.log("You are a minor.");}

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

3. If – else if – else Statement –


let age = 20;
if (age < 13) {
console.log("You are a child.");
} else if (age >= 13 && age < 18) {
console.log("You are a teenager.");
} else {
console.log("You are an adult.");
}
It Checks multiple conditions to categorize
age into child, teenager, or adult.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
4. Switch Statement –
let day = "Monday";
switch (day) {
case "Monday": It Checks the value of day and prints a message
console.log("Start of the work week."); based on its value. If none of the cases match, it runs
break; the default case.
case "Friday":
console.log("End of the work week.");
break;
case "Saturday":
case "Sunday":
console.log("Weekend!");
break;
default:
console.log("Midweek day.");
}

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Data Type in JavaScript –


• Data type indicates the types of data which you store in variable.
• There are two main categories: Primitive and Non-primitive.
1. Primitive Data Types
These are the basic types of data. Each value is immutable
(cannot be changed) and is stored directly.

1.String: Text wrapped in quotes.


• Example: "Hello", 'World'
let name = “Arman";

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

2. Number: Numbers, including integers and decimals.


Example: 5, 3.14
let age = 25;
3. Boolean: Represents true or false.
Example: true, false
let isAdult = true;
4. Undefined: A variable that is declared but not assigned a value.
let x;
console.log(x); // print -> undefined

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
5. Null: Represents an intentional absence of any value.
let y = null;
6. BigInt: Represents large integers beyond the safe limit of Number.
let bigNumber = 1234567890123456789012345678901234567890n;
2. Non-Primitive Data Types (Objects) –
These are more complex and can hold multiple values.
1.Object: A collection of key-value pairs.
let person = {
name: "John",
age: 30
};
Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
2. Array: A special kind of object used to store a list of values.
let colors = ["red", "green", "blue"];
3. Function: A block of code designed to perform a particular task.
function greet() {
return "Hello!";
}
 How JavaScript Handles Data Types –
let message = "Hi"; // It's a string
message = 123; // Now it's a number
Dynamic Typing: You don't need to specify the data type when you create a variable. JavaScript
automatically figures it out based on the value you assign.
javascript

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 JavaScript Functions :
A function in JavaScript is like a small machine or a recipe that you
create to do a specific task. It takes some input (if needed), processes it,
and gives back a result or does something.

Why Use Functions?


1. Reusability: Write a piece of code once and use it multiple times.
2. Organization: Break your code into smaller, manageable pieces.
3. Maintainability: Easier to update and debug your code.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
 How to Create a Function –
1. Function Declaration: You define a function using the
function keyword, give it a name, and write the steps inside
curly braces {}.
function greet() {
console.log("Hello, world!");
}
2. Function Expression: You can also store a function in a
variable.
const greet = function() {
console.log("Hello, world!");
};
Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

3. Arrow Function: A shorter way to write a function.


const greet = () => {
console.log("Hello, world!");
};
 How to Use (Call) a Function –
greet(); // Outputs: Hello, world!
 Functions with Parameters – •• Parameters: Variables listed in the function definition.
Arguments: Values you pass when calling the function.
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("Alice"); // Outputs: Hello, Alice!
Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Functions with Return Values –


function add(a, b) {
return a + b;
}
let sum = add(5, 3); // sum is now 8

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Objects in JavaScript –
An object in JavaScript is a collection of related data and functionalities.
You can think of it like a real-world object, such as a car or a person,
which has properties (data) and methods (functions).
Why Use Objects?
1. Organization: Group related data and functions together.
2. Reusability: Easily reuse the same structure for similar things.
3. Flexibility: Store and manipulate complex data.

Now lets discuss how to create an object –

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 How to Create an Object –


1. Using Object Literals: The simplest way to create an object is by
using curly braces {}.
let person = {
name: "Alice",
age: 30,
greet: function() {
console.log("Hello!");
}
};

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

2. Using new Object(): Another way is by using the Object constructor.


let person = new Object();
person.name = "Alice";
person.age = 30;
 Object Properties –
• Properties are key-value pairs that hold data about the object.Key: The
name of the property. let car = {
• Value: The data associated with the key. brand: "Toyota",
model: "Corolla",
year: 2021
};

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

Access properties using dot notation or bracket notation:


console.log(car.brand); // Outputs: Toyota
console.log(car["model"]); // Outputs: Corolla
 Object Methods -
• Methods are functions stored inside an object. They define behaviors or
actions.
let person = { this keyword: Refers to the object
name: "Alice", itself, used inside methods to
greet: function() { access the object’s properties
console.log("Hello, " + this.name);
}
};
person.greet(); // Outputs: Hello, Alice

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Modifying Objects – Nested Objects –


1. Add a property – let student = {
person.job = "Engineer"; name: "John",
2. Update a Property – marks: {
math: 85,
person.age = 31; science: 90
3. Delete a property – }
delete person.age; };
console.log(student.marks.math); // Outputs: 85

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Asynchronous in JavaScript -
In JavaScript, asynchronous means doing things in the background
without blocking the main program. This allows JavaScript to handle
tasks that take time, like fetching data from a server or reading a file,
without pausing other parts of your program.
Here’s an example to understand:
• Imagine you’re ordering pizza. While waiting for the delivery, you can
do other things, like watching TV or cleaning, instead of just sitting
idle. When the pizza arrives, the delivery person rings the doorbell,
and you handle it.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)
 Introduction to AJAX –
• AJAX is an acronym for Asynchronous JavaScript and XML. It is a group
of inter-related technologies like XML, HTML, CSS, and JavaScript, etc.
• AJAX allows you to send and receive data asynchronously without
reloading the web page. So it is fast.
• AJAX allows you to send only important information to the server, not
the entire page.
• Only valuable data from the client side is routed to the server side. It
makes your application interactive and faster.
• There are too many web applications running on the web that are using
AJAX technology like Gmail, Facebook, Twitter, Google Maps, YouTube, etc.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 AJAX Technologies -
• As described earlier, AJAX is not a technology but a group of inter-related
technologies. AJAX technologies include:
HTML/XHTML and CSS: These technologies are used for displaying
content and style. It is mainly used for presentation.
• DOM: It is used for dynamic display and interaction with data.
• XML or JSON: For carrying data to and from the server. JSON (JavaScript
Object Notation) is like XML but shorter and faster than XML.
• XMLHttpRequest: For asynchronous communication between client and
server.
• JavaScript: It is used to bring the above technologies together.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 XMLHttpRequest -
• An object of XMLHttpRequest is used for asynchronous
communication between client and server.
• It performs the following operations:
• Sends data from the client in the background.
• Receives the data from the server.
• Updates the webpage without reloading it.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 How AJAX Works(Working):

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 Working(How AJAX Works ?) -


1. Client-Side Event: The user triggers an event, such as clicking a
button or typing in a search box.
2. AJAX Request: A JavaScript function creates an XMLHTTPRequest
object and sends a request to the server asynchronously.
3. Server Processes Request: The server processes the request and
prepares a response.
4. AJAX Response: The server sends back the data, often in the form of
JSON or XML.
5. Update Web Page: The JavaScript on the client-side processes the
response and updates the web page without a full reload.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

<!DOCTYPE html>
<html> // Send the request
<head> xhr.send();
<title>AJAX Example</title> }
<script> </script>
function loadData() { </head>
// Create an XMLHttpRequest object <body>
var xhr = new XMLHttpRequest(); <h1>AJAX Example</h1>
<button onclick="loadData()">Fetch Data</button>
// Define the type of request (GET) and the URL (data.txt) <div id="result"></div>
xhr.open('GET', 'data.txt', true); </body>
</html>
// Define what to do when the response is received
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Update the content of the div with id "result"
document.getElementById('result').innerHTML = xhr.responseText; } };

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)
 Advantages of AJAX –
1. Faster Performance: Since only specific parts of the web page are updated, it
reduces the load on the server and speeds up the performance.
2. Improved User Experience: AJAX allows for smoother and more dynamic
interactions on a web page, such as instant feedback from forms or interactive
maps.
3. Reduced Bandwidth Usage: By updating only necessary parts of a page,
AJAX reduces the amount of data sent between the client and server, which
helps in saving bandwidth.
4. Asynchronous Processing: Users can continue to interact with a web page
while a request is being processed in the background.
5. Partial Page Updates: Only a section of a page is updated without reloading
the entire page, which makes the web application more responsive and user-
friendly.
Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

Networking
 IP Addressing- (V.IMP)
An IP (Internet Protocol) Address is a unique identifier assigned to each
device connected to a network. It acts like a postal address, ensuring data is
sent to the correct destination on the internet. Think of it as your computer’s
personal phone number that other devices use to find and communicate
with it.
There are two main versions of IP addresses:
1. IPv4: This is the older and more widely used format.
i. It consists of 32 bits and is usually written as four decimal numbers
separated by dots (e.g., 192.168.1.1).
ii. Each number ranges from 0 to 255.
Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 Classification of IP Addresses -
IP addresses are classified into different categories, primarily based on
their Class.
1. IP Address Classes (IPv4)
IPv4 addresses are divided into five classes: Class A, Class B, Class C, Class
D, and Class E. The first few bits of the IP address determine its class.
i. Class A
• Range: 1.0.0.0 to 126.255.255.255
• First Bit: Starts with 0.
• Purpose: Used for large networks with many devices.
• Default Subnet Mask: 255.0.0.0
• Number of Networks: 128 (2^7) networks.
• Number of Hosts per Network: Over 16 million (2^24 - 2) hosts.

Follow U Free
s
R R Notes
S I M T CLASSES
Available WHATSAPP
on - 9795358008
: https://telegram.me/rrsimtclasses
Web Technology (BCS502)
ii. Class B
• Range: 128.0.0.0 to 191.255.255.255
• First Bits: Starts with 10.
• Purpose: Used for medium-sized networks.
• Default Subnet Mask: 255.255.0.0
• Number of Networks: 16,384 (2^14) networks.
• Number of Hosts per Network: Over 65,000 (2^16 - 2) hosts.
iii. Class C
• Range: 192.0.0.0 to 223.255.255.255
• First Bits: Starts with 110.
• Purpose: Used for small networks.
• Default Subnet Mask: 255.255.255.0
• Number of Networks: 2 million (2^21) networks.
• Number of Hosts per Network: 254 (2^8 - 2) hosts.

Free Notes
RRSIMT CLASSES Available
WHATSAPP on : https://telegram.me/rrsimtclasses
– 9795358008 Follow us On
Web Technology (BCS502)
iv. Class D
• Range: 224.0.0.0 to 239.255.255.255
• First Bits: Starts with 1110.
• Purpose: Used for multicast groups (sending data to multiple
destinations).
• Subnet Mask: Not applicable.
v. Class E
• Range: 240.0.0.0 to 255.255.255.255
• First Bits: Starts with 1111.
• Purpose: Reserved for experimental purposes.
• Subnet Mask: Not applicable.

Free Notes
RRSIMT CLASSES Available
WHATSAPP on : https://telegram.me/rrsimtclasses
– 9795358008 Follow us On
Web Technology (BCS502)

 InetAddress Class
The InetAddress class in Java is part of the java.net package and is
used to represent an IP address. It provides methods to work
with both IPv4 and IPv6 addresses. This class allows you to
resolve hostnames to IP addresses and vice versa.
Main Uses of InetAddress:
i. Resolving hostnames to IP addresses: For example,
converting "www.google.com" to its corresponding IP
address.
ii. Resolving IP addresses to hostnames: Converting an IP
address back to its hostname.

Free Notes
RRSIMT CLASSES Available
WHATSAPP on : https://telegram.me/rrsimtclasses
– 9795358008 Follow us On
Web Technology (BCS502)

 Factory Methods of InetAddress -


Factory methods are special methods that create and return
objects. In the case of InetAddress, these methods are used to create
InetAddress objects. Let's go through the most important factory
methods in detail:
1. getLocalHost():
• Purpose: This method returns the InetAddress object
representing the code is running). local host (the machine on
which the code is running). It helps you find out the
IP address and
InetAddress localHost = InetAddress.getLocalHost(); hostname of your own
System.out.println("Local Host: " + localHost); machine.

Free Notes
RRSIMT CLASSES Available
WHATSAPP on : https://telegram.me/rrsimtclasses
– 9795358008 Follow us On
Web Technology (BCS502)

2. getByName(String host):
• Purpose: This method returns the InetAddress object for a given
hostname or IP address.
Example -
InetAddress address = InetAddress.getByName("www.google.com");
System.out.println("IP Address: " + address); • It looks up the IP address for
a given hostname. If you pass
an IP address, it will directly
return the corresponding
InetAddress object.

Follow us O Free
R R SNotes
n I M T Available
CLASSES onWHATSAPP
: https://telegram.me/rrsimtclasses
– 9795358008
Web Technology (BCS502)

3. getAllByName(String host):
• Purpose: This method returns an array of InetAddress objects for a given
hostname.
Example –
InetAddress[] addresses = InetAddress.getAllByName("www.google.com");
for (InetAddress address : addresses) {
System.out.println(address);
}
Some hostnames (especially large websites) can be associated
with multiple IP addresses for load balancing. This method
returns all the IP addresses associated with the hostname.

Follow us O Free
R R SNotes
n I M T Available
CLASSES onWHATSAPP
: https://telegram.me/rrsimtclasses
– 9795358008
Web Technology (BCS502)

4. getByAddress(byte[] addr):
• Purpose: This method returns an InetAddress object for a given raw IP
address in the form of a byte array.
Example –
byte[] ipAddr = {127, 0, 0, 1};
InetAddress address = InetAddress.getByAddress(ipAddr);
System.out.println("Address: " + address);

It creates an InetAddress object directly from an IP address provided as a byte array.

Follow us O Free
R R SNotes
n I M T Available
CLASSES onWHATSAPP
: https://telegram.me/rrsimtclasses
– 9795358008
Web Technology (BCS502)

 Summary of Factory Methods:


i. getLocalHost(): Gets the local machine's IP address and hostname.
ii. getByName(String host): Converts a hostname to an IP address.
iii. getAllByName(String host): Returns all IP addresses for a hostname.
iv. getByAddress(byte[] addr): Converts a raw IP address (in byte form)
to an InetAddress object.
• Think of InetAddress as a phonebook for the internet. It helps find the phone number (IP
address) when you know someone's name (hostname) and vice versa.
• Factory methods are like a set of predefined tools that create objects to make it
easier to use this phonebook efficiently.

Follow us O Free
R R SNotes
n I M T Available
CLASSES onWHATSAPP
: https://telegram.me/rrsimtclasses
– 9795358008
Web Technology (BCS502)

 Instance Methods -
Instance methods are methods that belong to an object of a class.
These methods can use and manipulate the data (fields or variables)
that belong to the object.
Key Points About Instance Methods:
1. Accessing Data: Instance methods can directly access and modify
the instance variables of the object.
2. Need an Object: To call an instance method, you need to create an
instance (object) of the class.
3. Defined with No static: They are defined without the static keyword.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

public class Car {


// Instance variables
String brand;
int speed;

// Instance method
public void setSpeed(int newSpeed) {
speed = newSpeed; // Updates the speed of this particular car
}

// Instance method
public void displayDetails() {
System.out.println("Brand: " + brand + ", Speed: " + speed);
}
}

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 TCP/IP Client Socket -


TCP/IP Client Socket is a concept used in computer networking. It allows a
device (like a computer or a phone) to connect to another device (like a server)
over the internet or any network using the TCP/IP protocol. Let's break this
down in simple terms:
What is TCP/IP?
1. TCP (Transmission Control Protocol): It ensures that data sent over the
network is delivered accurately and in the right order.
2. IP (Internet Protocol): It handles addressing and routing of data, making
sure it reaches the correct destination.
Together, TCP/IP is the foundation of how devices communicate over the internet.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 What is a Socket?
A socket is like a plug that allows a program on your device to connect to
another device over a network.
A client socket is used by the device that is initiating the connection (the
client).
 How TCP/IP Client Socket Works:
i. Creating a Socket: The client creates a socket to start the connection.
ii. Connecting to the Server: The client socket uses the server's IP address
and port number to establish a connection.
iii. Sending and Receiving Data: Once connected, the client can send data
to the server and receive responses.
iv. Closing the Connection: After communication is done, the client closes the socket.
Free Notes Available on : https://telegram.me/rrsimtclasses
Web Technology (BCS502)

 URL & URLConnection Class in Java – (V.IMP)


In Java, the URL and URLConnection classes help you work with
URLs (Uniform Resource Locators) to access resources on the
internet, like web pages, images, or files.
What is a URL?
• A URL is like an address on the internet that tells where to find a
resource. For example, https://www.example.com/page is a URL.
• It contains:
i. Protocol: The way of communication (e.g., http, https).
ii. Domain: The website address (e.g., www.example.com).
iii. Path: The specific file or page (e.g., /page).

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 URL Class in Java:


The URL class in Java represents a URL and provides methods to
access its different parts.
 Key Methods of URL Class:
1. getProtocol(): Returns the protocol (e.g., http or https).
2. getHost(): Returns the host (domain name).
3. getPort(): Returns the port number (default is 80 for HTTP, 443 for
HTTPS).
4. getPath(): Returns the path (the specific page or file).
5. getQuery(): Returns the query part (parameters after ?).

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)
Example -
import java.net.URL;

public class URLExample {


public static void main(String[] args) {
try {
URL url = new URL("https://www.example.com/page?name=arman");
System.out.println("Protocol: " + url.getProtocol());
System.out.println("Host: " + url.getHost());
System.out.println("Port: " + url.getPort());
System.out.println("Path: " + url.getPath());
System.out.println("Query: " + url.getQuery());
} catch (Exception e) {
e.printStackTrace();
}
}
};

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 TCP/IP Server Socket -


In Java, Server Sockets are used to create a server that listens for and
accepts requests from clients over the network. It is a part of the TCP/IP
protocol, which ensures reliable communication between devices.
What is a Socket?
A socket is an endpoint for sending or receiving data across a computer
network.
TCP (Transmission Control Protocol) ensures that data is delivered
accurately and in the same order it was sent.
IP (Internet Protocol) handles the addressing and routing of data.
Server Socket in Java:
Web Technology (BCS502)

A Server Socket listens for requests from clients. Once a request is received,
it establishes a connection and allows data to be sent back and forth.

 Socket Programming –
Socket programming is a way of enabling communication between two
computers (or devices) over a network. It allows these devices to send and
receive data, like chatting or exchanging files, using the internet or any
network.
What is a Socket?
A socket is like a phone line that connects two computers, allowing them to
talk to each other.
Free Notes Available on : https://telegram.me/rrsimtclasses
Web Technology (BCS502)
It has two main parts:
IP Address: The address of the computer on the network.
Port Number: A specific endpoint on the computer where the
connection happens.
 What is Datagram -
A datagram is a small, self-contained packet of data that is sent over a
network. It's a key part of the User Datagram Protocol (UDP), which is a
way of sending information between computers. Unlike a phone call
(which is continuous and connected), sending a datagram is like sending a
postcard. You send it out, and it gets to the destination without needing a
direct connection.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)
 Characteristics of a Datagram:
1. Connectionless:
1.No need to establish a connection between sender and receiver. It’s
like sending a text message without first making a phone call.
2. Unreliable:
1.The datagram might get lost, arrive out of order, or be duplicated
because there’s no guarantee it will reach its destination. It’s like
sending a letter without tracking.
3. Fast:
1.Because there’s no need to set up a connection, datagrams are sent
and received quickly. It’s like a quick text message compared to a
lengthy phone call.
Free Notes Available on : https://telegram.me/rrsimtclasses
Web Technology (BCS502)

4. Simple Structure:
1.Each datagram contains all the information needed to get it to the
destination, such as the destination address and data. It’s like a
postcard that has the address and message all in one.
5. Small Size:
1.Datagrams are typically small and can be easily sent over the network,
making them suitable for applications like online games, voice calls, or
video streaming where speed is important.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

 What is a Datagram Socket?


A datagram socket is a way for a program to send and receive datagrams
over the network using UDP (User Datagram Protocol). It’s like a door
that allows packets (datagrams) to come in and go out.
When to Use Datagram Sockets?
i. Real-time Applications: Like online gaming, voice-over IP (VoIP), or
video streaming where speed is more critical than perfect accuracy.
ii. Simple Messaging: Sending short messages quickly without worrying
about establishing a connection.

Free Notes Available on : https://telegram.me/rrsimtclasses


Web Technology (BCS502)

Thank You…

Free Notes Available on : https://telegram.me/rrsimtclasses

You might also like