Download Our Mobile App
Server-side scripting is a programming technique for creating code that may run software on the server side. In other words, server-side scripting is any scripting method that may operate on a web server. At the server end, actions such as website customization, dynamic changes in website content, response creation to user requests, database access, and many more are carried out.
Server-side scripting creates a communication channel between a server and a client. The server-side is made up of three parts: the database, the server, the APIs, and the backend web software written in the server-side scripting language. When a browser requests a page with server-side scripting, the web server evaluates the script before delivering the page to the browser. In this case, script processing may entail collecting information from a database, performing simple computations, or selecting the relevant material to be shown on the client end. The output is provided to the web browser when the script is processed. The web server hides the scripts from the end user until the content is delivered, making the data and source code safer.
Client side scripting
Client-side scripting is a programming technique used to manipulate the content and behavior of a web page directly within the user's web browser. This type of scripting allows developers to create interactive and dynamic user interfaces without needing to communicate with the server for every action. Client-side scripting languages are executed by the browser and can respond to user interactions in real-time.
Javascript Events
The change in the state of an object is known as an Event. In html, there are various events which represents that some activity is performed by the user or by the browser. When javascript code is included in HTML, js react over these events and allow the execution. This process of reacting over the events is called Event Handling. Thus, js handles the HTML events via Event Handlers.
Here are some examples of HTML events:
An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked
Event Performed
Event Handler
Description
click
onclick
When mouse click on an element
mouseover
onmouseover
When the cursor of the mouse comes over the element
mouseout
onmouseout
When the cursor of the mouse leaves an element
mousedown
onmousedown
When the mouse button is pressed over the element
mouseup
onmouseup
When the mouse button is released over the element
mousemove
onmousemove
When the mouse movement takes place.
Event Performed
Event Handler
Description
Keydown & Keyup
onkeydown & onkeyup
When the user press and then release the key
Event Performed
Event Handler
Description
focus
onfocus
When the user focuses on an element
submit
onsubmit
When the user submits the form
blur
onblur
When the focus is away from a form element
change
onchange
When the user modifies or changes the value of a form element
<html>
<head> Javascript Events </head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function clickevent()
{
document.write("This is JavaTpoint");
}
//-->
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
</html>
<html>
<head>
<h1> Javascript Events </h1>
</head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function mouseoverevent()
{
alert("This is JavaTpoint");
}
//-->
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
</body>
</html>
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onkeydown="keydownevent()"/>
<script>
<!--
function keydownevent()
{
document.getElementById("input1");
alert("Pressed a key");
}
//-->
</script>
</body>
</html>
Javascript Forms
Working with forms in JavaScript involves interacting with HTML forms on web pages. Forms are used to gather user input, such as text, selections, and checkboxes, which can then be submitted to the server for processing. JavaScript is commonly used to enhance the functionality and validation of forms to provide a better user experience.
Here's how you can work with forms in JavaScript:
1. **Accessing Form Elements:**
Use JavaScript to select form elements using methods like `document.getElementById`, `document.querySelector`, or `document.getElementsByName`. These methods allow you to access form controls like text fields, radio buttons, checkboxes, and more.
2. **Event Handling:**
Attach event listeners to form elements to respond to user interactions. Common events include `'submit'` for form submission, `'input'` for text input changes, and `'change'` for changes in selections or checkboxes.
3. **Form Validation:**
Use JavaScript to validate user input before the form is submitted. You can perform checks such as checking required fields, validating email addresses, or ensuring specific formats are followed.
4. **Preventing Default Behavior:**
For forms, it's often important to prevent the default behavior of submitting the form when handling form submissions with JavaScript. You can achieve this by using the `event.preventDefault()` method inside your event handler.
Here's an example of working with a form using JavaScript:
```html
<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
</head>
<body>
<form id="myForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<input type="submit" value="Submit">
</form>
<script>
const form = document.getElementById('myForm');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('email');
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
// Perform form validation
if (nameInput.value === '' || emailInput.value === '') {
alert('Please fill in all fields.');
} else {
alert('Form submitted successfully!');
// You can also submit the form data to a server using AJAX
}
});
</script>
</body>
</html>
```
In this example, the JavaScript code attaches an event listener to the form's `'submit'` event. When the user submits the form, the event handler checks if the required fields are filled out. If the fields are empty, an alert is shown. Otherwise, a success message is shown.
Remember that form handling in JavaScript can involve various levels of complexity, including more advanced validation, handling different types of form controls, and sending form data to servers for processing.
PHP connection to DB
Index.php
<?php
include("connection.php");
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<div id="form">
<h1>Login Form</h1>
<form name="form" method="POST" action="login.php" onsubmit="return isvalid()">
<label>Username</label>
<input type="text" id="user" name="user"><br><br>
<label>Password</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" name="submit" id="btn" value="login"/>
</form>
</div>
<script type="text/javascript">
function isvalid()
{
var user = document.form.user.value;
var password = document.form.password.value;
if(user.length=="" && password.length==""){
alert("username and password is empty");
return false;
}
else{
if(user.length==""){
alert("username is empty!");
return false;
}
if(password.length==""){
alert("password is empty!");
return false;
}
}
}
</script>
</body>
</html>
Style.css
body{
background-color: violet;
}
#form{
background-color: white;
width:25%;
margin: 120px auto;
padding: 50px;
box-shadow: 10px 10px 5px rgb(82,11,77);
border-radius: 6px;
}
#btn{
color: white;
background-color: rgb(108,15,190);
padding: 8px;
font-size: large;
border-radius: 10px;
}
@media screen and (max-width: 700px){
#eform{
width:65px;
padding: 40px;
}
}
Connection.php
<?php
$servername = "localhost";
$usename = "root";
$password = "";
$db_name = "test";
$conn = new mysqli($servername,$usename,$password, $db_name);
if($conn->connect_error){
die("connection failed".$conn->connect_error);
}
echo "";
?>
Login.php
<?php
include("connection.php");
//if(isset($_POST('submit'))){
$username = $_POST['user'];
$password = $_POST['password'];
$sql = "select * from test where username ='$username' and password ='$password'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count==1){
header("location:welcome.php");
}
else{
echo '<script>
window.location.href ="index1.php";
alert("login failed. Invalid username or password")
</script>';
}
//}
?>
Welcome.php
<!DOCTYPE html>
<html>
<head>
<title>welcome</title>
</head>
<body>
<h1>login sucess!</h1>
</body>
</html>
OOP( Object Oriented programming)
Programming Paradigms
Programming paradigms are fundamental styles or approaches to programming that dictate how you structure and organize code to solve problems. These paradigms provide guidelines and methodologies for software development and influence the way developers think about and design their programs. Different programming paradigms have distinct principles, concepts, and practices. Here are some of the most common programming paradigms.
Advantages of OOP:
1. **Modularity**: OOP promotes modularity by encapsulating data (attributes) and methods (functions) into objects. This modular approach makes it easier to manage and maintain co mide because changes to one part of the code do not necessarily affect other parts.
2. **Reusability**: OOP allows for the creation of reusable code components. Once a class is defined, it can be used to create multiple objects with the same structure and behavior. This reusability saves time and effort in development.
3. **Abstraction**: Abstraction is the process of simplifying complex reality by modeling classes based on real-world objects. OOP allows developers to abstract real-world entities into classes with clear interfaces, hiding the underlying complexity. This abstraction makes code more understandable and maintainable.
4. **Encapsulation**: Encapsulation is the concept of bundling data (attributes) and methods (functions) that operate on that data within a single unit (the object). Access to an object's internal data is typically controlled through access modifiers like public, private, and protected. Encapsulation helps maintain data integrity and reduces unintended interference from external code.
5. **Inheritance**: Inheritance allows the creation of new classes (subclasses or derived classes) that inherit properties and methods from existing classes (superclasses or base classes). This promotes code reuse and the creation of hierarchical relationships between classes.
6. **Polymorphism**: Polymorphism is the ability of different classes to be treated as instances of a common superclass. It allows for flexibility in code, as objects of different classes can respond to the same method calls in a way that is appropriate for their specific implementations. This promotes code extensibility and flexibility.
7. **Ease of Maintenance**: OOP's modular and organized structure makes it easier to understand and maintain code over time. When changes or updates are needed, developers can often modify or extend individual classes without affecting the entire codebase.
8. **Team Collaboration**: OOP can facilitate collaboration among development teams because it encourages a structured approach to software design. Developers can work on individual classes or modules independently, which can improve productivity in larger projects.
9. **Modeling Real-World Concepts**: OOP allows developers to model and represent real-world concepts and relationships in code, which can lead to more intuitive and comprehensible software designs.
10. **Security**: Encapsulation and access control provided by OOP can enhance security by preventing unauthorized access and modification of data and functionality.
11. **Code Extensibility**: OOP makes it easier to extend existing code by adding new classes or modifying existing ones. This extensibility is particularly valuable when adapting software to changing requirements.
12. **Testing and Debugging**: OOP code is often easier to test and debug because of its modular nature. Unit testing can be performed on individual classes, and problems can often be isolated to specific modules.
Application of OOP
1. **Software Development**: OOP is used extensively in general software development to create applications, whether they are desktop applications, web applications, or mobile apps. It helps in organizing code and managing complexity, making it easier to design, develop, and maintain software.
2. **Game Development**: Many video games are developed using OOP principles. Game objects such as characters, items, and environments are represented as classes, and their behaviors are defined using methods. Inheritance and polymorphism are often used to model game entities and their interactions.
3. **Graphical User Interfaces (GUIs)**: OOP is well-suited for building graphical user interfaces. UI elements like buttons, text boxes, and windows are often represented as objects, and their interactions are defined through event-driven programming.
4. **Simulation and Modeling**: OOP is used in scientific and engineering simulations to model real-world systems. Classes can represent physical objects, and their behaviors are defined using methods. This approach is commonly used in fields like physics, biology, and economics.
5. **Database Systems**: Object-Relational Mapping (ORM) frameworks use OOP concepts to map database tables to classes. This allows developers to work with databases in an object-oriented way, making it easier to interact with and manipulate data.
6. **Web Development**: OOP is applied in web development using various programming languages and frameworks. In web applications, classes often represent entities like users, products, or orders, and object-oriented design patterns are used to organize code efficiently.
7. **Mobile App Development**: OOP is employed in mobile app development for platforms like Android (Java/Kotlin) and iOS (Swift/Objective-C). User interface elements, data models, and app functionality are structured using object-oriented principles.
8. **Embedded Systems**: OOP is used in embedded systems programming, where classes can represent hardware components, sensors, and controllers. Object-oriented design helps manage the complexity of firmware development.
9. **AI and Machine Learning**: OOP can be used to structure machine learning models and algorithms. Classes may represent neural network layers, optimization algorithms, or data preprocessing steps. OOP can also be used in AI for game AI and agent-based modeling.
10. **Financial Software**: OOP is employed in the development of financial software and trading platforms. Classes can represent financial instruments, portfolios, or trading strategies, making it easier to manage complex financial systems.
11. **E-commerce and Content Management Systems**: OOP is used to create e-commerce platforms and content management systems (CMS). Classes represent products, users, content, and various functionalities within these systems.
12. **Robotics and Control Systems**: In robotics and control systems, OOP is used to model and control robotic components and devices. Classes can represent robot parts, sensors, and control algorithms.
13. **Healthcare and Medical Software**: OOP is applied in healthcare software for patient records management, medical imaging, and treatment planning. Classes may represent patient data, medical devices, and treatment protocols.
14. **CAD and 3D Modeling**: Computer-Aided Design (CAD) and 3D modeling software often use OOP to represent 3D objects, their properties, and interactions.
These are just a few examples of how Object-Oriented Programming is applied in various domains. OOP's ability to model complex systems and promote code reusability makes it a versatile and valuable programming paradigm in the field of software development.
C program
Function
A function is a group of statements that together perform a task. Every C program has at least one function, which is main().
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times.
Advantages of Function
Enables reusability and reduces redundancy
Makes a code modular
Provides abstraction functionality
The program becomes easy to understand and manage
Breaks an extensive program into smaller and simpler pieces
There are two types of function in C programming:
The standard library functions are built-in functions in C programming.
These functions are defined in header files. For example,
The printf() is a standard library function to send formatted output to the screen (display output on the screen). This function is defined in the stdio.h header file.
Hence, to use the printf()function, we need to include the stdio.h header file using #include <stdio.h>.
The sqrt() function calculates the square root of a number. The function is defined in the math.h header file.
You can also create functions as per your need. Such functions created by the user are known as user-defined functions.
Recursion
Recursion is a programming concept where a function calls itself in its own definition. In C, a recursive function is a function that performs a task in part and then calls itself to perform the remaining task. This process continues until a base condition is met, at which point the function stops calling itself and returns a result.
For eg
Int fun()
{
fun();
}
Program to find factorial of numbers using recursive.
#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}
long int multiplyNumbers(int n) {
if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
}
Fibonacci series
#include<stdio.h>
int main() //fibonacci series
{
int t1=0;
int t2 = 1;
int t3;
int i,n,nextterm;
//printf("The terms are %d %d\n",t1,t2);
printf("Enter the terms\n");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("The terms are %d\n",nextterm);
t1=t2;
t2=nextterm;
nextterm = t1+t2;
}
return 0;
}
SDLC( Software Development Life Cycle)
Software development is comprised of well-organized and defined processes that aim to create a programmed product to meet business objectives or goals. In fact, the software product is created by a team of software developers writing computer code. However, it also consists of various software design process steps, including requirement analysis, research, planning, designing a data and process flow, comprehensive testing, creating technical documentation, debugging, and deploying it.
What is SDLC?
SDLC is a process followed for a software project, within a software organization. It consists of a detailed plan describing how to develop, maintain, replace and alter or enhance specific software. The life cycle defines a methodology for improving the quality of software and the overall development process.SDLC provides a well-structured flow of phases that help an organization to quickly produce high-quality software which TT is well-tested and ready for production use.
A typical Software Development Life Cycle consists of the following stages −
Requirement analysis is the most important and fundamental stage in SDLC. It is performed by the senior members of the team with inputs from the customer, the sales department, market surveys and domain experts in the industry. This information is then used to plan the basic project approach and to conduct product feasibility study in the economical, operational and technical areas.
Planning for the quality assurance requirements and identification of the risks associated with the project is also done in the planning stage. The outcome of the technical feasibility study is to define the various technical approaches that can be followed to implement the project successfully with minimum risks.
Once the requirement analysis is done the next step is to clearly define and document the product requirements and get them approved from the customer or the market analysts. This is done through an SRS (Software Requirement Specification) document which consists of all the product requirements to be designed and developed during the project life cycle.
SRS is the reference for product architects to come out with the best architecture for the product to be developed. Based on the requirements specified in SRS, usually more than one design approach for the product architecture is proposed and documented in a DDS - Design Document Specification.
This DDS is reviewed by all the important stakeholders and based on various parameters as risk assessment, product robustness, design modularity, budget and time constraints, the best design approach is selected for the product.
A design approach clearly defines all the architectural modules of the product along with its communication and data flow representation with the external and third party modules (if any). The internal design of all the modules of the proposed architecture should be clearly defined with the minutest of the details in DDS.
In this stage of SDLC the actual development starts and the product is built. The programming code is generated as per DDS during this stage. If the design is performed in a detailed and organized manner, code generation can be accomplished without much hassle.
Developers must follow the coding guidelines defined by their organization and programming tools like compilers, interpreters, debuggers, etc. are used to generate the code. Different high level programming languages such as C, C++, Pascal, Java and PHP are used for coding. The programming language is chosen with respect to the type of software being developed.
This stage is usually a subset of all the stages as in the modern SDLC models, the testing activities are mostly involved in all the stages of SDLC. However, this stage refers to the testing only stage of the product where product defects are reported, tracked, fixed and retested, until the product reaches the quality standards defined in the SRS.
Once the product is tested and ready to be deployed it is released formally in the appropriate market. Sometimes product deployment happens in stages as per the business strategy of that organization. The product may first be released in a limited segment and tested in the real business environment (UAT- User acceptance testing).
Then based on the feedback, the product may be released as it is or with suggested enhancements in the targeting market segment. After the product is released in the market, its maintenance is done for the existing customer base.
Software development can be challenging to manage due to changing requirements, technology upgrades, and cross-functional collaboration. The software development lifecycle (SDLC) methodology provides a systematic management framework with specific deliverables at every stage of the software development process. As a result, all stakeholders agree on software development goals and requirements upfront and also have a plan to achieve those goals.
Here are some benefits of SDLC:
Increased visibility of the development process for all stakeholders involved
Efficient estimation, planning, and scheduling
Improved risk management and cost estimation
Systematic software delivery and better customer satisfaction
System Analyst
A systems analyst is an IT professional who works on a high level in an organization to ensure that systems, infrastructures and computer systems are functioning as effectively and efficiently as possible. System analysts carry the responsibilities of researching problems, finding solutions, recommending courses of actions and coordinating with stakeholders in order to meet specified requirements. They study the current system, procedures and business processes of a company and create action plans based on the requirements set.
Systems analysts need to be familiar with different operating systems, hardware configurations, programming languages, and software and hardware platforms. They can be involved starting from the analysis phase of the project until the post deployment assessment review.
Responsibility of System Analyst
Analysis: Systems analysts examine and understand the current systems and processes in an organization. They identify areas that need improvement or automation by studying user requirements and business objectives.
Design: After analyzing the existing systems, systems analysts create detailed specifications for the development of new systems or the modification of existing ones. They design the architecture, user interfaces, and other components based on the identified requirements.
Implementation: Systems analysts are often involved in the actual development or implementation of new systems. They work closely with programmers and other IT professionals to ensure that the designed system is effectively put into practice.
Testing: Before a new system is deployed, systems analysts conduct thorough testing to ensure that it meets the specified requirements and functions correctly. They may also assist in debugging and troubleshooting any issues that arise during the testing phase.
Documentation: Systems analysts document every phase of the system development life cycle. This documentation serves as a reference for future maintenance, upgrades, and troubleshooting. It also helps in training end-users and other IT professionals.
Communication: Effective communication is a crucial skill for systems analysts. They need to interact with various stakeholders, including end-users, managers, and IT professionals. Clear communication helps in understanding user needs and ensures that the developed systems align with organizational goals.
Project Management: Systems analysts often participate in project management activities. They may be responsible for defining project scope, estimating resources, creating timelines, and ensuring that the project stays within budget.
WAP in c using structure to input name,id and salary of staff and display the name, id and salary whose salary is higher than 30000?
#include <stdio.h>
#include <string.h>
// Define a structure to represent staff information
struct Staff {
char name[50];
int id;
float salary;
};
int main() {
int n; // Number of staff members
int i =0;
printf("Enter the number of staff members: ");
scanf("%d", &n);
// Declare an array of structures to store staff information
struct Staff staffArray[n];
// Input information for each staff member
for ( i = 0; i < n; i++) {
printf("\nEnter details for staff member %d:\n", i + 1);
printf("Name: ");
scanf("%s", staffArray[i].name); // Note: Using %s for string input
printf("ID: ");
scanf("%d", &staffArray[i].id);
printf("Salary: ");
scanf("%f", &staffArray[i].salary);
}
// Display details of staff members with salary higher than 25000
printf("\nStaff members with salary higher than 25000:\n");
for (i = 0; i < n; i++) {
if (staffArray[i].salary > 25000) {
printf("Name: %s\n", staffArray[i].name);
printf("ID: %d\n", staffArray[i].id);
printf("Salary: %.2f\n", staffArray[i].salary);
printf("-------------------------\n");
}
}
return 0;
}
Introduction of SQL DML Commands
Data Manipulation Language (DML) commands in SQL deal with the manipulation of data records stored within the database tables. It does not deal with changes to database objects and their structure. The commonly known DML commands are INSERT, UPDATE, and DELETE. Liberally speaking, we can consider even SELECT statements as a part of DML commands.
Command
Description
SELECT
Used to query or fetch selected fields or columns from a database table
INSERT
Used to insert new data records or rows in the database table
UPDATE
Used to set the value of a field or column for a particular record to a new value
DELETE
Used to remove one or more rows from the database table
1. SELECT
SELECT command or statement in SQL is used to fetch data records from the database table and present it in the form of a result set. It is usually considered as a DQL command, but it can also be considered as DML.
The basic syntax for writing a SELECT query in SQL is as follows :
SELECT column_name1, column_name2, …
FROM table_name
WHERE condition_ expression;
Example SELECT * FROM customers;
2. INSERT
INSERT commands in SQL are used to insert data records or rows in a database table. In an INSERT statement, we specify both the column_names for which the entry has to be made along with the data value that has to be inserted.
The basic syntax for writing INSERT statements in SQL is as follows :
INSERT INTO table_name (column_name_1, column_name_2, column_name_3, ...)
VALUES (value1, value2, value3, ...)
Example INSERT INTO customers
VALUES ('1006','2020-03-04',3200,'DL', '1008');
3. UPDATE
UPDATE command or statement is used to modify the value of an existing column in a database table.
The syntax for writing an UPDATE statement is as follows :
UPDATE table_name
SET column_name_1 = value1, column_name_2 = value2, ...
WHERE condition;
Example:
UPDATE customers
SET store_state = 'DL'
WHERE store_state = 'NY';
4. DELETE
DELETE statement in SQL is used to remove one or more rows from the database table. It does not delete the data records permanently. We can always perform a rollback operation to undo a DELETE command. With DELETE statements, we can use the WHERE clause for filtering specific rows.
The syntax for writing a DELETE statement is as follows :
DELETE FROM table_name WHERE condition;
Having learned the syntax, we are all set to try an example based on the DELETE command in SQL.
DELETE FROM customers
WHERE store_state = 'MH'
AND customer_id = '1001';
OSI stands for Open System Interconnection is a reference model that describes how information from a software application in one computer moves through a physical axemedium to the software application in another computer.
OSI consists of seven layers, and each layer performs a particular network function.
OSI model was developed by the International Organization for Standardization (ISO) in 1984, and it is now considered as an architectural model for the inter-computer communications.
OSI model divides the whole task into seven smaller and manageable tasks. Each layer is assigned a particular task.
Each layer is self-contained, so that task assigned to each layer can be performed independently.
There are the seven OSI layers. Each layer has different functions. A list of seven layers are given below:
Physical Layer
Data-Link Layer
Network Layer
Transport Layer
Session Layer
Presentation Layer
Application Layer
The main functionality of the physical layer is to transmit the individual bits from one node to another node.
It is the lowest layer of the OSI model.
It establishes, maintains and deactivates the physical connection.
It specifies the mechanical, electrical and procedural network interface specifications.
This layer is responsible for the error-free transfer of data frames.
It defines the format of the data on the network.
It provides a reliable and efficient communication between two or more devices.
It is mainly responsible for the unique identification of each device that resides on a local network.
It is a layer 3 that manages device addressing, tracks the location of devices on the network.
It determines the best path to move data from source to the destination based on the network conditions, the priority of service, and other factors.
The Data link layer is responsible for routing and forwarding the packets.
Routers are the layer 3 devices, they are specified in this layer and used to provide the routing services within an internetwork.
The protocols used to route the network traffic are known as Network layer protocols. Examples of protocols are IP and Ipv6.
The Transport layer is a Layer 4 ensures that messages are transmitted in the order in which they are sent and there is no duplication of data.
The main responsibility of the transport layer is to transfer the data completely.
It receives the data from the upper layer and converts them into smaller units known as segments.
This layer can be termed as an end-to-end layer as it provides a point-to-point connection between source and destination to deliver the data reliably.
There are two types of protocols used TCP (Transmission Control Protocol) and UDP (User Datagram Protocol)
It is a layer 3 in the OSI model.
The Session layer is used to establish, maintain and synchronizes the interaction between communicating devices.
A Presentation layer is mainly concerned with the syntax and semantics of the information exchanged between the two systems.
It acts as a data translator for a network.
This layer is a part of the operating system that converts the data from one presentation format to another format.
The Presentation layer is also known as the syntax layer.
An application layer serves as a window for users and application processes to access network service.
It handles issues such as network transparency, resource allocation, etc.
An application layer is not an application, but it performs the application layer functions.
This layer provides the network services to the end-users.
File Handling
When a program is terminated, the entire data is lost. Storing in a file will preserve your data even if the program terminates.
If you have to enter a large number of data, it will take a lot of time to enter them all.
However, if you have a file containing all the data, you can easily access the contents of the file using a few commands in C.
You can easily move your data from one computer to another without any changes.
When dealing with files, there are two types of files you should know about:
Text files
Binary files
Text files are the normal .txt files. You can easily create text files using any simple text editors such as Notepad.
When you open those files, you'll see all the contents within the file as plain text. You can easily edit or delete the contents.
They take minimum effort to maintain, are easily readable, and provide the least security and takes bigger storage space.
Binary files are mostly the .bin files in your computer.
Instead of storing data in plain text, they store it in the binary form (0's and 1's).
They can hold a higher amount of data, are not readable easily, and provides better security than text files.
In C, you can perform four major operations on files, either text or binary:
Creating a new file
Opening an existing file
Closing a file
Reading from and writing information to a file
When working with files, you need to declare a pointer of type file. This declaration is needed for communication between the file and the program.
FILE *fptr;
Opening a file is performed using the fopen() function defined in the stdio.h header file.
The syntax for opening a file in standard I/O is:
ptr = fopen("fileopen","mode");
The file (both text and binary) should be closed after reading/writing.
Closing a file is performed using the fclose() function.
fclose(fptr);
Here, fptr is a file pointer associated with the file to be closed.
For reading and writing to a text file, we use the functions fprintf() and fscanf().
They are just the file versions of printf() and scanf(). The only difference is that fprintf() and fscanf() expects a pointer to the structure FILE.
Write to a text file.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE *fptr;
fptr = fopen("D:\\program.txt","w");
if(fptr == NULL)
{
printf("Error!");
exit(1);
}
printf("Enter num: ");
scanf("%d",&num);
fprintf(fptr,"%d",num);
fclose(fptr);
return 0;
}
Form Validation
It is important to validate the form submitted by the user because it can have inappropriate values. So, validation is must to authenticate user.
JavaScript provides facility to validate the form on the client-side so data processing will be faster than server-side validation. Most of the web developers prefer JavaScript form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and more fields.
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
</script>
<body>
<form name="myform" method="post" action="abc.jsp" onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
WAP in javascript to find a factorial of a number.
<html>
<head>
</head>
<body style = "text-align: center; font-size: 20px;">
<h1> Welcome to the javascript </h1>
Enter a number: <input id = "num">
<br><br>
<button onclick = "fact()"> Factorial </button>
<p id = "res"></p>
<script>
function fact(){
var i, num, f;
f = 1;
num = document.getElementById("num").value;
for(i = 1; i <= num; i++)
{
f = f * i;
}
i = i - 1;
document.getElementById("res").innerHTML = "The factorial of the number " + i + " is: " + f ;
}
</script>
</body>
</html>
WAP to swap a number in javascript.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
//JavaScript program to swap two variables
//take input from the users
let a = prompt('Enter the first variable: ');
let b = prompt('Enter the second variable: ');
//create a temporary variable
let temp;
//swap variables
temp = a;
a = b;
b = temp;
console.log(`The value of a after swapping: ${a}`);
console.log(`The value of b after swapping: ${b}`);
</script>
</body>
</html>
WAP in javascript to find the greatest and lowest number among 10 numbers.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Javasript </h2>
<script type="text/javascript">
// Input 10 numbers
const numbers = [12, 34, 56, 78, 90, 23, 45, 67, 89, 10];
// Initialize variables to store the largest and smallest numbers
let largest = numbers[0];
let smallest = numbers[0];
// Loop through the numbers array to find the largest and smallest numbers
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] > largest) {
largest = numbers[i];
}
if (numbers[i] < smallest) {
smallest = numbers[i];
}
}
// Output the results
console.log("Largest number:", largest);
console.log("Smallest number:", smallest);
</script>
</body>
</html>
WAP in javascript to find greatest number among number by using function.
<!DOCTYPE html>
<html>
<head>
<title>maximum</title>
</head>
<body>
<h2>Maximum</h2>
<script type="text/javascript">
function largest( ){
let array =[10,20,30,40,60];
let max = array[0];
for(let i=0;i<array.length;i++){
if(array[i]>max){
max = array[i];
}
}
document.write('the largest number is ' + max);
}
largest();
</script>
</body>
</html>