0% found this document useful (0 votes)
17 views45 pages

Features of HTTP:: Hypertext Transfer Protocol

The document provides an overview of various internet protocols including HTTP, FTP, and SMTP, detailing their functions, features, and differences. HTTP is used for transferring data on the web, FTP for file transfers, and SMTP for sending emails. It also discusses the concept of URLs and the distinctions between the World Wide Web and the Internet, along with an introduction to MongoDB as a NoSQL database.

Uploaded by

kanusha4304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views45 pages

Features of HTTP:: Hypertext Transfer Protocol

The document provides an overview of various internet protocols including HTTP, FTP, and SMTP, detailing their functions, features, and differences. HTTP is used for transferring data on the web, FTP for file transfers, and SMTP for sending emails. It also discusses the concept of URLs and the distinctions between the World Wide Web and the Internet, along with an introduction to MongoDB as a NoSQL database.

Uploaded by

kanusha4304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

HTTP

o HTTP stands for HyperText Transfer Protocol.


o It is a protocol used to access the data on the World Wide Web (www).
o The HTTP protocol can be used to transfer the data in the form of plain text,
hypertext, audio, video, and so on.
o This protocol is known as HyperText Transfer Protocol because of its
efficiency that allows us to use in a hypertext environment where there are
rapid jumps from one document to another document.
o HTTP is similar to the FTP as it also transfers the files from one host to
another host. But, HTTP is simpler than FTP as HTTP uses only one
connection, i.e., no control connection to transfer the files.
o HTTP is used to carry the data in the form of MIME-like format.
o HTTP is similar to SMTP as the data is transferred between client and server.
The HTTP differs from the SMTP in the way the messages are sent from the
client to the server and from server to the client. SMTP messages are stored
and forwarded while HTTP messages are delivered immediately.

Features of HTTP:
o Connectionless protocol: HTTP is a connectionless protocol. HTTP client
initiates a request and waits for a response from the server. When the server
receives the request, the server processes the request and sends back the
response to the HTTP client after which the client disconnects the connection.
The connection between client and server exist only during the current
request and response time only.
o Media independent: HTTP protocol is a media independent as data can be
sent as long as both the client and server know how to handle the data
content. It is required for both the client and server to specify the content
type in MIME-type header.
o Stateless: HTTP is a stateless protocol as both the client and server know
each other only during the current request. Due to this nature of the protocol,
both the client and server do not retain the information between various
requests of the web pages.

HTTP Transactions
The above figure shows the HTTP transaction between client and server. The client
initiates a transaction by sending a request message to the server. The server
replies to the request message by sending a response message.

Messages
HTTP messages are of two types: request and response. Both the message types
follow the same message format.

Request Message: The request message is sent by the client that consists of a
request line, headers, and sometimes a body.
Response Message: The response message is sent by the server to the client that
consists of a status line, headers, and sometimes a body.

Uniform Resource Locator (URL)


o A client that wants to access the document in an internet needs an address
and to facilitate the access of documents, the HTTP uses the concept of
Uniform Resource Locator (URL).
o The Uniform Resource Locator (URL) is a standard way of specifying any kind
of information on the internet.
o The URL defines four parts: method, host computer, port, and path.
o Method: The method is the protocol used to retrieve the document from a
server. For example, HTTP.
o Host: The host is the computer where the information is stored, and the
computer is given an alias name. Web pages are mainly stored in the
computers and the computers are given an alias name that begins with the
characters "www". This field is not mandatory.
o Port: The URL can also contain the port number of the server, but it's an
optional field. If the port number is included, then it must come between the
host and path and it should be separated from the host by a colon.
o Path: Path is the pathname of the file where the information is stored. The
path itself contain slashes that separate the directories from the
subdirectories and files.

FTP
o FTP stands for File transfer protocol.
o FTP is a standard internet protocol provided by TCP/IP used for transmitting
the files from one host to another.
o It is mainly used for transferring the web page files from their creator to the
computer that acts as a server for other computers on the internet.
o It is also used for downloading the files to computer from other servers.

Objectives of FTP
o It provides the sharing of files.
o It is used to encourage the use of remote computers.
o It transfers the data more reliably and efficiently.

Why FTP?
Although transferring files from one system to another is very simple and
straightforward, but sometimes it can cause problems. For example, two systems
may have different file conventions. Two systems may have different ways to
represent text and data. Two systems may have different directory structures. FTP
protocol overcomes these problems by establishing two connections between hosts.
One connection is used for data transfer, and another connection is used for the
control connection.

Mechanism of FTP
The above figure shows the basic model of the FTP. The FTP client has three
components: the user interface, control process, and data transfer process. The
server has two components: the server control process and the server data transfer
process.

There are two types of connections in FTP:


o Control Connection: The control connection uses very simple rules for
communication. Through control connection, we can transfer a line of
command or line of response at a time. The control connection is made
between the control processes. The control connection remains connected
during the entire interactive FTP session.
o Data Connection: The Data Connection uses very complex rules as data
types may vary. The data connection is made between data transfer
processes. The data connection opens when a command comes for
transferring the files and closes when the file is transferred.

FTP Clients
o FTP client is a program that implements a file transfer protocol which allows
you to transfer files between two hosts on the internet.
o It allows a user to connect to a remote host and upload or download the files.
o It has a set of commands that we can use to connect to a host, transfer the
files between you and your host and close the connection.
o The FTP program is also available as a built-in component in a Web browser.
This GUI based FTP client makes the file transfer very easy and also does not
require to remember the FTP commands.

Advantages of FTP:
o Speed: One of the biggest advantages of FTP is speed. The FTP is one of the
fastest way to transfer the files from one computer to another computer.
o Efficient: It is more efficient as we do not need to complete all the
operations to get the entire file.
o Security: To access the FTP server, we need to login with the username and
password. Therefore, we can say that FTP is more secure.
o Back & forth movement: FTP allows us to transfer the files back and forth.
Suppose you are a manager of the company, you send some information to
all the employees, and they all send information back on the same server.

Disadvantages of FTP:
o The standard requirement of the industry is that all the FTP transmissions
should be encrypted. However, not all the FTP providers are equal and not all
the providers offer encryption. So, we will have to look out for the FTP
providers that provides encryption.
o FTP serves two operations, i.e., to send and receive large files on a network.
However, the size limit of the file is 2GB that can be sent. It also doesn't allow
you to run simultaneous transfers to multiple receivers.
o Passwords and file contents are sent in clear text that allows unwanted
eavesdropping. So, it is quite possible that attackers can carry out the brute
force attack by trying to guess the FTP password.
o It is not compatible with every system.

SMTP
o SMTP stands for Simple Mail Transfer Protocol.
o SMTP is a set of communication guidelines that allow software to transmit an
electronic mail over the internet is called Simple Mail Transfer Protocol.
o It is a program used for sending messages to other computer users based on
e-mail addresses.
o It provides a mail exchange between users on the same or different
computers, and it also supports:
o It can send a single message to one or more recipients.
o Sending message can include text, voice, video or graphics.
o It can also send the messages on networks outside the internet.
o The main purpose of SMTP is used to set up communication rules between
servers. The servers have a way of identifying themselves and announcing
what kind of communication they are trying to perform. They also have a way
of handling the errors such as incorrect email address. For example, if the
recipient address is wrong, then receiving server reply with an error message
of some kind.

Components of SMTP

o First, we will break the SMTP client and SMTP server into two components
such as user agent (UA) and mail transfer agent (MTA). The user agent (UA)
prepares the message, creates the envelope and then puts the message in
the envelope. The mail transfer agent (MTA) transfers this mail across the
internet.
o SMTP allows a more complex system by adding a relaying system. Instead of
just having one MTA at sending side and one at receiving side, more MTAs
can be added, acting either as a client or server to relay the email.

o The relaying system without TCP/IP protocol can also be used to send the
emails to users, and this is achieved by the use of the mail gateway. The mail
gateway is a relay MTA that can be used to receive an email.
Working of SMTP
1. Composition of Mail: A user sends an e-mail by composing an electronic
mail message using a Mail User Agent (MUA). Mail User Agent is a program
which is used to send and receive mail. The message contains two parts:
body and header. The body is the main part of the message while the header
includes information such as the sender and recipient address. The header
also includes descriptive information such as the subject of the message. In
this case, the message body is like a letter and header is like an envelope
that contains the recipient's address.
2. Submission of Mail: After composing an email, the mail client then submits
the completed e-mail to the SMTP server by using SMTP on TCP port 25.
3. Delivery of Mail: E-mail addresses contain two parts: username of the
recipient and domain name. For example, vivek@gmail.com, where "vivek" is
the username of the recipient and "gmail.com" is the domain name.
If the domain name of the recipient's email address is different from the
sender's domain name, then MSA will send the mail to the Mail Transfer
Agent (MTA). To relay the email, the MTA will find the target domain. It
checks the MX record from Domain Name System to obtain the target
domain. The MX record contains the domain name and IP address of the
recipient's domain. Once the record is located, MTA connects to the exchange
server to relay the message.
4. Receipt and Processing of Mail: Once the incoming message is received,
the exchange server delivers it to the incoming server (Mail Delivery Agent)
which stores the e-mail where it waits for the user to retrieve it.
5. Access and Retrieval of Mail: The stored email in MDA can be retrieved by
using MUA (Mail User Agent). MUA can be accessed by using login and
password.

Differences between WWW and Internet

WWW (World Wide Web) Internet

The World Wide Web is the common system for navigating The internet is a public network of network with a
the internet. It is not the only system that can be used for maze of wired and wireless connections between
such access, but it is by far the most common one. separate groups of servers computers and
countless devices from around the world

The World Wide Web is distinguished from other systems Along with Internters, there also exist the
through its use of HTTP (Hypertext Transfer Protocol). It can Intranets, which is the same type of information
be safely said that the HTTP is the language of the World network but more privatized in order to control
Wide Web access.

WWW is more software-oriented as compared to the Internet is primarily hardware-based.


Internet

The HTTP along with being the language of the World Wide The internet is governed by a set of rules and
Web also governs it by dealing with linking of files, regulations collectively known as Internet
documents and other resources Protocol (IP). The IP deals with data transmitted
through the internet.

The invention of the World Wide Web can be credited to Sir The first workable prototype of the Internet was
Tim Berners Lee. During his work at the European the ARPANET (Advanced Research Project Agency
Organization for Nuclear Research in 1989, he had Network) in the late 1960s. After its adoption on
developed the basic idea of the WWW to merge the January 1st 1983, researchers began to develop a
evolving technologies of computers, data networks and “network of networks” which evolved into the
hypertext into a powerful and easy to use global information modern form of the Internet
system.

Both the World Wide Web and the Internet are concepts covered under the Science and Technology Segment
of the UPSC IAS Exam. Aspirants can study this segment through the links given below
Introduction
With the rise in data all around the world, there has been an observable and increasing interest
surrounding the wave of the non-relational database, also known as ‘NoSQL‘. Businesses and
organizations are seeking new methods to manage the flood of data and are drawn toward the
alternate database management tools and systems that are different from the traditional
relational database systems. Here comes MongoDB into the picture.

MongoDB tutorial provides basic and advanced concepts of SQL. Our MongoDB
tutorial is designed for beginners and professionals.

MongoDB is a No SQL database. It is an open-source, cross-platform, document-


oriented database written in C++.

Our MongoDB tutorial includes all topics of MongoDB database such as insert
documents, update documents, delete documents, query documents, projection,
sort() and limit() methods, create a collection, drop collection, etc. There are also
given MongoDB interview questions to help you better understand the MongoDB
database.

What is MongoDB
MongoDB is an open-source document database that provides high performance,
high availability, and automatic scaling.

In simple words, you can say that - Mongo DB is a document-oriented database. It is


an open source product, developed and supported by a company named 10gen.

MongoDB is available under General Public license for free, and it is also available
under Commercial license from the manufacturer.

The manufacturing company 10gen has defined MongoDB as:

"MongoDB is a scalable, open source, high performance, document-oriented


database." - 10gen

MongoDB was designed to work with commodity servers. Now it is used by the
company of all sizes, across all industry.
History of MongoDB
The initial development of MongoDB began in 2007 when the company was building
a platform as a service similar to window azure.

Window azure is a cloud computing platform and infrastructure, created by Microsoft, to build,
deploy and manage applications and service through a global network.

MongoDB was developed by a NewYork based organization named 10gen which is


now known as MongoDB Inc. It was initially developed as a PAAS (Platform as a
Service). Later in 2009, it is introduced in the market as an open source database
server that was maintained and supported by MongoDB Inc.

The first ready production of MongoDB has been considered from version 1.4 which
was released in March 2010.

MongoDB2.4.9 was the latest and stable version which was released on January 10,
2014.

Purpose of building MongoDB


It may be a very genuine question that - "what was the need of MongoDB although
there were many databases in action?"

There is a simple answer:

All the modern applications require big data, fast features development, flexible
deployment, and the older database systems not competent enough, so the
MongoDB was needed.

The primary purpose of building MongoDB is:

o Scalability
o Performance
o High Availability
o Scaling from single server deployments to large, complex multi-site
architectures.
o Key points of MongoDB
o Develop Faster
o Deploy Easier
o Scale Bigger

First of all, we should know what is document oriented database?


Example of document oriented database
MongoDB is a document oriented database. It is a key feature of MongoDB. It offers
a document oriented storage. It is very simple you can program it easily.

MongoDB stores data as documents, so it is known as document-oriented database.

1. FirstName = "John",

2. Address = "Detroit",
3. Spouse = [{Name: "Angela"}].

4. FirstName ="John",
5. Address = "Wick"

There are two different documents (separated by ".").

Storing data in this manner is called as document-oriented database.

Mongo DB falls into a class of databases that calls Document Oriented Databases.
There is also a broad category of database known as No SQL Databases.

Features of MongoDB
These are some important features of MongoDB:

1. Support ad hoc queries

In MongoDB, you can search by field, range query and it also supports regular
expression searches.

2. Indexing

You can index any field in a document.

3. Replication

MongoDB supports Master Slave replication.

A master can perform Reads and Writes and a Slave copies data from the master
and can only be used for reads or back up (not writes)

4. Duplication of data
MongoDB can run over multiple servers. The data is duplicated to keep the system
up and also keep its running condition in case of hardware failure.

5. Load balancing

It has an automatic load balancing configuration because of data placed in shards.

6. Supports map reduce and aggregation tools.

7. Uses JavaScript instead of Procedures.

8. It is a schema-less database written in C++.

9. Provides high performance.

10. Stores files of any size easily without complicating your stack.

11. Easy to administer in the case of failures.

12. It also supports:

JSON data model with dynamic schemas

Auto-sharding for horizontal scalability

Built in replication for high availability

Now a day many companies using MongoDB to create new types of applications,
improve performance and availability.

Prerequisite
Before learning MongoDB, you must have the basic knowledge of SQL and OOPs.

Audience
Our MongoDB tutorial is designed to help beginners and professionals.

Problem
We assure that you will not find any problem in this MongoDB tutorial. But if there is
any mistake, please post the problem in contact form.
The Architecture of MongoDB NoSQL Database

Database: In simple words, it can be called the physical container for data. Each of the
databases has its own set of files on the file system with multiple databases existing on a single
MongoDB server.

Collection: A group of database documents can be called a collection. The RDBMS equivalent
to a collection is a table. The entire collection exists within a single database. There are no
schemas when it comes to collections. Inside the collection, various documents can have varied
fields, but mostly the documents within a collection are meant for the same purpose or for
serving the same end goal.

Document: A set of key-value pairs can be designated as a document. Documents are


associated with dynamic schemas. The benefit of having dynamic schemas is that a document
in a single collection does not have to possess the same structure or fields. Also, the common
fields in a collection document can have varied types of data.

Find out more about MongoDB in this comprehensive MongoDB Tutorial now!

Important MongoDB Features


 Queries: It supports ad-hoc queries and document-based queries.
 Index Support: Any field in the document can be indexed.
 Replication: It supports Master-Slave replication. MongoDB uses the native applications
to maintain multiple copies of data. Preventing database downtime is one of the replica
set’s features as it has a self-healing shard.
 Multiple Servers: The database can run over multiple servers. Data is duplicated to
foolproof the system in the case of hardware failure.
 Auto-sharding: This process distributes data across multiple physical partitions called
shards. Due to sharding, MongoDB has an automatic load balancing feature.
 MapReduce: It supports MapReduce and flexible aggregation tools.
 Failure Handling: In MongoDB, it’s easy to cope with cases of failures. Huge numbers
of replicas give out increased protection and data availability against database
downtimes like rack failures, multiple machine failures, and data center failures, or even
network partitions.
 GridFS: Without complicating your stack, any size of files can be stored. GridFS feature
divides files into smaller parts and stores them as separate documents.
 Schema-less Database: It is a schema-less database written in C++.
 Document-oriented Storage: It uses the BSON format which is a JSON-like format.
 Procedures: MongoDB JavaScript works well as the database uses the language
instead of procedures.

Why do you need MongoDB technology?


This technology overcame one of the biggest pitfalls of the traditional database systems, that is,
scalability. With the ever-evolving needs of businesses, their database systems also needed to
be upgraded. MongoDB has exceptional scalability. It makes it easy to fetch the data and
provides continuous and automatic integration. Along with these benefits, there are multiple
reasons why you need MongoDB:

 No downtime while the application is being scaled


 Performs in-memory processing
 Text search
 Graph processing
 Global replication
 Economical

Moreover, businesses are increasingly finding out that MongoDB is ticking all the right boxes
when it comes to meeting the business requirements. Here is how:

 MongoDB provides the right mix of technology and data for competitive advantage.
 It is most suited for mission-critical applications since it considerably reduces risks.
 It increasingly accelerated the time to value (TTV) and lowered the total cost of
ownership.
 It builds applications that are just not possible with traditional relational databases.

MongoDB Create Database


Use Database method:

There is no create database command in MongoDB. Actually, MongoDB do not


provide any command to create database.

It may be look like a weird concept, if you are from traditional SQL background
where you need to create a database, table and insert values in the table manually.

Here, in MongoDB you don't need to create a database manually because MongoDB
will create it automatically when you save the value into the defined collection at
first time.

You also don't need to mention what you want to create, it will be automatically
created at the time you save the value into the defined collection.
Here one thing is very remarkable that you can create collection manually by "db.createCollection()" but
not the database.

How and when to create database


If there is no existing database, the following command is used to create a new
database.

Syntax:

1. use DATABASE_NAME

If the database already exists, it will return the existing database.

Let' take an example to demonstrate how a database is created in MongoDB. In the


following example, we are going to create a database "javatpointdb".

See this example

1. >use javatpointdb
Swithched to db javatpointdb

To check the currently selected database, use the command db:

1. >db
javatpointdb

To check the database list, use the command show dbs:

1. >show dbs
local 0.078GB

Here, your created database "javatpointdb" is not present in the list, insert at
least one document into it to display database:

1. >db.movie.insert({"name":"javatpoint"})
WriteResult({ "nInserted": 1})
1. >show dbs
javatpointdb 0.078GB
local 0.078GB
Collections
A collection is a grouping of MongoDB documents. Documents within a collection can have
different fields. A collection is the equivalent of a table in a relational database system. A
collection exists within a single database

Collections Screen

The Collections screen lists the existing collections and views in the selected database. Each
list item includes the name and other general information for the collection or view.

To access the Collections screen for a database, from the Databases screen either:

 Click a Database Name in the main Databases view, or

 Click a database in the left navigation.

click to enlarge

Collection Information

The Collections screen displays the following information for each collection in the selected
database:

 Collection name

 Number of documents in the collection

NOTE

Compass bases the document count that appears on the Collections screen on cached
metadata using collStats. This count might differ from the actual document count in the
collection. For example, an unexpected shutdown can throw off the count. Use
the db.collection.countDocuments() method for the most accurate document count.

 Average size of documents in the collection

 Total size of all documents in the collection

 Number of indexes on the collection

 Total size of all indexes on the collection

 Collation properties for the collection. Hover over a Collation banner to view the
properties for that collection.

Create a Collection

You can create new collections in an existing database.

Click the Create Collection button.

From the Collections screen, click the Create Collection button.

Enter the collection information.

In the Create Collection dialog, enter the name of the collection to create.

Compass also provides you with Advanced Collection Options. You can select from the
following:

 Create a Capped Collection

 Create a Collection with Collation


 Create a Time Series Collection

 Create a Collection with Encrypted Fields


3

Click Create Collection to create the collection.

Drop a Collection
1

Click the trash can icon to delete a collection.

From the Collections screen, click on the trash can for the collection to delete. A confirmation
dialog appears.

Confirm the collection to delete.

In the dialog, enter the name of the collection to delete.

Click Drop Collection to drop the collection.

Collection Details

The Collection Detail screen shows detailed information for a collection, including the
documents the collection contains. To see collection details, either:

 Click a Collection Name in the main Collections screen, or

 Click a collection in the left navigation.

 Open the collection in a new tab.


After you select a collection, Compass shows you that collection's Documents
tab. Compass provides the following collection information and functionality in the detailed view:

 Manage Documents

 Import and Export Data to / from the collection

 Aggregation Pipeline Builder

 Schema Analysis

 View Query Performance

 Manage Indexes

 Set Validation Rules for Your Schema

NOTE

Data Lake Limitations

The following functionality is not available if you are connected to a Data Lake:

 Import data into a collection

 Schema Analysis

 View Query Performance

 Manage Indexes

 Set Validation Rules for Your Schema


Tabbed View

You can open multiple Collection Detail screens in separate tabs. To open a new tab to view
collection details:

Click the caret icon next to the database which contains the collection you wish to view.

Hover over the desired collection.


3

Click the appearing ellipses (...) button.


4

Click Open in New Tab.

Limitations

 Creating and dropping collections is not permitted in MongoDB Compass Readonly


Edition.

 The Create Collection button is not available if you are connected to a Data Lake.

Tabbed View

You can open multiple Collection Detail screens in separate tabs. To open a new tab to view
collection details:
1

Click the caret icon next to the database which contains the collection you wish to view.

Hover over the desired collection.


3

Click the appearing ellipses (...) button.


4

Regular Expression Syntax


Used in Pattern Matching
A regular expression is a pattern of text that consists of ordinary characters, for example,
letters a through z, and special characters.

Character(s
Matches in searched string
)

pattern Matches pattern anywhere in the name.

\ Marks the next character as either a special character, a literal, a back reference, or an octal escape. For example, 'd' matches
character "d". ' \d' matches a digit character. The sequence '\\' matches "\" and "\(" matches "(".

. Matches any single character.

^ Matches the position at the beginning of the searched string. For example ^CF matches any string starting 'CF'.
Character(s
Matches in searched string
)

$ Matches the position at the end of the searched string. For example EZ$ matches any string ending 'EZ'.

? Matches the preceding subexpression zero or one time. For example, "mast(er)?" matches "mast" or "master". Also, see below
for additional uses of '?'.

* Matches the preceding subexpression zero or more times. For example, zo* matches "z" and "zoo".

+ Matches the preceding subexpression one or more times. For example, 'zo+' matches "zo" and zoo", but not "z".

{n} Matches exactly n times, where n is a nonnegative integer. For example, 'o{2}' matches the two o's in "zoo", but not the o in
"zero".

{n,} Matches at least n times, where n is a nonnegative integer. For example, 'o{2,}' matches all the o's in "zooooom" but not the o
"zero".

{n,m} Matches at least n times and at most m times, where n and m are nonnegative integers ( n <= m). For example, 'o{2,4}' match
the first four o's in "zooooom", but not the o in "zero".

? When '?' immediately follows any of the qualifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. While the
default pattern matching is to match as much of the searched string as possible, a non-greedy pattern matches as little of the
searched string as possible. For example, 'o+?' matches a single o in "zooom", while 'o+' matches all the o's.

(pattern) Matches pattern as a subexpression and remembers the match. The remembered match can be used in a following back refere
(described below) or in the replacement string of a search and replace operation. To match the parentheses characters ( and ),
'\(' and '\)'.

x|y Matches either x or y. For example, 'MAST(ER|FILE)' matches either "MASTER" or "MASTFILE".
Character(s
Matches in searched string
)

[charlist] Matches any single character in charlist. For example, '[aeiou]' matches the e in "Relativity".

[^charlist] Matches any single character not in charlist. For example, '[^aeiou]' matches the R in "Relativity".

[a-z] Matches any single character in the specified character range. For example, '[a-z]' matches any lowercase alphabetic characte
the range "a" through "z", inclusive.

[^m-z] Matches any single character not in the specified character range. For example, '[^m-z]' matches any character except those in
range "m" through "z", inclusive.

\b Matches a word boundary (the position between a word and a space). For example, "le\b" matches the "le" of "file" in the
searched string "lengthy file name", not the "le" in "lengthy".

\B Matches a non-word boundary. For example, "le\B" matches the "le" of "lengthy" in the searched string "lengthy file name",
the "le" in "file".

\d Matches a digit character (equivalent to [0-9]).

\D Matches a non-digit character (equivalent to [^0-9]).

\s Matches a white space character.

\S Matches a nonwhite space character.

\w Matches any word character including underscore (equivalent to [A-Za-z0-9_]).


Character(s
Matches in searched string
)

\W Matches any non-word character (equivalent to [^A-Za-z0-9_]).

\num Matches a back reference to a remembered match, where num is a positive integer. For example, '(.)\1' matches two consecuti
identical characters.

Browser Object Model


1. Browser Object Model (BOM)

The Browser Object Model (BOM) is used to interact with the browser.

The default object of browser is window means you can call all the functions of
window by specifying window or directly. For example:

1. window.alert("hello javatpoint");

is same as:

1. alert("hello javatpoint");

You can use a lot of properties (other objects) defined underneath the window
object like document, history, screen, navigator, location, innerHeight, innerWidth,
Note: The document object represents an html document. It forms DOM (Document Object Model).

Visit the next page to learn about window object fully with example.

Window Object
1. Window Object
2. Properties of Window Object
3. Methods of Window Object
4. Example of Window Object

The window object represents a window in browser. An object of window is


created automatically by the browser.

Window is the object of browser, it is not the object of javascript. The javascript
objects are string, array, date etc.

Note: if html document contains frame or iframe, browser creates additional window objects for each
frame.

Methods of window object


The important methods of window object are as follows:

Method Description

alert() displays the alert box containing message with ok button.

confirm() displays the confirm dialog box containing message with ok and
cancel button.

prompt() displays a dialog box to get input from the user.

open() opens the new window.

close() closes the current window.

setTimeou performs action after specified time like calling function, evaluating
t() expressions etc.

Example of alert() in javascript

It displays alert dialog box. It has message and ok button.

1. <script type="text/javascript">
2. function msg(){
3. alert("Hello Alert Box");
4. }
5. </script>
6. <input type="button" value="click" onclick="msg()"/>

JavaScript History Object


1. History Object
2. Properties of History Object
3. Methods of History Object
4. Example of History Object

The JavaScript history object represents an array of URLs visited by the user. By
using this object, you can load previous, forward or any particular page.

The history object is the window property, so it can be accessed by:

1. window.history

Or,
1. history

Property of JavaScript history object


There are only 1 property of history object.

No. Property Description

1 length returns the length of the history URLs.

Methods of JavaScript history object


There are only 3 methods of history object.

No. Method Description

1 forward() loads the next page.

2 back() loads the previous page.

3 go() loads the given page number.

Example of history object


Let’s see the different usage of history object.

1. history.back();//for previous page


2. history.forward();//for next page
3. history.go(2);//for next 2nd page
4. history.go(-2);//for previous 2nd page

JavaScript Navigator Object


1. Navigator Object
2. Properties of Navigator Object
3. Methods of Navigator Object
4. Example of Navigator Object

The JavaScript navigator object is used for browser detection. It can be used to
get browser information such as appName, appCodeName, userAgent etc.

The navigator object is the window property, so it can be accessed by:

1. window.navigator

Or,

1. navigator

Property of JavaScript navigator object


There are many properties of navigator object that returns information of the
browser.

No. Property Description

1 appName returns the name

2 appVersion returns the version

3 appCodeNam returns the code name


e

4 cookieEnabled returns true if cookie is enabled otherwise false

5 userAgent returns the user agent

6 language returns the language. It is supported in Netscape and


Firefox only.

7 userLanguage returns the user language. It is supported in IE only.


8 plugins returns the plugins. It is supported in Netscape and
Firefox only.

9 systemLangua returns the system language. It is supported in IE only.


ge

10 mimeTypes[] returns the array of mime type. It is supported in


Netscape and Firefox only.

11 platform returns the platform e.g. Win32.

12 online returns true if browser is online otherwise false.

Methods of JavaScript navigator object


The methods of navigator object are given below.

No. Method Description

1 javaEnabled( checks if java is enabled.


)

2 taintEnabled( checks if taint is enabled. It is deprecated since JavaScript


) 1.2.

Example of navigator object

Let’s see the different usage of history object.

1. <script>
2. document.writeln("<br/>navigator.appCodeName: "+navigator.appCodeName);
3. document.writeln("<br/>navigator.appName: "+navigator.appName);
4. document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);
5. document.writeln("<br/>navigator.cookieEnabled: "+navigator.cookieEnabled);
6. document.writeln("<br/>navigator.language: "+navigator.language);
7. document.writeln("<br/>navigator.userAgent: "+navigator.userAgent);
8. document.writeln("<br/>navigator.platform: "+navigator.platform);
9. document.writeln("<br/>navigator.onLine: "+navigator.onLine);
10.</script>
Test it Now

navigator.appCodeName: Mozilla
navigator.appName: Netscape
navigator.appVersion: 5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
navigator.cookieEnabled: true
navigator.language: en-US
navigator.userAgent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
navigator.platform: Win32
navigator.onLine: true

JavaScript Screen Object


1. Screen Object
2. Properties of Screen Object
3. Methods of Screen Object
4. Example of Screen Object

The JavaScript screen object holds information of browser screen. It can be used
to display screen width, height, colorDepth, pixelDepth etc.

The navigator object is the window property, so it can be accessed by:

1. window.screen

Or,

1. screen

Property of JavaScript Screen Object


There are many properties of screen object that returns information of the browser.
No. Property Description

1 width returns the width of the screen

2 height returns the height of the screen

3 availWidth returns the available width

4 availHeight returns the available height

5 colorDepth returns the color depth

6 pixelDepth returns the pixel depth.

Example of JavaScript Screen Object

Let’s see the different usage of screen object.

1. <script>
2. document.writeln("<br/>screen.width: "+screen.width);
3. document.writeln("<br/>screen.height: "+screen.height);
4. document.writeln("<br/>screen.availWidth: "+screen.availWidth);
5. document.writeln("<br/>screen.availHeight: "+screen.availHeight);
6. document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
7. document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
8. </script>
Test it Now

screen.width: 1366
screen.height: 768
screen.availWidth: 1366
screen.availHeight: 728
screen.colorDepth: 24
screen.pixelDepth: 24

Document Object Model


1. Document Object
2. Properties of document object
3. Methods of document object
4. Example of document object

The document object represents the whole html document.

When html document is loaded in the browser, it becomes a document object. It is


the root element that represents the html document. It has properties and
methods. By the help of document object, we can add dynamic content to our web
page.

As mentioned earlier, it is the object of window. So

1. window.document

Is same as

1. document

According to W3C - "The W3C Document Object Model (DOM) is a platform and
language-neutral interface that allows programs and scripts to dynamically access
and update the content, structure, and style of a document."

Properties of document object


Let's see the properties of document object that can be accessed and modified by
the document
bject.

Methods of document object


We can access and change the contents of document by its methods.

The important methods of document object are as follows:

Method Description

write("string") writes the given string on the doucment.

writeln("string") writes the given string on the doucment with newline


character at the end.
getElementById() returns the element having the given id value.

getElementsByName() returns all the elements having the given name value.

getElementsByTagNam returns all the elements having the given tag name.
e()

getElementsByClassNa returns all the elements having the given class name.
me()

Accessing field value by document object


In this example, we are going to get the value of input text by user. Here, we are
using document.form1.name.value to get the value of name field.

Here, document is the root element that represents the html document.

form1 is the name of the form.

name is the attribute name of the input text.

value is the property, that returns the value of the input text.

Let's see the simple example of document object that prints name with welcome
message.

1. <script type="text/javascript">
2. function printvalue(){
3. var name=document.form1.name.value;
4. alert("Welcome: "+name);
5. }
6. </script>
7.
8. <form name="form1">
9. Enter Name:<input type="text" name="name"/>
10.<input type="button" onclick="printvalue()" value="print name"/>
11.</form>

Output of the above example


Enter Name:

JavaScript Constructor Method


A JavaScript constructor method is a special type of method which is used to
initialize and create an object. It is called when memory is allocated for an object.

Points to remember
o The constructor keyword is used to declare a constructor method.
o The class can contain one constructor method only.
o JavaScript allows us to use parent class constructor through super keyword.

Constructor Method Example


Let's see a simple example of a constructor method.

1. <script>
2. class Employee {
3. constructor() {
4. this.id=101;
5. this.name = "Martin Roy";
6. }
7. }
8. var emp = new Employee();
9. document.writeln(emp.id+" "+emp.name);
10.</script>
Test it Now

Output:

101 Martin Roy

JavaScript Array
JavaScript array is an object that represents a collection of similar type of
elements.

There are 3 ways to construct array in JavaScript

1. By array literal
2. By creating instance of Array directly (using new keyword)
3. By using an Array constructor (using new keyword)

1) JavaScript array literal


The syntax of creating array using array literal is given below:

1. var arrayname=[value1,value2.....valueN];

As you can see, values are contained inside [ ] and separated by , (comma).

Let's see the simple example of creating and using array in JavaScript.

1. <script>
2. var emp=["Sonoo","Vimal","Ratan"];
3. for (i=0;i<emp.length;i++){
4. document.write(emp[i] + "<br/>");
5. }
6. </script>
Test it Now

The .length property returns the length of an array.

Output of the above example

Sonoo
Vimal
Ratan

2) JavaScript Array directly (new keyword)


The syntax of creating array directly is given below:

1. var arrayname=new Array();

Here, new keyword is used to create instance of array.

Let's see the example of creating array directly.

1. <script>
2. var i;
3. var emp = new Array();
4. emp[0] = "Arun";
5. emp[1] = "Varun";
6. emp[2] = "John";
7.
8. for (i=0;i<emp.length;i++){
9. document.write(emp[i] + "<br>");
10.}
11.</script>
Test it Now

Output of the above example

Arun
Varun
John

3) JavaScript array constructor (new keyword)


Here, you need to create instance of array by passing arguments in constructor so
that we don't have to provide value explicitly.

The example of creating object by array constructor is given below.

1. <script>
2. var emp=new Array("Jai","Vijay","Smith");
3. for (i=0;i<emp.length;i++){
4. document.write(emp[i] + "<br>");
5. }
6. </script>
Test it Now

Output of the above example

Jai
Vijay
Smith

JavaScript Array Methods


Let's see the list of JavaScript array methods with their description.

Methods Description

concat() It returns a new array object that contains two or more


merged arrays.

copywithin() It copies the part of the given array with its own elements
and returns the modified array.

entries() It creates an iterator object and a loop that iterates over


each key/value pair.

every() It determines whether all the elements of an array are


satisfying the provided function conditions.

flat() It creates a new array carrying sub-array elements


concatenated recursively till the specified depth.

flatMap() It maps all array elements via mapping function, then


flattens the result into a new array.

fill() It fills elements into an array with static values.

from() It creates a new array carrying the exact copy of another


array element.

filter() It returns the new array containing the elements that pass
the provided function conditions.

find() It returns the value of the first element in the given array
that satisfies the specified condition.

findIndex() It returns the index value of the first element in the given
array that satisfies the specified condition.

forEach() It invokes the provided function once for each element of an


array.

includes() It checks whether the given array contains the specified


element.
indexOf() It searches the specified element in the given array and
returns the index of the first match.

isArray() It tests if the passed value ia an array.

join() It joins the elements of an array as a string.

keys() It creates an iterator object that contains only the keys of


the array, then loops through these keys.

lastIndexOf() It searches the specified element in the given array and


returns the index of the last match.

map() It calls the specified function for every array element and
returns the new array

of() It creates a new array from a variable number of arguments,


holding any type of argument.

pop() It removes and returns the last element of an array.

push() It adds one or more elements to the end of an array.

reverse() It reverses the elements of given array.

reduce(function, It executes a provided function for each value from left to


initial) right and reduces the array to a single value.

reduceRight() It executes a provided function for each value from right to


left and reduces the array to a single value.

some() It determines if any element of the array passes the test of


the implemented function.

shift() It removes and returns the first element of an array.


slice() It returns a new array containing the copy of the part of the
given array.

sort() It returns the element of the given array in a sorted order.

splice() It add/remove elements to/from the given array.

toLocaleString() It returns a string containing all the elements of a specified


array.

toString() It converts the elements of a specified array into string


form, without affecting the original array.

unshift() It adds one or more elements in the beginning of the given


array.

values() It creates a new iterator object carrying values for each


index in the array.

You might also like