You are on page 1of 702

Module 4 - Web

Development

Disclaimer: The content is curated for educational purposes only.


© Edunet Foundation. All rights reserved.
After going through this module, students will be able to

● Understand how web works.


● Structuring the Web
● Scripting and Styling the web
● Enhancing the web using PHP.
● Java the key language.

Disclaimer: The content is curated for educational purposes only.


© Edunet Foundation. All rights reserved.
Understand how web works.

© Edunet Foundation. All rights reserved.


In this section, we will discuss:

● Learn basic concepts regarding the internet,browsers, andHTML.


● Use of HTML (Hypertext Markup Language) in web pages.
● Protocols
● Forms and Input
● Database
● User Account and security
● APIs and Caching.

© Edunet Foundation. All rights reserved.


Learn basic concepts
regarding the
internet,browsers and
HTML.
Basics of Internet

● Internet is a world-wide global system of


interconnected computer networks.
● Internet uses the standard Internet
Protocol (TCP/IP).

Image Source: https://am7s.com/what-is-the-internet/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
Basics of Internet(contd)

● Every computer in internet is identified


by a unique IP address.
● IP Address is a unique set of numbers
(such as 110.22.33.114) which identifies
a computer location.

Image Source: https://edu.gcfglobal.org/en/internetbasics/what-is-the-internet/1/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
World Wide Web(WWW)

● The World Wide Web (WWW) is a


collection of documents and other web
resources which are identified by URLs,
interlinked by hypertext links, and can
be accessed and searched by browsers
via the Internet.

Image Source: https://www.informationq.com/internet-and-www/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
World Wide Web(WWW)(contd)

● World Wide Web is also called the Web


and it was invented by Tim Berners-Lee
in 1989.
● The pages can be retrieved and viewed
by using browser.

Image Source:
https://www.tutorialride.com/computer-network/world-wide-web-in-computer-netw
© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
HTTP

● HTTP stands for Hypertext Transfer


Protocol
● WWW is about communication between
web clients and servers
● HTTP is an Application Protocol for
transferring Resources across the
internet.
Image Source: https://www.pickaweb.co.uk/kb/what-is-http/
© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
HTTP(contd)

● Communication between client


computers and web servers is done by
sending HTTP Requests and receiving
HTTP Responses

Image Source: https://www.cdnfinder.com/content-delivery-network-guide/http/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
Uniform Resource Locator (URL)

● The URL is a standard for specifying any


kind of information on the Internet.
● The URL consists of four parts: protocol,
host computer, port and path.
● The host is the name of computer on
which the information is located.

Image Source: https://fakebelieve.blog/2018/08/07/the-power-of-a-url/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
Uniform Resource Locator (URL)

● The protocol is the client or server


program which is used to retrieve the
document or file.
● The URL can optionally contain the port
number and it is separated from the
host name by a colon.

Image Source: https://sitechecker.pro/what-is-url/


© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
Web browser

● A web browser is a software application


for accessing information on the World
Wide Web.
● When a user requests a web page from
a particular website, the web browser
retrieves the necessary content from a
web server and then displays the page
on the screen.
Image Source:
https://www.webchoiceonline.com.au/the-best-web-browsers-which-one-should-y
© Edunet Foundation. All rights reserved.
Learn basic concepts
regarding the
internet,browsers and
HTML.
HTML

● HTML stands for Hyper Text Markup


Language
● HTML is the standard markup language
for Web pages
● HTML elements are the building blocks
of HTML pages

Image Source: https://www.javatpoint.com/what-is-html


© Edunet Foundation. All rights reserved.
Use of HTML (Hypertext
Markup Language) in web
pages
Uses of HTML

● Web pages development


● Web document Creation
● Internet navigation
● Cutting edge feature
● Responsive images on web pages

Image Source: https://www.educba.com/pre-tag-in-html/


© Edunet Foundation. All rights reserved.
Use of HTML (Hypertext
Markup Language) in web
pages
Uses of HTML(contd)

● Client-side storage
● Offline capabilities usage
● Data Entry support with HTML
● Game development usage
● Native APIs usage to enrich website

Image Source:
https://www.slideshare.net/manojkumardeswal/learn-html-manoj-kumar-deswal
© Edunet Foundation. All rights reserved.
Protocols

What is protocol?

● A protocol is a set of rules and


guidelines for communicating data.
● Rules are defined for each step and
process during communication between
two or more computers.
● Networks have to follow these rules to
successfully transmit data.

Image Source:
https://www.net.t-labs.tu-berlin.de/teaching/computer_networking/01.02.htm
© Edunet Foundation. All rights reserved.
Protocols

Types of protocol

● Transmission Control Protocol (TCP)


● Internet Protocol (IP)
● User Datagram Protocol (UDP)
● Post office Protocol (POP)
● Simple mail transport Protocol (SMTP)

Image Source: https://www.educba.com/types-of-networking-protocols/


© Edunet Foundation. All rights reserved.
Protocols

Types of protocol(contd)

● File Transfer Protocol (FTP)


● Hypertext Transfer Protocol (HTTP)
● Hypertext Transfer Protocol Secure
(HTTPS)
● Telnet
● Gopher

Image Source: https://www.itgrow.xyz/2020/01/types-of-internet-protocol.html


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Forms

● An HTML form is used to collect user


input.
● The user input can then be sent to a
server for processing.

Image Source: https://www.sitepoint.com/form-validation-with-php/


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Forms(contd)

● HTML Forms are required to collect


different kinds of user inputs, such as
contact details like name, email address,
phone numbers, or details like credit
card information, etc.
● Forms contain special elements called
controls like inputbox, checkboxes,
radio-buttons, submit buttons, etc.
Image Source:
https://fahmidasclassroom.com/how-to-upload-folder-using-html-and-php/
© Edunet Foundation. All rights reserved.
Forms and Input

HTML Forms(contd)

● <form> Element
● <input> Element
● The Action Attribute
● The Target Attribute
● The Method Attribute

Image Source: https://slideplayer.com/slide/9288191/


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Element

● It allows you to specify various types of


user input fields, depending on the type
attribute.

Image Source: https://www.html-5-tutorial.com/input-element.php


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Element(contd)

● Text Fields
● password field
● checkbox
● radio button
● submit button
● reset button
● file select box

Image Source:
https://www.w3resource.com/html/input/HTML-input-tag-and-element.php
© Edunet Foundation. All rights reserved.
Forms and Input

HTML Form Elements

● <input> Element
● <select> Element
● <textarea> Element
● <button> Element
● <fieldset> and <legend> Elements
● <datalist> Element
● <output> Element

Image Source: https://codebridgeplus.com/html-form-elements/


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Types

● Input Type Color


● Input Type Datetime-local
● Input Type Email
● Input Type File
● Input Type Month
● Input Type Number
● Input Type Range

Image Source: https://www.tutorialathome.in/html/html-5-forms-iii


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Types(contd)

● Input Type Search


● Input Type Tel
● Input Type Time
● Input Type Url
● Input Type Week

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Attributes

● The value Attribute


● The readonly Attribute
● The disabled Attribute
● The size Attribute
● The maxlength Attribute
● The min and max Attributes
● The multiple Attribute

Image Source:
https://deals.weku.io/community-deals/@munivihar/html-lessons-lesson-25
© Edunet Foundation. All rights reserved.
Forms and Input

HTML Input Attributes(contd)

● The pattern Attribute


● The placeholder Attribute
● The required Attribute
● The step Attribute
● The autofocus Attribute
● The height and width Attributes
● The list Attribute
● The autocomplete Attribute

Image Source: https://codebridgeplus.com/html-input-attributes/


© Edunet Foundation. All rights reserved.
Database

What is Data?

● Data is a collection of a distinct unit of


information.
● This “data” is used in a variety of forms
of text, numbers, media and many more.
● Data is basically information that can be
translated into a particular form for
efficient movement and processing.

Image Source: https://www.twinkl.co.in/teaching-wiki/data


© Edunet Foundation. All rights reserved.
Database

What is a Database?

● A database is an organized collection of


data, so that it can be easily accessed
and managed.
● You can organize data into tables, rows,
columns, and index it to make it easier
to find relevant information.

Image Source: https://i.ytimg.com/vi/Tq7KcGNDNm0/hqdefault.jpg


© Edunet Foundation. All rights reserved.
Database

What is a Database?(contd)

● The main purpose of the database is to


operate a large amount of information by
storing, retrieving, and managing data.

Image Source: https://gamesforepc.com/what-is-database/


© Edunet Foundation. All rights reserved.
Database

DBMS

● A database management system


(DBMS) is a software package designed
to define, manipulate, retrieve and
manage data in a database.
● DBMS also provides protection and
security to the databases.
● It also maintains data consistency in
case of multiple users.
Image Source: https://www.edureka.co/blog/what-is-dbms
© Edunet Foundation. All rights reserved.
Database

RDBMS

● A Relational Database Management


System is a collection of program that
allows to create, update, searching and
interact with a relational database.

Image Source:
https://www.astera.com/type/blog/relational-database-management-system/
© Edunet Foundation. All rights reserved.
Database

RDBMS(contd)

● An RDBMS may also provide a visual


representation of the data.

For example, it may display data in a tables


like a spreadsheet, allowing you to view and
even edit individual values in the table.

Image Source:
https://www.researchgate.net/figure/Relational-database-data-model_fig1_316498
© Edunet Foundation. All rights reserved.
Database

Difference between DBMS


vs RDBMS

● Number of operators
● Hardware and software needs
● Data modification
● Data volume
● Keys and Indexes

Image Source:
https://www.researchgate.net/figure/Relational-database-data-model_fig1_316498
© Edunet Foundation. All rights reserved.
Database

Difference between DBMS


vs RDBMS(contd)

● Data consistency
● Database structure
● Data fetching speed
● Client server architecture

Image Source:
http://onlinetutorialhub.blogspot.com/2017/11/top-15-differences-between-dbms-a
© Edunet Foundation. All rights reserved.
Database

Types of Database

● Relational Database
● Object-Oriented Database
● Distributed Database
● NoSQL Database
● Graph Database
● Cloud Database
● Centralization Database
● Operational Database

Image Source: https://www.slideshare.net/DenisReznik/iforum-sql-vs-nosql/15


© Edunet Foundation. All rights reserved.
User Account and security

● SSL
● Web page content
● Script Security
● Infrastructure
● The Data
● Tracking
● Archival and Backup

Image Source:
https://medium.com/koinex-crunch/enhancing-account-security-together-164fa8bf
© Edunet Foundation. All rights reserved.
APIs and Caching

HTML Geolocation

● The Geolocation API (JavaScript-based)


is used for locating the user's position.
● This new feature of HTML5 allows you
to navigate the latitude and longitude
coordinates of the current website's
visitor.
● It lets you share your location with
trusted websites.

Image Source:https://www.w3schools.com/html/html5_geolocation.asp
© Edunet Foundation. All rights reserved.
HTML Geolocation

Getting the User's current position

● To get the user's current location,


getCurrentPosition() method of the
navigator.geolocation object is used.
This method accepts three parameters:
● Success
● Error
● options

Image Source: https://www.w3schools.com/html/html5_geolocation.asp


© Edunet Foundation. All rights reserved.
APIs and Caching

Handling Errors and Rejections

● The second parameter of the


getCurrentPosition() method is used to
handle errors
Following are the possible options for invoking
the error call back function:
● Unknown random error Occurred
● If the user has denied for sharing
location
● Location information is not available
● Request for location is timed-out.
Image Source:https://www.w3schools.com/html/html5_geolocation.asp
© Edunet Foundation. All rights reserved.
APIs and Caching

Displaying location on Google Map

● This services used to provide the exact


location in map.
● Till now, we have seen how to show
your location using latitude and
longitude values, but it is not sufficient.
● Hence we can also show the exact
location on Google map with this API.

Image Source: https://www.w3schools.com/html/html5_geolocation.asp


© Edunet Foundation. All rights reserved.
APIs and Caching

Location properties

● The following table determines


properties used in getCurrentPosition()
and their returning values.

Image Source: https://www.javatpoint.com/html-geolocation


© Edunet Foundation. All rights reserved.
APIs and Caching

HTML Drag/Drop

● Drag and drop is a very common


feature.
● It is when you "grab" an object and drag
it to a different location.
● It is a powerful user interface concept
which is used to copy, reorder and
delete items with the help of mouse.

Image Source:https://www.w3schools.com/html/html5_draganddrop.asp
© Edunet Foundation. All rights reserved.
APIs and Caching

HTML Drag/Drop(contd)

Stages during Drag and Drop operations


● Make an element draggable
● What to drag
● Where to Drop
● Do the Drop

Image Source:https://www.bitdegree.org/learn/html5-drag-and-drop
© Edunet Foundation. All rights reserved.
APIs and Caching

HTML Web Storage

● With web storage, web applications can


store data locally within the user's
browser.
● Web storage is more secure, and large
amounts of data can be stored locally,
without affecting website performance.
● Unlike cookies, the storage limit is far
larger (at least 5MB) and information is
never transferred to the server.
Image Source:https://www.w3schools.com/html/html5_webstorage.asp
© Edunet Foundation. All rights reserved.
HTML Web Storage

HTML Web Storage Objects

HTML web storage provides two objects for


storing data on the client:
● window.localStorage - stores data with
no expiration date
● window.sessionStorage - stores data for
one session (data is lost when the
browser tab is closed)

Image Source:https://www.w3schools.com/html/html5_webstorage.asp
© Edunet Foundation. All rights reserved.
HTML Web Storage

The localStorage Object

● The localStorage object stores the data


with no expiration date.
● The data will not be deleted when the
browser is closed, and will be available
the next day, week, or year.

Image Source:https://www.w3schools.com/html/html5_webstorage.asp
© Edunet Foundation. All rights reserved.
HTML Web Storage

The sessionStorage Object

● The sessionStorage object is equal to


the localStorage object, except that it
stores the data for only one session.
● The data is deleted when the user
closes the specific browser tab.

Image Source:https://www.w3schools.com/html/html5_webstorage.asp
© Edunet Foundation. All rights reserved.
APIs and Caching

Web Worker

● A web worker is a JavaScript that runs in


the background, independently of other
scripts, without affecting the
performance of the page.
● You can continue to do whatever you
want: clicking, selecting things, etc.,
while the web worker runs in the
background.

Image Source:https://www.youtube.com/watch?v=AcIDmzPqlKA
© Edunet Foundation. All rights reserved.
Web Worker

Check Web Worker Support

● Before creating a web worker, check


whether the user's browser supports it

Image Source:https://www.w3schools.com/html/html5_webworkers.asp
© Edunet Foundation. All rights reserved.
Web Worker

Create a Web Worker File

● The important part of the code above is


the postMessage() method - which is
used to post a message back to the
HTML page.
● Normally web workers are not used for
such simple scripts, but for more CPU
intensive tasks

Image Source:https://www.w3schools.com/html/html5_webworkers.asp
© Edunet Foundation. All rights reserved.
Web Worker

Create a Web Worker Object

● web worker file, we need to call it from


an HTML page.
● Then we can send and receive
messages from the web worker.

Image Source:https://www.w3schools.com/html/html5_webworkers.asp
© Edunet Foundation. All rights reserved.
Web Worker

Terminate and Reuse a Web Worker

● To terminate a web worker, and free


browser/computer resources, use the
terminate() method
w.terminate();
● If you set the worker variable to
undefined, after it has been terminated,
you can reuse the code
w = undefined;

Image
Source:https://developers.google.com/web/fundamentals/primers/service-workers
© Edunet Foundation. All rights reserved.
APIs and Caching

HTML SSE API

● To terminate a web worker, and free


browser/computer resources, use the
terminate() method
w.terminate();
● If you set the worker variable to
undefined, after it has been terminated,
you can reuse the code
w = undefined;

Image Source:https://dzone.com/articles/html-5-server-sent-events
© Edunet Foundation. All rights reserved.
HTML SSE API

Server-Sent Events - One Way


Messaging

● A server-sent event is when a web page


automatically gets updates from a
server.
● This was also possible before, but the
web page would have to ask if any
updates were available. With
server-sent events, the updates come
automatically.
Examples: Facebook updates, stock price
Image Source:https://www.ably.io/concepts/server-sent-events
updates, news feeds, sport results, etc. © Edunet Foundation. All rights reserved.
HTML SSE API

Receive Server-Sent Event


Notifications

● Create a new EventSource object, and


specify the URL of the page sending the
updates
● Each time an update is received, the
onmessage event occurs
● When an onmessage event occurs, put
the received data into the element with
id="result"
Image Source:https://www.w3schools.com/html/html5_serversentevents.asp
© Edunet Foundation. All rights reserved.
HTML SSE API

Check Server-Sent Events Support

● some extra lines of code to check


browser support for server-sent events

Image Source:https://www.w3schools.com/html/html5_serversentevents.asp
© Edunet Foundation. All rights reserved.
HTML SSE API

The EventSource Object

● we used the onmessage event to get


messages

Image Source:https://www.w3schools.com/html/html5_serversentevents.asp
© Edunet Foundation. All rights reserved.
Structuring the web

Disclaimer: The content is curated for educational purposes only.


© Edunet Foundation. All rights reserved.
In this section, we will discuss:

● Introduction to HTML
● Structuring of Web Page using HTML
● Multimedia and embedding
● HTML Table and Forms
● APIs

© Edunet Foundation. All rights reserved.


Introduction to HTML

What is an HTML?
● HTML stands for Hyper Text Markup
Language
● HTML is the standard markup language
for creating Web pages
● HTML describes the structure of a Web
page
● HTML consists of a series of elements
● HTML elements tell the browser how to
display the content
● The extension of HTML Page is .html

Image Source:
https://cdn.lynda.com/course/170427/170427-637251494437967118-16x9.jpg/
© Edunet Foundation. All rights reserved.
Introduction to HTML

Advantages of HTML

● HTML is widely used.


● Every browser
supports HTML Language.
● Easy to learn and use.
● Do not need to purchase any extra
software because it is by default in every
window.

Image Source:
https://brandongaille.com/wp-content/uploads/2018/08/HTML5-Advantages-and-D
© Edunet Foundation. All rights reserved.
Introduction to HTML

Disadvantages of HTML

● HTML can create only static and plain


pages so if we need dynamic pages
then HTML is not useful.
● I need to write a lot of code for making a
simple webpage.
● Security features are not good at HTML.
● If we need to write long code for making
a webpage then it produces some
complexity.
Image Source:
https://brandongaille.com/wp-content/uploads/2018/08/HTML5-Advantages-and-D
© Edunet Foundation. All rights reserved.
Structure of a Web Page

HTML Web Page Structure


● The <!DOCTYPE html> declaration
defines that this document is an HTML5
document
● The <html> element is the root element
of an HTML page
● The <head> element contains meta
information about the HTML page
● The <title> element specifies a title for
the HTML page (which is shown in the
browser's title bar or in the page's tab)
Image Source:
https://cdn.lynda.com/course/170427/170427-637251494437967118-16x9.jpg/
© Edunet Foundation. All rights reserved.
Structure of a Web Page

HTML Web Page Structure


(Continued)

● The <body> element defines the


document's body, and is a container for
all the visible contents, such as
headings, paragraphs, images,
hyperlinks, tables, lists, etc.
● The <h1> element defines a large
heading
● The <p> element defines a paragraph
Image Source:
https://cdn.lynda.com/course/170427/170427-637251494437967118-16x9.jpg/
© Edunet Foundation. All rights reserved.
Structuring of web page
using HTML

Add title to your Web Page

● The <title> tag defines the title of the


document.
● This title is created using the
<title>...</title> tags which are
themselves always nested within the
<head>...</head> tags.
● The title must be text-only, and it is
shown in the browser's title bar or in the
page's tab.
● We can NOT have more than one <title>
Image Source: https://www.w3schools.com/tags/tag_title.asp
element in an HTML document. © Edunet Foundation. All rights reserved.
Structure of a Web Page

Adding Content to Web Page

● The <body> element defines the


document's body, and is a container for
all the visible contents, such as
headings, paragraphs, images,
hyperlinks, tables, lists, etc.
● The <h1> element defines a large
heading
● The <p> element defines a paragraph

Image Source:
https://cdn.lynda.com/course/170427/170427-637251494437967118-16x9.jpg/
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

What is Multimedia?

● Multimedia comes in many different


formats. It can be almost anything you
can hear or see, like images, music,
sound, videos, records, films,
animations, and more.

● Web pages often contain multimedia


elements of different types and formats.
● Multimedia files have formats and
different extensions like: .wav, .mp3,
.mp4, .mpg, .wmv, and .avi. Image Source: https://www.w3schools.com/tags/tag_title.asp
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Images in HTML

● Images can improve the design and the


appearance of a web page.
● Use the HTML <img> element to define
an image
● Use the HTML src attribute to define the
URL of the image
● Use the HTML alt attribute to define an
alternate text for an image, if it cannot
be displayed
● Use the HTML width and height
Image Source: https://www.w3schools.com/html/html_images.asp
attributes to define the size of the ©image
Edunet Foundation. All rights reserved.
Multi Media and Embedding

Images in HTML

● Images can improve the design and the


appearance of a web page.
● Use the HTML <img> element to define
an image
● Use the HTML src attribute to define the
URL of the image
● Use the HTML alt attribute to define an
alternate text for an image, if it cannot
be displayed
● Use the HTML width and height
Image Source: https://www.w3schools.com/html/html_images.asp
attributes to define the size of the ©image
Edunet Foundation. All rights reserved.
Multi Media and Embedding

Annotating images with figures and


figure captions

● The <figure> tag specifies self-contained


content, like illustrations, diagrams,
photos, code listings, etc.
● The <figcaption> tag defines a caption
for a <figure> element.
● The <figcaption> element can be placed
as the first or last child of the <figure>
element.
Image Source: https://www.w3schools.com/tags/tag_figcaption.asp
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images

● The background-image property sets


one or more background images for an
element.

● By default, a background-image is
placed at the top-left corner of an
element, and repeated both vertically
and horizontally.
Image Source: https://www.w3schools.com/cssref/pr_background-image.asp
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images

● The background-image property sets


one or more background images for an
element.

● By default, a background-image is
placed at the top-left corner of an
element, and repeated both vertically
and horizontally.
Image Source: https://www.w3schools.com/cssref/pr_background-image.asp
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images


Background-origin

● The background-origin property


specifies the origin position (the
background positioning area) of a
background image.
● Set two background images for a <div>
element. Let the "paper.gif" background
image starts from the upper left corner
of the padding edge,
● and let the "img_tree.gif" background
image starts from the upper left corner
Image Source:
of the content https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_background-origin2
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images


Background-position

● The background-position property sets


the starting position of a background
image.
● By default, a background-image is
placed at the top-left corner of an
element, and repeated both vertically
and horizontally.

Image Source:
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_background-position
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images


Background-repeat

● The background-repeat property sets


if/how a background image will be
repeated.
● By default, a background-image is
repeated both vertically and horizontally.
● The background image is placed
according to the background-position
property. If no background-position is
specified, the image is always placed at
the element's top left corner. Image Source:
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_background-repeaty
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

CSS Background Images


Background-repeat

● The background-size property specifies


the size of the background images.
● There are four different syntaxes you
can use with this property: the keyword
syntax ("auto", "cover" and "contain"),
● the one-value syntax (sets the width of
the image (height becomes "auto"),
● The two-value syntax (first value: width
of the image, second value: height)
● and the multiple background syntax
Image Source:
(separated with comma). https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_background_hero
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Audio On the Web

● The HTML <audio> element is used to


play an audio file on a web page.
● The controls attribute adds audio
controls, like play, pause, and volume.
● The <source> element allows you to
specify alternative audio files which the
browser may choose from.
● There are three supported audio
formats: MP3, WAV, and OGG
Image Source:
https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_audio_all
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Video On the Web

● The HTML <video> element is used to


show a video on a web page.
● The controls attribute adds video
controls, like play, pause, and volume.
● It is a good idea to always include width
and height attributes.
● To start a video automatically use the
autoplay attribute
● There are three supported video
formats: MP4, WebM, and Ogg
Image Source:
https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_video_autoplay
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Displaying Video Text Tracks

● The <track> tag specifies text tracks for


<audio> or <video> elements.
● This element is used to specify subtitles,
caption files or other files containing
text, that should be visible when the
media is playing.
● Tracks are formatted in WebVTT format
(.vtt files).
Image Source:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

iframe in HTML

● The <iframe> tag specifies an inline


frame.

● An inline frame is used to embed


another document within the current
HTML document.

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe_frameborder_
© Edunet Foundation. All rights reserved.
Multi Media and Embedding
iframe in HTML
(Continued)

● Use the height and width attributes to


specify the size of the iframe.

● The height and width are specified in


pixels by default:

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe_frameborder_
© Edunet Foundation. All rights reserved.
Multi Media and Embedding
iframe in HTML
(Continued)

● By default, an iframe has a border


around it.

● To remove the border, add the style


attribute and use the CSS border
property

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe_frameborder_
© Edunet Foundation. All rights reserved.
Multi Media and Embedding
iframe in HTML
(Continued)

● An iframe can be used as the target


frame for a link.

● The target attribute of the link must refer


to the name attribute of the iframe

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe_frameborder_
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Embedding in HTML

● The <embed> tag defines a container


for an external resource, such as a web
page, a picture, a media player, or a
plug-in application.

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_embed_video
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Object in HTML

● The <object> tag defines a container for


an external resource.

● The external resource can be a web


page, a picture, a media player, or a
plug-in application.

Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_object_video
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

What is SVG?

● SVG stands for Scalable Vector


Graphics
● SVG is used to define vector-based
graphics for the Web
● SVG defines the graphics in XML format
● Every element and every attribute in
SVG files can be animated
● SVG is a W3C recommendation
● SVG integrates with other W3C
standards such as the DOM and XSL Image Source:
https://www.w3docs.com/uploads/media/default/0001/03/3e1a8c030f58a1cafe3a8
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Advantages of SVG

● SVG images can be created and edited


with any text editor
● SVG images can be searched, indexed,
scripted, and compressed
● SVG images are scalable
● SVG images can be printed with high
quality at any resolution
● SVG images are zoomable
● SVG graphics do NOT lose any quality if
they are zoomed or resized
● SVG is an open standard Image Source:
https://www.w3docs.com/uploads/media/default/0001/03/3e1a8c030f58a1cafe3a8
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Creating a Circle using SVG

● An SVG image begins with an <svg>


element
● The width and height attributes of the
<svg> element define the width and
height of the SVG image
● The <circle> element is used to draw a
circle
● The cx and cy attributes define the x and
y coordinates of the center of the circle.
If cx and cy are not set, the circle's
Image Source: https://www.w3schools.com/graphics/svg_inhtml.asp
center is set to (0, 0) © Edunet Foundation. All rights reserved.
Multi Media and Embedding
Creating a Circle using SVG
(Continuation)

● The r attribute defines the radius of the


circle
● The stroke and stroke-width attributes
control how the outline of a shape
appears. We set the outline of the circle
to a 4px green "border"
● The fill attribute refers to the color inside
the circle. We set the fill color to yellow
● The closing </svg> tag closes the SVG
image Image Source: https://www.w3schools.com/graphics/svg_inhtml.asp
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Creating a Rectangle using SVG

● The x attribute defines the left position of


the rectangle (e.g. x="50" places the
rectangle 50 px from the left margin)
● The y attribute defines the top position
of the rectangle (e.g. y="20" places the
rectangle 20 px from the top margin)
● The CSS fill-opacity property defines the
opacity of the fill color (legal range: 0 to
1)
● The CSS stroke-opacity property defines
the opacity of the stroke color (legal Image Source:
https://www.w3schools.com/graphics/tryit.asp?filename=trysvg_rect2
© Edunet Foundation. All rights reserved.
Multi Media and Embedding

Picture tag in HTML

● The <picture> tag gives web developers


more flexibility in specifying image
resources.
● he <picture> element contains two tags:
one or more <source> tags and one
<img> tag.
● The most common use of the <picture>
element will be for art direction in
responsive designs.
Image Source:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_picture
© Edunet Foundation. All rights reserved.
Tables and Forms

Tables in HTML

● HTML tables allow web authors to


arrange data into rows and columns.
● An HTML table is defined with the
<table> tag.
● Each table row is defined with the <tr>
tag. A table header is defined with the
<th> tag.
● By default, table headings are bold and
centered.
● A table data/cell is defined with the <td>
Image Source: https://www.w3schools.com/html/html_tables.asp
tag. © Edunet Foundation. All rights reserved.
Tables and Forms

Adding borders in Table

● If you do not specify a border for the


table, it will be displayed without
borders.

● A border is set using the CSS border


property

Image Source: https://www.w3schools.com/html/html_tables.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Adding Cell Padding in Table

● Cell padding specifies the space


between the cell content and its borders.

● If you do not specify a padding, the table


cells will be displayed without padding.

● To set the padding, use the CSS


padding property
Image Source: https://www.w3schools.com/html/html_tables.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Left-align Headings in Table

● By default, table headings are bold and


centered.

● To left-align the table headings, use the


CSS text-align property

Image Source: https://www.w3schools.com/html/html_tables.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

What is Form in HTML?

● An HTML form is used to collect user


input.
● The user input can then be sent to a
server for processing.
● The HTML <form> element defines a
form that is used to collect user input
● Form elements are different types of
input elements, like: text fields,
checkboxes, radio buttons, submit
buttons, and more.
Image Source: https://www.w3schools.com/html/html_forms.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

What is Form in HTML?

● An HTML form is used to collect user


input.
● The user input can then be sent to a
server for processing.
● The HTML <form> element defines a
form that is used to collect user input
● Form elements are different types of
input elements, like: text fields,
checkboxes, radio buttons, submit
buttons, and more.
Image Source: https://www.w3schools.com/html/html_forms.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms

● The <input> element can be displayed in


several ways, depending on the type
attribute.
● <input type="text"> defines a single-line
text input field:

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="password"> defines a


password field:

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="submit"> defines a button


for submitting form data to a
form-handler.

● The form-handler is typically a server


page with a script for processing input
data.

● The form-handler is specified in the


form's action attribute Image Source: https://www.w3schools.com/html/html_form_input_types.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="reset"> defines a reset


button that will reset all form values to
their default values

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="radio"> defines a radio


button.

● Radio buttons let a user select ONLY


ONE of a limited number of choices

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="checkbox"> defines a


checkbox.

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="checkbox"> defines a


checkbox.

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● <input type="button"> defines a button

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="color"> is used for


input fields that should contain a color.

● Depending on browser support, a color


picker can show up in the input field

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="date"> is used for


input fields that should contain a date.

● Depending on browser support, a date


picker can show up in the input field.

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="email"> is used for


input fields that should contain an e-mail
address.

● Depending on browser support, the


e-mail address can be automatically
validated when submitted.

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="file"> defines a


file-select field and a "Browse" button for
file uploads.

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="range"> defines a


control for entering a number whose
exact value is not important (like a slider
control).
● Default range is 0 to 100.
● However, you can set restrictions on
what numbers are accepted with the
min, max, and step attributes
Image Source: https://www.w3schools.com/html/html_form_input_types.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Elements in Forms


(Continued)

● The <input type="search"> is used for


search fields (a search field behaves like
a regular text field).

Image Source: https://www.w3schools.com/html/html_form_input_types.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms

● The input value attribute specifies an


initial value for an input field

Image Source: https://www.w3schools.com/html/html_form_attributes.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input readonly attribute specifies


that an input field is read-only.

● A read-only input field cannot be


modified (however, a user can tab to it,
highlight it, and copy the text from it).

● The value of a read-only input field will


be sent when submitting the form!
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input disabled attribute specifies


that an input field should be disabled.

● A disabled input field is unusable and


un-clickable.

● The value of a disabled input field will


not be sent when submitting the form!
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input size attribute specifies the


visible width, in characters, of an input
field.

● The default value for size is 20.

● The size attribute works with the


following input types: text, search, tel,
url, email, and password.
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input maxlength attribute specifies


the maximum number of characters
allowed in an input field.

● When a maxlength is set, the input field


will not accept more than the specified
number of characters.

Image Source: https://www.w3schools.com/html/html_form_attributes.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input min and max attributes specify


the minimum and maximum values for
an input field.

● The min and max attributes work with


the following input types: number, range,
date, datetime-local, month, time and
week.
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input multiple attribute specifies that


the user is allowed to enter more than
one value in an input field.

● The multiple attribute works with the


following input types: email, and file.

Image Source: https://www.w3schools.com/html/html_form_attributes.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input pattern attribute specifies a


regular expression that the input field's
value is checked against, when the form
is submitted.

● The pattern attribute works with the


following input types: text, date, search,
url, tel, email, and password.
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)
● The input placeholder attribute specifies
short a hint that describes the expected
value of an input field (a sample value or
a short description of the expected
format).

● The short hint is displayed in the input


field before the user enters a value.

● The placeholder attribute works with the


following input types: text, search, url, Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input required attribute specifies


that an input field must be filled out
before submitting the form.

● The required attribute works with the


following input types: text, search, url,
tel, email, password, date pickers,
number, checkbox, radio, and file.
Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)
● The input autocomplete attribute
specifies whether a form or an input field
should have autocomplete on or off.

● Autocomplete allows the browser to


predict the value. When a user starts to
type in a field, the browser should
display options to fill in the field, based
on earlier typed values.

● The autocomplete attribute works with


<form> and the following <input> types: Image Source: https://www.w3schools.com/html/html_form_attributes.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input autofocus attribute specifies


that an input field should automatically
get focus when the page loads.

Image Source: https://www.w3schools.com/html/html_form_attributes.asp


© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input formenctype attribute specifies


how the form-data should be encoded
when submitted (only for forms with
method="post").

● Note: This attribute overrides the


enctype attribute of the <form> element.

● The formenctype attribute works with the


following input types: submit and image. Image Source:https://www.w3schools.com/html/html_form_attributes_form.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)
● The input formmethod attribute defines
the HTTP method for sending form-data
to the action URL.

● Note: This attribute overrides the


method attribute of the <form> element.

● The formmethod attribute works with the


following input types: submit and image.

● The form-data can be sent as URL


Image Source:https://www.w3schools.com/html/html_form_attributes_form.asp
variables (method="get") or as an© HTTP
Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input formtarget a attribute specifies


a name or a keyword that indicates
where to display the response that is
received after submitting the form.

● Note: This attribute overrides the target


attribute of the <form> element.

● The formtarget attribute works with the


following input types: submit and image. Image Source:https://www.w3schools.com/html/html_form_attributes_form.asp
© Edunet Foundation. All rights reserved.
Tables and Forms

Input Attributes in Forms


(Continued)

● The input formnovalidate attribute


specifies that an <input> element should
not be validated when submitted.

● Note: This attribute overrides the


novalidate attribute of the <form>
element.

● The formnovalidate attribute works with


the following input types: submit. Image Source:https://www.w3schools.com/html/html_form_attributes_form.asp
© Edunet Foundation. All rights reserved.
APIs

What are APIs ?

● APIs stands for Application Program


Interface.
● API is a set of routines, protocols and
tools for building software applications.
● Basically an API specifies how software
component should interact.

Image Source:
https://www.lorenzo-datasolutions.com/sap-successfactors-api-urls/
© Edunet Foundation. All rights reserved.
APIs

What are APIs

● APIs are used when programming


Graphical User Interface (GUI)
components.
● A good API makes it easier to develop a
program by providing all the building
blocks.

Image Source:
https://www.lorenzo-datasolutions.com/sap-successfactors-api-urls/
© Edunet Foundation. All rights reserved.
APIs

GeoLocation API

● Geolocation API is used to identify the


users geographical location for the web
application.
● Geolocation services use Network
routing addresses such as IP address,
WiFi and MAC address or internal GPS
devices to identify users location.

Image Source:
https://www.udemy.com/course/html5-geolocation-in-depth-build-location-aware-a
© Edunet Foundation. All rights reserved.
APIs

GeoLocation API Methods

● getCurrentPosition()
● watchPosition()
● clearWatch()

Image Source:
https://www.udemy.com/course/html5-geolocation-in-depth-build-location-aware-a
© Edunet Foundation. All rights reserved.
APIs

Drag and Drop

● HTML Drag and Drop (DnD) is a


powerful user interface concept which is
used to copy, reorder and delete items
with the help of mouse.

Image Source:
https://www.techrepublic.com/blog/web-designer/learn-to-use-the-html5-drag-and-
© Edunet Foundation. All rights reserved.
APIs

Events for Drag and Drop

● Drag
● Dragstart
● Dragenter
● Dragover
● Dragleave
● Drop
● Dragend

Image Source: http://tutorials.jenkov.com/html5/drag-and-drop.html


© Edunet Foundation. All rights reserved.
APIs

Web Storage

● With web storage, web applications can


store data locally within the user's
browser.
● Storing data with the help of web
storage is similar to cookies, but it is
better and faster than cookies storage.
● Web storage sometimes also known as
DOM storage.

Image Source: https://scriptverse.academy/tutorials/html5-web-storage.html


© Edunet Foundation. All rights reserved.
APIs

Advantages of Web Storage

● Web storage can use storage upto 5MB


per domain.
● It will not send data to server side,
hence faster than cookies.
● Data stored by local storage never
expires, but cookies data expires after
sometime.
● Web storage is more secure than
cookies.

Image Source: https://scriptverse.academy/tutorials/html5-web-storage.html


© Edunet Foundation. All rights reserved.
APIs

Types of Web Storage

● Local Storage : stores data with no


expiration date.
● Session Storage : stores data for one
session (data is lost when browser tab is
closed).

Image Source:
https://stackoverflow.com/questions/19867599/what-is-the-difference-between-loc
© Edunet Foundation. All rights reserved.
APIs

Web Worker

● A Web worker is a java-script that runs


in the background, independently of
other scripts, without affecting the
performance of the page.You can
continue to do whatever you want :
clicking, selecting things, etc., while the
web worker runs in the background.

Image Source:
https://blog.sessionstack.com/how-javascript-works-the-building-blocks-of-web-wo
© Edunet Foundation. All rights reserved.
APIs

Features of the Web Worker


● Web workers are threaded javascript.
● Web workers requires more space and
CPU times.
● Web workers enhances the speed of a
website.
● Web workers executes code on the
client side.
● Web worker threads communicate with
each other using postMessage()
callback method.
Image Source:
https://blog.sessionstack.com/how-javascript-works-the-building-blocks-of-web-wo
© Edunet Foundation. All rights reserved.
APIs

Types of Web Worker


● Dedicated web workers : It can be
accessed by only one script which has
called it.Dedicated worker thread ends
as its parent thread ends.
● Shared web workers : It can be shared
by multiple scripts and can communicate
using the port.
● Service workers : They doesn't directly
interact with the web page and runs in
the background.
Image Source: https://www.educba.com/html5-web-workers/
© Edunet Foundation. All rights reserved.
APIs

SSE

● Server-Sent Events (SSE) allow a web


page to get updates from a server.
● The Server-Sent Events are
mono-directional (always come from
server to client ).

Image Source:https://prochazka.dev/server-sent-events/
© Edunet Foundation. All rights reserved.
APIs

Events for SSE

● onopen
● Onmessage
● onerror

Image Source:https://prochazka.dev/server-sent-events/
© Edunet Foundation. All rights reserved.
Scripting and Styling the
web

Disclaimer: The content is curated for educational purposes only.


© Edunet Foundation. All rights reserved.
In this section, we will discuss:

● CSS Overview
● Syntax
● CSS values and units
● Stylingtext
● Stylingbox
● CSSlayout

© Edunet Foundation. All rights reserved.


CSS Overview

What is CSS ?

● CSS is referred to as Cascading Style


Sheet.
● CSS is a simple design language
intended to simplify the process of
making web pages presentable.
● CSS describes how HTML elements are
to displayed on screen, paper, or in
other media.

Image Source:
https://justpublishingadvice.com/what-is-css-inline-css-tricks-and-tips-for-total-beg
© Edunet Foundation. All rights reserved.
CSS Overview

Why CSS ?

● CSS allows web designers, bloggers,


developers and so forth to make
websites unique and attractive.
● CSS allows us to play with page layout,
adjust colors and fonts, add effects to
images, etc.
● CSS allows us to separate the
presentation from the structure (HTML)
into different files.

Image Source:
https://www.granneman.com/teaching/web-development-granneman-way/videos/
© Edunet Foundation. All rights reserved.
CSS Overview

Advantages of CSS

● CSS saves time


● Pages load faster
● Easy maintenance
● Global web standards
● Multiple device compatibility
● Superior styles to HTML

Image Source: https://www.educba.com/advantages-of-css/


© Edunet Foundation. All rights reserved.
CSS Syntax

How does CSS affect HTML

● A CSS rule set is made of three parts:


○ Selector
○ Property
○ Value

Image Source: https://www.w3schools.com/css/css_syntax.asp


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS id Selector

● The id selector uses the id attribute of


an HTML element to select a specific
element.
● The id of an element is unique within a
page, so used to select one unique
element.
● To select an element with specific id,
write a hash (#) character, followed by id
of element.

Image Source: http://referencedesigner.com/tutorials/css/css_tutorial_03.php


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS class Selector

● The class selector selects HTML


elements with a specific class attribute.
● To select elements with a specific class,
write a period (.) character, followed by
the class name.
● HTML elements can also refer to more
than one class.

Image Source: http://referencedesigner.com/tutorials/css/css_tutorial_04.php


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS universal Selector

● Rather than selecting elements of a


specific type, the universal selector quite
simply matches the name of an element
type.
● The universal selector (*) selects all
HTML elements on the page.

Image Source: https://www.educba.com/types-of-css-selectors/?source=leftnavr


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS grouping Selector

● The grouping selector select all the


HTML elements with the same style
definitions.
● It will be better to group the selectors, to
minimize the code.
● To group selectors, separate each
selector with a comma.

Image Source: https://www.educba.com/css-commands/


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS Combinators selector

● A CSS selector can contain more than


one simple selector. Between the
selectors, we can use combinators.
● There are four different combinators:
○ descendent selector (space)
○ Child selector (>)
○ Adjacent sibling selector (+)
○ General sibling selector (~)

Image Source: https://www.tutorialbrain.com/css_tutorial/css_selectors/


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS Pseudo-class selector

● A pseudo-class is used to define a


special state of an element.
● For example, it can be used to:
○ Style an element when a user
mouses over it.
○ Style visited and unvisited links
differently.
○ Style an element when it gets
focus.

Image Source: https://www.tutorialbrain.com/css_tutorial/css_pseudo_class/


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS Pseudo-elements selector

● A pseudo-element is used to style


specified parts of an element.
● Some pseudo-elements are:
○ ::first-line
○ ::first-letter
○ ::before
○ ::after
○ ::selection

Image Source: https://www.w3schools.com/css/css_pseudo_elements.asp


© Edunet Foundation. All rights reserved.
CSS Syntax

CSS Attribute selector

● Some attribute selectors are:


○ [attribute] Selector
○ [attribute="value"] Selector
○ [attribute~="value"] Selector
○ [attribute|="value"] Selector
○ [attribute^="value"] Selector
○ [attribute$="value"] Selector
○ [attribute*="value"] Selector
Image Source: https://www.tutorialbrain.com/css_tutorial/css_attribute_selector/
© Edunet Foundation. All rights reserved.
CSS Syntax

Types of CSS

● There are three ways of inserting a style


sheet:
○ External CSS
○ Internal CSS
○ Inline CSS

Image Source: https://www.tutorialbrain.com/css_tutorial/css_attribute_selector/


© Edunet Foundation. All rights reserved.
CSS Syntax

Types of CSS (External CSS)

● An external style sheet can be written in


any text editor, and must be saved with
a .css extension.
● The external .css file should not contain
any HTML tags.

Image Source: https://www.bitdegree.org/learn/inline-css


© Edunet Foundation. All rights reserved.
CSS Syntax

Types of CSS (Internal CSS)

● An internal style sheet may be used if


one single HTML page has a unique
style.
● The internal style is defined inside the
<style> element, inside the head
section.

Image Source: https://www.bitdegree.org/learn/inline-css


© Edunet Foundation. All rights reserved.
CSS Syntax

Types of CSS (Inline CSS)

● An inline style may be used to apply a


unique style for a single element.
● To use inline styles, add the style
attribute to the relevant element. The
style attribute can contain any CSS
property.

Image Source: https://www.bitdegree.org/learn/inline-css


© Edunet Foundation. All rights reserved.
CSS values and units

Numerical Values
● Length values for specifying e.g.
element width, border thickness, or font
size.
● Pixels (px) are referred to as absolute
units because they will always be the
same size regardless of any other
related settings.
● em: 1em is the same as the font-size of
the current element (more specifically,
the width of a capital letter M.)
Image Source:
https://www.google.com/url?sa=i&url=https%3A%2F%2Fgetflywheel.com%2Flayo
© Edunet Foundation. All rights reserved.
CSS values and units

Numerical Values
● ex, ch: Respectively these are the height
of a lower case x, and the width of the
number 0. These are not as commonly
used or well-supported as ems.
● rem: The rem (root em) works in exactly
the same way as the em, except that it
will always equal the size of the default
base font-size
● vw, vh: Respectively these are 1/100th
of the width of the viewport, and 1/100th
of the height of the viewport.
Image Source:
https://www.google.com/url?sa=i&url=https%3A%2F%2Fgetflywheel.com%2Flayo
© Edunet Foundation. All rights reserved.
CSS values and units

Unitless Values

● Some values accept numbers, without


any unit added to them.
● An example of a property which accepts
a unitless number is the opacity
property, which controls the opacity of
an element (how transparent it is). This
property accepts a number between 0
(fully transparent) and 1 (fully opaque).

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
CSS values and units

Percentages

● A measurement of relative size.


Percentages take the form of a number
followed by %.
● Percentages can be used by the likes of
the width, height, padding, and margin
properties as well as font-size.

Image Source:
https://htmldog.com/references/css/values/percenta
© Edunet Foundation. All rights reserved.
Stylingtext

● The font-familyFonts
property is used to change the
face of a font.
● The font-style property is used to make a font
italic or oblique.
● The font-variant property is used to create a
small-caps effect.
● The font-weight property is used to increase or
decrease how bold or light a font appears.
● The font-size property is used to increase or
decrease the size of a font.
● The font property is used as shorthand to
specify a number of other font properties.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Stylingtext

Color
● CSS uses color values to specify a color.
● Typically, these are used to set a color either
for the foreground of an element (i.e., its text)
or else for the background of the element.
● They can also be used to affect the color of
borders and other decorative effects.

Image Source: https://www.tutorialspoint.com/css/css_colors.htm


© Edunet Foundation. All rights reserved.
Stylingtext

● CSS Colors - Hex Codes: A hexadecimal is a 6


Colorof a color. The first two
digit representation
digits(RR) represent a red value, the next two
are a green value(GG), and the last are the
blue value(BB).
● CSS Colors - RGB Values: This color value is
specified using the rgb( ) property. This
property takes three values, one each for red,
green, and blue. The value can be an integer
between 0 and 255 or a percentage.

Image Source: https://www.tutorialspoint.com/css/css_colors.htm


© Edunet Foundation. All rights reserved.
Stylingtext
● The text-align property in CSS is used for
aligning the inner content of a block element.
● left – The default value. Content aligns along
Text Alignment
the left side.
● right – Content aligns along the right side.
● center – Content centers between the left and
right edges. White space on the left and right
sides of each line should be equal.
● justify – Content spaces out such that as many
blocks fit onto one line as possible and the first
word on that line is along the left edge and the
last word is along the right edge.
● inherit – The value will be whatever the parent
element’s is.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Stylingtext

● The line-height property defines the amount of


space above Line
andheight
below inline elements. That
is, elements that are set to display: inline or
display: inline-block.
● The line-height property can accept the
keyword values normal or none as well as a
number, length, or percentage.
● The recommended method for defining line
height is using a number value, referred to as a
“unitless” line height..

Image Source:
https://www.google.com/imgres?imgurl=https%3A%2F%2Fiamvdo.me%2Fconten
© Edunet Foundation. All rights reserved.
Stylingtext

Letter & Word spacing


● The letter-spacing property controls the amount
of space between each letter in a given
element or block of text.
● The word-spacing property is similar to
letter-spacing, though naturally its use governs
the amount of space between the words in a
piece of text, not the individual characters.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Stylingbox

Box properties
● CSS box model is a container which contains
multiple properties including borders, margin,
padding and the content itself.
● It is used to create the design and layout of
web pages. It can be used as a toolkit for
customizing the layout of different elements.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Stylingbox
● The overflow property specifies whether to clip
the contentOverflow
or to add scrollbars when the
content of an element is too big to fit in the
specified area.
● visible - Default. The overflow is not clipped.
The content renders outside the element's box
● hidden - The overflow is clipped, and the rest of
the content will be invisible
● scroll - The overflow is clipped, and a scrollbar
is added to see the rest of the content
● auto - Similar to scroll, but it adds scrollbars
only when necessary

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Stylingbox
● In CSS we broadly have two types of boxes —
block Box
boxesdisplay typesboxes. These
and inline
characteristics refer to how the box behaves in
terms of page flow, and in relation to other
boxes on the page:
● The box will break onto a new line.
● The box will extend in the inline direction to fill
the space available in its container. In most
cases this means that the box will become as
wide as its container, filling up 100% of the
space available.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Styling box

Background color
● The background-color property in CSS is used
to specify the background color of an element.
● The background covers the total size of the
element with padding and border but excluding
margin.
● It makes the text so easy to read for the user.

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Styling box

● The background-image property in CSS


Background
applies a graphic (e.g. image
PNG, SVG, JPG, GIF,
WEBP) or gradient to the background of an
element.

● The url() value allows you to provide a file path
to any image, and it will show up as the
background for that element.
● Another option when using backgrounds is to
tell the browser to create a gradient.

Image Source: https://css-tricks.com/almanac/properties/b/background-image/


© Edunet Foundation. All rights reserved.
CSS layout
● Normal Flow, or Flow Layout, is the way that
Block andNormal
Inline elements
flow are displayed on a
page before any changes are made to their
layout.
● The flow is essentially a set of things that are
all working together and know about each other
in your layout.
● Once something is taken out of flow it works
independently.

© Edunet Foundation. All rights reserved.


CSS layout

Normal flow

Image Source:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flow_Layout#:~:text=N
© Edunet Foundation. All rights reserved.
CSS layout

● The display property specifies if/how an


Theisdisplay
element displayed. property
● Every HTML element has a default display
value depending on what type of element it is.
● The default display value for most elements is
block or inline .
● This panel contains a <div> element, which is
hidden by default ( display: none ).

© Edunet Foundation. All rights reserved.


CSS layout

The
#geeks1{ display property
height: 100px;

width: 200px;

background: teal;

display: block;

Image Source: https://www.geeksforgeeks.org/css-display-property/


© Edunet Foundation. All rights reserved.
CSS layout

● CSS FlexibleFlexbox
Box Layout, commonly known as
Flexbox, is a CSS3 web layout model.
● It is in the W3C's candidate recommendation
stage.
● The flex layout allows responsive elements
within a container to be automatically arranged
depending upon screen size.

© Edunet Foundation. All rights reserved.


CSS layout
.flex-container {

display: flex;

background-color: DodgerBlue;
Flexbox
}

.flex-container > div {

background-color: #f1f1f1;

margin: 10px;

padding: 20px;

font-size: 30px;

Image Source:
https://www.w3schools.com/css/tryit.asp?filename=trycss3_flexbox
© Edunet Foundation. All rights reserved.
CSS layout

● CSS grid layoutGrid


or CSS grid is a technique in
Cascading Style Sheets that allows web
developers to create complex responsive web
design layouts more easily and consistently
across browsers.
● There have been other methods for controlling
web page layout methods, such as tables, the
box model, and CSS flex box

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
CSS layout

Grid

Image Source:
https://www.w3schools.com/css/tryit.asp?filename=trycss_grid_layout_named
© Edunet Foundation. All rights reserved.
CSS layout

Floats
● The float CSS property places an element on
the left or right side of its container, allowing
text and inline elements to wrap around it.
● The element is removed from the normal flow
of the page, though still remaining a part of the
flow (in contrast to absolute positioning)

Image Source:
https://www.google.com/url?sa=i&source=imgres&cd=&cad=rja&uact=8&ved=2ah
© Edunet Foundation. All rights reserved.
Enhancing the web using
PHP
In this section, we will discuss:

● PHP Fundamentals overview


● PHP Forms, files and cookies
● Form Validations
● Introduction to PHP Script
● Looping statement in PHP Script
● Working with Predefined functions
● Maintaining Validations in PHP Script
In this section, we will discuss:

● Working with Different types of Mouse Events


● Object Oriented Programming and PHP5
● Debugging PHP Code
● PHP Session Handling Features
● Smarty Installation
● Handling Date & Time in PHP
● Installing and Managing MySQL (access control overview)
● Understanding and using MySQL clients
● Database Access, Design Patterns, Mail Function, PEAR and cURL
PHP Fundamentals
Overview
Introduction

● PHP scripts can be written using any


text editor like: Notepad, Notepad++,
simple text or vi.
● PHP files end with extension .php

Image Source:
https://www.techopedia.com/2/28997/development/web-development/php-101
PHP Fundamentals
Overview
Use of start and end tag

● <?php tag is the start tag and ?> is the


end tag of php script.
● PHP interpreter ignores all other code
outside of these tags.
● In a PHP program we can use multiple
start and end tags.
PHP Fundamentals
Overview
Comments in PHP scripts

● The lines those are written in between


the comments are ignored by the
interpreter.
● In PHP comments are of 2 types:

○ Single line comment:

○ For it we use // Image Source: http://www.easytolearning.com/php-comments


PHP Fundamentals
Overview
Comments in PHP scripts

● Multiline comment:

○ This type of comment is used to


make a block of lines as comment
just like C language

○ We use /*...................*/ symbol for


this. Image Source: http://www.easytolearning.com/php-comments
PHP Fundamentals
Overview
Variables in PHP

● Variables are the memory locations


used to store some values.
● In PHP variables are loosely typed,
means there is no need to define data
type of variables.
● In PHP variables are prefixed with a
$(dollar sign) and are case sensitive.
● The first letter of a variable name
must be an underscore or letter and Image Source: https://www.youtube.com/watch?v=esCHWLYIusU
it cannot be a number.
PHP Fundamentals
Overview

PHP echo and print Statements

● They are both used to output data to the


screen.
● echo has no return value while print has
a return value of 1 so it can be used in
expressions.
● echo can take multiple parameters
(although such usage is rare) while print
can take one argument.
● echo is marginally faster than print. Image Source: https://www.w3schools.com/php/php_echo_print.asp
PHP Fundamentals
Overview

PHP Data Types

● PHP supports the following data types:

− String, Integer

− Float, Boolean

− Array, Object

− NULL,Resource
Image Source: https://www.tutorialandexample.com/php-data-types/
PHP Forms, files and
cookies

PHP Forms

● Forms are the basic interface between


user and server.
● For form creation, we should use HTML.
● Using forms we can accept data from
user and then we can handle the data
using PHP.
● Data can be saved in any database
server like MySql.
Image Source: http://www.learncomputer.com/php-form-handling/
PHP Forms, files and
cookies
Creating forms in PHP using HTML

● We should specify a unique name for


every entry element like (form, textbox,
● password box, select, text area etc.), for
this we can use Name attribute.
● We should specify Value rather than
HTML default value.
● We can pass hidden variables from form
to form using Hidden data entry
elements.
PHP Forms, files and
cookies
Server variables

● There are some useful server variables


apart of PHP_SELF and $_SERVER,
those can be used to provide
information on the web server and the
current request.
PHP Forms, files and
cookies
How to pass Information using form?

● There are two different ways of passing


information between browser and
server.

− GET and

− POST
● These methods are used in form tag as:
<form method=”GET”> and
● <form method=”POST”> Image Source: http://www.learncomputer.com/php-form-handling/
PHP Forms, files and
cookies
Steps in form handling

● Form display

− user sends a request to server to


display form. Web server will verify
the web page and revert it to the
client machine.
● Form processing

− After display form on client


machine, user can enter values in
form. When the form is submitted, Image Source: http://www.learncomputer.com/php-form-handling/
it is validated and processed at
server side.
PHP Forms, files and
cookies
Editing data with an HTML Form

● To accomplish this task there are


various form elements are found in
HTML such as:

− Text and Textarea, Checkboxes,


Radio Buttons, Select, etc.
Image Source: http://www.learncomputer.com/php-form-handling/
PHP Forms, files and
cookies
File handling in PHP

● In a file manipulation process following


tasks can be included:

− Open file for read and write

− Close file

− Perform operations on file

− Write results Image Source: http://www.easytolearning.com/file-handling-in-php


PHP Forms, files and
cookies
File connections

● There are four types of file connections


that can be made in PHP:

− HTTP

− FTP

− Standard I/O

− Filesystem Image Source: http://www.easytolearning.com/file-handling-in-php


PHP Forms, files and
cookies
File read

● fread() function can be used.


● This function takes a file pointer and a
file size in bytes as parameters.
● If the file size is not clear, we can use
filesize() function as parameter.
PHP Forms, files and
cookies
File Write

● fwrite() function, which takes two


parameters first file pointer and a string,
with an optional length in bytes.
PHP Forms, files and
cookies
feof

● This function is used to check for


end-of-file on a file pointer and takes a
filename as argument.
● It is basically used in loop to perform the
same function on each line in a file.
PHP Forms, files and
cookies
file_exists

● This function simply checks for the


availability of file on local file system
with the specified name.
● Function will simply return true if the file
exists, otherwise false will be returned.
PHP Forms, files and
cookies
PHP file upload

● The main use of PHP file handling is to


upload files on web server.
● We can perform this task using HTML
form.
PHP Forms, files and
cookies
Description of form contents

● Enctype
● Action
● Method
● Input type
● Input name
PHP Forms, files and
cookies
Writing text file using PHP

● We can write in text file using PHP. For


the same first file should be opened in
write mode
PHP Forms, files and
cookies
Reading a text file using PHP

● To perform a read operation in text file,


first of all we should open file in read
mode.
● We can read file in line by line manner
or it can be completely read.
PHP Forms, files and
cookies
File close

● File close can be done using fclose().


● fclose() function does not require
assignment in any variable.
PHP Forms, files and
cookies
Introduction to Cookie

● Cookie is a small piece of information


that can be stored on a client-side
machine by PHP script.
● We can set a cookie on a user’s
machine by sending an HTTP header
containing data in key value pair format.
Image Source: Image Source:
https://www.youtube.com/watch?v=esCHWLYIusU
PHP Forms, files and
cookies
Working with Cookies

● To set a cookie we have to use


setcookie() function.
● Syntax of setcookie() function:
● setcookie ( name, value, expire, path,
domain);
● Cookies can be retrieved using
$_COOKIE global variable like:
● echo $_COOKIE[“user”];
Form Validations

PHP form validation

● Proper validation of form data is


important to protect your form from
hackers and spammers!

Image Source: https://www.w3schools.com/php/php_form_validation.asp


Introduction to PHPScript

Introduction

● PHP is an Open source scripting


language that is widely used to create
Dynamic websites having database
connectivity.
● The name PHP is short form of
“Hypertext Preprocessor”.
● It is cross-platform language and can be
used everywhere.
Image Source:
● It can run on almost all Operating https://www.researchgate.net/figure/Execution-of-PHP-script_fig2_266032271

systems.
Introduction to PHPScript

Types of scripting languages

● There are two types of scripting


languages:
● Client-side scripting
● This type of script is executed on
client side by browser.
● Server-side scripting
● This type of script is executed on
server side. PHP comes under this Image Source:
https://www.researchgate.net/figure/Execution-of-PHP-script_fig2_266032271
category.
Introduction to PHPScript

Types of two way communication in


server side scripting

● Server side scripting is invisible to the


user. In server side scripting, the
following two types of two way
communication is done:
● Server to client
● Web pages can be assembled from
back end server output.
● Client to server
Image Source:
● Customer entered information can be https://www.researchgate.net/figure/Execution-of-PHP-script_fig2_266032271

acted upon.
Introduction to PHPScript

Tasks of server side scripting


language

● The following are some of the tasks that


can be implemented using server side
scripting language.
Introduction to PHPScript

Features of PHP5

● Here are the lists of features of PHP5.


Looping statements in PHP
Script
Different looping statements

● PHP has two major groups of looping


statements: for and while.
● The For statements are best used when
you want to perform a loop a specific
number of times.
● The While statements are best used to
perform a loop an undetermined number
of times.
● In addition, you can use the break and
continue statements within looping
statements.
Working with Predefined
functions
Steps in using functions

● Calling the function by passing some


arguments.
● After the calling control will move to the
function definition and then the set of
statements written inside the function
block are get executed.
● After the execution of function, control
will return to the module, from where the
Image Source:
function was called. http://www.learncomputer.com/php-form-handling/
Working with Predefined
functions
Types of PHP functions

● In built functions
● Date and time functions
● String functions
● User defined functions
Working with Predefined
functions
Variable Scope

● Based on variables accessibility (scope


of variables), variables can be classified
in two types:
● Global variables
● Local variables
Working with Predefined
functions
Default arguments in functions

● Default arguments can be used in PHP,


when we want to call function with same
default parameters in case user doesn’t
pass those parameters at the time of
function call.
Working with Predefined
functions
Predefined functions in PHP

● In PHP there are number of predefined


functions are available for various
categories:
Working with Predefined
functions
Date or time functions

● By default date() and strftime() both


functions display date and time in
mm/dd/yy hh:mm:ss format.
● We can also change the format if
needed by passing parameters in these
functions.
Working with Predefined
functions
String functions in PHP

● strlen()
● substr()
● strtoupper() and strtolower()
● strpos()
Maintaining Validations in
PHP Script

PHP Form validation

● While creating forms in PHP using


HTML we should keep some points in
our mind:
● We should specify a unique name for
every entry element like (form, textbox,
password box, select, text area etc.), for
this we can use Name attribute.

Image Source: https://www.w3resource.com/w3r_images/validation.jpg


© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Form validation

● We should specify Value rather than


HTML default value.
● We can pass hidden variables from form
to form using Hidden data entry
elements.

Image Source: https://www.w3resource.com/w3r_images/validation.jpg


© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Variables

● $GLOBALS
● $_SERVER
● $_REQUEST
● $_POST
● $_GET
● $_FILES
● $_ENV
● $_COOKIE
● $_SESSION
Image Source:
https://codelack.com/wp-content/uploads/2017/05/Php_variable-e1496174087403
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Global Variables - $_Global

● $GLOBALS is a PHP super global


variable which is used to access global
variables from anywhere in the PHP
script (also from within functions or
methods).

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Global Variables - $_Global

● <?php
$x = 75;
$y = 25;
function addition() {
$GLOBALS['z'] = $GLOBALS['x']
+ $GLOBALS['y'];
}
addition();
echo $z;
?> Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Global Variables - $_Server

● $_SERVER is a PHP super global


variable which holds information about
headers, paths, and script locations.

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Element/Code Description

$_SERVER['PHP_SELF'] Returns the filename of the currently executing script

$_SERVER['GATEWAY_INTERFAC Returns the version of the Common Gateway Interface (CGI) the server is
E'] using

$_SERVER['SERVER_ADDR'] Returns the IP address of the host server

$_SERVER['SERVER_NAME'] Returns the name of the host server (such as www.w3schools.com)

$_SERVER['SERVER_SOFTWARE'] Returns the server identification string (such as Apache/2.2.24)


Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script
$_SERVER['SERVER_PROTOCOL'] Returns the name and revision of the information
protocol (such as HTTP/1.1)

$_SERVER['REQUEST_METHOD'] Returns the request method used to access the page


(such as POST)

$_SERVER['REQUEST_TIME'] Returns the timestamp of the start of the request (such


as 1377687496)

$_SERVER['QUERY_STRING'] Returns the query string if the page is accessed via a


query string

$_SERVER['HTTP_ACCEPT'] Returns the Accept header from the current request

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

<!DOCTYPE html><html><body><?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
Image Source:
?> © Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Global Variables - $_Request

● PHP $_REQUEST is a PHP super


global variable which is used to collect
data after submitting an HTML form.

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Example

<html> <body>
<form method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php

© Edunet Foundation. All rights reserved.


Maintaining Validations in
PHP Script

Example

if ($_SERVER["REQUEST_METHOD"] ==
"POST") {
// collect value of input field
$name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}}?></body></html>
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

PHP Global Variables - $_POST

● PHP $_POST is a PHP super global


variable which is used to collect form
data after submitting an HTML form with
method="post". $_POST is also widely
used to pass variables.

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script
● <html> <body>
<form method="post" action="<?php ech
o $_SERVER['PHP_SELF'];?>">

Name: <input type="text" name="fname"


>
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"]
== "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Primary Validating Function

<?php
function validate($str) {
return trim(htmlspecialchars($str));
} // calling validate function
echo '<pre>';
echo validate(' <script> ');
echo '</pre>';
?>

© Edunet Foundation. All rights reserved.


Maintaining Validations in
PHP Script

Email Validation Function

We use in-built
function filter_var() with FILTER_VALIDATE
_EMAIL flag to validate emails.
The filter_var() can be used for many
purposes. To say that we are using it to
validate an email, we have to set the second
parameter (called as flag)
to FILTER_VALIDATE_EMAIL.
Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Email Validation Function

$email = validate($_POST['email’]);
if (!filter_var($email,
FILTER_VALIDATE_EMAIL)) { $emailError =
'Invalid Email'; }

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Email Validation Function

Complete code available in notes

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

URL Validation

Here we use filter_var() function


with FILTER_VALIDATE_URL flags

$website = validate($_POST['website']);
if (!filter_var($website,
FILTER_VALIDATE_URL))
{
$websiteError = 'Invalid URL’;
}
The only validation should be done to
description input is, sending the input though Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2020/01/PHP-Superglobal-
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

URL Validation Example

<?php
$url = "https://www.w3schools.com";

if (filter_var($url, FILTER_VALIDATE_URL))
{
echo("$url is a valid URL");
} else {
echo("$url is not a valid URL");
}
?>
© Edunet Foundation. All rights reserved.
Maintaining Validations in
PHP Script

Checkbox Validation
Most of browsers set value of check box to
"on" if it is checked. We
use filter_var() function
with FILTER_VALIDATE_BOOLEAN flag to
convert it to boolean. This function will
convert "on" to true, which makes later
processes easy for us.

$remember =
validate($_POST['remember']);
$remember = filter_var($remember,
https://html.form.guide/assets/img/sample-cake-form-prev.3ddee477.png
FILTER_VALIDATE_BOOLEAN); © Edunet Foundation. All rights reserved.
Working with Different types
of Mouse Events
Event Description
Checkbox Validation
onclick The event occurs when the user clicks on an element

oncontextmenu The event occurs when the user right-clicks on an element to open a context
menu

ondblclick The event occurs when the user double-clicks on an element

onmousedown The event occurs when the user presses a mouse button over an element

onmouseenter The event occurs when the pointer is moved onto an element

© Edunet Foundation. All rights reserved.


Working with Different types
of Mouse Events
Event Description
Checkbox Validation
onmouseleave The event occurs when the pointer is moved out of an element

onmousemove The event occurs when the pointer is moving while it is over an element

onmouseout The event occurs when a user moves the mouse pointer out of an element,
or out of one of its children

onmouseover The event occurs when the pointer is moved onto an element, or onto one of
its children

onmouseup The event occurs when a user releases a mouse button over an element

© Edunet Foundation. All rights reserved.


Working with Different types
of Mouse Events

Onclick Event

The onclick event occurs when the user


clicks on an element.
<element onclick="myScript">

<button onclick="getElementById('demo').in
nerHTML = Date()">What is the
time?</button>

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2019/11/event-attributes.pn
© Edunet Foundation. All rights reserved.
Working with Different types
of Mouse Events

Onclick Event

<html><body><h1>The onclick Event</h1>


<p>The onclick event is used to trigger a
function when an element is clicked on.</p>
<p>Click the button to trigger a function that
will output "Hello World" in a p element with
id="demo".</p>
<button onclick="myFunction()">Click
me</button>
<p id="demo"></p>
© Edunet Foundation. All rights reserved.
Working with Different types
of Mouse Events

Onclick Event

<script>
function myFunction() {

document.getElementById("demo").innerHT
ML = "Hello World";
}
</script></body></html>

© Edunet Foundation. All rights reserved.


Working with Different types
of Mouse Events

Ondblclick Event

Syntax :
<element ondblclick="myScript">

<html><body>
<p>This example demonstrates how to
assign an "ondblclick" event to a p
element.</p>

<p id="demo"
ondblclick="myFunction()">Double-click
me.</p> © Edunet Foundation. All rights reserved.
Working with Different types
of Mouse Events

Ondblclick Event

<script>
function myFunction() {

document.getElementById("demo").innerHT
ML = "I was double-clicked!";
}
</script></body></html>

© Edunet Foundation. All rights reserved.


Object Oriented
Programming and PHP5
What is Object-Oriented
Programming?

● Object-Oriented Programming, also


known as OOP is a special way of
programming. It is considered to be
more powerful and fast for certain tasks
than the normal way of programming in
PHP. OOP helps you to create and
manage tasks easily.

Image Source:
https://di3xp7dfi3cq.cloudfront.net/pub/media/magefan_blog/10-applications-of-ob
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
What is Object-Oriented
Programming?

● Some advantages of OOP:


● Easy to manage
● Easy to use
● Prevents repetition
● Fast and efficient

Image Source:
https://di3xp7dfi3cq.cloudfront.net/pub/media/magefan_blog/10-applications-of-ob
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is a Class?

● The first term we find in OOP is class. A


class is a blueprint. It is a piece of code
describing how to manage a topic or
task in the way we want.
● For instance, a class is like a blueprint of
a car.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is a Class?

● You can build more than one cars from a


blueprint. In the same way, you can
create more Objects from a class.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is an Object?

● An Object is an instance of a class.


● It is like a car built from the blueprint.
You can build more than one object from
a class like creating multiple cars from a
blueprint.

Image Source:
https://lh3.googleusercontent.com/proxy/KhmzJ5_D0HmPEB_H625AXKySsn3IX6
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is an Object?

● Each car can have its own color,


dimensions, features equipment and
more. In the same way, different objects
can have different properties.

Image Source:
https://lh3.googleusercontent.com/proxy/KhmzJ5_D0HmPEB_H625AXKySsn3IX6
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is an Property?

● Properties are variables of an object.


They are the values associated with the
object. They describe the appearance of
the Object.

● Properties can be added, changed,


removed. Some can also be read-only.

Image Source:
https://image.slidesharecdn.com/introductiontoobjectorientedprogramming-14121
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is an Property?

● Color is a property of our car.


● We can also perform actions on our car
(like changing the color).

Image Source:
https://image.slidesharecdn.com/introductiontoobjectorientedprogramming-14121
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

What is an Method?

● Methods are actions that are performed


on Objects. Changing the color of my
car is a method performed on my car
object.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Declaring Class

● The class keyword followed by the class


name is used to declare a class.
<?php class House
{
// code
}
Here, class says to PHP that you are going
to write a class. House is the name of your
class.
Image Source: https://i.ytimg.com/vi/yrIbbKuSqK8/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Naming a Class

● The name you use for a class ("House"


in the above example),
● Should not be a PHP reserved word
Should start with a letter or underscore.
● Can have letters, numbers or
underscores after the first character.
● (ex: TowerHouse, LongHouse, Courty
ardHouse)
Image Source: https://i.ytimg.com/vi/yrIbbKuSqK8/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Properties

● Classes can have variables within it.


Those variables are called properties.
A property is a normal PHP variables
which is in any data types (integer,
string, array, object, etc).

Image Source:
https://todaypoints.azurewebsites.net/wp-content/uploads/2016/04/oopConcept-I
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Properties Example

<?php class House


{
public $primaryColor = 'black’;
public $secondaryColors = [ 'bathroom' =>
'white', 'bedroom' => 'light pink', 'kitchen' =>
'light blue' ];
public $hasPool = false;
public $extra;
}
Image Source:
https://todaypoints.azurewebsites.net/wp-content/uploads/2016/04/oopConcept-I
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Properties

As in the above example, we can declare


any type of variable as a property.
We can add default values for those
properties. (Black is the default
for $primaryColor) Also, note that the
property $extra does not have a default
value.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Objects

We can create multiple objects from a class.


These objects are called instances of the
class. This process is called instantiation.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Objects Example

<?php
class House
{
public $primaryColor = 'black’;
public $secondaryColors = [ 'bathroom' =>
'white', 'bedroom' => 'light pink', 'kitchen' =>
'light blue' ];
public $hasPool = false;
public $extra;
} Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Objects Example

After the class declaration, you can create


instances from it.
$myHouse = new House();
$friendHouse = new House();
Now each object is created having the
default values of the class.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Objects Example

You can check it by echoing the color of


each object.
echo $myHouse -> primaryColor; echo
$friendHouse -> primaryColor;
Both would echo out the default value black.

Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Objects

-> is the object operator, which is used to


access properties and methods of an object.

Image Source: https://i.ytimg.com/vi/yrIbbKuSqK8/maxresdefault.jpg


© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

How to declare a method?

<?php
class Example
{
public function echo($string)
{
echo $string;
}
}
We use the public keyword to make the
method available inside and outside the
Image Source:
class. https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

How to call a method?

$example = new Example();


$example -> echo('Hello World’);

● First, we create an object ($example)


from the class Example
● Next, we call the
method echo with -> (object operator)
and () (parentheses)
● The parentheses contain
the arguments as usual
Image Source:
https://javatutorial.net/wp-content/uploads/2014/11/class-object-featured-image.p
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

How to call a method?

<?php class House {


public $primaryColor = 'black';
public function changeColor($color) {
$this -> primaryColor = $color;
}
} // creates an object from the class

Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

How to call a method?

// creates an object from the class


$myHouse = new House();
# black (default value)
echo $myHouse -> primaryColor;
// change the color of the house
$myHouse -> changeColor('white');
# white
echo $myHouse -> primaryColor; ?>
Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

$this Keyword

● $this refers to the current object.


● $this is a pseudo-variable (also a
reserved keyword) which is only
available inside methods. And, it refers
to the object of the current method.

Image Source: https://i.ytimg.com/vi/dG4nZkTnhX4/maxresdefault.jpg


© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

$this Keyword
● Inside the class (by adding a set_name()
method and use $this):
<?php
class Fruit {
public $name;
function set_name($name) {
$this->name = $name;
}
}
$apple = new Fruit();
$apple->set_name("Apple");
Image Source:
echo $apple->name; © Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

new Keyword

● To create an instance of a class,


the new keyword must be used. An
object will always be created unless the
object has a constructor defined that
throws an exception on error.
● If there are no arguments to be passed
to the class's constructor, parentheses
after the class name may be omitted.
Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Creating an instance

● <?php
$instance = new SimpleClass();

// This can also be done with a variable:


$className = 'SimpleClass';
$instance = new $className(); // new S
impleClass()
?>
Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Object Assignment

<?php
$instance = new SimpleClass();
$assigned = $instance;
$reference =& $instance;
$instance->var = '$assigned will have this va
lue';
$instance = null; // $instance and $reference
become null
var_dump($instance);
var_dump($reference);
var_dump($assigned); Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Object Assignment

<?php
class Test
{
static public function getNew()
{
return new static;
}
}

class Child extends Test


{} Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Object Assignment

$obj1 = new Test();


$obj2 = new $obj1;
var_dump($obj1 !== $obj2);

$obj3 = Test::getNew();
var_dump($obj3 instanceof Test);

$obj4 = Child::getNew();
var_dump($obj4 instanceof Child);
?> Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Constructors

● A constructor is a public method which is


named as __construct.
class Example
{
public function __construct()
{ // your constructor function echo "Hello
World";
}}

● The __construct() method will be called


once when you create an object from Image Source:
https://beginnersbook.com/wp-content/uploads/2013/05/constructor_overloading.j
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
Constructors

<?php
class House {
public $name;
public $color;
public function __construct($name,
$color) {
$this -> name = $name;
$this -> color = $color;
}
Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
Constructors

public function echoData()


{
echo "The color of the {$this -> name} is
{$this -> color}";
}
}
$blackHouse = new House("John's House",
"black");
$blackHouse -> echoData(); ?>
Image Source:
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
Destructors

● A destructor is called when the object is


destructed or the script is stopped or
exited.
<?php
class House {
public $name;
public $color;
public function __construct($name,
$color) {
$this -> name = $name;
$this -> color = $color; Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2019/11/Destructor-in-PHP.
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
Destructors

public function __destruct() {


echo "The color of the {$this -> name} is
{$this -> color}";
}}
$blackHouse = new House("John's House",
"black"); ?>

© Edunet Foundation. All rights reserved.


Object Oriented
Programming and PHP5
Visibility

● Visibility of a class member


(property, method or constant) is where
it can be accessed. (Eg: inside the
class, outside the class)

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility

● Public - Can be accessed from


everywhere
● Private - Can only be accessed within
the class
● Protected- Can be accessed by the
class declared it and by the classes that
inherit the above declared class.

Image Source:
https://2.bp.blogspot.com/-BENn14np4qA/USjZDNwoaXI/AAAAAAAAAIE/a7gReK
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Public

● A public property or method can be


declared adding the public keyword in
front of its declaration. (If you followed
the previous chapters, you will
remember that we used this.)

Image Source:
https://2.bp.blogspot.com/-BENn14np4qA/USjZDNwoaXI/AAAAAAAAAIE/a7gReK
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Public

class Example {
public $property = 'property'; // a public
property public function myMethod()
{ // a public method echo 'Hello'; } }

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Public

A method declared without a visibility


keyword will be public.
class Example {
function myMethod() {
// a public method }
}

● Properties cannot be declared without


a visibility keyword.
Image Source:
https://2.bp.blogspot.com/-BENn14np4qA/USjZDNwoaXI/AAAAAAAAAIE/a7gReK
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Private

● A private property or method can be


declared adding the private keyword in
front of its declaration.

Image Source:
https://2.bp.blogspot.com/-BENn14np4qA/USjZDNwoaXI/AAAAAAAAAIE/a7gReK
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Private

class Example {
private $property = 'property’;
// a private property
private function privateMethod()
{
// a private method
echo $this -> property;
// this is valid } }

A private class member can only be accessed


from the methods in the class. Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Protected

A protected property or method can be


declared adding the protected keyword in front
of its declaration.

class Example {
protected $property = 'This is a protected
property’;
protected function myMethod()
{
// I'm protected!
}
} Image Source:
https://2.bp.blogspot.com/-BENn14np4qA/USjZDNwoaXI/AAAAAAAAAIE/a7gReK
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Types of Visibility - Protected

● Protected properties and methods can


be accessed by,
● The class which declared the variable
● The classes which *inherits the above
declared class
● * Note: You will learn more about
inheriting in the next chapters. Just
remember that inheriting is another
interesting concept in object-oriented
programming. Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

<?php
class User {
public $name = 'Hyvor';
public function changeName($name) {
$this -> name = $name;
}
}

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

$user = new User();


// Accessing public property from outside
echo $user -> name;
echo '<br>'; // a line break
// Accessing public method from outside
$user -> changeName('Hyvor Developer');
echo $user -> name;
?>
Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-visibility.jpg
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Interfaces

● Interfaces allow you to specify what


methods a class should implement.
Why?
● When you need to let a class to
compulsorily implement some methods
in it, you can use interfaces. This is a
good practice when creating real-world
web applications in PHP.
Image
Sourcehttps://phpenthusiast.com/theme/assets/images/blog/factory_design_patte
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Interfaces

● Declaring Interfaces
Interfaces are declared using
the Interface keyword.
<?php
Interface MyFirstInterface

{
// Defining methods
}

Image
?> Sourcehttps://phpenthusiast.com/theme/assets/images/blog/factory_design_patte
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Interfaces

● Declaring Interfaces
Interfaces are declared using
the Interface keyword.
<?php
Class Car_model implements
MyFirstInterface
{
// Defining methods body
}

Image
?> Sourcehttps://phpenthusiast.com/theme/assets/images/blog/factory_design_patte
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Interfaces

● Interfaces can be extended like classes


using the extends operator.
● interface a
{
public function foo();
}

interface b extends a
{
public function baz(Baz $baz);
Image
} Sourcehttps://phpenthusiast.com/theme/assets/images/blog/factory_design_patte
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Inheritance

● In Object-Oriented Programming, when


a class derives from another class, it is
called inheritance.
● The derived class is the child, and the
other class which the child derived from
is the parent class. (Sometimes they are
called subclass and superclass
respectively)
Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-inheritance-2.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Inheritance

● Syntax:
● class Tom extends Person {...} is the
syntax for the child class.

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-inheritance-2.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Inheritance

Class Animal
{ // variables and methods
}
Class Dog extends Animal
{// variables and methods
}
Class Cat extends Animal
{// variables and methods
}
Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-inheritance-2.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Inheritance


<?php
class Person {
public $name;
public $age;
public function __construct($name,
$age) {
$this -> name = $name;
$this -> age = $age;
}
public function introduce() {
echo "My name is {$this -> name}.
Image Source:
My age is {$this -> age}"; https://tutorials.supunkavinda.blog/static/images/php-oop-inheritance-2.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP OOP Inheritance

/* Tom is inherited from Person */


class Tom extends Person {
# __construct() is inherited
# introduce() is inherited
public function sayHello() {
echo "Hello, World <br>";
}
}
$tom = new Tom('Tom', 29);
$tom -> sayHello();
$tom -> introduce(); Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-inheritance-2.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
PHP OOP Abstract Classes and
Methods

● When the parent class Knows what to


do and
● Need its child class to do some tasks
● it can let its child classes to do the task.
This is an abstraction.

Image Source:
https://1.bp.blogspot.com/-3WnKibey_3w/WWGroOYi5nI/AAAAAAAACCA/HA82Y
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5
Declare Abstract Classes and
Methods

● The abstract keyword is used to define


an abstract class.
● <?php abstract class ParentClass { /* ...
*/ }
● ?>

Image Source:
https://1.bp.blogspot.com/-3WnKibey_3w/WWGroOYi5nI/AAAAAAAACCA/HA82Y
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Declaring Abstract Methods

● When you prepend the abstract keyword


to a method's declaration it becomes an
abstract method. And, remember,
abstract methods do not have a body.
Therefore, curly brackets {} are not
used.

Image Source:
https://1.bp.blogspot.com/-3WnKibey_3w/WWGroOYi5nI/AAAAAAAACCA/HA82Y
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Declaring Abstract Methods

<?php abstract class ParentClass


{ abstract public function myMethod1();
abstract protected function
myMethod2($name, $age);
abstract protected function myMethod3() :
int;
}
● Abstract method's visibility can either be
public or protected, but not private.
Image Source:
https://online.visual-paradigm.com/images/tutorials/class-diagram-tutorial/08-abstr
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Abstraction Rules

● The child class should override


(redeclare) all the abstract methods.
● The arguments for methods should be
the same as the abstract method.
● The child class can have arguments with
default values where the abstract class
hasn't defined.

Image Source:
https://online.visual-paradigm.com/images/tutorials/class-diagram-tutorial/08-abstr
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Abstraction Rules

● If the abstract class uses type


hinting (type declaration for return
values), the child class should use the
same.
● Objects cannot be created from abstract
classes.

Image Source:
https://online.visual-paradigm.com/images/tutorials/class-diagram-tutorial/08-abstr
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Abstraction Rules

Abstract Method Child Method's


Visibility Visibility
Public Public

Protected Protected or Public

Image Source:
https://online.visual-paradigm.com/images/tutorials/class-diagram-tutorial/08-abstr
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Abstraction Rules

● Abstract class example see in notes

Image Source: https://static.javatpoint.com/images/abstract-class-in-java.jpg


© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Only Abstract Methods

● An interface can only have method


signatures. It means that all the methods
cannot have a body - only the
declaration.
● And, all the methods must have public
visibility

Image Source:
https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/03/example-of-a
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Only Abstract Methods


abstract class AbstractClass
{
// Force Extending class to define this met
hod
abstract protected function getValue();
abstract protected function prefixValue($p
refix);

// Common method
public function printOut()
{
print $this->getValue() . "\n"; Image Source:
https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/03/example-of-a
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Only Abstract Methods

class ConcreteClass1 extends AbstractClas


s
{
protected function getValue() {
return "ConcreteClass1";
}

public function prefixValue($prefix) {


return "{$prefix}ConcreteClass1";
}
Image Source:
} https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/03/example-of-a
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Only Abstract Methods

<?php Interface MyInterface


{
public function myMethod1();
public function myMethod2($name, $age);
public function myMethod3() : int;
}

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-abstract.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Implements Keyword

Unlike abstract classes, we use


the implements keyword to implement an
interface in a child class.
<?php
class MyClass implements MyInterface
{ /* ... */ }

Image Source:
https://tutorials.supunkavinda.blog/static/images/php-oop-abstract.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Implements Keyword

A class can implement multiple interfaces


separated by commas in the declaration
(After the implements keyword).
Multiple Interface Example code in notes

Image Source:
https://miro.medium.com/max/596/1*SoyFBd8-AKktEDGou3C0kg.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

Implements Keyword

Interface Example code in notes

Image Source:
https://miro.medium.com/max/596/1*SoyFBd8-AKktEDGou3C0kg.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - What are Traits?

● PHP only supports single inheritance: a


child class can inherit only from one
single parent.
● So, what if a class needs to inherit
multiple behaviors? OOP traits solve this
problem.

Image Source:
https://miro.medium.com/max/596/1*SoyFBd8-AKktEDGou3C0kg.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - What are Traits?

● Syntax
● <?php
trait TraitName {
// some code...
}
?>
Use
● <?php
class MyClass {
use TraitName;
} Image Source:
https://miro.medium.com/max/596/1*SoyFBd8-AKktEDGou3C0kg.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - What are Traits?

● <?php
trait message1 {
public function msg1() {
echo "OOP is fun! ";
}
}
class Welcome {
use message1;
}
$obj = new Welcome();
$obj->msg1(); Image Source:
https://miro.medium.com/max/596/1*SoyFBd8-AKktEDGou3C0kg.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - Constants

● Constants cannot be changed once it is


declared.

● Class constants can be useful if you


need to define some constant data
within a class.

Image Source:https://clevertechie.com/img/main/php-constant.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - Constants

● A class constant is declared inside a


class with the const keyword.

● Class constants are case-sensitive.


However, it is recommended to name
the constants in all uppercase letters.

Image Source:https://clevertechie.com/img/main/php-constant.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP – Constants - Example

● <?php
class Goodbye {
const LEAVING_MESSAGE = "Thank
you for visiting W3Schools.com!";
public function byebye() {
echo self::LEAVING_MESSAGE;
}
}

$goodbye = new Goodbye();


$goodbye->byebye(); Image Source:https://clevertechie.com/img/main/php-constant.png
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP – Static methods

● Static methods can be called directly -


without creating an instance of a class.
● Static methods are declared with the
static keyword:
● Static properties cannot be accessed
through the object using the arrow
operator ->.
● Like any other PHP static variable, static
properties may only be initialized using a
literal or constant Image Source:
https://i1.wp.com/www.thecodingtutorials.com/wp-content/uploads/2020/03/static-
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP – Static methods

● Syntax:
● <?php
class ClassName {
public static function staticMethod() {
echo "Hello World!";
}
}
?>
● ClassName::staticMethod();
Image Source:
https://i1.wp.com/www.thecodingtutorials.com/wp-content/uploads/2020/03/static-
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP – Static methods

● <?php
class greeting {
public static function welcome() {
echo "Hello World!";
}
}

// Call static method


greeting::welcome();
?>
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - Static Properties

● Static properties can be called directly -


without creating an instance of a class.

● Static properties are declared with the


static keyword:

Image Source:
https://i1.wp.com/www.thecodingtutorials.com/wp-content/uploads/2020/03/static-
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - Static Properties

● Syntax:
● <?php
class ClassName {
public static $staticProp
= "W3Schools";
}
?>
● To access a static property use the class
name, double colon (::), and the
property name:
Image Source:
● ClassName::staticProp; https://i1.wp.com/www.thecodingtutorials.com/wp-content/uploads/2020/03/static-
© Edunet Foundation. All rights reserved.
Object Oriented
Programming and PHP5

PHP - Static Properties

<html>
<body>
<?php
class pi {
public static $value = 3.14159;
}
// Get static property
echo pi::$value;
?>
</body>
</html> © Edunet Foundation. All rights reserved.
Debugging PHP Code

Definition

Testing and debugging phase in


development process of any application is
very important, because in this phase it is
ensured that the code written will function as
per expectation.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Use

To debug PHP applications, various


strategies can be used for example we can
use turning on error reporting option in
Apache and PHP, use print statements in
PHP code to locate the source more difficult
bug through PHP script.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Dumping Variables to stdout

The var_dump function is one way to see


what’s happening in your PHP program. It’ll
dump a variable value to stdout. There are
other functions you can use for debugging
through outputs. Here are a few and how
they’ll help you:

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Dumping Variables

● var_dump ($var) dumps the variable


type and value to stdout.
● print_r ($var) prints the variable value
in human-readable form to stdout.
● get_defined_vars() gets all the defined
variables including built-ins and custom
variables (print_r to view them).

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Dumping Variables

● debug_zval_dump ($var) dumps the


variable with its reference counts. This is
useful when there are multiple paths to
update a single reference.
● debug_print_backtrace() prints a
backtrace that shows the current
function call-chain.
● debug_backtrace() gets the backtrace.
You can print_r, log it to a file, or send it
to a logging endpoint asynchronously. Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Example
<?php
$myVar = "hello world!";
var_dump($myVar);
print_r($myVar);
$allVars = get_defined_vars();
print_r($allVars);
debug_zval_dump($allVars);

function sayHello($hello) {
echo $hello;
debug_print_backtrace();
Image Source:
} https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Switching error reporting level

PHP has a few ways to configure error


reporting. You can use the php.ini file, if you
have access to it. Otherwise, you might use
the htaccess configuration.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Switching error reporting level

● error_reporting sets the level of


logging. E_NOTICE is useful during
development since it will tell you about
defects such as unassigned variables.
● display_errors tells PHP if and where
to display error messages.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Switching error reporting level

● display_startup_errors should only be


used when debugging.
● log_errors and error_log work together
to send errors to a log file. Do this in
production rather than displaying them
to end users.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Monitoring error logs

● It’s one thing to log errors—that’s almost


a given. It’s a whole other thing to take
action when errors are logged.

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Monitoring error logs

● Log aggregation. You want to see all


your logs in one place. If you can
centralize your logs and metrics across
instances, that’s even better! You’d be
able to spot trouble wherever it
happens.
● Alerting. There’s nothing better than
automation. If you’re a programmer, you
know what I mean! You’ll want to
automate almost anything if you can. Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

Monitoring error logs

● Traces in your logs. What’s a trace?


It’s not just a stack dump that lets you
see what was going on when an error
happened. It’s also a way to track
performance, which is often a sign or a
cause of a bug.
● Deduplication of log entries. When a
bug causes an error, it can fill up the
logs pretty quickly.
Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
Debugging PHP Code

PHP Debugging Tools

● You can debug PHP using one of many


debugging tools to attach a debugger
client. PhpStorm works with debug
utilities like Xdebug and ZendDebugger.
● PHPStorm
● Zend Debugger
● VS Code
● Xdebug

Image Source:
https://stackify.com/wp-content/uploads/2019/01/word-image-10.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Sessions

● A session is a way to store information


(in variables) to be used across multiple
pages.

● Unlike a cookie, the information is not


stored on the users computer.

Image source: https://www.sitesbay.com/php/images/session-in-php.png


© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Sessions

● Session variables solve this problem by


storing user information to be used
across multiple pages (e.g. username,
favorite color, etc). By default, session
variables last until the user closes the
browser.
● Session variables hold information about
one single user, and are available to all
pages in one application.
Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Sessions

● A session is started with the


session_start() function.

● Session variables are set with the PHP


global variable: $_SESSION.

Image source: https://www.sitesbay.com/php/images/session-in-php.png


© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Sessions

<?php
// Start the session
session_start();
?>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set."; Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

Get PHP Session Variable Values


<?php
session_start();
?>
<html><body>
<?php
// Echo session variables that were set on
previous page
echo "Favorite color is
" . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is
" . $_SESSION["favanimal"] . ".";
Image source: https://www.sitesbay.com/php/images/session-in-php.png
?> © Edunet Foundation. All rights reserved.
PHP Session Handling
Features

Modify a PHP Session Variable

<?php
session_start();
?>
<html>
<body>
<?php
// to change a session variable, just overwrite
it
$_SESSION["favcolor"] = "yellow";
print_r($_SESSION);
?> Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

Destroy a PHP Session

● To remove all global session variables


and destroy the session, use
session_unset() and session_destroy():

Image source: https://www.sitesbay.com/php/images/session-in-php.png


© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

Destroy a PHP Session

<?php
session_start();
?>
<html><body><?php
// remove all session variables
session_unset();

// destroy the session


session_destroy();
?></body></html> Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Session Functions

● session_abort — Discard session array


changes and finish session
● session_cache_expire — Return current
cache expire
● session_cache_limiter — Get and/or set
the current cache limiter
● session_commit — Alias of
session_write_close
● session_create_id — Create new
session id
● session_decode — Decodes session Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
PHP Session Handling
Features

PHP Session Functions

● session_destroy — Destroys all data


registered to a session
● session_encode — Encodes the current
session data as a session encoded
string
● session_gc — Perform session data
garbage collection
● session_get_cookie_params — Get the
session cookie parameters
● session_id — Get and/or set the current
session id Image source: https://www.sitesbay.com/php/images/session-in-php.png
© Edunet Foundation. All rights reserved.
Smarty Installation

Windows XAMPP Installation

● XAMPP is a completely free, easy to


install Apache distribution containing
MariaDB, PHP, and Perl. The XAMPP
open source package has been set up
to be incredibly easy to install and to
use.

Image source: https://www.sitesbay.com/php/images/session-in-php.png


© Edunet Foundation. All rights reserved.
Smarty Installation

XAMPP Installation

● https://youtu.be/h6DEDm7C37A

Image source: https://www.sitesbay.com/php/images/session-in-php.png


© Edunet Foundation. All rights reserved.
Smarty Installation

Ubuntu LAMP Installation

● Step 1:
sudo tasksel install lamp-server
● Step 2:
sudo apt install phpMyAdmin
● Step 3: Configuration
To use phpMyAdmin to administer a MySQL
database hosted on another server, adjust the
following in /etc/phpmyadmin/config.inc.php:
$cfg['Servers'][$i]['host'] =
'db_server';$cfg['Servers'][$i]['host'] =
Image source: https://www.sitesbay.com/php/images/session-in-php.png
'db_server'; © Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

Introduction

● Dates are so much part of everyday life


that it becomes easy to work with them
without thinking.
● PHP also provides powerful tools for date
arithmetic that make manipulating dates
easy.

https://www.plus2net.com/php_tutorial/images/date-time.jpg
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

Introduction (Continue)

● PHP's time() function gives you all the


information that you need about the
current date and time.
● It requires no arguments but returns an
integer.

https://www.tutorialspoint.com/php/php_date_and_time.htm
© Edunet Foundation. All rights reserved.
Handling Date & Time in Key & Description
PHP seconds Seconds past the minutes (0-59)
minutes Minutes past the hour (0 - 59)
hours Hours of the day (0 - 23)
Introduction (Continue) mday Day of the month (1 - 31)

wday Day of the week (0 - 6)

mon Month of the year (1 - 12)

● The function getdate() optionally accepts year Year (4 digits)


a time stamp and returns an associative yday Day of year ( 0 - 365 )
array containing information about the
weekday Day of the week
date.
● There is a complete list of elements month Month of the year
contained in the array returned by 0 Timestamp
getdate()

https://www.tutorialspoint.com/php/php_date_and_time.htm
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

Introduction (Continue)

● The date() function returns a formatted


string representing a date.
● You can exercise an enormous amount of
control over the format that date() returns
with a string argument that you must pass
to it.

https://www.tutorialspoint.com/php/php_date_and_time.htm
© Edunet Foundation. All rights reserved.
Format & Description
Handling Date & Time in a 'am' or 'pm' lowercase
A 'AM' or 'PM' uppercase
PHP d Day of month, a number with leading zeroes
D Day of week (three letters)
Introduction (Continue) F Month name
h Hour (12-hour format - leading zeroes)
H Hour (24-hour format - leading zeroes)
g Hour (12-hour format - no leading zeroes)
G Hour (24-hour format - no leading zeroes)
● The date() optionally accepts a time stamp i Minutes ( 0 - 59 )
if omitted then current date and time will L Leap year ('1' for yes, '0' for no)
be used. m Month of year (number - leading zeroes)
● Any other data you include in the format M Month of year (three letters)
string passed to date() will be included in s Seconds of hour
the return value. y Year (two digits)
Y Year (four digits)
z Day of year (0 - 365)
https://www.tutorialspoint.com/php/php_date_and_time.htm
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

Installation

● The PHP date/time functions are part of


the PHP core. No installation is required to
use these functions.

https://cdn.lynda.com/course/188214/188214-636673517617174317-16x9.jpg
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

Runtime Configuration

● The behavior of these functions is


affected by settings in php.ini

https://www.w3schools.com/php/php_ref_date.asp
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

PHP Date & Time Functions

● checkdate()

○ Validates a Gregorian date


● date_add()

○ Adds days, months, years, hours,


minutes, and seconds to a date

https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_create_from_format()

○ Returns a new DateTime object


formatted according to a specified
format
● date_create()

○ Returns a new DateTime object


https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_date_set()

○ Sets a new date


● date_default_timezone_get()

○ Returns the default timezone used


by all date/time functions

https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_diff()

○ Returns the difference between


two dates
● date_format()

○ Returns a date formatted


according to a specified format
https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_sub()

○ Subtracts days, months, years,


hours, minutes, and seconds from
a date
● date_time_set()

○ Sets the time


https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_sunrise()

○ Returns the sunrise time for a


specified day and location
● date_sunset()

○ Returns the sunset time for a


specified day and location
https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● date_timezone_get()

○ Returns the time zone of the given


DateTime object
● date_timezone_set()

○ Sets the time zone for the


DateTime object
https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● gmmktime()

○ Returns the Unix timestamp for a


GMT date
● strtotime()

○ Parses an English textual datetime


into a Unix timestamp
https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP
PHP Date & Time Functions
(Continue)

● timezone_location_get()

○ Returns location information for a


specified timezone
● timezone_name_get()

○ Returns the name of the timezone

https://errorsea.com/wp-content/uploads/2019/11/php-Date-Time-functions.png
© Edunet Foundation. All rights reserved.
Handling Date & Time in
PHP

PHP Date & Time Constants

● DATE_ATOM: Atom (example:


2019-01-18T14:13:03+00:00)
● DATE_COOKIE: HTTP Cookies
(example: Fri, 18 Jan 2019 14:13:03
UTC)
● DATE_ISO8601: ISO-8601 (example:
2019-01-18T14:13:03+0000)

https://www.edureka.co/blog/wp-content/uploads/2019/07/DATE-FORMAT-IN-JA
© Edunet Foundation. All rights reserved. VA.jpg
Handling Date & Time in
PHP
PHP Date & Time Constants
(Continue)

● DATE_RFC822: RFC 822 (example:


Fri, 18 Jan 2019 14:13:03 +0000)
● DATE_RFC850: RFC 850 (example:
Friday, 18-Jan-19 14:13:03 UTC)
● DATE_RFC1036: RFC 1036 (example:
Friday, 18-Jan-19 14:13:03 +0000)

https://www.edureka.co/blog/wp-content/uploads/2019/07/DATE-FORMAT-IN-JA
© Edunet Foundation. All rights reserved. VA.jpg
Handling Date & Time in
PHP
PHP Date & Time Constants
(Continue)

● DATE_RFC1123: RFC 1123 (example:


Fri, 18 Jan 2019 14:13:03 +0000)
● DATE_RFC2822: RFC 2822 (example:
Fri, 18 Jan 2019 14:13:03 +0000)
● DATE_RFC3339: Same as
DATE_ATOM (since PHP 5.1.3)

https://www.edureka.co/blog/wp-content/uploads/2019/07/DATE-FORMAT-IN-JA
© Edunet Foundation. All rights reserved. VA.jpg
Handling Date & Time in
PHP
PHP Date & Time Constants
(Continue)

● SUNFUNCS_RET_TIMESTAMP:
Timestamp (since PHP 5.1.2)
● SUNFUNCS_RET_STRING:
Hours:minutes (example: 09:41) (since
PHP 5.1.2)
● SUNFUNCS_RET_DOUBLE: Hours as
a floating point number (example: 9.75)
(since PHP 5.1.2)
https://www.edureka.co/blog/wp-content/uploads/2019/07/DATE-FORMAT-IN-JA
© Edunet Foundation. All rights reserved. VA.jpg
Handling Date & Time in
PHP
PHP Date & Time Constants
(Continue)

● DATE_RFC3339_EXTENDED:
RFC3339 Extended format (since PHP
7.0.0) (example:
2019-01-18T16:34:01.000+00:00)
● DATE_RSS: RSS (Fri, 18 Jan 2019
14:13:03 +0000)
● DATE_W3C: World Wide Web
Consortium (example:
2019-01-18T14:13:03+00:00)
https://www.edureka.co/blog/wp-content/uploads/2019/07/DATE-FORMAT-IN-JA
© Edunet Foundation. All rights reserved. VA.jpg
Installing and Managing
MySQL

Concept of Database

● A database intends to have a collection


of data stored together to serve multiple
applications as possible.
● Such a database would permit not only
the retrieval of data but also the
continuous modification of data needed
for control of operations.

https://cdn.lynda.com/course/548706/548706-637199619492944531-16x9.jpg
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Concept of Database (Continue)

● When we are creating any website, it is


mandatory to store complete information
about entities.
● Accurate and relevant data is the most
important source of information.
● We can store this data in any type of
DBMS like MySql, Oracle, DB2, Sybase
or SQL SERVER.

https://www.computerhope.com/jargon/d/database.jpg
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Concept of Database (Continue)

● We can also manage data by providing


data efficiency and integrity rules.
● If we store data in a traditional file
system, it would not be appropriate for
managing data.
● It may be possible to search the
database to obtain answers to queries
or information for planning purposes.
https://media.ttmind.com/Media/tech/article_16_3-27-201911-28-56AM.png
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Concept of Database (Continue)

● The database is implemented through


three general levels. These levels are:
1. Internal Level or Physical level
2. Conceptual Level
3. External Level or View Level

https://www.guru99.com/images/1/091318_0814_DBMSSchemas1.png
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Database Key Terminology

● Relation: In general, a relation is a


table, i.e., data is arranged in rows and
columns.
● Cardinality: The number of tuples or
rows in a relation is termed as
cardinality.

https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Relational_database
© Edunet Foundation. All rights reserved. _terms.svg/1200px-Relational_database_terms.svg.png
Installing and Managing
MySQL

Database Key Terminology (Continue)

● Tuple: The rows of tables in a


relationship are generally termed as
Tuples.
● Attributes: The columns or fields of a
table is termed as Attributes.

https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Relational_database
© Edunet Foundation. All rights reserved. _terms.svg/1200px-Relational_database_terms.svg.png
Installing and Managing
MySQL

Database Key Terminology (Continue)

● Degree: The number of attributes in a


relation determines the degree of
relation. A relation having three
attributes is said to have a relation of
degree 3.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

Database Key Terminology (Continue)

● Key: It is a unique value that is sufficient


to identify any record in a table.
● Join: When we want to access
information from more than one table,
we should join two tables using join
operation.

https://www1.udel.edu/evelyn/SQL-Class2/joins.jpg
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Database Key Terminology (Continue)

● Query: In SQL this is a statement that is


written to gather information from a
database.
● Schema: Schema is the way to relate or
map multiple tables.

https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTj7eO4_1pbqHbuM
© Edunet Foundation. All rights reserved. wl5Z7kgQYv4uzY0r-Vu0Dpm-WrRdk_Ht-BK&usqp=CAU
Installing and Managing
MySQL

Introduction to MYSQL

● MySQL is a fast, easy-to-use RDBMS


being used for many small and big
businesses. MySQL is developed
● In 1979, Monty Widenius invented
MYSQL.

https://upload.wikimedia.org/wikipedia/en/thumb/6/62/MySQL.svg/1200px-MySQL
© Edunet Foundation. All rights reserved. .svg.png
Installing and Managing
MySQL

Introduction to MYSQL (Continue)

● As we are using PHP scripting language


for web site development, it is
recommended that we should use
MYSQL DBMS for storing and managing
data.
● It is very good and freely available.

https://img-a.udemycdn.com/course/750x422/2390114_404d_3.jpg
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Introduction to MYSQL (Continue)

MYSQL Characteristics:
1. Very fast and consistent performance
2. Highly reliable
3. Easy to use
4. Freely available (Open source)
5. Can run on various platforms like Linux,
Windows, HP-UX

https://www.edureka.co/blog/wp-content/uploads/2018/10/Features-of-sql.png
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Introduction to MYSQL (Continue)

6. Scalability
7. Robust
8. Web data strength
9. Data security
10. Comprehensive application
development

https://www.edureka.co/blog/wp-content/uploads/2018/10/Features-of-sql.png
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

MYSQL Statements

Data Definition Statements


● These types of statements are written to
create or alter database objects.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Data Manipulation Statements


● These types of statements are written to
modify the state of database objects.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Transactional and Locking Statements


● These are statements used to control
transaction of database objects, which
include execution of other statements.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Replication Statements
● These statements are used to control
master or slave servers.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Prepared Statements
● Prepared statements are the queries
those are compiled once on the server
level and parameters are then passed to
the server instead of building the query
each.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Database Administration Statements


● These types of statements are used to
provide or revoke rights on database
objects.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

MYSQL Statements (Continue)

Utility Statements
● These statements are used for getting
help from database system for any type
of statements or functionality
commands.

© Edunet Foundation. All rights reserved.


Installing and Managing
MySQL

Stored Procedures

● These are precompiled sets of database


queries, stored on the server. Stored
procedures are much faster than regular
database queries.
● They are called using CALL statement.

https://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Stored Procedures (Continue)

Advantages:
1. Reduce network traffic
2. Centralize business logic in the
database
3. Make database more secure

https://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Stored Procedures (Continue)

Disadvantages:
1. Resource usages
2. Troubleshooting
3. Maintenances

https://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

PHP With MYSQL

● PHP will work with virtually all database


software, including Oracle and Sybase
but most commonly used is freely
available MySQL database.
● With PHP, you can connect to and
manipulate databases.
● MySQL is the most popular database
system used with PHP.
https://miro.medium.com/max/1000/1*3r_XMjYvnS3ETjtC6Xb6ng.png
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

PHP With MYSQL (Continue)

● PHP combined with MySQL are


cross-platform (you can develop in
Windows and serve on a Unix platform)
● To work with MYSQL using PHP,
Downloaded and installed a latest
version of MySQL.

https://lh3.googleusercontent.com/proxy/i7MZIhpc1gQf5wNrY66fr9tyCySgry1dVkI
-hiz1AKBdEpkVQrjWwPpYeOypTM8MboWEmiWsvFNmYY8eqKYweaeISXPpjA
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

PHP With MYSQL (Continue)

● If we want to use PHP with MySQL, then


first of all we need to install a webserver
(Mostly Apache) in case of LAMP.
● Then we should install PHP and MySQL
both.

https://udemy-images.udemy.com/course/750x422/155640_6f5f_3.jpg
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Connecting to Database

● When we want to connect with MySQL


database, we need some credentials to
complete the process like:
1. Database name
2. Host name
3. User name
4. Password

https://www.tutorialspoint.com/php/connect_to_mysql_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Connecting to Database (Continue)

● mysql_connect() function is used to


make a connection, which receives
three parameters(hostname, username,
password).
● After creation of connection
successfully, we use mysql_select_db()
function to connect with database using
database name.

https://www.tutorialspoint.com/php/connect_to_mysql_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL
Creating MYSQL Database Using
PHP

● To create and delete a database you


should have admin privilege.
● It is very easy to create a new MySQL
database.
● PHP uses mysql_query() function to
create a MySQL database.
● This function takes two parameters and
returns TRUE on success or FALSE on
failure.
https://www.tutorialspoint.com/php/create_mysql_database_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL
Creating MYSQL Database Using
PHP (Continue)

● Syntax:
bool mysql_query( sql, connection );
● Sql

○ Required - SQL query to create a


database
● connection

○ Optional - if not specified then last


open connection by
https://www.tutorialspoint.com/php/create_mysql_database_using_php.htm
mysql_connect will be used.© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL
Creating MYSQL Database Using
PHP (Continue)

● Once you establish a connection with a


database server then it is required to
select a particular database where your
all the tables are associated.
● PHP provides function
mysql_select_db() to select a
database. It returns TRUE on success or
FALSE on failure.
https://www.tutorialspoint.com/php/create_mysql_database_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL
Creating MYSQL Database Using
PHP (Continue)
● Syntax
bool mysql_select_db( db_name, connection
);
● db_name

○ Required - Database name to be


selected
● connection

○ Optional - if not specified then last


opend connection by https://www.tutorialspoint.com/php/create_mysql_database_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL
Creating MYSQL Database Using
PHP (Continue)

● In case you need to create many tables


then its better to create a text file first
and put all the SQL commands in that
text file and then load that file into $sql
variable and excute those commands.

https://www.tutorialspoint.com/php/create_mysql_database_using_php.htm
© Edunet Foundation. All rights reserved.
Installing and Managing
MySQL

Fetching Data

● The most frequently used option is to use


function mysql_fetch_array()
● This function returns row as an associative
array, a numeric array, or both.
● This function returns FALSE if there are no
more rows.

https://www.tutorialspoint.com/php/mysql_select_php.htm
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients

Introduction

● MySQL client GUI interface is easy


software for Windows or Linux to use for
controlling database.
● A database could be even warehoused.
● Also, it has front end for MySQL, a user
interface for communicating with the
data component.

https://cdn.freshdesignweb.com/wp-content/uploads/site/mysql-interface.jpg
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients

Introduction (Continue)

● MYSQL Client parallels the two-tier


programming model that separates the
data layer from the user interface.
● It allows the makers of the database
software focus on their product’s
strongest suit: data storage and
management.

https://miro.medium.com/max/904/1*--XmrOJdNZE_u8lNTxZzoA.png
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients

Introduction (Continue)

Renowned MYSQL Client Software are:


1. PHP MyAdmin
2. Workbench
3. DBTools Manager
4. SQL Examiner
5. xBase View

https://en.wikipedia.org/wiki/PhpMyAdmin
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients

phpMyAdmin

● phpMyAdmin is a free software tool


written in PHP, intended to handle the
administration of MySQL over the Web.
● phpMyAdmin supports a wide range of
operations on MySQL.
● Frequently used operations can be
performed via the user interface.
● while you still have the ability to directly
execute any SQL statement.
https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients

phpMyAdmin (Continue)

Features
● Intuitive web interface
● Support for most MySQL features
● Import data from CSV and SQL
● Export data to various formats
● Administering multiple servers
● Creating complex queries using
Query-by-example (QBE)
https://i0.wp.com/fossnaija.com/wp-content/uploads/2017/08/phpmyadmin.png?ss
© Edunet Foundation. All rights reserved. l=1
Understanding and Using
MySQL Clients

phpMyAdmin (Continue)

● Searching globally in a database or a


subset of it
● Transforming stored data into any format
using a set of predefined functions, like
displaying BLOB-data as image or
download-link
● Creating graphics of your database
layout in various formats
https://i0.wp.com/fossnaija.com/wp-content/uploads/2017/08/phpmyadmin.png?ss
© Edunet Foundation. All rights reserved. l=1
Understanding and Using
MySQL Clients

Management Console Overview

● On the right side of the screen, in the


Database server section you can find
information about the MySQL server.
● The databases which you will manage
are stored on the same server as the
software and the hostname is -
localhost.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the other two sections - Web server


and phpMyAdmin you can also see
information regarding the MySQL server,
the MySQL client and the phpMyAdmin
version.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the middle part of the page, in the


General Settings section, you can see
the MySQL charset and you will be able
to define the MySQL connection
collation.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the panel on the left side of the page


you will see the list of the databases
for which your cPanel user has
privileges.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the Databases tab you will find a list


with all the databases which can be
managed through the cPanel user.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● Using SQL tab you can perform a


MySQL query towards the MySQL
server. Just type in the query and click
the Go button and the phpMyAdmin tool
will execute the query and provide the
results from it.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the Status tab you can find detailed


information regarding the MySQL server
since the last restart.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the Import tab you can import


database tables from a file, saved on
your local computer.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● The Engines tab opens a page with a


list of all the engines supported by the
MySQL server.
● The default one is MyISAM. Another
popular storage engine, used by many
databases is InnoDB.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the Variables tab you can see all the


current MySQL variables and their
values.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● In the Settings tab you can configure


phpMyAdmin the way you want it to.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● There are different operations which you


can perform on the whole database and
on a separate table.
● Database Operations
● Database Table Operations

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● To execute MySQL queries by using the


tool, there are two ways to do that with
the phpMyAdmin interface.
● Execute MySQL queries with the SQL
tab
● Construct and execute MySQL queries
with the Query tab

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● To create new tables inside a database,


first open the phpMyAdmin tool, click on
the Databases tab and click on the
name of the desired database.
● On the new page that opens you will see
a list of all the current tables inside the
database and a section named Create
table.
https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Understanding and Using
MySQL Clients
Management Console Overview
(Continue)

● On the next page you can configure the


structure of the columns in the new
table.
● When you are ready, click the Save
button to create the new table.

https://www.siteground.com/tutorials/phpmyadmin/administration/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Design Patterns

● Design Patterns are “descriptions of


communicating objects and classes that
are customized to solve a general
design problem in a particular context.”
● Design patterns provide a generic
reusable solution to the programming
problems that we encounter every day.

https://www.script-tutorials.com/design-patterns-in-php/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Design Patterns (Continue)

● Design patterns help to speed up the


development, as the templates are
proven and from the developer’s
position, only implementation is
required.
● Design patterns not only make software
development faster, but also
encapsulate big ideas in a simpler way.
Photo by Neil Thomas on Unsplash
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Design Patterns (Continue)

● By now there are 23 different known


design patterns, and they can be
separated into three categories by
purpose:
● Creational Patterns: used to construct
objects such that they can be decoupled
from their implementing system

https://www.script-tutorials.com/design-patterns-in-php/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Design Patterns (Continue)

● Structural Patterns: used to form large


object structures between many
disparate objects
● Behavioral Patterns: used to manage
algorithms, relationships, and
responsibilities between objects

https://www.script-tutorials.com/design-patterns-in-php/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Design Patterns (Continue)

The 5 Most Common Design Patterns in


PHP Applications
1. Factory
2. Strategy
3. Adapter
4. Observer
5. Decorator

https://www.script-tutorials.com/design-patterns-in-php/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PHP Mail Functions

● The mail() function allows you to send


emails directly from a script.
● For the mail functions to be available,
PHP requires an installed and working
email system.
● The program to be used is defined by
the configuration settings in the php.ini
file.
https://4.bp.blogspot.com/-7UgYDn3hh6c/WaDzoVwo_FI/AAAAAAAAAA0/NSCa
NWs59R4cboW9Ii1HPVF_NOrqX8fhwCLcBGAs/s640/send-mail-in-php.png
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PHP Mail Functions (Continue)

● The mail functions are part of the PHP


core. There is no installation needed to
use these functions.
● The behavior of the mail functions is
affected by settings in php.ini

https://www.w3schools.com/php/php_ref_mail.asp
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PHP Mail Functions (Continue)

● Syntax
mail(to,subject,message,headers,parameter
s);

https://www.w3schools.com/php/func_mail_mail.asp
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PHP Mail Functions (Continue)

Parameter Description

to Required. Specifies the receiver / receivers of the


email
subject Required. Specifies the subject of the email. Note:
This parameter cannot contain any newline
characters

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PHP Mail Functions (Continue)

Parameter Description

message Required. Defines the message to be sent. Each line


should be separated with a LF (\n). Lines should not
exceed 70 characters.
headers Optional. Specifies additional headers, like From, Cc,
and Bcc. The additional headers should be separated
with a CRLF (\r\n).

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and CURL
PHP Mail Functions (Continue)

Parameter Description

parameters Optional. Specifies an additional parameter to the


sendmail program (the one defined in the
sendmail_path configuration setting). (i.e. this can be
used to set the envelope sender address when using
sendmail with the -f sendmail option)

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Sending Plain Text Email

● The simplest way to send an email with


PHP is to send a text email.
● In the example, we first declare the
variables
1. recipient's email address
2. subject line
3. message body
● Then, we pass these variables to the
mail() function to send the email.
https://www.tutorialrepublic.com/php-tutorial/php-send-email.php
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Sending HTML Email

● When you send a text message using


PHP, all the content will be treated as
simple text.
● We're going to improve that output, and
make the email into a HTML-formatted
email.
● To send an HTML email, the process will
be the same.
● However, this time we need to provide
additional headers as well as an HTML
https://www.tutorialrepublic.com/php-tutorial/php-send-email.php
formatted message. © Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
Sending Attachements in Email

● The PHP mail() function with some


MIME type headers can be used to send
email with attachment in PHP.
● To send an email with mixed content
requires to set Content-type header to
multipart/mixed.
● Then text and attachment sections can
be specified within boundaries.
https://www.geeksforgeeks.org/php-send-attachment-email/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL

● The PHP Extension and Application


Repository, or PEAR, is a repository of
PHP software code.
● Stig S. Bakken founded the PEAR
project in 1999 to promote the re-use of
code that performs common functions.

https://1.bp.blogspot.com/-56yMnwfCrPc/XEgzu66f2-I/AAAAAAAAzGw/PIVukGD
XCsg140XiLwj8GYAkG5Lv7p_2wCLcBGAs/s728-e100/php-pear-hacked-packag
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● PEAR project seeks to provide a


structured library of code, maintain a
system for distributing code and for
managing code packages, and promote
a standard coding style.

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

Commonly used PEAR packages are:


● Net_SMTP
● Mail
● HTTP_Request2
● VersionControl_SVN
● HTTP2
● Text_LanguageDetect
● XML_Util
● Mail_Mime
● OLE
● XML_Parser © Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● The cURL stands for ‘Client for URLs’,


originally with URL spelled in uppercase
to make it obvious that it deals with
URLs. It is pronounced as ‘see URL’.
● The cURL project has two products
libcurl and curl.

https://lh3.googleusercontent.com/proxy/pUwJ27RT_Il90DZwQqMz49GezSmBwk
bRmX9oaQgjXwE0NdDW0vDwoGMg1XBiYIN0ZxDIrrYjWat8gJIv4sMjUwSW-P6b
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● libcurl: A free and easy-to-use


client-side URL transfer library,
supporting FTP, TPS, HTTP, HTTPS,
GOPHER, TELNET, DICT, FILE, and
LDAP.
● libcurl is free, thread-safe, IPv6
compatible, feature rich, well supported
and fast.
● https://i.ytimg.com/vi/qwG10Hs3Blo/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● libcurl supports TTPS certificates, HTTP


POST, HTTP PUT, FTP uploading,
kerberos, HTTP based upload, proxies,
cookies, user & password
authentication, file transfer resume,
HTTP proxy tunneling and many more.

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● curl: A command line tool for getting or


sending files using URL syntax. Since
curl uses libcurl, it supports a range of
common internal protocols, currently
including HTTP, HTTPS, FTP, FTPS,
GOPHER, TELNET, DICT, and FILE.

https://curl.haxx.se/logo/curl-logo.svg
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● The module for PHP that makes it


possible for PHP programs to access
curl functions within PHP. cURL support
is enabled in PHP, the phpinfo() function
will display in its output.
● You are requested to check it before
writing your first simple programme in
PHP.

© Edunet Foundation. All rights reserved.


Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

Some basic cURL functions:


● curl_init() function will initialize a new
session and return a cURL handle.
● curl_exec($ch) function should be
called after initialize a cURL session and
all the options for the session are set. Its
purpose is simply to execute the
predefined CURL session (given by ch).
https://www.geeksforgeeks.org/php-curl/
© Edunet Foundation. All rights reserved.
Database Access, Design
Patterns, Mail Function,
PEAR and cURL
PEAR & cURL (Continue)

● curl_setopt($ch, option, value) set an


option for a cURL session identified by
the ch parameter. Option specifies which
option is to set, and value specifies the
value for the given option.
● curl_close($ch) close curl resource,
and free up system resources.

https://www.geeksforgeeks.org/php-curl/
© Edunet Foundation. All rights reserved.
JAVA: The key language.

Disclaimer: The content is curated for educational purposes only.


© Edunet Foundation. All rights reserved.
In this section, we will discuss:

● Introduction to Java Programming


● The Java Virtual Machine
● Variables and datatypes
● Conditional and looping constructs Arrays
● Object-oriented programming with Java Classes and Objects
● Exception handling with try- throw-catch-finally constructs

© Edunet Foundation. All rights reserved.


Introduction to Java
Programming

What is JAVA

● A general-purpose object-oriented
language.
● Write Once Run Anywhere (WORA).
● Designed for easy Web/Internet
applications.
● Widespread acceptance.

Image Source:
https://www.edureka.co/blog/wp-content/uploads/2018/01/what-is-java-000.png
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

What is JAVA

● It is a simple programming language.


● Writing, compiling and debugging a
program is easy in java.
● It helps to create modular programs and
reusable code.

Image Source:
https://www.edureka.co/blog/wp-content/uploads/2018/01/what-is-java-000.png
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

Why Java is important


● Two reasons : –
○ Trouble with C/C++ language is
that they are not portable and are
not platform independent
languages.
○ Emergence of World Wide Web,
which demanded portable
programs.
● Portability and security necessitated the
invention of Java
Image Source:
https://image.isu.pub/160804060928-8208a310b192b21ae0301fad5f0f5d02/jpg/p
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

History of JAVA

● Java is a high level object-oriented


programming language developed by
James Gosling at Sun Microsystems in
the early 1990s.
● James Gosling was unhappy using c++
programming language so he developed
Java.
● Originally designed in (1991) as a small
language for consumer electronics
(cable boxes, toasters etc.)
Image Source:
https://cdn.lynda.com/video/560731-42-636149676558616265_338x600_thumb.jp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

History of JAVA

● A team of Sun Microsystems in the


guidance of James Gosling decided to
develop an advanced programming
language for the betterment of
consumer electronic devices.
● They developed a platform independent
software based on the power of
networks that can run on different
application areas, such as computers
and electronic devices.
Image Source:
https://cdn.lynda.com/video/560731-42-636149676558616265_338x600_thumb.jp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

History of JAVA

● It was initially called 'Oak‘.


● It was renamed as 'JAVA' released in
1995 as a core component of Sun
Microsystems Java platform.

Image Source:
https://cdn.lynda.com/video/560731-42-636149676558616265_338x600_thumb.jp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Editions

● J2SE(Java 2 Standard Edition) - to


develop client-side standalone
applications or applets.
● J2ME(Java 2 Micro Edition ) - to
develop applications for mobile devices
such as cell phones.
● J2EE(Java 2 Enterprise Edition ) - to
develop server-side applications such as
Java servlets and Java ServerPages.

Image Source:
https://quiz.tcalive.in/wp-content/uploads/2018/09/Picture1-460x282.jpg
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

How is JAVA different from C

● Major difference is that C is a structure


oriented language and Java is an object
oriented language and has mechanism
to define classes and objects.
○ Java does not support an explicit
pointer type
○ Java does not have preprocessor,
so we cant use #define, #include
and #ifdef statements.
Image Source:
https://image.slidesharecdn.com/ccjavaandworldwideweb-140426000150-phpapp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

How is JAVA different from C

○ Java does not include structures,


unions and enum data types.
○ Java does not include keywords
like goto, sizeof and typedef.
○ Java adds labeled break and
continue statements.
○ Java adds many features required
for object oriented programming.
Image Source:
https://image.slidesharecdn.com/ccjavaandworldwideweb-140426000150-phpapp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

How is JAVA different from C++

● Class definitions take the similar form in


java as in C++, but there is no closing
semicolon.
● Operator overloading is not possible in
java.

Image
Source:https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/04/Differe
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

How is JAVA different from C++

● Java does not support global variables.


Every variables and method is declared
within class and forms part of that class.
● Java doesn’t use pointers.
● The destructor function is replaced with
a finalize() function.
● There are no header files in java.
● Java supports multithreading.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/04/Difference-bet
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

Applications of JAVA

● Desktop GUI applications


● Embedded systems
● Web applications, including e-commerce
applications, front and back office
electronic trading systems, settlement
and confirmation systems, data
processing projects, and more

Image Source:
https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/01/applications-o
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

Applications of JAVA

● Web servers and application servers


● Mobile applications including Android
applications
● Enterprise applications
● Scientific applications
● Middleware products

Image Source:
https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/01/applications-o
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Environment

● Java includes many development tools,


classes and methods
○ Development tools are part of
Java Development Kit (JDK) and
○ The classes and methods are part
of Java Standard Library (JSL),
also known as Application
Programming Interface (API).

Image Source:
https://qph.fs.quoracdn.net/main-qimg-dcbbbb2f41e23c8f38f8b9632ff1189d.webp
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Environment

● JDK constitutes of tools like java


compiler, java interpreter and many.
● API includes hundreds of classes and
methods grouped into several packages
according to their functionality.

Image
Source:https://qph.fs.quoracdn.net/main-qimg-dcbbbb2f41e23c8f38f8b9632ff1189
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

Advantages of JAVA

● Simple & Familiar


● Object-Oriented
● Compiled & Interpreted
● Platform Independent & Portable
● Robust
● Secure
● Distributed
● Multithreaded
● Dynamic & Extensible.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Simpler & Familiar


● Java was designed to be simple and
familiar to learn language.
● Fundamental concepts can be grasped
quickly as the features borrowed from C
& C++.
● Features were removed that led to poor
programming practices or were rarely
used.
● It does not use pointers, goto statement,
Preprocessor header files etc.
Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Object-Oriented
● All coding and data reside within object
and classes.
● Java has built-In exception handling.
● Everything in Java (except the primitive
data types) is an object.
● The object model in java is simple and
easy to extend so that complex
programming problems can be reduced
to simple solutions.
● Extensive set of classes, arranged in
packages e.g. java.awt, java.io, java.net
. Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Compiled & Interpreted

● Java is both a compiled and Interpreted


language.
● Java Compiler generates
platform-independent byte codes that
are interpreted into machine readable
instructions by a Java Virtual Machine
(Java Interpreter) at runtime..

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Perform-Independent & Portable

● Java programs are designed to work in


a networked environment on a variety of
computers and operating systems.
● The size of the primitive data types are
machine independent.
● Compiler generates platform
independent byte codes rather than
native machine code, so it can be
implemented on any machine.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Robust

● Java has hard-and-fast rules for


compile-time and runtime error
checking.
● Java supports automatic garbage
collection so all memory corruptions or
unauthorized memory accesses are
impossible.
● Many error-prone features of C/C++
programming were removed.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Secure

● Usage in networked environment


requires more security.
● JVM verifies all byte codes before
execution & ensures all programs follow
the rules regarding object access and
usage.
● Java ensures that program cannot gain
access to memory locations without
proper authorization.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Distributed

● Java is network friendly.


● Java is designed as a distributed
language for creating applications on
networks.
● Multiple programmers can work together
on a single project from multiple remote
locations.
● Both data and programs can be shared
on networks.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Multithreaded

● This feature allows us to handle multiple


tasks simultaneously.
● Designed to run multiple threads.
● Easy to implement.
● Other systems have provided facilities
via light weight libraries, but Java has
in-built language support.
● Great for multimedia displays.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Advantages of JAVA

Dynamic & Extensible

● Provides a highly dynamic runtime


environment.
● Allows dynamically linking in new class
libraries, methods and objects.
● New code can be linked on demand
from anywhere on the network and new
types can be created as needed
dynamically.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/06/Advantages-of-
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Development Kit

JDK is a free software development package


from Sun Microsystems. Java Development
Kit (JDK) contains tools needed to develop the
Java programs, and JRE to run the programs.
The Basic tools are- •

● appletviewer – Run and debug applets


without a web browser.

Image
Source:https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTBvqDboD
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Development Kit

● Java – The java interpreter runs the


Java applets & applications by reading
and interpreting bytecode files. The
same launcher is used for deployment
and development purpose.
● Javac – This is the core of java, which
translates the java source code to
bytecode files that the interpreter can
understand.

Image
Source:https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTBvqDboD
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Development Kit

● javadoc – It is used to generate API


documentation. • javah – Produces
header files for use with native methods.
● javap – Java disassembler, which
enables us to convert bytecode files into
a program description.
● jdb – Java Debugger, which helps us to
find errors in our programs.

Image
Source:https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTBvqDboD
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Runtime Environment

● Java Runtime Environment contains


JVM, class libraries, and other
supporting files.
● It does not contain any development
tools such as compiler, debugger, etc.
Actually JVM runs the program, and it
uses the class libraries, and other
supporting files provided in JRE.
Image
Source:https://images.idgesg.net/images/article/2020/01/jw-whatisjre-fig1-100827
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Runtime Environment

● If you want to run any java program, you


need to have JRE installed in the
system.
● It primarily contains-

Image
Source:https://images.idgesg.net/images/article/2020/01/jw-whatisjre-fig1-100827
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Runtime Environment


● Java Virtual Machine – interprets the
intermediate java byte code and
generates the desired output.
● Runtime class libraries – contains set
of class libraries.
● User Interface Toolkits – AWT and
Swing are examples of toolkits that
support various input methods for the
users to interact with the application
program.
Image Source:
https://images.idgesg.net/images/article/2020/01/jw-whatisjre-fig1-100827419-larg
© Edunet Foundation. All rights reserved.
Introduction to Java
Programming

JAVA Runtime Environment

● Deployment Technologies –

○ Java plug-in : for execution of a


Java applet on the browser.

○ Java web Start : for remote


deployment of an application.

Image
Source:https://images.idgesg.net/images/article/2020/01/jw-whatisjre-fig1-100827
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

What is Virtual Machine

● Before understanding what is JVM let us


first know what virtual machine is.
● A virtual machine is a layer of
abstraction that gives a program one
simplified interface for interacting with a
variety of physical computers and their
operating systems.

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2019/11/Java-Virtual-Machi
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

What is JAVA Virtual Machine

● As the name indicates, JVM is not a real


hardware machine but a software layer
which resembles an hardware platform.
● JVM converts Java byte code into
machine language and executes it.
● The byte code can be executed on any
platform where there exist JVM.

Image Source:
https://cdn.educba.com/academy/wp-content/uploads/2019/11/Java-Virtual-Machi
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

What is JAVA Virtual Machine

● JVM‘s are available for many hardware


and software platforms.
● The use of the same byte code for all
JVM’s on all platforms allows Java to be
described as a "write once, run
anywhere" programming language.
● Thus, the JVM is a crucial component of
the Java platform.

Image
Source:https://cdn.educba.com/academy/wp-content/uploads/2019/11/Java-Virtua
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Components of JVM

● Byte code verifier


● Class loader
● Execution engine
● Garbage collector
● Security Manager

Image Source:
https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/07/JVM.png
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Byte Code Verifier

● As the name suggests, bytecode verifier


is used to verify the bytecode.
● Bytecode verifier checks for unusual
code.
● Byte code verifier is a crucial component
for security.

Image
Source:https://lh3.googleusercontent.com/proxy/YAOhV9KJEbR9vmTfZQPWcfTI-
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Class Loader

● Class loader loads java classes into java


virtual machine.
● All Java virtual machines include one
class loader that is embedded in the
virtual machine.

Image
Source:https://javatutorial.net/wp-content/uploads/2017/10/hierarchy-of-class-load
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Class Loader

● The main feature of the class loader is


that JVM. doesn’t need to have any
knowledge about the classes that will be
loaded at runtime.
● Class loader reads bytecode and
creates the instance of java.lang.class.

Image
Source:https://javatutorial.net/wp-content/uploads/2017/10/hierarchy-of-class-load
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Execution Engine

● The execution engine helps JVM to


convert bytecode into machine code.
● It has two parts:
○ Interpreter
○ Just-in-time-interpreter
● Execution engine is responsible for
executing the instructions contained in
the methods of loaded classes.

Image
Source:https://www.javacodegeeks.com/wp-content/uploads/2018/04/jvm_archi_e
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Garbage Collector

● Garbage collection is the process of


automatically freeing objects that are no
longer referenced by the program.
● It periodically check for the object on
heap , whose link is broken so it can
collect garbage from heap.
● Garbage collection relieves java
programmer from memory management.

Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/03/types-
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Security Manager

● Security manage constantly monitors


the code.
● It is special java object that is
responsible for guarding security
policies for java applications.
● It is always consulted before any
potentially dangerous operation is
requested by a java application.

Image
Source:https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcT9k3xgLqw
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Comparison of JVM

● Java Virtual Machine (JVM) is platform


independent, meaning it can run on
different Operating Systems (OS) like
Windows or UNIX.
● JVM does not really exist but is created
within another environment.

Image Source:
https://image.slidesharecdn.com/java-120313105732-phpapp02/95/javajava-virtu
© Edunet Foundation. All rights reserved.
The Java Virtual Machine

Comparison of JVM

● As long as a JVM is available natively to


a system, a Java program can run in the
system.
● The JVM stands on top of the operating
system (OS), which means it is
independent of the OS.

Image Source:
https://image.slidesharecdn.com/java-120313105732-phpapp02/95/javajava-virtu
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Variable

There are different types of variables in Java.


They are as follows:

● Instance Variables (Non-Static Fields)


● Class Variables (Static Fields)
● Local Variables
● Parameters

Image
Source:https://data-flair.training/blogs/wp-content/uploads/sites/2/2019/07/Types-
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Instance Variable

● Objects store their individual states in


“non-static fields”, that is, fields declared
without the static keyword.
● Non-static fields are also known as
instance variables because their values
are unique to each instance of a class.
● For example, the currentSpeed of one
bicycle is independent from the
currentSpeed of another.
Image
Source:https://i0.wp.com/codippa.com/wp-content/uploads/2019/09/instance-varia
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Class Variable

● A class variable is any field declared


with the static modifier; this tells the
compiler that there is exactly one copy
of this variable in existence, regardless
of how many times the class has been
instantiated.

Image Source:https://i.ytimg.com/vi/3gYr83ni388/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Class Variable

● A field defining the number of gears for a


particular kind of bicycle could be
marked as static since, conceptually, the
same number of gears will apply to all
instances.
● The code static int numGears = 6;
would create such a static field.

Image Source:https://i.ytimg.com/vi/3gYr83ni388/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Local Variable
● A method stores its temporary state
in local variables. The syntax for
declaring a local variable is similar to
declaring a field (for example, int
count = 0;)
● There is no special keyword
designating a variable as local; that
determination comes entirely from
the location in which the variable is
declared—between the opening and
closing braces of a method. Image
Source:https://image.slidesharecdn.com/oopinjava-161127140542/95/type-of-vari
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Local Variable

● As such, local variables are only


visible to the methods in which they
are declared;
● they are not accessible from the rest
of the class.

Image
Source:https://image.slidesharecdn.com/oopinjava-161127140542/95/type-of-vari
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Parameter

● They are the variables that are passed


to the methods of a class.

Image
Source:https://image.slidesharecdn.com/methods-091116064834-phpapp02/95/m
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Datatype

● Data type specifies the size and type of


values that can be stored in an identifier.
● The Java language is rich in its data
types.
● Different data types allow you to select
the type appropriate to the needs of the
application.

Image Source:https://static.javatpoint.com/images/java-data-types.png
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Datatype

Data types in Java are classified into two


types:

● Primitive—which include Integer,


Character, Boolean, and Floating Point.
● Non-primitive—which include Classes,
Interfaces, and Arrays.

Image Source:https://static.javatpoint.com/images/java-data-types.png
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Primitive Datatype

● There are eight primitive datatypes


supported by Java. Primitive datatypes
are predefined by the language and
named by a keyword.
● There are two data types available in
Java −
○ Primitive Data Types
○ Reference/Object Data Types

Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Primitive Datatype

Let us now look into the eight primitive data


types in detail.

● Byte
● Short
● Int
● Long
● Float
● Double
● Boolean
● char Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Byte

● Byte data type is an 8-bit signed two's


complement integer
● Minimum value is -128 (-2^7)
● Maximum value is 127 (inclusive)(2^7
-1)
● Default value is 0
● Byte data type is used to save space in
large arrays, mainly in place of integers,
since a byte is four times smaller than
an integer.
● Example: byte a = 100, byte b = -50 Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Short

● Short data type is a 16-bit signed two's


complement integer
● Minimum value is -32,768 (-2^15)
● Maximum value is 32,767 (inclusive)
(2^15 -1)
● Short data type can also be used to
save memory as byte data type. A short
is 2 times smaller than an integer
● Default value is 0.
● Example: short s = 10000, short r =
-20000 Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Integer
● Int data type is a 32-bit signed two's
complement integer.
● Minimum value is - 2,147,483,648
(-2^31)
● Maximum value is
2,147,483,647(inclusive) (2^31 -1)
● Integer is generally used as the default
data type for integral values unless there
is a concern about memory.
● The default value is 0
● Example: int a = 100000, int b = Image
-200000 Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Long
● Long data type is a 64-bit signed two's
complement integer
● Minimum value is
-9,223,372,036,854,775,808(-2^63)
● Maximum value is
9,223,372,036,854,775,807
(inclusive)(2^63 -1)
● This type is used when a wider range
than int is needed
● Default value is 0L
● Example: long a = 100000L, long b = Image
-200000L Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Float

● Float data type is a single-precision


32-bit IEEE 754 floating point
● Float is mainly used to save memory in
large arrays of floating point numbers
● Default value is 0.0f
● Float data type is never used for precise
values such as currency
● Example: float f1 = 234.5f
Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Double

● double data type is a double-precision


64-bit IEEE 754 floating point
● This data type is generally used as the
default data type for decimal values,
generally the default choice
● Double data type should never be used
for precise values such as currency
● Default value is 0.0d
● Example: double d1 = 123.4
Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Boolean

● boolean data type represents one bit of


information
● There are only two possible values: true
and false
● This data type is used for simple flags
that track true/false conditions
● Default value is false
● Example: boolean one = true
Image
Source:https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Primitive Datatypes

Character

● char data type is a single 16-bit Unicode


character
● Minimum value is '\u0000' (or 0)
● Maximum value is '\uffff' (or 65,535
inclusive)
● Char data type is used to store any
character
● Example: char letterA = 'A'
Image
Sourcehttps://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primiti
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Reference/Object Datatype

● Reference variables are created using


defined constructors of the classes.
They are used to access objects. These
variables are declared to be of a specific
type that cannot be changed. For
example, Employee, Puppy, etc.
● Class objects and various type of array
variables come under reference
datatype.
Image
Source:https://www.itcsolutions.eu/wp-content/uploads/2011/01/References3.gif
© Edunet Foundation. All rights reserved.
Variables and Datatypes

Reference/Object Datatype

● Default value of any reference variable


is null.
● A reference variable can be used to
refer any object of the declared type or
any compatible type.
● Example: Animal animal = new
Animal("giraffe");

Image
Source:https://www.itcsolutions.eu/wp-content/uploads/2011/01/References3.gif
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Control Statements

we will see four types of control statements


that you can use in java programs based on
the requirement

● if statement
● nested if statement
● if-else statement
● if-else-if statement

Image Source:
https://simplesnippets.tech/wp-content/uploads/2018/03/control-statements-in-jav
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Statements

If statement consists a condition, followed by


statement or a set of statements as shown
below:

if(condition){
Statement(s);
}

Image
Source:https://media.geeksforgeeks.org/wp-content/uploads/20191118171408/If-
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Statements

● The statements gets executed only


when the given condition is true.
● If the condition is false then the
statements inside if statement body are
completely ignored.

Image
Source:https://beginnersbook.com/wp-content/uploads/2017/08/if_statement_flow
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Statements

● The statements gets executed only


when the given condition is true.
● If the condition is false then the
statements inside if statement body are
completely ignored.

Image
Source:https://beginnersbook.com/wp-content/uploads/2017/08/if_statement
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else Statements
This is how an if-else statement looks:

if(condition) {

Statement(s);

else {

Statement(s);

}
Image Source:
https://beginnersbook.com/wp-content/uploads/2017/08/If_else_flow_diagram.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else Statements

● The statements inside “if” would execute


if the condition is true, and the
statements inside “else” would execute if
the condition is false.

Image
Source:https://beginnersbook.com/wp-content/uploads/2017/08/If_else_flow_diag
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else If Statements

● if-else-if statement is used when we


need to check multiple conditions.
● In this statement we have only one “if”
and one “else”, however we can have
multiple “else if”.
● It is also known as if else if ladder. This
is how it looks:

Image Source:
https://i1.wp.com/coderforevers.com/wp-content/uploads/2018/10/Java-if-else-Lad
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else If Statements
Syntax:-

if(condition_1) {

statement(s);

else if(condition_2) {

statement(s);

Image Source:
} https://i1.wp.com/coderforevers.com/wp-content/uploads/2018/10/Java-if-else-Lad
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else If Statements

else if(condition_3) {

statement(s);
}

else {

statement(s);
}

Image Source:
https://i1.wp.com/coderforevers.com/wp-content/uploads/2018/10/Java-if-else-Lad
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

If Else If Statements

● The most important point to note here is


that in if-else-if statement, as soon as
the condition is met, the corresponding
set of statements get executed, rest
gets ignored.
● If none of the condition is met then the
statements inside “else” gets executed.

Image Source
https://i1.wp.com/coderforevers.com/wp-content/uploads/2018/10/Java-if-else-Lad
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Nested If Statements

● The nested if statement represents the if


block within another if block.
● Here, the inner if block condition
executes only when outer if block
condition is true.

Image Source: https://o7planning.org/en/11561/cache/images/i/12387382.png


© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Nested If Statements

Syntax:-

if(condition){

//code to be executed

if(condition){

//code to be executed

} Image Source:https://o7planning.org/en/11561/cache/images/i/12387382.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Nested If Statements

Syntax:-

if(condition){

//code to be executed

if(condition){

//code to be executed

} Image Source:https://o7planning.org/en/11561/cache/images/i/12387382.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Switch Case Statements

● Switch case statement is used when


we have number of options (or choices)
and we may need to perform a different
task for each choice.
● Switch Case statement is mostly used
with break statement even though it is
optional.
● The syntax of Switch case statement
looks like this –
Image Source:
https://beginnersbook.com/wp-content/uploads/2017/08/switch_case_flow_diagra
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays
switch Switch
(variable or an integer
Case expression)
Statements
{

case constant:

case constant:

default:

;
}
Image Source:
https://beginnersbook.com/wp-content/uploads/2017/08/switch_case_flow_diagra
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Break Statement in Switch Case

● Break statement is optional in switch


case but you would use it almost every
time you deal with switch case.
● Before we discuss about break
statement.
● Let’s have a look at the example below

Image Source: https://static.javatpoint.com/cpages/images/cswitch.png


© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Break Statement in Switch Case

● Break statements are used when you


want your program-flow to come out of
the switch body.
● Whenever a break statement is
encountered in the switch body, the
execution flow would directly come out
of the switch, ignoring rest of the cases

Image Source: https://static.javatpoint.com/cpages/images/cswitch.png


© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Looping Construct in JAVA


Looping constructs in Java are:

● For statement
● For-each statement
● While statement
● Do while statement
● Continue Statement
● Break Statement

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Types-of-Loop
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

For Loop

● When you know exactly how many times


you want to loop through a block of
code, use the for loop instead of a while
loop:

Image Source:
https://beginnersbook.com/wp-content/uploads/2015/03/for_loop_Java.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

For Loop

Syntax of for loop:

for (statement 1; statement 2;


statement3) {
// code block to be executed

Image Source:
https://beginnersbook.com/wp-content/uploads/2015/03/for_loop_Java.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

For Loop

● Statement 1 is executed (one time)


before the execution of the code block.
● Statement 2 defines the condition for
executing the code block.
● Statement 3 is executed (every time)
after the code block has been executed.

Image
Source:https://beginnersbook.com/wp-content/uploads/2015/03/for_loop_Java.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

For Each Loop


● It starts with the keyword for like a
normal for-loop.
● Instead of declaring and initializing a
loop counter variable, you declare a
variable that is the same type as the
base type of the array, followed by a
colon, which is then followed by the
array name.

Image Source:
https://i.pinimg.com/originals/50/5d/a5/505da552a8af7974e0417bec12d5ece7.pn
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

For Each Loop

Syntax:

for (type var : array)

{ statements using var;

Image Source:
https://i.pinimg.com/originals/50/5d/a5/505da552a8af7974e0417bec12d5ece7.pn
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

While Loop

● The Java while loop is used to iterate a


part of the program several times.
● If the number of iteration is not fixed, it is
recommended to use while loop.

Image Source:https://static.javatpoint.com/cpages/images/while.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

While Loop

Syntax:-

while(condition){

//code to be executed

Image Source: https://static.javatpoint.com/cpages/images/while.png


© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Do While Loop

● The Java do-while loop is used to iterate


a part of the program several times.
● If the number of iteration is not fixed and
you must have to execute the loop at
least once, it is recommended to use
do-while loop.
● The Java do-while loop is executed at
least once because condition is checked
after loop body.
Image Source:
https://beginnersbook.com/wp-content/uploads/2015/03/do-while_java.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Do While Loop

Syntax:-

do{

//code to be executed

}while(condition);

Image Source:
https://beginnersbook.com/wp-content/uploads/2015/03/do-while_java.jpg
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Continue Statement

● Continue statement is mostly used


inside loops.
● Whenever it is encountered inside a
loop, control directly jumps to the
beginning of the loop for next iteration,
skipping the execution of statements
inside loop’s body for the current
iteration. Image Source:
https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/09/Flowchart-
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Continue Statement

We can use Java break statement in all types


of loops such as for loop, while loop and
do-while loop.

Syntax:

jump-statement;

break;
Image Source:
https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2019/09/Flowchart-
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Break Statement

● When a break statement is encountered


inside a loop, the loop is immediately
terminated and the program control
resumes at the next statement following
the loop.
● The Java break statement is used to
break loop or switch statement. It breaks
the current flow of the program at
specified condition. In case of inner
loop, it breaks only inner loop. Image Source: https://static.javatpoint.com/cpages/images/break.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Break Statement

Syntax:-
The syntax of a break is a single statement
inside any loop −

break;

Image Source: https://static.javatpoint.com/cpages/images/break.png


© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Array

● Java array is an object which contains


elements of a similar data type.
● Additionally, The elements of an array
are stored in a contiguous memory
location.
● It is a data structure where we store
similar elements.
● We can store only a fixed set of
elements in a Java array. Image Source:https://media.geeksforgeeks.org/wp-content/uploads/Arrays1.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Array

There are two types of arrays in Java they are −


● Single dimensional array
● Multi-dimensional array

Image
Source:https://cdn.educba.com/academy/wp-content/uploads/2019/11/Types-of-A
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Single Dimensional Array

● A single dimensional array of Java is a


normal array where, the array contains
sequential elements (of same type) −

Syntax to Declare an Array in Java

1. dataType[] arr; (or)


2. dataType []arr; (or)
3. dataType arr[];
Image
Source:https://media.geeksforgeeks.org/wp-content/cdn-uploads/Blank-Diagram-
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Single Dimensional Array

● We can declare, instantiate and initialize


the java array together by:

int a[]={33,3,4,5};//declaration, instantiation


and initialization

Image
Source:https://media.geeksforgeeks.org/wp-content/cdn-uploads/Blank-Diagram-
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Multi Dimensional Array

● A multi-dimensional array in Java is an


array of arrays.
● A two dimensional array is an array of
one dimensional arrays and a three
dimensional array is an array of two
dimensional arrays.
Image Source:https://media.geeksforgeeks.org/wp-content/uploads/two-d.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Multi Dimensional Array

Syntax to Declare Multidimensional Array


in Java

1. dataType[][] arrayRefVar; (or)


2. dataType [][]arrayRefVar; (or)
3. dataType arrayRefVar[][]; (or)
4. dataType []arrayRefVar[];
Image Source:https://media.geeksforgeeks.org/wp-content/uploads/two-d.png
© Edunet Foundation. All rights reserved.
Conditional and Looping
Constructs Arrays

Multi Dimensional Array

Example to instantiate Multidimensional


Array in Java:-

int[][] arr=new int[3][3];//3 row and 3 column

Image Source:https://media.geeksforgeeks.org/wp-content/uploads/two-d.png
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Object-Oriented Programming

● As the name suggests, Object-Oriented


Programming or OOPs refers to
languages that uses objects in
programming.
● Object-oriented programming aims to
implement real-world entities like
inheritance, hiding, polymorphism etc in
programming.
Image Source: https://i.ytimg.com/vi/xoL6WvCARJY/maxresdefault.jpg
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Object-Oriented Programming

● The main aim of OOP is to bind together


the data and the functions that operate
on them so that no other part of the
code can access this data except that
function.

Image Source: https://i.ytimg.com/vi/xoL6WvCARJY/maxresdefault.jpg


© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
OOPs Concept

● Polymorphism
● Inheritance
● Encapsulation
● Abstraction
● Class
● Object
● Method
● Message Passing
Image Source:
https://i2.wp.com/francescolelli.info/wp-content/uploads/2019/08/java-oops.png?fit
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Polymorphism

● If one task is performed in different


ways, it is known as polymorphism. For
example: to convince the customer
differently, to draw something, for
example, shape, triangle, rectangle, etc.
● In Java, we use method overloading and
method overriding to achieve
polymorphism.
● Another example can be to speak
something; for example, a cat speaks Image Source:
https://miro.medium.com/max/638/1*cFSJ95jyw-ACiWaIRxAbbg.jpeg
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Inheritance

● Inheritance is an important pillar of


OOP(Object Oriented Programming).
● It is the mechanism in java by which
one class is allow to inherit the
features(fields and methods) of another
class.

Image Source:
https://cdn.programiz.com/sites/tutorial2program/files/java-working-inheritance.pn
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Inheritance

The keyword used for inheritance is extends.

Syntax:

class derived-class extends base-class

//methods and fields

} Image Source:
https://cdn.programiz.com/sites/tutorial2program/files/java-working-inheritance.pn
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Encapsulation

● Binding (or wrapping) code and data


together into a single unit are known as
encapsulation.
● For example, a capsule, it is wrapped
with different medicines.
● A java class is the example of
encapsulation.
● Java bean is the fully encapsulated
class because all the data members are
private here. Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/02/Encapsulation-i
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Abstraction

● Hiding internal details and showing


functionality is known as abstraction.
● For example phone call, we don't know
the internal processing.
● In Java, we use abstract class and
interface to achieve abstraction.

Image Source:
https://1.bp.blogspot.com/-S_KNWGJx3sY/XY-rE_uKOuI/AAAAAAAASVE/EYr_f9
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Class

● Collection of objects is called class. It is


a logical entity.
● A class can also be defined as a
blueprint from which you can create an
individual object.
● Class doesn't consume any space.

Image Source:
https://media.geeksforgeeks.org/wp-content/uploads/Blank-Diagram-Page-1-5.pn
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Object

● Any entity that has state and behavior is


known as an object. For example, a
chair, pen, table, keyboard, bike, etc. It
can be physical or logical.
● An Object can be defined as an instance
of a class. An object contains an
address and takes up some space in
memory.
Image Source:
https://cdn.techbeamers.com/wp-content/uploads/2019/04/Java-Class-and-Object
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Object

● Objects can communicate without


knowing the details of each other's data
or code.
● The only necessary thing is the type of
message accepted and the type of
response returned by the objects.
● Example: A dog is an object because it
has states like color, name, breed, etc.
as well as behaviors like wagging the
tail, barking, eating, etc. Image Source:
https://cdn.techbeamers.com/wp-content/uploads/2019/04/Java-Class-and-Object
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Method

● A method is a collection of statements


that perform some specific task and
return result to the caller.
● A method can perform some specific
task without returning anything. Methods
allow us to reuse the code without
retyping the code.

Image Source:
https://media.geeksforgeeks.org/wp-content/uploads/methods-in-java.png
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Method

● In Java, every method must be part of


some class which is different from
languages like C, C++ and Python.
● Methods are time savers and help us to
reuse the code without retyping the
code.

Image Source:
https://media.geeksforgeeks.org/wp-content/uploads/methods-in-java.png
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Message Passing

● Objects communicate with one another


by sending and receiving information to
each other.
● A message for an object is a request for
execution of a procedure and therefore
will invoke a function in the receiving
object that generates the desired
results.
Image Source:
https://bparanj.gitbooks.io/ruby-basics/content/message-passing-diagram.png
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Message Passing

● Message passing involves specifying


the name of the object, the name of the
function and the information to be sent.

Image Source:
https://bparanj.gitbooks.io/ruby-basics/content/message-passing-diagram.png
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Classes and Objects in Java

● Classes and Objects are basic concepts


of Object Oriented Programming which
revolve around the real life entities.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Java-Class-an
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Define Class

● A class is a user defined blueprint or


prototype from which objects are
created.
● It represents the set of properties or
methods that are common to all objects
of one type.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Java-Class-an
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Class declaration can include these
components

● Modifiers
● Class name
● Superclass
● Interfaces
● Body

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Java-Class-an
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Class declaration can include these
components
● Modifiers : A class can be public or has
default access (Refer this for details).
● Class name: The name should begin
with a initial letter (capitalized by
convention).
● Superclass(if any): The name of the
class’s parent (superclass), if any,
preceded by the keyword extends. A
class can only extend (subclass) one
parent.
Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Java-Class-an
© Edunet Foundation. All rights reserved.
Object-Oriented
Programming with Java
Classes and Objects
Class declaration can include these
components

● Interfaces(if any): A comma-separated


list of interfaces implemented by the
class, if any, preceded by the keyword
implements. A class can implement
more than one interface.
● Body: The class body surrounded by
braces, { }.

Image Source:
https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/01/Java-Class-an
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
What is Exception

● An exception is an “unwanted or
unexpected event”, which occurs during
the execution of the program i.e, at
run-time, that disrupts the normal flow of
the program’s instructions.
● When an exception occurs, execution of
the program gets terminated.

Image Source:
https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/95/e
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Why does an Exception occur

● An exception can occur due to several


reasons like Network connection
problem, Bad input provided by user,
Opening a non-existing file in your
program etc

Image Source:
https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/95/e
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs 1. statement 1;
Advantages of Exception handling 2. statement 2;
3. statement 3;
● Suppose there are 10 statements in 4. statement 4;
your program and there occurs an
5. statement 5;//exception occurs
exception at statement 5, the rest of the
code will not be executed i.e. statement 6. statement 6;
6 to 10 will not be executed. 7. statement 7;
● If we perform exception handling, the
8. statement 8;
rest of the statement will be executed.
● That is why we use exception handling 9. statement 9;
in Java. 10. statement 10;

© Edunet Foundation. All rights reserved.


Exception handling with
try-throw-catch-finally
constructs
Hierarchy of Java Exception Classes

● The java.lang.Throwable class is the


root class of Java Exception hierarchy
which is inherited by two subclasses:
Exception and Error.
● A hierarchy of Java Exception classes
are as follows:

Image Source:
https://simplesnippets.tech/wp-content/uploads/2018/05/java-exception-handling-c
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Types of Java Exceptions

There are mainly two types of exceptions:


checked and unchecked. Here, an error is
considered as the unchecked exception.
According to Oracle, there are three types of
exceptions:

● Checked Exception
● Unchecked Exception
● Error
Image Source: https://static.javatpoint.com/images/types-of-java-exceptions.jpg
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Difference between Checked and
Unchecked Exception

● Checked Exception
○ The classes which directly inherit
Throwable class except
RuntimeException and Error are
known as checked exceptions
○ e.g. IOException, SQLException
etc. Checked exceptions are
checked at compile-time.
Image Source:
https://1.bp.blogspot.com/-TPzCj5sOo7w/XlYI5WsMoaI/AAAAAAAADwI/lCxhZXJ
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Difference between Checked and
Unchecked Exception

● Unchecked Exception
○ The classes which inherit
RuntimeException are known as
unchecked exceptions
○ e.g. ArithmeticException,
NullPointerException,
ArrayIndexOutOfBoundsException
etc.
○ Unchecked exceptions are not
checked at compile-time, but they Image Source:
are checked at runtime. https://1.bp.blogspot.com/-TPzCj5sOo7w/XlYI5WsMoaI/AAAAAAAADwI/lCxhZXJ
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Java Exception Keywords

● Try
● Catch
● Throw
● Throws
● Finally

Image Source: https://images.slideplayer.com/37/10712844/slides/slide_15.jpg


© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Try

The try block contains set of statements where

an exception can occur.

try

// statement(s) that might cause exception


}
Image Source:
https://www.guru99.com/images/java/052016_0839_JavaExcepti6.jpg
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Catch

● Catch block is used to handle the


uncertain condition of try block.
● A try block is always followed by a
catch block, which handles the
exception that occurs in associated try
block.

Image Source:
https://www.guru99.com/images/java/052016_0839_JavaExcepti6.jpg
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Catch

● Catch block is used to handle the


uncertain condition of try block.
● A try block is always followed by a
catch block, which handles the
exception that occurs in associated try
block.

Image Source:
https://www.guru99.com/images/java/052016_0839_JavaExcepti6.jpg
© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Throw

● Throw keyword is used to transfer


control from try block to catch block.

Image Source: https://i.ytimg.com/vi/ZOFYF5spXGo/maxresdefault.jpg


© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Throws

● Throws keyword is used for exception


handling without try & catch block.
● It specifies the exceptions that a
method can throw to the caller and
does not handle itself.

Image Source: https://i.stack.imgur.com/jXAmN.png


© Edunet Foundation. All rights reserved.
Exception handling with
try-throw-catch-finally
constructs
Finally

● It is executed after catch block.


● We basically use it to put some
common code when there are multiple
catch blocks.

Image Source:
https://qph.fs.quoracdn.net/main-qimg-6196f606623fffd5c336485ed0c1318a.web
© Edunet Foundation. All rights reserved.
Working with types:
Wrapper Class

Introduction

● We use wrapper classes to use these


data types in the form of objects.
● Wrapper class in Java makes the Java
code fully object-oriented.
● For example, converting an int to
Integer.

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Hierarchy of the wrapper classes

Image Source :
© Edunet Foundation. All rights reserved. https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/upl
Working with types:
Wrapper Class

Need for Wrapper class

● Provide a mechanism to ‘wrap’ or bind


the values of primitive data types into an
object
● We can not provide null values to
Primitive types but wrapper classes can
be null.
● Data types like converting primitive
types to string objects and vice-versa.

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Advantages

Image Source:
https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/uploads/sites/2/2020/03/advantages-of-
wrapper-class-in-java.jpg

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Conversion

Primitive type to wrapper class

● Two ways for converting


● Using constructors
● using static factory methods such as
valueOf() (except Character)

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Conversion

Wrapper class to primitive type

● Converting from wrapper to primitive


type is simple.
● We can use the corresponding methods
to get the primitive type.
● e.g. intValue(), doubleValue(),
shortValue() etc.

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Autoboxing and Unboxing

Autoboxing

● Autoboxing is the automatic conversion


of the primitive types into their
corresponding object wrapper classes.
● For example, converting an int to an
Integer, a char to a Character, and so
on.

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Autoboxing and Unboxing

Unboxing

● Unboxing happens when the conversion


happens from wrapper class to its
corresponding primitive type.
● It means we can pass or assign a
wrapper object to an argument or
reference accepting primitive type. e.g.

© Edunet Foundation. All rights reserved.


Working with types:
Wrapper Class

Methods

● Refer Oracle Docs for more information


& methods

© Edunet Foundation. All rights reserved.


Packages

Package in Java

● A package is a collection of similar types


of Java entities such as classes,
interfaces, subclasses, exceptions,
errors, and enums.
● A package can also contain
sub-packages.

© Edunet Foundation. All rights reserved.


Packages

Advantages of using packages

Image Source:
https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/uploads/sites/2/2020/03/Advantages-of
-java-packages.jpg

© Edunet Foundation. All rights reserved.


Packages

Types of Packages

Image Source:
https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/uploads/sites/2/2020/03/types-of-packa
ges-in-java.jpg

© Edunet Foundation. All rights reserved.


Packages

Built-In Packages

Image Source:
https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/uploads/sites/2/2020/03/Built-in-pack
ages-in-java.jpg

© Edunet Foundation. All rights reserved.


Packages

User-defined Package

● As the name suggests, these packages


are defined by the user.
● We create a directory whose name
should be the same as the name of the
package.
● Then we create a class inside the
directory.

© Edunet Foundation. All rights reserved.


Packages

User-defined Package

How do Packages in Java Work?

● The names of packages and the


directory structure are closely related to
each other.

Image Source: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzaha/clpckdir.html

© Edunet Foundation. All rights reserved.


Packages

User-defined Package

Package Naming Conventions

● Packages names follow the reverse


order of domain names, that is,
ibm.edunet.nsti.

© Edunet Foundation. All rights reserved.


Packages

User-defined Package

Compiling a Java Package

● -d specifies the destination where to


locate the generated class file. You can
use any directory name like /home (in
case of Linux), C:/folderName (in case
of windows), etc. If you want the
package to be present in the same
directory, you can use the dot ( . )

© Edunet Foundation. All rights reserved.


Packages

User defined Packages


Executing

● You need to use a fully qualified name


e.g. ibm.nsti.edunet.Example etc to run
the class.
● Here -d represents the destination. The .
represents the current folder.

© Edunet Foundation. All rights reserved.


Packages

Accessing Packages or
Classes from Another Package

● By using * after the import statement, we


can access all the classes of the
package but not the sub-packages.
● By using * after the import statement, we
can access all the classes of the
package but not the sub-packages.

© Edunet Foundation. All rights reserved.


Packages

Accessing Packages or
Classes from Another Package

● Using a Fully qualified name means we


can access the declared class of
different packages without using the
import statement.
● But you need to use a fully qualified
name every time when you are
accessing the class or interface which is
present in a different package.

© Edunet Foundation. All rights reserved.


Applets

Introduction

● Applets are small java programs that are


primarily used in internet computing.
● It can be transported over the internet
from one computer to another and run
using the Applet Viewer or any web
browser that supports Java.

© Edunet Foundation. All rights reserved.


Applets

Types of Applets

● We can be classified the java applets


into two ways
● Local Applet
● Remote Applet

© Edunet Foundation. All rights reserved.


Applets

Types of Applets

Local Applet

● An applet developed locally and stored


in a local system that is known as
a Local Applet.
● When a web page is trying to find a local
applet, it doesn’t need to use the
Internet and the local system doesn’t Image Source: https://webeduclick.com/wp-content/uploads/2019/07/local.png

require the Internet Connection.

© Edunet Foundation. All rights reserved.


Applets

Types of Applets

Remote Applet

● A remote applet is that which is


developed by someone else and stored
on a remote computer connected to the
Internet.
● If our system is connected to the
Internet, we can download the remote
Image Source: https://webeduclick.com/wp-content/uploads/2019/07/remote.png
applet onto our system via the Internet.

© Edunet Foundation. All rights reserved.


Applets

How Applets different from


Applications

1. Applets are not full featured application


programs.
2. Applets are usually written to accomplish
a small task or a component of a task.

© Edunet Foundation. All rights reserved.


Applets

Preparing to Write Applets

● Building an applet code(.java file)


● Creating an executable applet(.class
file)
● Designing a web page using HTML
● Preparing <Applet Tag>
● Incorporating <Applet> tag into the web
page.
● Creating HTML file.
● Testing the applet code.
© Edunet Foundation. All rights reserved.
Applets

Building Applet Code

● To building the applet code two classes


of java library are essential namely
Applet and Graphics.
● The Applet class is contained in
java.applet package provides life and
behaviour to the applet through its
methods such as int(), start() and
paint().

© Edunet Foundation. All rights reserved.


Applets

Applet Life Cycle

● An applet is a window based event


driven program and it waits until an
event occurs.
● Initialization State
● Running State
● Idle or Stopped State
● Dead State
● Display State Image Source : https://webeduclick.com/applet-life-cycle/

© Edunet Foundation. All rights reserved.


Applet

Applet Program

© Edunet Foundation. All rights reserved.


Applets

How to execute Applet

● Executable applet is nothing but the


.class file of applet, which is obtained by
compiling the source code of the applet.
● The compiled output file called
appletname.class should be placed in
the same directory as the source file.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

GUI (graphical user interface)

● Any program that uses GUI (graphical


user interface) such as Java application
written for windows, is event driven.
● Event describes the change in state of
any object. For Example : Pressing a
button, Entering a character in Textbox,
Clicking or Dragging a mouse, etc.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Event Handling

Components of Event Handling

● Three main components:


● Events
● Events Source
● Listeners

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Event Handling

How Events are handled?

● A source generates an Event and send it


to one or more listeners registered with
the source.
● Once event is received by the listener,
they process the event and then return.
● Events are supported by a number of
Java packages, like java.util, java.awt
and java.awt.event.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Event Handling

Important Event Classes and Interface

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Event Handling

Steps to handle events

● Implement appropriate interface in the


class.
● Register the component with the
listener.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Abstract Window Toolkit

AWT Hierarchy

Image Source: https://www.studytonight.com/java/images/heirarchy-of-component-class.jpg

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Abstract Window Toolkit

Window Fundamentals

● Java Abstract window tool kit package is


used for displaying the data within a GUI
Environment.
Image Source:
https://3.bp.blogspot.com/-a_F050aJCqQ/UtkzS2PvfiI/AAAAAAAAFnw/vQeJnozRfDo/s1600/awt.j
pg

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing ● Void SetSize(int Width, int Height)
● Void SetLocation (int x,int y)
● Void setBounds(int x,int y,int width,int height)
● Void setForeground(Color c)
AWT Hierarchy
● Void setBackground(Color c)

Window Fundamentals - Component

● Component class is at the top of AWT


hierarchy. Component is an abstract
class that encapsulates all the attributes
of visual component.
● A component object is responsible for
remembering the current foreground and
background colours and the currently
selected text font. Image Source:
https://www.ntu.edu.sg/home/ehchua/programming/java/images/AWT_ContainerComponent.png
© Edunet Foundation. All rights reserved.
Basics of AWT and Swing
● Void add (object o)
● Void remove(object o)
AWT Hierarchy ● void removeAll()

Window Fundamentals - Container

● Container is a component in AWT that


contains another component like button,
text field, tables etc.
● Container is a subclass of component
class. Container class keeps track of
components that are added to another
component.
Image Source:
https://www.ntu.edu.sg/home/ehchua/programming/java/images/AWT_ContainerComponent.png
© Edunet Foundation. All rights reserved.
Basics of AWT and Swing ● Panel()
● Void setLocation()
● Void setSize()
AWT Hierarchy ● Void setBounds()

Window Fundamentals - Panel

● Panel class is a concrete subclass of


Container. Panel does not contain title
bar, menu bar or border. It is container
that is used for holding components.

Image Source:
https://www.ntu.edu.sg/home/ehchua/programming/java/images/AWT_ContainerComponent.png
© Edunet Foundation. All rights reserved.
● Frame()
Basics of AWT and Swing ● Frame(String Title)
● Void setsize()
● Void show()
AWT ● Void setBackground(Color c)
● Void setLocation(int x,int y)

Working With Frames

● Frame Class is also a Sub Class of


Window Class and frame class allows to
Create a pop-Menus.

Image Source:
https://www.ntu.edu.sg/home/ehchua/programming/java/images/AWT_ContainerComponent.png
© Edunet Foundation. All rights reserved.
Basics of AWT and Swing

AWT

Creating Frame Example

● Creating a Frame
● Setting Frame Properties
● Dimension getSize()
● Canvas

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

Buttons

● In Java, AWT contains a Button Class. It


is used for creating a labelled button
which can perform an action.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

Check boxes

● In Java, AWT contains a Checkbox


Class. It is used when we want to select
only one option i.e true or false. When
the checkbox is checked then its state is
“on” (true) else it is “off”(false).

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

TextFields

● In Java, AWT contains aTextField Class.


It is used for displaying single line text.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

TextAreas

● In Java, AWT contains aTextArea Class.


It is used for displaying multiple-line text.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

Choice Class

● In Java, AWT contains a Choice Class. It


is used for creating a drop-down menu
of choices. When a user selects a
particular item from the drop-down then
it is shown on the top of the menu.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

List Class

● In Java, AWT contains a List Class. It is


used to represent a list of items
together. One or more than one item can
be selected from the list.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

Canvas

● In Java, AWT contains a Canvas Class.


A blank rectangular area is provided. It
is used when a user wants to draw on
the screen.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT MenuItem and Menu

● In Java, AWT contains a MenuItem and


Menu Class.MenuItem is used for
adding Lable in Menu. The menu is used
to create a drop-down of menu
components

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT MenuItem and Menu

● In Java, AWT contains a MenuItem and


Menu Class.MenuItem is used for
adding Lable in Menu. The menu is used
to create a drop-down of menu
components

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT PopupMenu

● In Java, AWT contains a Popup Menu.


● It is a popup which is dynamic in nature.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT Panel

● In Java, AWT contains a Panel.


● The panel provides a free space where
components can be placed.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT Dialog

● In Java, AWT contains a Dialog. It is a


type of window which is having a border
and a title. But it does not have any
maximize and minimize button.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

AWT Controls

AWT Toolkit

● In Java, AWT contains a Toolkit.


● It is a super class of Abstract Window
Toolkit and can be implemented
anywhere.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Layout Manger

● The Layout manager is used to layout


(or arrange) the GUI java components
inside a container.

Image Source: http://pawlan.com/monica/articles/awtlayout/art/appcall.gif

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Layout Manger

BorderLayout

● A BorderLayout places components in


up to five areas: top, bottom, left, right,
and center.
● It is the default layout manager for every Image Source: https://www.guru99.com/images/uploads/2012/06/java-border-layout-manager.jpg

java JFrame

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Layout Manger

FlowLayout

● FlowLayout is the default layout


manager for every JPanel.
● It simply lays out components in a single
Image Source: https://www.guru99.com/images/uploads/2012/06/java-border-layout-manager.jpg
row one after the other.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Layout Manger

GridBagLayout

● It is the more sophisticated of all layouts.


It aligns components by placing them
within a grid of cells, allowing
Image Source: https://www.guru99.com/images/uploads/2012/06/java-border-layout-manager.jpg
components to span more than one cell.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Swing Framework
● Swing Framework contains a set of
classes that provides more powerful and
flexible GUI components than those of
AWT.
● Swing provides the look and feel of
modern Java GUI.
● Swing classes are defined in
javax.swing package and its
sub-packages.
© Edunet Foundation. All rights reserved.
Basics of AWT and Swing

Swing

Main Features of Swing

● Platform Independent
● Customizable
● Extensible
● Configurable
● Lightweight
● Rich Controls
● Pluggable Look and Feel

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Swing and JFC

● JFC is an abbreviation for Java


Foundation classes, which encompass a
group of features for building Graphical
User Interfaces(GUI) and adding rich
graphical functionalities and interactivity
to Java applications.
● Java Swing is a part of Java Foundation
Classes (JFC).

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Features of JFC

● Swing GUI components.


● Look and Feel support.
● Java 2D.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Swing Hierarchy

Image Source : https://www.studytonight.com/java/images/swing-heirarchy-1.gif

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Swing Classes

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing

Creating a JFrame

● By instantiating JFrame class.


● By extending JFrame class.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

● Swing isWhat
a GUIis toolkit
Swingthat
GUI??
facilitates the
creation of highly interactive GUI
applications.
● Swing is more flexible and robust when
it comes to implementing graphical
components.
● Swing can be regarded as more
graphically-rich than AWT not only
because they provide some entirely new
graphical components like a tabbed
window and tree structure. © Edunet Foundation. All rights reserved.
Basics of AWT and Swing

Swing GUI

Key Items

● A Swing GUI consists of two key items

○ Components

○ Containers

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Components

● In Swing, Components are derived from


the JComponent class where
JComponent provides the functionality
that is common to all components.
● Example: JComponent supports the
pluggable look and feel.

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Swing Component Part-1

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Swing Components - 2

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Container

● A Container holds a group of


components. Thus, a container is a
special type of component that is
designed to hold other components.
● Thus, all Swing GUIs will have at least
one container.
● Because containers are components, a
container can also hold other containers

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Containers - Top level

● It inherits Component and Container of


AWT.
● It cannot be contained within other
containers.
● Heavyweight.
● Example: JFrame, JDialog, JApplet

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

Containers - Lightweight

● It inherits JComponent class.


● It is a general purpose container.
● It can be used to organize related
components together.
● Example: JPanel

© Edunet Foundation. All rights reserved.


Basics of AWT and Swing

Swing GUI

● Swing is a very large subsystem and


makes use of many packages

© Edunet Foundation. All rights reserved.


Threads

MultiThreading

● Java Multithreading, Doing some work


or process is called Thread. Multi
Threading is nothing but process of
managing and executing multiple tasks
at a time.

© Edunet Foundation. All rights reserved.


Threads

Important Terminology

● Multitasking is the process of executing


more than one task at a time.
● Java Multithreading is the process
executing multiple threads at a time.
● Multiprocessing is same like
multitasking, but it involves more CPU’s.
● Parallel Processing is nothing but using
more CPU’s in one system.

© Edunet Foundation. All rights reserved.


Threads

Thread Life Cycle

● New
● Runnable
● Running
● Waiting
● Terminated
Image Source : https://www.studytonight.com/java/images/thread-life-cycle.jpg

© Edunet Foundation. All rights reserved.


Threads

Achieve Multithreading

● We can achieve multithreading in Java


in two ways:
● By Implementing the Runnable Interface
● By extending Thread class

© Edunet Foundation. All rights reserved.


Threads

Achieve Multithreading

Creating Thread Class

● Thread class is the main class on which


Java's Multithreading system is based.

© Edunet Foundation. All rights reserved.


Threads

Achieve Multithreading

Runnable Interface

● After implementing runnable interface ,


the class needs to implement the run()
method, which is of form,
● public void run()

© Edunet Foundation. All rights reserved.


Threads

Achieve Multithreading

Extending Thread

● This is another way to create a thread


by a new class that
extends Thread class and create an
instance of that class.
● The extending class must
override run() method which is the entry
point of new thread.

© Edunet Foundation. All rights reserved.


Threads

isAlive() and join()

● In java, isAlive() and join() are two


different methods that are used to check
whether a thread has finished its
execution or not.
● The isAlive() method returns true if the
thread upon which it is called is still
running otherwise it returns false.
● But, join() method is used more
commonly than isAlive(). This method
waits until the thread on which it is
called terminates © Edunet Foundation. All rights reserved.
Threads

Thread Priority

● Priorities are spoken to by a number in


the vicinity of 1 and 10.
● Three priorities of thread.
● public static int MIN_PRIORITY
● public static int NORM_PRIORITY
● public static int MAX_PRIORITY

© Edunet Foundation. All rights reserved.


Threads

Interthread Communication

● Java provide benefits of avoiding thread


pooling using inter-thread
communication.
● The wait(), notify(), and notifyAll()
methods of Object class are used for
this purpose.

© Edunet Foundation. All rights reserved.


Threads

Thread Pooling

● Pooling is usually implemented by loop.


● i.e. to check some condition repeatedly.
● Once condition is true appropriate action
is taken. This waste CPU time.

© Edunet Foundation. All rights reserved.


Threads

Thread Deadlock

● Deadlock is a situation of complete


Lock, when no thread can complete its
execution because lack of resources.

Image Source : https://www.studytonight.com/java/images/thread-life-cycle.jpg

© Edunet Foundation. All rights reserved.


Threads

Thread Synchronization

● Java Multithreading, If a thread is acting


on any object and preventing another
thread to act upon the same object is
called Thread Synchronization, it is used
to remove consistency problem.
● Daemon thread in java is a service
provider thread.
● Synchronization is used to prevent
thread interference.
© Edunet Foundation. All rights reserved.
Threads

Advantages of Multithreading

● Multithreading allows multiple operations


to perform at once.
● It saves time as there can be the
execution of multiple operations
possibly.
● Threads are independent of each other
which makes the functionality better.

© Edunet Foundation. All rights reserved.


Concepts of Networking

Introduction

● The networking classes and interfaces


will be available in the java.net package
and provide the support for the two
protocols, they are as follows.
● TCP stand for Transmission Control
Protocol which is used to provide
communication between two
applications.
● UDP stands for User Datagram
Protocol which is used to transmit
packets of data between an application.
© Edunet Foundation. All rights reserved.
Concepts of Networking

Working with Java Networking

● IP Address
● Protocol
● MAC Address
● Port Number

© Edunet Foundation. All rights reserved.


Concepts of Networking

Socket Overview

● The purpose of socket programming is


that providing communication between
two applications running on various
JRE. It may be a connection oriented
and connection less.
● Connection oriented socket
programming uses Socket and Image Source :
ServerSocket classes. https://dkb46014en6d6.cloudfront.net/tutorials/wp-content/uploads/sites/2/2020/04/java-socket-pr
ogramming-process.jpg
● The connection-less socket
programming uses DatagramSocket and
DatagramPacket classes. © Edunet Foundation. All rights reserved.
Concepts of Networking

Socket programming - Server

● Java Networking, Following is an


example to understand the concept of
socket programming.
● Here client is going to send the
message and server will receives that.
● MyServer.java

© Edunet Foundation. All rights reserved.


Concepts of Networking

Socket programming – Client

● Java Networking, Following is an


example to understand the concept of
socket programming.
● Here client is going to send the
message and server will receives that.
● MyClient.java

© Edunet Foundation. All rights reserved.


Concepts of Networking

java.net

● java.net package encapsulate large


number of classes and interface that
provides an easy-to use means to
access network resources.
● Here are some important classes and
interfaces of java.net package.

© Edunet Foundation. All rights reserved.


Concepts of Networking

InetAddress

● Inet Address encapsulates both


numerical IP address and the domain
name for that address.
● Inet address can handle both IPv4 and
Ipv6 addresses.
● Inet Address class has no visible
constructor.

© Edunet Foundation. All rights reserved.


Concepts of Networking

java.net

URL Class

● Java URL Class present in java.net


package, deals with URL (Uniform
Resource Locator) which uniquely
identify or locate resources on internet.

© Edunet Foundation. All rights reserved.


Concepts of Networking

java.net

Important Methods of URL class

● getProtocol() : Returns protocol of URL


● getHost() : Returns hostname(domain
name) of URL
● getPort() : Returns port number of URL
● getFile() : Returns filename of URL

© Edunet Foundation. All rights reserved.

You might also like