Java Full Course in 10 Hours | Java Tutorial for Beginners [2023] | Java Online Training | Edureka
Aug 15, 2023
Java Full Course in 10 Hours | Java Tutorial for Beginners [2023] | Java Online Training | Edureka
π₯Edureka Java Training (Use Code βπππππππππβ): https://www.edureka.co/java-j2ee-trai β¦ This Edureka Java Full Course will help you in understanding the various fundamentals of Java programming in detail with examples. Check out Java Tutorial Playlist: https://goo.gl/ES3dI3 This Java tutorial for beginners covers the following topics: 00:00 Agenda 3:36 - Introduction to Java 23:46 - Java Environmental SetUp 28:43 - Java Internals 35:05 - Java Working 38:21 - First Java Program 53:27 - Modifiers in Java 54:34 - Access Control Modifiers 1:00:12 - Non Access Modifiers 1:10:05 - Variables in Java 1:14:59 - Data types in Java 1:25:52 - Operators 1:28:56 - Operators Types and Examples 1:33:11 - Control Statements in Java 1:35:51 - Selection Statements 1:37:17 - Iteration Statements 1:44:04 - Jump Statements 1:46:06 - Methods in Java 2:09:00 - Arrays in Java 2:27:50 - Strings 2:52:45: Classes and Objects 2:57:17 - Java Naming Conventions 2:57:30 - Types of variables 3:01:30 - Constructor 3:19:09 - Java Static Keyword 3:24:32 - Java this keyword 3:29:27 - Object-Oriented Programming Concepts 4:29:44 - Interface 4:50:55 - What is a Package? 4:58:12 - Access Modifiers 5:05:00 - Demo - Access package from another package 5:08:55 - Regular Expression 5:21:50 - Exception 5:31:45 - Exception handling 5:50:27 - XML in Java 6:36:00 - Serialization in Java 6:54:00 - Wrapper Classes 6:58:06 - Generics in Java ----- Edureka Java Training ------ π΅ Java Certification Training: http://bit.ly/3a5wPG1 π΅ Selenium Certification Training: http://bit.ly/3r1XBpF π΅ Microservices Certification Training: http://bit.ly/2MjLnJK π΅ Spring Certification Training: http://bit.ly/3sTulTB π΅ Test Automation Engineer Masters Program: http://bit.ly/369W6xE Subscribe to our channel to get video updates. π’π’ ππ¨π© ππ ππ«ππ§ππ’π§π ππππ‘π§π¨π₯π¨π π’ππ¬ ππ¨ ππππ«π§ π’π§ 2023 πππ«π’ππ¬ π’π’ β© NEW Top 10 Technologies To Learn In 2023 - Β Β Β β’Β TopΒ 10Β TechnologiesΒ ToΒ LearnΒ InΒ 2023Β β¦Β Β #edureka #javaedureka #JavaFullCourse #Javatutorial #Javaonlinetraining #Javaforbeginners Instagram: https://www.instagram.com/edureka_lea β¦ Facebook: https://www.facebook.com/edurekaIN/ LinkedIn: https://www.linkedin.com/company/edureka Telegram: https://t.me/edurekaupdates For Java Training \u0026 Certification, please write back to us at [email protected] or call us at IND: 9606058406 / US: 18338555775 (toll free).
Content
0 ->
10.8 -> Java is one
11.6 -> of the most fundamental
programming languages
14.35 -> that anybody can learn
despite being so simple.
17.2 -> It is a Marvel
18.065 -> what can be achieved
with the use of java?
20.7 -> Hi everyone.
21.5 -> I welcome you all to this Java
full court session
24.388 -> by Edureka,
25.278 -> but before we begin, let's look
at our agenda for today.
28.532 -> So we're going to start out by
talking about Java, what it is,
31.905 -> and why do we need it?
33.2 -> Then we're going
to discuss a few basic
35.4 -> concepts like variables
36.702 -> and data types in Java followed
by which we are going to talk
40.1 -> about operators control
statements and methods.
43 -> We are also going to discuss
the meat and potatoes
45.9 -> of this session classes objects
48 -> and object oriented
programming Concepts
50.5 -> in Java followed by which
we are going to talk
53.3 -> about exception handling
54.9 -> then we're going to discuss
Java collection Frameworks
58.369 -> and finally close this Action
by discussing the Dom parser
62.1 -> in Java also do click
64.2 -> on the Subscribe button
to never miss an update
66.905 -> on the hottest Technologies by
the Edureka YouTube channel.
70.2 -> Okay, before we start off
let me introduce myself.
73.082 -> I am vinoth and I have been
74.5 -> with this industry
IT industry specifically
77.2 -> into Java development
for last 12 years.
80.1 -> Alright, so the first topic is
about introduction to Java.
85.5 -> So what are we going to cover
in this particular topic?
88.8 -> So it's going to be
introduction to Java
91.7 -> what Java is all about will have
Java installation done as well.
96.5 -> So that you guys
can use it in future.
98.767 -> You guys can try your hands
on we'll talk about modifiers
102.165 -> and variables in Java.
103.5 -> This is pretty much similar to
105.264 -> what we have in other
programming languages will talk
108.3 -> about Java data types as well,
110.3 -> which is nothing but data type
112.3 -> as we have the it's a storage
for different data types,
116.407 -> right or the data
117.7 -> that is store whatever
you want to process.
120.1 -> Song is first put into memory
122.1 -> and that is what
data type is all about.
124.7 -> So you have different storage is
126.3 -> like for character you
have something else
128.8 -> and for float you will have
something else for long.
131.8 -> We will have something else
133.2 -> sort of data type
conversion in Java.
136.6 -> So so you could convert
from one data type
139.823 -> to other data type in Java.
141.9 -> There are implicit
conversions done.
143.9 -> We're in the programmer
need not take care about it.
146.9 -> Java programming by itself would
take care about converting it
150.6 -> which is implicit conversion
and there are few conversions,
154.9 -> which programmers have
to take care about they
157.9 -> have to explicitly mention
159.7 -> that you have to convert
from this data type
162 -> to this data type.
163.3 -> And if you don't do it
164.4 -> you would end up in
compilation errors or something.
167.1 -> We'll talk about operators
operators are nothing
169.7 -> but the operators
170.734 -> that work upon this data type
172.553 -> and which is nothing
but transformation.
175 -> So you kind of use
this operators to add up for say
178.9 -> for example Of two integers
you want to add it up.
181.9 -> So you would have
this operators used.
184.4 -> We'll talk about control
statements in Java as
187.692 -> well control statements.
189.51 -> Like you have
190.494 -> if else and for loops
and stuff like that,
193.7 -> so we'll talk about it.
195.035 -> So Java is pretty much similar
196.95 -> to other programming
languages thing is
199.384 -> it has some unique features
201.076 -> which makes it really important
202.928 -> in the current industry
the IT industry
205.3 -> when it comes to Big Data
and stuff like that.
207.8 -> So we'll touch base on all
this important features of java,
211.582 -> which would help
you to understand.
213.8 -> Why do we really use it?
215.6 -> Alright.
216.1 -> So the first
topic is Introduction.
218.8 -> So what is Java so Java as we
said the programming language
223.5 -> which has object-oriented
programming model.
226.2 -> So when I say object-oriented
programming model everything
229.5 -> in Java is taken as an object.
232.3 -> So object is nothing
233.756 -> but something that has got State
and behavior say for example,
238.198 -> you have chair, right?
239.722 -> Jed has got a particular State
241.8 -> and it has got
a particular Behavior.
243.917 -> If you do something
if you move it,
245.709 -> it would go this way
246.8 -> and that way
and stuff like that.
248.6 -> So basically any object
250.369 -> if we think about
in reality realm any object
253.8 -> for that matter would have
some kind of state
256.6 -> and it would have
some kind of behavior
259.052 -> which incorporates on its own.
261.015 -> Right?
261.8 -> So basically similar to that
Java is programming language,
265.3 -> which is based on object
oriented programming model.
268.6 -> So everything Java
could be thought of as an object
272.569 -> or you define a class.
274.4 -> So say for example
you have house right?
278 -> So house could be thought
279.9 -> of as an object or class
rather a house has a class
283.8 -> and it would have
certain attributes right
286.6 -> like number of rooms
or stuff like that.
289.319 -> So that is nothing
but the state of the house.
293.3 -> So this was actually brought
in by Sun Microsystems in 1995,
299.1 -> and basically Java is nothing
301.4 -> but we have jvm but jvm
is nothing but you kind
305.2 -> of kind of can say it's
a specification right
308.7 -> Sun Microsystems has said
that this is how it should be
312.585 -> so that any company tomorrow
314.551 -> I can go and create
my own version of java,
317.5 -> but it has to be aligned
to this particular specification
320.897 -> that is given
by Sun Microsystems.
322.9 -> So Java is nothing
but reference implementation
326.088 -> of java is provided
by Sun Microsystems,
328.719 -> but nevertheless
329.834 -> as I said give him
itself is a specification
332.743 -> which anyone can Implement
actually but we will talk about
336.6 -> Sun Microsystems talk about
the reference implementation
340.2 -> that is nothing but one
created by Sun Microsystems.
343.525 -> So everything in Java
would have a state
346.069 -> and behavior and
which would be defined by class.
349.5 -> Again, it was started off by
a team led by James Gosling
354.1 -> and we know it's open source,
356.2 -> which doesn't stop anyone
from putting in whatever code.
359.833 -> I want to still we have lot
of versions coming in Java.
363.4 -> So it's not that you
just have one version
365.711 -> created by Sun Microsystems
367.368 -> and it's been used
across the industry.
369.7 -> You have like find
some issues or
371.7 -> if they want to have
some kind of enhancement
374.491 -> in the open a particular
module the keep doing it.
377.6 -> So right now we have
like Java is at version 12,
381 -> which is like we have lot
of enhancements coming in.
383.9 -> It's a evolving thing
it's ever evolving thing.
387.2 -> And as I said,
this is open source tomorrow.
389.979 -> If you become a good
programmer in Java,
392.47 -> you could go and actually
write something for Java
395.6 -> and which would be
moderated by someone
397.835 -> and which would be put
as open source.
400.2 -> And anyone can use it
other thing is Java
403.8 -> the very important feature
why we use Java
407.1 -> or why Java is so widely used is
right once and run everywhere.
412.1 -> So you write a class
or you write program once
415.308 -> and you compile it
416.575 -> and this particular
compiled version of class.
419.703 -> Be run anywhere on any machine
or you could transport
423.205 -> this particular compiled
version of java,
425.9 -> which is nothing but classify we
call it as a class file again,
429.8 -> you did not get into
what is class file.
432.14 -> But just to say
433.022 -> that you compile it you get
a compiled version of it
436.028 -> and this compiled version
437.5 -> of class could be transported
anywhere in the network
440.783 -> or you could put it
anywhere and just run it
443.5 -> so you could take it
on your pen drive as well
446 -> and go anywhere
446.882 -> and plug your pendrive
448.242 -> get this class path
download this class path
450.9 -> or download this class rather
452.882 -> and just run it so it right
once and run everywhere
456.3 -> and the magic part is it
could be run on any environment.
459.736 -> It could be run on any platform.
461.683 -> That's why it's
platform independent.
463.833 -> So I could write a program today
on Windows compile it
467.093 -> and tomorrow I can just take it
on my pen drive and run it
470.6 -> on Linux as well.
471.9 -> So you don't have
to take care about it.
474.2 -> Java by itself has a feature
to make it platform independent.
478.7 -> So As you could imagine this
is one of the reasons why
482.14 -> it's been widely used
483.572 -> because since we
are getting into a phase
486.3 -> of distributed computing,
488.025 -> we cannot have everything run
on same platform.
491.2 -> You don't know
where your so you
493.1 -> as a programmer write something
494.65 -> but you don't know
495.607 -> where this particular program
is going to run.
498 -> It could be on any platform.
499.7 -> So this is why
it is more important.
501.829 -> So unlike dotnet, right?
503.111 -> You need to have Microsoft
504.551 -> just to give you
this thing comparison
506.6 -> with dotnet so for.net
you need to have
509.815 -> Microsoft stack implemented,
512 -> but for this you need
not could be run everywhere.
516.3 -> So Java can be used
to create complete applications
519.649 -> that may run
on a single computer
521.672 -> or can be distributed
523 -> among servers and clients
in the network.
525.311 -> As I said, this is more
about the application
527.955 -> of platform-independent
programming language.
530.544 -> So it could be used
531.64 -> on any machine you
need not take care
533.758 -> about which machine
your program is going to run on.
536.803 -> All right, so let's
talk about Java.
539.646 -> Earth so what features
do we have in Java?
542.8 -> First thing is Java is
pretty much simple
545.876 -> when it comes to SDK
547.424 -> or when it comes
to API application interface.
550.9 -> It's pretty much simple.
552.4 -> It's kept as simple as possible.
554.3 -> It's pretty much similar
to other programming languages
557.4 -> and it's verbose.
558.5 -> So anyone can just read
through it and understand
561.6 -> what it is trying to do
563.004 -> so they have kept it
to that level so similar
565.617 -> to any high-level languages,
567.264 -> right the coach
should be such that
569.1 -> as you read through it.
570.213 -> You should understand
571.2 -> what it is doing and that's
what they have tried to do.
574.2 -> Its high-performance.
575.7 -> One of the things that I
already mentioned about.
578.4 -> It's an evolving system.
579.935 -> It's not that it's been
just done once and been used
583.11 -> throughout its evolving system.
585.027 -> So as and when this continuous
Improvement done, right,
588.361 -> so as then when if I as
the application programmer
591.508 -> if I find something not working
593.5 -> as expected I can raise a ticket
596 -> and they could go
through the ticket
598.1 -> or there's a Java development.
599.8 -> Which has been driven by Oracle.
601.4 -> Now, they would look
at the priority
603.235 -> of this particular stuff.
604.528 -> And if there are a lot
605.727 -> of tickets been raised by
other companies as well.
608.4 -> And if something
609.219 -> could be done on the aspect
on the particular aspect
612.237 -> that you raised they
would surely Incorporated
614.9 -> and notify you
615.8 -> in a particular release
the enhancement is coming up
618.8 -> and stuff like that.
620 -> So it's a evolving system
and you know,
622.452 -> the performance is always
624 -> if there's some drawback or
if there's something not working
627.1 -> as expected they
628.158 -> would surely Rectify it
in the future releases.
631.8 -> So that way it keep it up
to the mark the keep
635.261 -> the high-performance thing
going it is secured.
638.8 -> So Java basically runs
in virtual machine sandbox,
642.7 -> and no one can get
into this particular space.
645.477 -> So no one can intrude it.
646.951 -> I would say
647.633 -> so that keeps it free from virus
and stuff like that
650.8 -> or untrusted process.
652.4 -> And other thing
653.553 -> that is important is
unlike C. Java doesn't expose
657.791 -> pointers so in see There
could be malicious user
661.5 -> who could get into the memory
location through pointers
664.807 -> and can manipulate the contents
of a particular memory.
668.123 -> Right?
668.558 -> Whereas in Java.
669.7 -> It doesn't expose the pointer.
671.7 -> It doesn't give you the pointer
to a memory location.
674.7 -> So you can't actually go
and change the content
677.405 -> of a memory location
when you are using Java
680.176 -> so that keeps it secure.
682.7 -> So it's robust.
684.1 -> So Java checks the code during
compilation time and runtime.
688.178 -> So basically what happens is
690.136 -> as I said when you compile
it you get a class file
693.559 -> and whenever you try
to run this class file
696.493 -> on any of the machines,
698.029 -> it will ensure
that it's properly done
700.5 -> or if there's some issue
with the class file.
702.877 -> It would say that it's
a correctly classify.
705.2 -> So basically you have
some kind of checks done
707.847 -> during the compilation
709.141 -> as well compilation is nothing
710.694 -> but if you have something
tactical error say, for example,
714.047 -> if you miss the semicolon at the
end of a particular statement
717.5 -> or an end of any statement,
719.5 -> It would prompt you
during the compilation time
722.064 -> that this is not
what is expected or it
724.3 -> would ask you to correct it
725.906 -> once you have everything as
for the expectation,
728.807 -> it would compile it
and create a class file
731.4 -> and when you put this glass file
to any of the machines
735.059 -> during the runtime
it checks as well.
737.6 -> And the other thing is
738.894 -> about you don't have to take
care about memory allocation
742.1 -> and releasing unlike
in other programming languages.
745.473 -> Java by itself
746.4 -> does garbage collection
garbage collection is nothing
749.4 -> but when a particular memory
is not being utilized
752.5 -> by your program
753.5 -> of goes out of scope it
would Java by itself has
756.7 -> a thread I don't want
to get into threads
758.9 -> and stuff like that.
759.9 -> But Java would enough
the memory contains by itself.
763.9 -> You don't have to explicitly
write a code to clean
767.166 -> it and see you have
to write a code to clean.
770.241 -> It errors in Java.
771.5 -> It's done by itself.
772.9 -> So that makes it robust
other thing is it's portable
776.4 -> as we already spoke.
777.6 -> You can write
a programming windows.
779.7 -> You can run the same program
or you can write a program
782.6 -> in Windows compile
it get a class file
785.038 -> or the compiled version
of the class and just put it
788.4 -> on any platform.
789.761 -> It could be Windows.
791.3 -> It could be you run it
on Unix or Linux or Mac
795 -> or anywhere so you don't have
to take care about it.
798.231 -> So Java by itself does it
799.875 -> and that's where jvm comes
into picture which we'll talk
803.494 -> about in the the further slides.
806.4 -> So other thing is it's Dynamic
809 -> which means that it has
runtime polymorphism.
812.1 -> So all the objects
are evaluated during runtime.
815.6 -> It's not just that it's done
during the compile time.
818.447 -> There.
818.801 -> Is this something done
during the runtime as well.
821.7 -> So basically it's called
as runtime polymorphism.
824.9 -> But just to keep in mind
not everything is linked up
828.011 -> during the compile time
is something done
830.552 -> during the runtime as well.
832.9 -> So it could be
distributed as well.
835.166 -> You don't have to have
all the code put
837.621 -> into one machine and run
it from my machine.
840.4 -> I could run something written
on your machine as well.
843.755 -> If into net in the same network
or if if they are exposed
847.3 -> to a network we could run
programs on different machines.
851.6 -> So that's what distributed
is all about.
853.922 -> So you could think of big data.
855.794 -> So this is one
856.684 -> of the major features why
Java is been widely used
859.9 -> in big data, right?
861.3 -> So big data is nothing
but you have chunks
863.9 -> of data you have like petabytes
866.12 -> of information coming
in every minute
868.7 -> or every hour or every day,
870.8 -> right and you want
to process it.
872.767 -> So it cannot be done
in one machine
874.901 -> if you want to run
everything on one machine
877.6 -> as we had earlier, right?
879.3 -> Everything was monolithic
everything was done
882.1 -> on one machine sort of so that's
884.262 -> where you would want
to have servers right.
887 -> Now.
887.8 -> The server thing is
889.2 -> it's not being used that much
since there's a lot of English.
892.2 -> Intense stuff like that.
893.879 -> So distributed computing
is nothing but we have
897.1 -> like pure computers
or normal computers
899.902 -> that we have and programs
are actually done
903 -> on this machines
rather than rather
905.369 -> than having a high-end machines.
907.746 -> So basically this feature is
909.9 -> what helps Java
to be used in big data.
913.6 -> And as I said,
914.66 -> it's run on commodity Hardware
as against server Hardware
919 -> which needs a lot
of investment for companies.
922.4 -> Java is multi threaded
so multi-threaded is
925.974 -> nothing but so you have
multiple cores on your machine,
929.8 -> right?
930.3 -> You have like four cores
and stuff like that.
932.8 -> So you could utilize all this
for course say for example,
936.2 -> you want to do addition
of two numbers
938.404 -> and multiplication of two
numbers right different numbers.
941.8 -> So you don't have to run
everything on One Core.
945.138 -> So this could
946.018 -> since you have four processors
right for course,
949.2 -> you could have
addition run on one core
951.6 -> and you could have
this multiplication going on
954.2 -> at the same time
at the same instance, right?
956.84 -> You could have this
multiplication going on as well.
959.864 -> You could run them
as a thread right?
962 -> You don't have to have
one waiting for other.
964.7 -> You don't have to do it
in a sequential manner
966.996 -> when you're operating
on different variables, right?
969.6 -> So that's what multi-threaded
is all about.
972.3 -> As I said you could have
this operations carried out
975.3 -> on different course
in the same instance of time.
978.9 -> Object-oriented again
as I spoke earlier,
982.6 -> everything is performed
using objects and Java
986.019 -> can be easily extended
987.691 -> since it is based
on object model.
990.684 -> Now, let's talk
about which sectors
993.3 -> or which industry sectors
actually use Java.
997.5 -> So you have Android apps.
1001.007 -> So Android apps Cal
could be written on Java.
1004.6 -> So basically the underneath
is Android API,
1007.7 -> which is similar
to jdk so jdk is nothing
1010.6 -> but Java development kit.
1012.4 -> It's widely used
in financial services industry.
1015.533 -> If if you would have
some idea about it.
1018.283 -> You could see
1019.2 -> that mostly all Financial
companies use Java.
1022.4 -> So the Legacy systems
1023.853 -> that we have in financial
companies is mostly
1026.9 -> developed on Java.
1028.423 -> So one of the aspects
for this is more
1031.269 -> about it's pretty secure.
1033.192 -> So that's why it's
been written on Java lots
1036.5 -> of global investment Banks.
1038.5 -> Like Citigroup Barclays Standard
Chartered and other Banks
1042.453 -> use Java for writing
1043.84 -> front and back office
electronic trading system.
1047.1 -> So one of the main features
why it's been used
1050.5 -> in financial industry
is about security.
1053.5 -> It provides high
level of security
1055.8 -> as we spoke earlier
Java web applications.
1059.1 -> So basically you have
web servers on which
1062.02 -> your application would be hosted
1064.3 -> and you could request
for a particular JSP
1067.5 -> or JSP is nothing but
a dynamic HTML page right there
1072.4 -> in the contents could change
basically you could request
1075.9 -> for some particular JSP
1077.3 -> and you could get it
so say for example,
1079.56 -> you are trying to log on
1080.993 -> to a particular application
you get a login page
1083.9 -> that is nothing but a JSP.
1085.9 -> So basically a mini
of the web applications
1088.7 -> is developed on Java as well.
1091.3 -> One of the main features why
web applications are developed
1094.476 -> because you have a lot
of web servers supporting,
1097.3 -> Java you Have
to deploy application
1100 -> on a particular web server
1101.8 -> and could access it
from anywhere across glue.
1104.7 -> You should be
on internet though.
1107.3 -> Embedded system when it comes
to embedded system.
1110.539 -> It has to be lightweight, right.
1112.8 -> So Java it I remember
Java version 8 had lot
1116.9 -> of feature making it pretty much
light weight when it comes
1120.543 -> to embedded systems.
1122.1 -> So basically you have
Micro addition j2me.
1126 -> What we are talking here
is j2se and the thing
1129.5 -> that we so there are
three flavors of java.
1133.2 -> So one is j2se,
1135 -> which is nothing
but standard edition
1137.1 -> and which is standard edition,
1138.984 -> which you have like all
the data types and stuff
1142.039 -> like that all four loops
and stuff like that.
1144.9 -> Right that is about j2se.
1147.6 -> You have G to EE
which is Enterprise Edition,
1150.765 -> which is nothing
1151.565 -> but the web application that
we spoke about and we have j2me
1156.684 -> which is micro Edition,
1158.761 -> which is nothing
but for embedded systems
1161.846 -> as its name suggests,
it is micro Edition,
1165.6 -> which is light in weight.
1167.7 -> And as we can imagine
that in embedded system,
1170.921 -> it has to be lighter
since it is burnt into a chip,
1174.5 -> right and you cannot have
a big application.
1177.7 -> So that's why
we have lightweight
1180.1 -> when it comes to j2me.
1183 -> So again as I touch base
on this it's about web servers
1187.243 -> and application servers
1189.153 -> which makes Java compatible
for web applications.
1193.4 -> So we have Apache Tomcat
1195.2 -> which is pretty much widely used
which was a web server earlier.
1200.1 -> Now, they have Apache Tom e
or which is Tom double e
1204.761 -> which is nothing but application
server version of it.
1209.1 -> So basically when it
comes to web servers
1212 -> or application servers,
1213.836 -> what you do is you
1215.23 -> as a client could send
a request to our web server
1219 -> and web server
1220.2 -> or the application server
would just process
1222.936 -> this particular request
1224.4 -> and send the response
the way the It's written.
1228.2 -> So basically it would serve
the expected result out.
1232.4 -> So you have
Enterprise applications.
1235.4 -> Again, this is
Java Enterprise Edition,
1238.323 -> which makes it favorable
for web applications.
1242.438 -> So all these
specifications j2me.
1244.9 -> J2w.
1245.8 -> J2se, this are nothing but
specifications exposed by Java.
1250.6 -> So if you as a developer
wants to do something
1254.1 -> or if you want to write your own
version of it you can do it.
1257.976 -> So where is Java used
again scientific applications?
1263.1 -> So I as you could imagine
in scientific applications,
1266.74 -> you need to have
high level of accuracy
1269.4 -> and precision rather.
1271 -> They could be
mathematical equations
1273.4 -> and mathematical computations
which needs lot of CPU time
1277.6 -> because it's very
CPU intensive right?
1280.1 -> When you do a very
precise calculation
1282.6 -> with high level of high degree.
1284.819 -> It needs lot of CPU time, right?
1287.5 -> So that's where Java is good at.
1290.738 -> So basically this is about as
a spoke about multi-threading
1295.2 -> utilizing all the course
to the fullest suppose.
1298.7 -> You have four core processor
using all these four cores
1302.7 -> is been done by
Java Java has feature
1305.6 -> or through threads you
could actually read through
1309.023 -> or actually utilize this
1310.7 -> for course to the fullest
Big Data Technologies again,
1315.5 -> big data is nothing.
1316.735 -> But as I said,
1317.6 -> it's distributed you cannot have
everything run on one machine,
1321.3 -> which was the case earlier.
1322.9 -> You would have one server put up
1324.7 -> and everything is done
on that particular server.
1327.4 -> Now, it cannot be the case.
1329.4 -> That's where Big Data comes
into picture wherein you
1332.4 -> have distributed architecture
1334.005 -> and you have this data
1335.333 -> being processed across Network
rather than just on one machine
1339.007 -> and mind you as I said,
1340.471 -> this machines are
commodity hardware
1342.7 -> and not server level Hardware
1344.6 -> or the Enterprise level Hardware
1346.4 -> which makes Cheaper Internet
of Things So Internet
1351.6 -> of Things is coming up
1353.152 -> the booming thing wherein you
could connect things together.
1357.317 -> Say, for example,
you have cars, right?
1360.5 -> So you could
connect cars together
1363.3 -> so you could have
sensors in your car
1365.506 -> which could emit data and you
could connect them together.
1369 -> So basically it's all connecting
things together or say,
1372.639 -> for example, let me talk
about internet itself.
1375.6 -> So earlier if you remember
computers were not connected
1379.8 -> it were all pure right.
1382.5 -> It could just be used
for your own purpose.
1385.7 -> Now internet has started
1387.2 -> wherein you have all
these computers connected
1389.737 -> and if you are connected
to the internet,
1392.011 -> you could go onto Google
and search something
1394.6 -> or whatever you want to sort of
1397.1 -> So basically this is what
internet of things is all about.
1401.13 -> So consider this
instead of computer.
1403.714 -> It could be any other objects
a car for example,
1407.17 -> as I said so consider
car has sensor
1409.658 -> and it is emitting
this sensor data every minute
1413 -> and we could utilize
this sensor data
1415.571 -> and do something
with it or one car
1418 -> can know where the other car is.
1420.7 -> So that's what internet
1422.1 -> of thing is about all about
connecting things together.
1425.819 -> Let's start off
with the setup setup for Java.
1429.8 -> So basically you could go
to this particular site
1432.5 -> and just download the SDK
based on this jdk, right?
1436.8 -> So basically based
on whatever platform you are at.
1440.2 -> If you are using Windows,
1441.5 -> you have to select Windows
if you are using something else
1444.3 -> if you have mac,
you can select Mac.
1446.4 -> So this is pretty much similar
1448.3 -> to other softwares you get
an exe file download it
1452 -> and you just have
to run that exe file.
1455.6 -> So basically I can show you
what gets downloaded.
1460 -> So I have downloaded
version 12 for Java
1462.947 -> as you could see here
and and since its Windows,
1466.5 -> it is mentioned as Windows.
1468.231 -> So this is nothing
but an exe file that you get
1471.1 -> which you could run
1472.329 -> and you would have
Java installed on your machine.
1476.16 -> So it's pretty simple.
1477.662 -> It's pretty much similar
1479.3 -> to other software's you
have say for example,
1483 -> or I could just show
you the location
1485.172 -> where it is installed.
1486.5 -> So if you get into
the program files,
1489.1 -> you can see javabean
installed here, right?
1492.4 -> And it says jdk 12.
1493.9 -> So once you install Java,
1495.656 -> once you download
this particular stuff jdk and
1498.782 -> once you install this
this executable you
1501.6 -> should be able to see
this Java folder
1504.045 -> in your program files.
1506.1 -> So it shows here.
1508.8 -> It's for you can select whatever
you want to see you have
1512.318 -> as you could see here.
1513.7 -> This line X there
is Windows Mac OS
1515.84 -> and stuff like that.
1517.1 -> You have to select
the platform you are
1519 -> on and should be good to go.
1521.5 -> This is done.
1522.422 -> You could see you get a exe
which you have to run.
1526.38 -> So basically to run Java
what you have to do is
1530.3 -> yeah.
1531 -> So you go to the system you have
control panel system you go here
1535.7 -> and you have to click
on Advanced system settings.
1539.3 -> Basically, what we are trying
to do is we are going to set
1542.4 -> an environment variable right
1544.3 -> and what we are going to set
is this path variable.
1547.6 -> So you have
1548.5 -> if you want to put it specific
to a particular user you
1552.062 -> can put it here put it
in the upper space
1554.638 -> or you want it
across the system.
1556.7 -> You could basically put
the path variable here
1559.472 -> in the system variables.
1561 -> So once you install it
you have to make sure
1563.759 -> that you have this particular
1565.62 -> path being put in
your path environment variable.
1569.1 -> So basically tells the OS
1571.023 -> that you have executables within
this particular directory.
1577.6 -> So once that is done,
1579.88 -> once you have
this properly setup,
1583.203 -> let me open a partial.
1585.8 -> So partial is nothing but it's
1587.3 -> pretty much simpler
to command prompt
1590 -> but it's a Linux flavor of it.
1592.615 -> So basically you could run
Linux commands as well.
1596.961 -> Okay, so I will I
will once this is done.
1600.3 -> Give me a second.
1602.5 -> Okay.
1603.1 -> So with partial you can do LS
1605.8 -> which would give you a listing
unlike in command prompt.
1609.6 -> You have to give dir.
1611.238 -> So it's basically
good for programming.
1614.5 -> So once you have
this properly set
1617.3 -> once you have
this path properly set
1619.7 -> if you write Java here,
1621.246 -> if you write Java
on your command prompt,
1623.937 -> you should be able to see
this help coming up here.
1629 -> So if it's not properly set up,
1630.9 -> you won't see this it would give
you unrecognized command.
1635.6 -> Yeah, open command prompt
and type Java.
1638.3 -> So once the path is properly set
you should be able to see this.
1643.1 -> So let's set up Eclipse as well.
1645.9 -> So it could be eclipse
1647.4 -> or IntelliJ whatever
you are comfortable
1650.14 -> with so you could use
either of them
1652.6 -> since IntelliJ has
much more features.
1655.3 -> You could use IntelliJ as well.
1657.8 -> So you go to Eclipse download
1661.2 -> and whatever flavor you
can take the latest one
1664.4 -> Whatever flavor you
want to install
1666.1 -> if you if you want
a simple one you can do it.
1668.869 -> If you're trying to do
something on web.
1671.269 -> You can download
that one as well.
1673.3 -> So basically for simple purpose
1675.473 -> for whatever we are going
to do you can have normal ones.
1679.8 -> So let me quickly open
up my so this is nothing
1683.5 -> but the IDE integrated
development environment
1686.961 -> that I use with just IntelliJ
1689.7 -> all the IDS are
pretty much similar.
1692.365 -> So IntelliJ similar to Eclipse,
so it's coming up.
1697.4 -> So basically what you do is
1699.13 -> you have to select a workspace
first workspace is nothing
1702.576 -> but all your program
1703.85 -> all the class files all
the class and everything
1706.843 -> that you write would be put
into this particular Works piece
1710.7 -> and you can create
a new class and start off.
1713.8 -> So when we get
to the hello world program,
1716.4 -> which is the first program
that we are going to talk
1718.8 -> about it would give
you a clear idea
1720.8 -> on what we are talking about.
1723.3 -> So let's talk
about Java internals
1726.7 -> how it looks like
1727.892 -> and all the features
that we spoke about.
1730.7 -> So basically so far
1731.919 -> what we have covered is more
about Java is object
1735 -> oriented program or it uses
object-oriented programming.
1739.3 -> Paradigm which is nothing
1740.995 -> but everything is thought of as
a class with a particular State
1745.2 -> and behavior right
is platform independent.
1748.5 -> That's why it's been widely used
it secured as well.
1751.62 -> That's why it's been used in
banking applications and stuff.
1755 -> It's good for
distributed computing
1757.2 -> since its platform independent.
1758.936 -> You don't you just
have to write it once
1761.035 -> and you can run it everywhere.
1763.1 -> So basically this platform
independent aspect is
1766.864 -> what helps it to be widely used
in Big Data applications.
1772 -> So let's talk
about the internals.
1775.1 -> So what is jvm jvm is nothing.
1777.7 -> But again, it's
a specification right?
1780.546 -> You could have your own jvm son
1782.95 -> by itself gives
specification for a jvm.
1786.1 -> This is what the GBM
should be all about so
1789.33 -> I could create my own jvm.
1791.4 -> But we usually we use
the reference implementation
1795 -> of sun Microsystems Oracle now.
1798.8 -> Right, so jvm is
a virtual machine
1802.1 -> that runs the bytecode.
1804.1 -> So basically there has to be
some level of compilation done
1808.4 -> before give him
can understand it.
1811 -> So that's where you
have Java compiler.
1813.849 -> And so what this does is nothing
but it takes your source code.
1818.474 -> It takes the class files as
or it takes the class
1822.282 -> that you write
1823.359 -> as is so Java compiler
would consume it
1826.3 -> and kind of compile it
into a DOT class file so
1830.3 -> dot class file is nothing
but compressed version of it
1833.467 -> and compiled version
of it as well.
1835.8 -> And this dot class file is
1838 -> nothing but it's also known
as bytecode and this is
1843.082 -> what a jvm could understand.
1845.4 -> So once you have
this class file,
1847 -> it could be sent to the jvm
1849 -> and jvm could understand
it and run the applications.
1852.813 -> So what makes Java
platform independent is
1855.967 -> this Java compiler is platform.
1858.2 -> Pendant you don't have
to take care about it.
1860.4 -> You just have
to run the compiler.
1862.3 -> And whenever you want to run
this particular byte code
1866.2 -> on any of the machines,
1867.969 -> you just have to have jvm
for that particular machine.
1872.5 -> Right?
1873.3 -> So basically if you
want to have online X,
1876.3 -> right if you want
to run it on Windows,
1878.7 -> you would have jvm
installed on Windows
1881.393 -> or you would download
the jvm for Windows.
1884.3 -> And if you want to run it
on Ubuntu or the Linux
1887.911 -> or Mac would just have
to have the jvm downloaded
1891.6 -> for that particular platform
1893.6 -> and it should be able to sense
this particular byte code.
1897.6 -> So basically this is what makes
it platform-independent.
1901.476 -> Right?
1901.9 -> As I said,
once you have this bytecode
1904.2 -> once you compile it this
bytecode could be transported
1907.317 -> or ported into any
1908.324 -> of the machines
in operating systems
1910.217 -> and you should be able to run it
1912.1 -> that is what it is all about.
1913.8 -> It's right ones
and run anywhere.
1916.2 -> So as I earlier
mentioned you could
1918.5 -> As get this class file
into your pen drive
1921.6 -> and take it anywhere
1922.9 -> and you could just
plug your pen drive
1925 -> and just run through
1926.181 -> that's how simple it is.
1928.1 -> So, this is Java
runtime environment where
1931.5 -> in you have set of jvm plus you
have libraries libraries,
1937.2 -> it does nothing
1938.003 -> but you know,
1938.7 -> although programs put together
all the programs source code
1942.2 -> for Java put together.
1943.7 -> So our T dot jar is
one of the libraries
1946.279 -> which would have
most of the classes
1948.663 -> or you have you till classes
maybe string class string
1952.772 -> is a class itself,
1953.997 -> which is exposed by Java.
1955.8 -> So this particular jar file
1958.6 -> or it's a Java archive jar
is nothing but Java archive
1963.4 -> which is set of java classes
or the class files rather
1967.092 -> which would have lot
of class files within so
1970.1 -> in our T dot jar you would have
something like string class
1974 -> and stuff like that a lot
of other classes,
1976.7 -> which is been used by the sea.
1978.5 -> Some are which has been
used by Java itself?
1981.412 -> So basically in JRE this is
1983.523 -> what you have jvm
plus set of libraries
1986.446 -> plus other additional files.
1988.6 -> So as spoke jvm is nothing
but specific to environment,
1992.6 -> but all these things
like Artie dot jar
1994.961 -> and stuff like that
would be independent GRE
1997.666 -> does not contain tools
1999.133 -> and utilities such as compilers
2001.2 -> or debuggers for developing
applets and application.
2004.612 -> So GRE by itself
the runtime environment,
2007.288 -> so it doesn't have compilers
and stuff like that.
2011.4 -> So jdk is nothing
but it specifically
2014.584 -> for development you
could see here.
2017.2 -> It's JRE plus development tools
you have compilers
2021.4 -> and stuff like that as well.
2023.6 -> So to run a class file,
2025.4 -> you just need the JRE but
if you are a developer,
2028.8 -> you would need jdk so
what we downloaded earlier
2032.211 -> if you remember
2033.3 -> that was jdk right jdk
for Windows or jdk for liners.
2038.3 -> So basically if you see
this one could see here as jdk.
2043.1 -> So essentially you need jdk only
if you are a programmer
2046.999 -> if you just want to run
the class file GRE would suffice
2051.4 -> so why is jdk GRE and jvm
2054.5 -> as we spoke about you
could see jdk is a superset.
2058.6 -> It has everything right GDK
would have your jvm.
2062.8 -> Plus it would have
as we spoke here.
2066.6 -> It's JRE plus your
development tools as well.
2071.7 -> As you could see here details
it has everything here.
2075.9 -> It would be really
confusing right now.
2078.8 -> If you directly get
into what all this is all about,
2082.4 -> but basically you
could imagine jdk is a superset
2085.9 -> and Jerry is nothing but
it's your runtime environment
2090.176 -> which has jvm
and some additional files
2093.2 -> or RT dot jar
2094.5 -> as we said
2095.307 -> which is nothing but set
of files set of class files
2099.1 -> that is exposed by Java
2100.8 -> which could be used
like string for example,
2103.822 -> right?
2104.8 -> Let's see how it works.
2106.195 -> So basically you have
your source file.
2108.542 -> So this is what a developer
would typically right
2111.6 -> would create a DOT Java file.
2113.5 -> So whatever you write
you create a class.
2116.5 -> You just create a new class
and write something to it.
2119.757 -> What you get is dot Java you
get the extension dot Tower.
2123.2 -> So basically this
is your source code,
2126.022 -> whatever you write you
2127.654 -> as a developer would
write this class.
2130.4 -> Is would be sent for compilation
or whenever you are good enough
2134.6 -> done with your coding
you would compile it.
2137 -> And once the compilation
is done once everything
2140.037 -> looks good enough.
2141.223 -> Once the compiler
2142.295 -> doesn't Mark anything and
doesn't flag anything rather,
2145.7 -> which means everything
is syntactically, right?
2148.6 -> You will get Java bytecode.
2150.48 -> Just nothing but dot class 5.
2152.9 -> Now.
2153.1 -> This dot class file
could be moved across Network
2157.2 -> or you could as I said,
2159 -> you could just put it
in your pen drive
2161.4 -> and can take it anywhere
2163.2 -> and you could run it
on any of the environments.
2166.548 -> You just have to have jvm.
2168.327 -> So basically you
could run this class file,
2171.2 -> which is compiled on Windows.
2173.04 -> You could run it on any
2174.5 -> of the environment
any of the platform's.
2177.5 -> So this is something that we
spoke about during runtime.
2181.145 -> There's a verification as well.
2183.2 -> So so when classloader would
load this particular class file,
2188.3 -> it would ensure
2189.4 -> that it is up to the Mark
or it's not manipulated
2192.8 -> sort of so if it all it
sees something wrong,
2196.3 -> then it would flag it off
2197.979 -> as you know corrupted
file or something.
2200.8 -> So this is nothing
2202.138 -> but Java class file libraries
are T dot jar that we spoke
2206.5 -> about Java archive.
2208.1 -> So this is what is happening.
2209.952 -> When you run a particular
class five, right?
2212.8 -> So you have this class loaded
and then you have this compilers
2218.1 -> just-in-time compiler
actually running it for you.
2221.4 -> So basically the part of jvm so
jvm is remember jvm is nothing
2226.1 -> but it's a platform.
2227.511 -> It is specific to platform.
2229.417 -> So basically for Windows you
would have a different jvm.
2233.22 -> And for line X you
would have a different jvm.
2236.457 -> So yeah, you get this class
2238.4 -> you load this class
using class loader
2241.1 -> and you run through
the application or run
2243.938 -> through the class files.
2246.2 -> So typically this is
2247.588 -> how Java operates so just
to give a just on this one.
2251.2 -> So you have a source code you
have dot Java file written
2254.6 -> you compile it you
get our class file
2257.1 -> and you can put
this class file anywhere.
2259.7 -> You can run this class file
anywhere on your network
2262.594 -> or wherever you want to you just
have to take this class file
2266 -> and on the machine
on which you run.
2268.4 -> What would happen is
2269.8 -> you load this class file
first using class loader
2273.4 -> and with jvm jvm would
have just-in-time compiler
2277.026 -> which would run
a particular class for you.
2280.3 -> Right?
2281 -> So what we are trying to do
here is you're running
2283.9 -> the source code
2284.7 -> that's written on any
environment you are running it
2287.7 -> on any other environment.
2289.078 -> So basically you
could write this on Windows.
2291.564 -> You could write
source code on Windows,
2293.8 -> but you could run it
on say for example line X.
2296.6 -> So that is what makes
it platform independent.
2299.9 -> So here let's create one class
2303.3 -> and as we created I
will More about it
2307.2 -> so that you could open
up your eclipse
2310 -> and could create something
like a new project
2314.6 -> so it could be a bit different
for you the look
2317.8 -> and feel might not be
exactly the same as mine,
2321.006 -> but you just have to create
a new project select Java.
2324.7 -> So basically I could
a project name.
2327.392 -> So whatever you want
to so basic nomenclature is
2331 -> like it has to start
with uppercase letter,
2333.9 -> which is camel casing right?
2335.8 -> So you should follow
camel casing venue.
2338.3 -> That's one of the best practices
2339.9 -> it won't flag you as
some error or something,
2342.5 -> but that's a normal
industrial practice that
2345.6 -> whenever you create
a Java project.
2347.95 -> It has to use camel casing
created record, Java.
2353.3 -> So it's creating
a project for me.
2355.6 -> And as you can see here,
2357.6 -> I have this particular project
being created right now.
2361.9 -> What I do is
I create Java class.
2365 -> So basically as we
2366.6 -> said everything could
be seen as a class,
2369.861 -> right that's what
object-oriented is all about.
2373.5 -> So basically what I would do
is I would create a class here.
2378.6 -> So this is my source folder
2380.6 -> where enormous Source class
would be there.
2383.9 -> So as you can see here
new Java class so say
2388.2 -> I create calm dot Ed u-- Rica.
2391.6 -> So this is nothing
but your name space
2394.446 -> or the package, right?
2396.5 -> So you could give whatever
you want to basically this is
2400.121 -> to avoid collisions, right?
2401.9 -> If we don't have a name space
there would be lot of collisions
2404.999 -> within the class.
2406 -> So there are a lot
of people working
2407.9 -> on the same project right so I
could create a class with name.
2412.1 -> Class A and the other person
might read classy as well.
2416.8 -> So when this is club together
into one particular application
2420.563 -> there would be Collision
So to avoid this basically
2423.7 -> what you have is
2424.9 -> you have a namespace.
2426.234 -> So I would write as calm
down dear a card dot Class A.
2429.6 -> The other person
would write something else
2432.1 -> and that would avoid class name
collisions Applause collisions.
2436.7 -> So this is compounded
Eureka is my package
2440.3 -> or namespace and hello
world is my Java class name.
2447.9 -> So as you could see here,
2449.803 -> there's a package calm
down Ed Eureka,
2452.62 -> which is again a namespace
2454.6 -> and there's a class by name
hello world that's been created.
2458.804 -> Right?
2459.4 -> And if you want to see
you could actually go
2462.807 -> and so you can see
a folder structure
2465.6 -> created here in the source.
2467.246 -> So this is your Source folder
right within your project.
2470.6 -> There was a source folder
where in we created the class.
2473.637 -> So if you go
2474.3 -> to the source folder you
could see a packet structure
2476.9 -> or you could see a directory
structure being created
2479.8 -> which starts with calm
2481.1 -> and within calm you
would have at Eureka
2483.5 -> and here you can see
Hello World dot Java.
2486.307 -> So remember we said
2487.553 -> that your source code
would have all the Java files.
2490.9 -> So basically this is
what I was referring to.
2496.3 -> This is a method
2497.4 -> that the default method
that's been called.
2500.031 -> So when you run
this particular class file
2502.6 -> jvm would actually look out
for this particular method.
2506.7 -> So you need to have
the same signature
2509.176 -> as has so you would have a main
2511.251 -> method wherein your program
execution would start, right?
2515 -> So as then when you compile
it and run the class file,
2519 -> so basically when you compile
it you would get a class file,
2522.2 -> right and when you run
2523.8 -> this class file jvm would check
out for this main or a method
2528.236 -> that has the same
signature as this one.
2530.988 -> That's a main method
2532.4 -> and your program execution
would start running from here.
2536.2 -> So basically it's a entry point
for your execution, right?
2540.4 -> So this would be
2541.577 -> a simple program wherein we
would just print hello world.
2546.084 -> So basically you have
2547.7 -> like system system is
a class and this is
2551.035 -> how you print in Java.
2553.3 -> So I don't want to confuse
right away by saying
2556.64 -> what is system
worries out and println,
2559.43 -> but basically what you
have is a system is a class
2563.2 -> as I said everything
Could Be Imagined as a class.
2566.587 -> So in Java everything
is a class.
2568.9 -> So basically you
could just click here
2571.3 -> and you could see
the source code of it, right?
2574 -> This is the source code
and this is coming
2576.3 -> from our T dot jar
remember in jvm.
2579.2 -> We spoke about in GRE.
2581.1 -> We had our DDOT jar.
2583.5 -> We had Jerry we had jvm
plus plus class files.
2587.8 -> So all this has been written
by Java by the Java community.
2592.1 -> So basically you can see here.
2594.3 -> This system itself is a class.
2596.5 -> So out is instance variable
2598.7 -> and println is nothing
but a method within out so
2603 -> what this statement
particular thing is going
2605.699 -> as nothing but writing
it on to your console.
2608.5 -> So let's print hello world.
2613.2 -> So basically when you build
a project it's compiling it
2616.645 -> as you could see here.
2618.049 -> It's saying it's building it.
2622.834 -> So once it has built it you
could see a class file here.
2627.1 -> Right?
2627.9 -> So you could see here
hello world dot class.
2631 -> This is because we built it
when you build it.
2635.2 -> Your Java file would be
compiled by your compiler
2639.4 -> and it would create
a DOT class file.
2641.3 -> And remember as I said,
2643.2 -> this class file dot class file
could be run on any machine.
2647.4 -> So this is Windows machine
2649.334 -> that have written
this file Java file
2652.064 -> and compiled on now.
2653.531 -> This dot class file could run
on Linux or any platform
2657.419 -> that you want to run it on.
2659.7 -> So, let me talk
about this class.
2661.823 -> Right?
2662.6 -> So you have a public key word,
2664.677 -> which is nothing
but access modifier
2667.1 -> which gives visibility.
2668.7 -> So basically what we are trying
to say here is hello world is
2672.545 -> publicly could be publicly seen
2674.531 -> so it could be seen anywhere
within the application.
2677.8 -> So basically for class level
you have public which
2681.369 -> as the name suggests.
2682.9 -> As the name gives out it
could be seen anywhere
2686.166 -> within your application
2687.8 -> that the visibility
key access modifier.
2690.7 -> All right, so you have
the keyword class here,
2693.8 -> which is for the class.
2695.2 -> You need to have
it mentioned as class.
2697.4 -> If you write something else,
2698.8 -> then it would give you
a compilation error.
2701.3 -> So it has to be
exactly the same.
2703.6 -> All right, that's
the syntax of it.
2705.7 -> Hello is nothing
but the name of your class,
2708.7 -> then you have this public
static void main,
2711.4 -> which is nothing but as I said,
2713.3 -> this is the entry point
for your application
2716.212 -> or your class file.
2717.5 -> So when you run
this particular class,
2719.594 -> it would start off from here.
2721.3 -> You have a static keyword
static keyword is nothing
2725.1 -> but it's at the class level.
2727.21 -> So basically you
need not create instance.
2730.3 -> We haven't reached
that point yet.
2732.5 -> So basically hello is a class
2734.8 -> and you could create
instance of hello,
2737.4 -> which is nothing
but object right?
2739.889 -> So when you have
a static keyword here
2742.705 -> You need not create object
of hello to run it
2746.09 -> if it's not static,
2747.638 -> then you need to have
object of hello created.
2751.1 -> So basically what I'm trying
2753.253 -> to say is see you have
one more method here,
2757.6 -> which is test.
2760.2 -> Now this doesn't have
a static keyword here.
2763.3 -> So basically what we
can do is we can print So
2772.297 -> yeah, this is a non-static
method right now.
2775.8 -> We cannot call it directly.
2777.9 -> If it's a non-static.
2779.26 -> You need to have a instance
of Hello World created.
2782.51 -> So basically how you
create instance is nothing
2785.5 -> but hello world.
2786.73 -> That's your hello world object.
2789.5 -> So when I say
instance I'm talking
2792.1 -> about creating object, right
2795 -> and you could create
new hello world.
2798.5 -> So object of hello world is
created using new keyword right?
2803.8 -> When you do this you
would get object of it or now.
2808.3 -> What I do is so basically
2810.3 -> what I was trying to say is
you cannot call test
2813.6 -> as is if you do it you would get
a compilation error saying
2817.625 -> that non static method test
cannot be referenced
2821.3 -> from a static context, right?
2823.4 -> You cannot call it
without having your object.
2826.9 -> So basically I can call it
2828.9 -> on Hello World object DOT test
Now I can call it now.
2833.4 -> It doesn't give
me compilation error.
2836 -> I'll create one
more static method
2838 -> which would give you some idea.
2841.4 -> So I will rename this
as non static test
2845.9 -> and this would be static test.
2849.946 -> Right and we are printing
your static method
2853.6 -> and here we are printing
non static method.
2856.9 -> So hello world
dot nonstatictest.
2861.1 -> Now, whereas the static test
did not be called using object
2865.9 -> so we could directly
call static test.
2869.6 -> Sorry, I haven't
written static here.
2872.4 -> So this is a static method.
2875.5 -> Okay, so now you could see here.
2879.546 -> It compiles fine.
2881.7 -> Right?
2883 -> So what I was trying to say is
2885.3 -> when you have a static
method you do not have
2888 -> object to call it.
2889.147 -> Whereas non-static method
you need to have object.
2892.269 -> That's what the static
is all about.
2894.475 -> Then you have void is nothing
but the return type
2897.5 -> it's not returning
anything from here.
2899.676 -> So that's why it's void.
2901.088 -> You have main method.
2902.323 -> That's the key word
2903.441 -> that the entry point
for your application.
2905.7 -> You have this arguments.
2907.684 -> You can see string
array of strings
2910.3 -> which are arguments provided
to a particular program.
2913.4 -> So you could pass
on as many arguments
2916.196 -> as you want or
if your program is say,
2918.9 -> for example,
2919.769 -> you want to pass your name as
an argument you can do that.
2924.2 -> So this is arguments then we
2926.9 -> have main which represents
the Above the program
2930.046 -> which I already mentioned then
2932.135 -> we have system dot out
dot println is nothing
2935.2 -> but the print statement
2937.1 -> so as I mentioned system
2938.527 -> is nothing everything
could be thought of
2940.993 -> as a class system is a class
out is instance variable
2944.2 -> and println is
a method within out.
2946.8 -> So basically you don't have
to think much about it just
2950.047 -> to understand the structure
of it just to understand
2953.178 -> how a particular class
is been written.
2955.511 -> This is what we have.
2956.8 -> This is how we write
a class right again,
2959.8 -> just to brief on this
you have access modifier
2963 -> which denotes the visibility
of a particular class.
2966.5 -> You have the class name you have
the main method which is nothing
2969.841 -> but the entry point
2970.972 -> for your class you
have a static method,
2973.315 -> which says whether you need
2975.023 -> an object to call
a particular method
2977.3 -> or could be called
directly from a class.
2980.005 -> You have a return type here.
2981.9 -> So this is how typically
any method would be written
2985 -> and you can write
2986 -> whatever statements you want to
within this particular method.
2989.389 -> This case we have printed
out hello world.
2991.9 -> So basically you
could follow this
2994.1 -> when you do it on Eclipse,
2996.4 -> so it might be a bit different
based on the eclipse version
3000.146 -> that you would have
3001.374 -> but it should be
pretty much similar.
3004 -> All right, so you create
a new Java project.
3007.7 -> So I showed this
already on IntelliJ,
3010.8 -> which is also widely used IDE.
3013.9 -> But yeah, you could use
Eclipse as well.
3016.4 -> So basically you
3017.414 -> could see the project name
being written as hello world,
3021 -> right and here it mentions
the JRE to be used.
3025.6 -> So here you can see class class
being created and let's see
3030.687 -> how we can run this.
3033 -> So we compiled it and we saw
that dot class file was created.
3038.13 -> Now we can run this.
3039.9 -> So as I said main
is the entry point
3042.7 -> so it would start
running from here.
3045.2 -> So your program control
would come here.
3048.1 -> And the first thing
3049.273 -> that it would see is you
have printed hello world,
3052.3 -> so it should print this one
then I would keep it simple.
3056.235 -> I don't want to let's see
what's been printed here, right?
3061.1 -> So you could see here.
3062.5 -> Hello world being
printed first, right?
3064.9 -> This is where the program
execution started from.
3068 -> So it came to mean so
hello world it printed
3071.556 -> out hello world.
3073 -> Then you give a call to
this non static method.
3076.607 -> So it printed non-static method
3079 -> which is been printed
in this particular method
3081.9 -> and then it gave
a call to static method
3084.9 -> and you could see static method
being printed here.
3088 -> So one thing to remember is
the program execution starts
3091.8 -> from Maine and it just you
know executes this main method.
3096.1 -> So whatever content
you want to write you
3098.1 -> would basically write it
in the main method
3101.488 -> so you could see here hello
world being printed out.
3106.4 -> Let's see how easy it is
to coat the same in the J shell.
3111.2 -> So J shell is nothing
but shell prompt
3113.939 -> that was created
3115.124 -> in Java version 9 since nine
you would have gesture.
3119.1 -> So since I have
Java version 12,
3122.3 -> I should have J shell as well.
3128.9 -> So yeah, J shell is
nothing but a prompt
3132.8 -> so it's nothing but
instead of writing
3135.15 -> into integrated workspace.
3136.8 -> You could have J shell
3138.082 -> and you could pry
out something here.
3140.2 -> It's not something
for production use
3142.3 -> as such it's basically
3143.83 -> to test something right
you as a developer could
3147.165 -> if you want to see what
3148.7 -> it does instead of writing
everything into the main.
3151.83 -> So if you write a class you
3153.305 -> would have to write
things into the main
3155.607 -> and then run it and stuff
like that with J. Shell.
3158.5 -> It's just a kind of interpreter
wherein we could write something
3162.144 -> some command and see
what the output is.
3164.6 -> So basically you could say for
example we printed hello world,
3168.8 -> right so system dot
out Dot println.
3174.6 -> Hello world, right
if you remember this is
3177.7 -> what we typed into
our main method plate.
3180.7 -> So if you want to run
this you have to have
3183.8 -> all this artifacts created
3185.533 -> as is right to have a class
you need to have main method
3189.214 -> and then build the class
3190.886 -> and then run it basically
initial you could run it
3194.3 -> just to see what's output.
3196.7 -> As I said,
3197.379 -> this is not application
as such this is just
3200.3 -> for the developer to test
3202.046 -> what the output for
a particular command would be
3205.6 -> and what a modifiers in Java.
3208.3 -> So one thing
3209.4 -> that we saw in the program
was access modifier.
3212.9 -> We already saw about actually
this one right public
3216.233 -> and these are public
here as well.
3218.5 -> So these are nothing
but modifiers right public
3221.643 -> as I said this public means
the access modifier which shows
3225.5 -> that hello world
3226.528 -> could be accessed anywhere
throughout your application.
3230.1 -> So here we can see as a board
or the fries changes.
3233.533 -> Meaning of other phase
in some so basically it
3236.533 -> just trying to say that one
of the aspects are one thing
3240.293 -> that access modifier
could be used is
3242.8 -> to control the visibility
of a particular class
3246.075 -> or a method as well.
3247.753 -> We have access modifier
for your methods as well.
3252.1 -> So this is just one
3253.32 -> of the things right we
would see other modifiers
3256.4 -> as well modifies in general has
some other things as well.
3260.2 -> But when it comes to access
modifiers it basically
3263.5 -> controls the visibility
of a class visibility of a class
3267 -> or a method or so.
3268.7 -> Yeah modifiers here
3270.2 -> as you could see there is access
and on access modifiers,
3274.611 -> let's see access modifiers.
3276.8 -> So we use public already.
3279.443 -> So this one is nothing
but a access modifier
3282.8 -> which is public which says
3284.715 -> that it could be used
throughout the application so
3288.4 -> visible to the world
3289.742 -> as it says public is nothing
but visible to the world.
3293.3 -> If we talked about
in a logical order
3295.556 -> if we talk about the visibility
3297.7 -> so default is visible
to the package.
3300.8 -> So default is nothing
3302.245 -> but within the package
it would be visible.
3305.186 -> So basically you could default
3307.274 -> is without any keyword
without any access multi-faith.
3310.824 -> That's a default scope So
3312.53 -> within the package it
would be accessible only
3315.6 -> within the package.
3316.9 -> So you have like
calm down Eureka.
3319.3 -> That's your package.
3320.4 -> Right?
3320.9 -> So this hello world
would be accessible
3323.8 -> if it has a default scope.
3325.8 -> It would be accessible only
within calm down Ed Eureka.
3329.4 -> If you try to access it
3330.766 -> from some other package
you would get an error.
3333.7 -> So that's the default
visibility:visible to
3336.9 -> the package private is nothing
but it is visible to the class.
3341.8 -> It is only visible to the class.
3343.9 -> So this is the lowest visibility
only visible to the class.
3347.442 -> If you try to access it
from outside class even
3350.245 -> within the same package
you would get an error
3353.133 -> because You won't be able
to access it is accessible only
3356.523 -> within the class public
is accessible to the world.
3359.58 -> It could be accessed from
anywhere within your application
3363.265 -> or anywhere within your wherever
your class file.
3366.2 -> So basically if you
if you have a jar file,
3369.1 -> but what I'm trying to say
is public is accessible
3372.7 -> anywhere right protected is
again visible to the package
3377.751 -> and all the sub classes.
3380 -> So we will talk
about sub classes.
3382.4 -> So subclasses is nothing
but in C we have inheritance,
3386.476 -> right say for example
3388.1 -> integer integer is a class
3390.6 -> as I said in object-oriented
Paradigm or in Java everything
3394.871 -> could be visualized as a class.
3397.1 -> So integer itself is
a class, right?
3400 -> So there's a number
there is a super class
3402.916 -> which is number which has all
the common state and behavior
3406.9 -> that a particular number
would have right
3409.596 -> so number is a super class
3411.411 -> and you have subclasses
3413.067 -> like Teacher float
would be a subclass
3415.686 -> of number long would be
a subclass of number.
3418.8 -> Basically.
3419.523 -> This is inheritance,
3420.7 -> right you are inheriting integer
float long double and everything
3426.5 -> from number class.
3427.9 -> So number is a super class
and all this integer float
3432.3 -> and everything is
a subclass of number.
3435.157 -> So when it comes to protect it,
3437.6 -> it says that it is visible
to the package
3440.676 -> and of the sub classes,
3443 -> so just to keep
in mind as of now,
3445.403 -> you can think of access
modifier as visibility
3448.6 -> of a particular component
3450.325 -> or could be visibility
of a class or visibility
3453.5 -> of a method or instance
variable as well.
3456.6 -> This is what drives
the encapsulation factor
3459.567 -> of object-oriented Paradigm.
3461.5 -> So basically we control the
access or all this components
3465.607 -> or we control the access
3467.3 -> of class variables
methods and everything
3470.1 -> which makes it encapsulated
cannot be breached.
3473.6 -> Sort of as you could see this is
3476.6 -> like I could make this one
as default as well.
3480.7 -> All right, so this
is default scope.
3483.2 -> It would still run
because it's within the class.
3488.4 -> Right now suppose I make
this one as private, right?
3494.4 -> Just to show you what
this encapsulation is all about
3497.7 -> or what this access modifier
is all about suppose.
3500.9 -> I make this one private right
still this one runs
3503.911 -> because it within the class
you are trying to access it
3507.3 -> within the class now.
3509 -> I create a new class
say for example,
3511.8 -> we say axis modified test.
3517.6 -> So I create a main class
here again main method.
3522.9 -> Now suppose if I try
to run this, right?
3525.727 -> So basically I create
the same stuff here.
3528.7 -> See I create
a hello world object.
3532.2 -> Okay.
3535.3 -> Now this one is
private right now.
3537.483 -> If I try to access it from here,
3539.7 -> what I was trying
to say is if I SEC
3545.769 -> as you could see here it says
3548 -> that nonstatictest has
a private axis to hello world.
3552.2 -> So you cannot use
it from outside.
3553.925 -> That's what I was trying to say.
3555.683 -> So basically since it
has got a private scope
3558.1 -> you cannot access it
from other class.
3560.3 -> And if I remove this private now
with gives it default scope and
3564.202 -> as we said default is nothing
3566.06 -> but it has got access
3567.406 -> within package you could see
this error going off here
3570.804 -> now it is accessible, right?
3573.1 -> So that's what is it is all
3574.9 -> about when you have
a private scope.
3577.6 -> It's within a class.
3579.4 -> There is default is
3580.797 -> within a package public
is accessible anywhere
3584.078 -> and protected is visible
to the package
3586.849 -> and just the subclasses.
3589.611 -> So let's talk about
non access modifiers.
3592.8 -> This is not controlling the axis
of class method or variable
3597.2 -> when it static you did
not create object of a class.
3600.9 -> So basically for static
test you could see
3603.5 -> that we didn't create
object of a class.
3605.9 -> We didn't call static test
on a particular object of class.
3609.3 -> It could be called directly.
3610.966 -> That's what static is all
about the static modifier
3614 -> for calling methods
3615.166 -> and variables without an object
to which it belongs
3618.178 -> as we saw we
didn't create object
3620.173 -> of our fellow world we directly
cause the static method final is
3624.1 -> nothing but you
can't change it final
3626.5 -> as the name suggests.
3627.9 -> You can't change it
once it is created.
3630.135 -> So finalizing
the implementations
3632.2 -> of classes methods
3633.6 -> and so this is nothing
but instance variable
3636.304 -> which we would be talking
3637.783 -> about the slides to come just
3639.5 -> to tell you this is
an instance variable
3641.8 -> which we have assigned
the value 10 now suppose
3645.024 -> within this particular method I
try to change the value to 11.
3649.3 -> You would get an error saying
3651.2 -> that cannot assign a value
to final variable.
3654.098 -> So final is like its final
can't change it
3656.9 -> once you have created it.
3658.2 -> You can't change it.
3659.2 -> But if I remove
3660.115 -> this final you could see
this error would go off.
3663 -> You don't see
this error anymore.
3664.895 -> Whereas by putting final
you would see this error.
3667.877 -> So that's what
final is all about.
3669.782 -> So basically this is good enough
for constants, right?
3673.029 -> So if you have constants
3674.5 -> within your class you
would make it final
3677.231 -> so that no one can change
it abstract is nothing but
3680.591 -> you could mention it as abstract
3682.728 -> when it doesn't
have implementation
3685 -> of all the methods.
3686.8 -> So what I am trying to say
is abstract modifier is
3689.8 -> again a non access modifier
and what it tries to say is say,
3693.817 -> for example,
3694.629 -> you have a shape class
cheap class is abstract class
3698.389 -> because shape doesn't say
you want to calculate
3701.6 -> area of shapes.
3703.1 -> So basically shape class
3704.885 -> by itself wouldn't know what
the area of the ship would be.
3709.2 -> Is a class where in the generic
class it doesn't know
3712.89 -> what the implementation
of area would be 4 Square.
3716.271 -> It would be Side Square
3717.899 -> for rectangle its length
into breadth or Circle.
3721.193 -> It's pie R square.
3722.515 -> So basically shaped by
itself wouldn't know
3725.505 -> what it's area would be
3727.162 -> but now shape is a super class
and say you have subclasses
3731.162 -> of it like Square you
would have Circle and so on.
3734.616 -> So now basically
you want to ensure
3736.909 -> that when you create a subclass
3739 -> of the shape class
you want to ensure
3741.499 -> that that particular class
implements the area that's
3744.812 -> when you create it as abstract.
3746.889 -> So the shape method would have
3748.9 -> of the shape class would have
area method as abstract
3752.8 -> which would be implemented
by the subclasses
3755.776 -> which has to be ensured
its kind of ensuring
3758.803 -> or if the subclasses
don't actually implement
3761.746 -> it you would get a error.
3763.477 -> So basically Circle would have
its own implementation of areas
3767.696 -> in pie R square square.
3769.371 -> Would have its
own implementation
3771.7 -> saying Side Square.
3773.105 -> So basically what I'm trying to
say is area is abstract method
3777.458 -> for shape class.
3778.6 -> And when you have
abstract method the class
3781.3 -> itself is abstract.
3782.624 -> So you have like shape calm
down Eddie record dot shape.
3786.594 -> I'm creating a class now.
3788.377 -> I'm creating a abstract method
So when you say abstract,
3792.3 -> you don't have
to provide implementation.
3794.547 -> It's just a chain break
this thing you don't have
3797.064 -> implementation of it.
3798.329 -> You just have
the signature of it.
3800.394 -> So basically as I said,
3801.9 -> when you have an abstract
method the class
3804.6 -> itself should be abstract.
3806.371 -> So we'll have to make
this abstract as well.
3809.3 -> So you created a shape class
3811.06 -> which would have a area and
which would give you this thing.
3814.682 -> So basically we want to have
subclass and want to show
3817.918 -> how the sub classes
are created at this point.
3820.504 -> But basically this is
what abstract is all about.
3823.105 -> You don't have
the implementation of it,
3825.4 -> but you are ensuring
that subclass is implemented.
3828.226 -> So here you can see
Just a signature.
3830.544 -> You don't have implementation
3832.1 -> unlike this implementation
is nothing but
3834.452 -> if you write something
within this braces,
3836.726 -> this is an implementation
for this particular method,
3839.785 -> whereas in shape class.
3841.121 -> You just provided
the method signature,
3843.394 -> but we don't have
limitation of it.
3845.511 -> So that's what abstract
is all about synchronized
3848.5 -> and volatile is much
3849.941 -> about using threads
synchronized is we are saying
3853.5 -> that only one thread could get
a control at one point.
3857.1 -> So as we said threads are
nothing but parallel execution
3860.724 -> you could have
thread say for example,
3863.16 -> you could have read
one calling a method.
3865.901 -> So we have as non
static method test
3868.271 -> right say this is a method.
3870.1 -> So what we are trying
to say here is
3872.398 -> if it's synchronized we can make
3874.5 -> this a synchronized
private synchronized.
3877.343 -> So this is what id is all about.
3879.545 -> So when you have this integrated
development environment,
3883.4 -> you don't have
to type everything
3885.464 -> when you type S why you could
see synchronized coming up here.
3889.4 -> Put selected.
3890.3 -> So when you put
a synchronized here,
3892.459 -> what we are trying to say is
only one thread could access it
3896.4 -> at a given point only
one thread at one point.
3899.8 -> So if multiple threads
are trying to access it
3902.6 -> one thread has to wait for it.
3904.459 -> So only one thread
would get entry to this
3907 -> and the other thread
should wait for it.
3909.3 -> So that's what synchronized is
all about and volatile.
3912.8 -> It's basically for
memory visibility or
3915.6 -> what we are trying to say is
so basically every processor
3919.9 -> has got its own cache.
3922.107 -> So what we are trying to say is
3924.6 -> when you use a volatile access
specifier don't store it
3928.7 -> in Cash Store it directly
into the main memory
3931.7 -> so that all the threats
3933.052 -> would get the most
recent value being assigned
3935.9 -> to a variable also
volatile is not needed
3938.6 -> when you have using synchronized
3940.5 -> as such so it's
mutually exclusive.
3943.5 -> So let's talk about variable.
3945.415 -> So variables are nothing
but it's a holder, right?
3949.2 -> Holds value and variables are
nothing but it's reference
3952.937 -> to that particular meal
3954.6 -> or it's a dress or something
3957 -> that is pointing to a memory
location a memory location
3960.2 -> where the squirrel use
are being stored
3962.188 -> and you could access it using
this particular variable name
3965.699 -> or you could access
the memory location
3968 -> where the value is stored
using a variable name
3970.8 -> what I'm trying to say here is
3973 -> so this is a variable
and you could access
3976.4 -> so this 10 is stored
somewhere in the memory
3979.148 -> and you could access this part
of memory location
3982.215 -> where this 10 is stored
using this variable
3984.9 -> or you can manipulate it
as well can change the vat.
3988.7 -> So basically there are
three types of variables in Java
3992 -> this local instance class
or static local is nothing
3995.79 -> but local to your method
whenever you have a method
3999.603 -> or you kind of create
a variable within a method
4003 -> that is nothing
but local scope which is
4005.555 -> like it has the axis
its visibility only within that.
4009.18 -> Particular method once control
goes out of this method you
4012.991 -> can no longer access
is particular variable
4015.8 -> that is local.
4016.766 -> So if I Define something
here say, for example,
4019.942 -> I Define something here.
4021.611 -> So this is a local variable
4023.8 -> since its defined
within a method.
4026.2 -> So once the control you
would have this only
4029.027 -> within this particular method,
4031 -> once the control goes
out of this method.
4033 -> This is no longer accessible.
4034.727 -> Basically, this is
4035.8 -> where garbage collection
for Java is useful.
4039.1 -> Once you control goes
4040.424 -> out of this particular method
garbage collector would kick in
4044.302 -> and were dean of this variable
4046.005 -> or clean of this particular
memory location or would make
4049.5 -> it available for use.
4051.3 -> So that's the local scope.
4053.012 -> The next one is
4053.994 -> instance instance is
nothing but something
4056.73 -> that is defined
at the instance level.
4059.2 -> So this is instance variable.
4061.3 -> So since it's
at the class level,
4063.9 -> right this is you could see
it at the mid-level.
4067.2 -> This is at the class level.
4069.1 -> This is nothing but
an instance variable now there
4072.6 -> is static variable as well.
4075.3 -> So this is how you define
a static variable.
4078.3 -> So instance variable is
nothing but it's per instance
4082.6 -> so you could go and change
this instance variable
4085.9 -> to something else suppose.
4087.9 -> I assign a value for T here now.
4090.4 -> I could have one more object
created suppose I call
4094.246 -> this object one
4095.4 -> and I have Hello World object.
4097.919 -> So I create
one more object here.
4100.4 -> So what we are trying
to do is we are trying
4102.9 -> to change the instance
variable through objects.
4106.3 -> So basically this is
what it is when you
4109.2 -> have an instance variable
normal instance variable,
4112 -> which is non static
you could access it
4114.7 -> through objects, right?
4116.278 -> So throughout object one you
4118.208 -> assign for object one you
assign instance variable value
4122 -> to 44 object to rinse
you change the instance
4126.1 -> variable value to 50.
4128 -> I won't say Changed it.
4129.711 -> But you assigned it.
4131.2 -> This is how you deal
with instance variable.
4134 -> It's at the instance level.
4135.869 -> It's at the object level.
4137.6 -> Whereas for static.
4138.979 -> It's at the class level.
4140.7 -> It's one per class.
4142.035 -> It's not one per instance.
4143.864 -> It's one per class.
4145.193 -> So basically what you can do
is you could do something
4148.9 -> of this sort where in its
at the class level.
4151.552 -> It's not at the object level.
4153.3 -> You are assigning value hundred
to a static variable.
4156.4 -> So as you could see here,
4158.2 -> it's not a particular instance
4160 -> that you're operating
on its the class directly
4163 -> just to give you a just
we have local variable
4165.73 -> which is within a particular
method and scope
4168.4 -> remains within a method.
4169.9 -> Once the program control moves
4171.999 -> out of this particular method
Java would or jvm would come in
4176.131 -> and kick in garbage collector to
clean this off Sony accessible
4180.5 -> within this menu you
have instance variable,
4183.2 -> which is at the class level,
4185.384 -> but it's non-static
and which means
4188 -> that it has copy.
4189 -> Per object when you
have multiple objects,
4191.9 -> you could change
the values the way you want
4195 -> per object static is nothing
4197.1 -> but 1 per class and
as you could see here,
4200.4 -> we change the value of
the static variable 202 class.
4204.4 -> So that's about variables.
4206.5 -> We have an instance.
4208.4 -> So instance variables
are declared in a class
4210.722 -> when the space is allocated.
4212.213 -> I will just read
through this one.
4214.1 -> So when a space is allocated
for an object in the Heap slot
4217.6 -> for each instance variable
is values created.
4220.497 -> We had a your instance variable
4222.46 -> and whenever you create
but basically an instance
4225.8 -> of a class is created
in a part of a memory,
4228.5 -> which is called Heap.
4230 -> So whenever hello
world object is created a slot
4233.6 -> for this instance variable
4235.4 -> would be treated as well
instance variables are created
4238.9 -> when an object is created
4240.554 -> with the use of keyword
new and destroyed
4243.2 -> when the object is destroyed.
4245.1 -> So unlike local variables,
4246.848 -> which is within
the method scope.
4249.2 -> Variable is within
the class scope.
4251.2 -> So basically whenever
you create an instance
4253.742 -> of a particular class,
4255 -> your memory would be allocated
4256.723 -> for that particular
instance variable.
4258.9 -> And whenever it's done
4260.2 -> whenever it's destroyed
by the garbage collector,
4262.9 -> it would go off
4263.98 -> access modifiers can be given
two instance variables.
4267.7 -> You could have like
private public protected default
4271.2 -> all the access modifiers.
4272.8 -> We assign to students variable.
4274.731 -> So basically you could have it
4276.6 -> as private private is just
within this class.
4279.8 -> You cannot access it
4280.8 -> outside this class you
could have public as well,
4283.74 -> which is like would be accessed
anywhere within this application
4287.6 -> you could have protected
4289.24 -> which is like within the package
4291.465 -> or the subclass and you can have
the default one which is nothing
4295.759 -> but package axis,
4296.9 -> which would be accessible just
within this package
4299.9 -> that is calm dotted Eureka.
4301.6 -> So instance variable
have default values
4304.2 -> for numbers the default value
zero for Boolean it
4307.4 -> is false for all.
4308.9 -> Big references it is null
4310.823 -> so values can be assigned
during the Declaration
4314.7 -> or within the Constructor you
could assign values directly
4319.1 -> while declaring it something
4321.1 -> like this instead of 0 is
the default one for integer
4324.8 -> as they have mentioned.
4326.07 -> But yeah, you could assign
4327.6 -> if you put it as 10
4328.9 -> here it would be taken
as a default value
4331.5 -> zero zero Constructor
is nothing but a method
4334.5 -> which constricts an object
4336.5 -> of a class values can be
assigned during the Declaration
4340.2 -> or within the Constructor
instance variables
4343.368 -> can be accessed directly
by calling the variable name
4347.2 -> inside the class.
4348.2 -> However, with static methods
4350.8 -> when instance variables
are given access ability.
4353.913 -> They should be using
fully qualified name.
4356.571 -> So what we are trying to say
here is this is a static method
4360.287 -> from which we are trying
to access instance variable
4363.6 -> in this particular
static method you need
4366.2 -> to have object reference.
4368.2 -> This is Object
that we created so
4370.8 -> object reference dot instance
variable you need to have
4374.175 -> as we have mentioned here.
4375.8 -> So here as we can
see object reference
4378.147 -> to a variable name.
4379.352 -> You need to have
fully qualified name.
4381.7 -> When you try to access it
within the static method.
4384.2 -> You need to have
fully qualified name.
4386.1 -> Whereas here within a method
which is non static.
4389.8 -> This is non-static here.
4391.501 -> I can access instance variable
without object reference.
4395.5 -> So here as we can see it
could be accessed without but
4399.5 -> if I do it here it
would throw me an error.
4402.508 -> It's not accessible here at all.
4404.8 -> Non-static Fields instance
variable cannot be referenced
4408.351 -> from static context
instance variables are
4411.3 -> not accessible directly here.
4413.6 -> It has to have fully
qualified this thing,
4416.1 -> which is object reference
dot instance variable.
4418.9 -> Whereas when it's called
4420.6 -> within non static method you
could use the direct so static
4424.919 -> as we spoke about
it's one per class,
4427.6 -> so it's declared.
4428.9 -> Using static keyword.
4430.4 -> So static variables
are stored in static memory.
4433.3 -> It is rare to use
static variables other
4435.6 -> than declared final
4437.061 -> and used as either public
or private constants as we said,
4442.3 -> it's mostly used for constants
and static variables are created
4447.215 -> when program starts
4448.6 -> and destroyed when
the program stops.
4451.054 -> So one thing to remember
is it's one per class.
4454.1 -> It's not one per object
instance is one per object.
4457.4 -> We have a copy of that
particular instance variable one
4460.7 -> per object case of instance,
4462.887 -> whereas case of static
it is one per class.
4466.5 -> So the scope remains are
the life cycle remains right
4470.052 -> when the class is loaded
in the program is stopped
4473.4 -> in the class is unloaded static
variables are declared public
4477.6 -> since they must be available
for users of the class.
4480.7 -> It's not mandatory though,
4482.5 -> but usually if it's
a constant it is declared
4486 -> as public static variables
can be accessed by A calling
4490 -> with the class name.
4491.207 -> So we saw here last name
dot static variable.
4494.6 -> So how do we decide what amount
of memory is to be allocated?
4498.502 -> So these are the data types
that we have.
4501.1 -> So each variable in Java
has a specific type
4503.804 -> which determines the size
of memory the range of values
4507.2 -> that can be stored
and the set of operations
4509.974 -> that can be applied
4511.2 -> to the variable data types
can be categorized
4514.26 -> into two major types
primitive and non primitive.
4517.633 -> So basically primitive
is not object primitive
4521.134 -> is supported by language itself,
4523.6 -> which is kind of it
has got 8 primitive
4526.222 -> or its pre defined
by the language
4528.5 -> and named as keywords and it
has 8 primitive data types
4532.5 -> that is byte short integer.
4534.6 -> Then you have long float
double character and Boolean.
4538.6 -> This is pretty much similar
to other programming languages
4541.7 -> that you have by it
consumes one one bite.
4544.8 -> These are 8 primitive data type
set of predefined non-primitive.
4549.1 -> It's nothing but string string
is object itself.
4552.806 -> So that's something
4554.3 -> that is non pyramid
or if we Define
4556.593 -> your own class C student
for that matter here, right?
4560.1 -> We have defined student class
that's non primitive.
4563.1 -> So this student class has non
primitive you have strings
4566.667 -> for storing string,
4567.922 -> which is again kind
of non primitive.
4570.3 -> We have arrays
4571.91 -> or basically it's all
as reference variables
4575.3 -> since referencing
a particular memory location
4578.322 -> through variable name.
4579.798 -> This is where we have table
showing white consumes one bite
4583.831 -> and it's range is from -
4585.5 -> 128127 short is like two bites
and you could imagine
4590.2 -> that it would be
from - 32768232767.
4594.9 -> So it's pretty much similar
to other programming languages
4597.991 -> that you have like in C as well
we have similar to this thing.
4601.3 -> One thing is characteristics
to bite in C takes one bite.
4604.752 -> I believe though.
4605.8 -> It doesn't use all
the two bites every time it.
4609 -> On encoding type.
4610.6 -> So Boolean is one
which is true of all
4613.234 -> since it has to store 1 or 0.
4615.3 -> So it's pretty much similar.
4616.7 -> So just to talk on the bytes
required by test 1 byte short is
4621.3 -> 2 bytes integer is 4 bytes long
is 8 bytes float is nothing
4626.282 -> but it has decimal values
stored signed decimal values.
4630.6 -> So it again concerns
4632.4 -> for bites double is sign
again float values
4636.5 -> or sign decimal values
4638.8 -> which consumes 8 bytes
character is 2 bytes
4642.576 -> and bullion is one bit.
4644.6 -> So basically so decide
4646.3 -> whether to use float
or double depends on the nature
4649.5 -> of the application.
4650.697 -> So if you want to have
more Precision or
4653.172 -> if you want to have more range
you could go with double so non
4657.159 -> primitive or reference
data type is a variable
4660.2 -> that holds a particular
object or holds bit
4663.2 -> that represents a way
to access an object the pointer
4666.767 -> to a memory location baisakhi.
4668.8 -> So as we spoke Java doesn't
expose the pointer directly.
4672.4 -> It doesn't give you directly
pointed to the memory location,
4675.705 -> but it gives you
the reference variable.
4678 -> So you cannot manipulate
memory location directly.
4681.5 -> You cannot add some values
4683.4 -> to the memory location
through pointers or something
4686.106 -> but through reference variable
you can access it
4688.6 -> and assign someone so
4690.112 -> yeah, it does not hold
the object itself,
4693 -> but it holds a reference address
4695.461 -> to the object reference type
does not have size or bit range.
4700.6 -> So here we can see string Str
is equal to Ed Eureka.
4705.3 -> So the one shown
4706.6 -> in red is actually the memory
we're dead Eureka is stored.
4710.714 -> You have a reference
and Str is the reference to it.
4714.796 -> So here we can see
variables and data types.
4718 -> So we have a main method again
and we have bite.
4722.1 -> We declare a bite
here by D is equal
4724.6 -> to 10 short s is equal to 20,
4727.1 -> so, I think it's
pretty straightforward.
4729.2 -> You kind of have this data types
created you just have
4732.826 -> to assign values to it.
4734.4 -> These are all Primitives
as you could see till here.
4737.5 -> It's primitive so you could see
that values are being assigned
4741.4 -> and it's been printed out here.
4743.5 -> So I think it's
pretty straightforward.
4745.5 -> You can assign a value
to a variable n just print.
4748.1 -> So again, we use system
dot out dot println
4751.4 -> for printing it you
could try it out on your own.
4754.8 -> You could try it out
this data type program.
4757.9 -> You could just assign something
and just try to print it out.
4761.5 -> We are talking about
data type conversions.
4764.5 -> So we have implicit
4766.076 -> and explicit conversion
4768.1 -> in some case programmers
don't have to actually
4771.1 -> write explicit conversions
from one data type to other
4774.3 -> but in many
cases programmers need
4777.1 -> so the arrow in the diagram
4778.8 -> shows the possible
implicit type casting
4781.8 -> that a permissible bit
primitive data types.
4785.1 -> It's just with primitive data
types right as the diagrams.
4789 -> Those int can be converted
implicitly to Long float double
4794.7 -> since int X likes less space.
4797.925 -> It could be applied to any
of the numbers for vice versa.
4802.232 -> They have to be
converted explicitly.
4805 -> Whereas if you want
to convert long to integer,
4808.3 -> you have to
mention it explicitly.
4811.1 -> So basically we are talking
about when you're trying
4814.4 -> to store integer into long
integer takes less space
4817.701 -> and long takes more space.
4819.366 -> So it should can
be easily accommodated
4821.8 -> since long takes more space.
4823.8 -> If it is more than the range
of the integer.
4826.5 -> It wouldn't know
how to assign it to an integer.
4829.4 -> So that's why it has
to be explicitly
4832 -> convert implicit conversions.
4834.3 -> We can on the J shell
you could type this.
4837.8 -> So here what we are trying is we
have a character C is equal to a
4842.884 -> and you could see see
4844.5 -> is assigned a now
integer K is equal
4847.7 -> to C. Which could be done
you could assign character
4852.411 -> to an integer.
4853.8 -> So basically it's
a ASCII code for it.
4857.5 -> So 97 is the ASCII code for see
which would be assigned to K.
4862.2 -> So now when you
assign see to float,
4865.587 -> which works as well,
4867.3 -> so you get ninety seven point
zero you could assign
4871.2 -> character to long as well,
4873.25 -> which is in bytes integer,
4875.657 -> you could assign
double as well,
4878.2 -> which is 8 bytes float
and you could see
4881.1 -> but it cannot be done
the other way around
4883.4 -> as we spoke.
4884.4 -> So you cannot have integer
4886.661 -> or you cannot have double
assigned to character.
4890.7 -> So it would
give you incompatible
4893.1 -> our possible lossy conversion
from double to character.
4897.2 -> It has to be explicitly done.
4899.2 -> If you want to do that need
of type conversions.
4902.8 -> So here we have integer
a full 200 initiated a variable
4907.9 -> with type Teacher then
you have a string B,
4911.526 -> which is assigned value.
4913.399 -> Hello.
4914.2 -> So basically here you
can see string being used
4917.572 -> which is a reference variable
and you have string s is equal
4922.6 -> to a plus b as equal to a plus
b then it adds up like hundred
4928 -> plus since hello is a string
it would concatenated
4932.9 -> so you could see hundred
4934.312 -> and hello being concatenated
and you could see hundred.
4937.5 -> Hello the data type of both
the variables are different
4940.957 -> but to perform any operation we
need both the variables to be
4944.8 -> of same type here integer value
is converted into string
4948.544 -> and gets concatenated
with other string.
4951.3 -> So basically had we
been an integer you
4954.338 -> would have got edition of it say
4956.8 -> for example integer B is equal
to 200 and if you hundred
4961.3 -> plus 200 you would get 300 but
4963.7 -> since it's a string in this case
hundred is converted into string
4967.5 -> and it is concatenated.
4968.9 -> Hello explicit type conversions.
4972 -> We saw the previous case
4973.8 -> where an double was being
assigned to character
4976.884 -> which prompted us
with lossy conversion.
4979.5 -> So this is similar to that.
4981.481 -> So basically here
4982.78 -> what we are trying to do
is we are trying to assign
4986.6 -> double to integer.
4988 -> So you have double D
is equal to 45 B,
4991.9 -> which is 45 right again
double is 8 bytes decimal
4996.2 -> signed decimal number
4998.8 -> so you assign 45 to it.
5001.1 -> And now we are trying to assign
this double value to integer.
5005.7 -> So it's possible
lossy conversion,
5008.8 -> but you have a provision
to type Custer.
5011.81 -> So basically what we're trying
to do here is you're trying
5016.2 -> to assign again double
to integer which is possible
5019.862 -> if you type casted so
5021.4 -> when I say typecasting it's
nothing but opening parenthesis,
5025.3 -> then the destination data type
then your data.
5028.761 -> To a table.
5029.7 -> So basically to the right
side you could see
5032.4 -> that through explicit
type casting we can assign
5036.071 -> double to integer.
5037.738 -> So costing may lose information.
5040.2 -> For example, floating
Point values are truncated
5043.3 -> when they are cast two integers
example the value of D.
5047.8 -> That is 45.5 when converted
to integer gives 45
5053.03 -> so we could see here
the bottom like the double
5056.838 -> we assigned the value
of 45.5 to double
5059.9 -> but when we convert
it into integer,
5062.5 -> we got 45.5 Force truncated
since double since integer
5067.9 -> since the destination data type
5070.2 -> that's integer dozens
to decimal values.
5073.5 -> Now, this is like
type conversion methods
5076.8 -> which is there
any wrapper classes?
5080 -> What we are trying to do here
is we are trying to convert 23,
5084.789 -> which is string into integer.
5087.4 -> So you have a string.
5089 -> As is equal to 23 you
assign the value 23 so mind
5094.1 -> you this is this
is string right now.
5096.5 -> We have integer dot parse int
and we pass the string
5100.6 -> which would be
converted into integer.
5103 -> So this integer class
5104.7 -> that you see here
right here is nothing
5107.623 -> but butter wrapper class you
have string into an integer,
5112.7 -> which is nothing
but integer dot value of string
5115.9 -> which converts it
into digital data type itself.
5120.2 -> So the you could see
the destination is is integer.
5124.4 -> Now integer to string
you have integer.
5127.556 -> We have a tostring method
5129.37 -> which with converts
integer into string.
5132.3 -> So basically you have integer I
which is been assigned 23.
5136.684 -> Now you have
integer dot tostring I
5139.515 -> which would convert
this integer into string.
5142.9 -> We have one more method
5144.577 -> which is string dot value
of which would also convert.
5148.586 -> Integer into string.
5150.1 -> Let's talk about
operators operators are
5153.446 -> nothing but it operate
on this data types.
5156.6 -> So you have unary
5158.1 -> which is kind of pretty
much similar to what you
5161.6 -> have C C++ you have post fix
and you have prefix post fixes.
5167.4 -> I plus plus or expression
5169.4 -> plus plus and the operator is
after the variable which means
5173.792 -> that it would be assigned value
5176.1 -> and then it would be added
prefix is before the operator
5180.4 -> which would be added first
5181.65 -> and then assign or the operation
would be done first
5184.4 -> and then assign that's
prefix arithmetic is
5187.657 -> pretty much similar
like multiplicative you have
5191.3 -> like multiplication division and
mod you have additive which is
5196.2 -> plus and minus you
have shifting operation,
5199.03 -> which is bits shifting
to the left and bit shifting
5202.4 -> to the right you have
relational operators less
5205.9 -> than greater than less
than equal to greater
5208.1 -> than equal to.
5209 -> Instance of Quality
quality of two data types
5213.4 -> or two variables which check
5215.5 -> whether they are equal
and not equal.
5217.9 -> We have a bitwise
5220 -> and bitwise xor bit
wise inclusive or
5224.2 -> which is happening
at the bit level.
5226.7 -> We have logical
and logical or so.
5229.9 -> Basically, this is
for conditions, right?
5232.583 -> If you want to have
like two conditions,
5235.2 -> like if int I is greater than 0
5238.4 -> and int J is greater
than zero sort of you add
5242.1 -> or you have logical anding
5243.912 -> between two conditions
logical conditions
5246.9 -> or illogical or
pretty much similar
5249.515 -> to other programming languages.
5251.899 -> Like it's or
between two conditions.
5254.5 -> We say that either this or
that we have a ternary operator,
5258.7 -> which says that
5259.727 -> if the condition matches we
would have a condition followed
5263.7 -> by a question mark
followed by colon,
5266.1 -> and we would have some value
5268.5 -> Followed by colon followed
by some other value.
5272 -> So what we are trying
to say here is
5274.4 -> if the condition is
true assign value 1
5277.1 -> if the condition is false
then assign value to so
5280.3 -> instead of having it written in
5282.4 -> if else you try to put it
within turn your printer.
5286.9 -> So basically this is when you
have simple assignment operator,
5290.788 -> if you have a logic
5292 -> if you have some particular
logic been written it would be
5295.229 -> a better practice to have
5296.7 -> if else so that
it's readable right
5298.705 -> because ternary operator
5300.198 -> it would be very
difficult to actually
5302.5 -> through we have
assignment operator
5304.807 -> which is equal to which is
plus equal to is nothing
5308.2 -> but adds the value
on the right hand side
5310.759 -> to the left hand side
and assigns it
5313.1 -> to the left hand side table -
5315.25 -> equal to does the same thing.
5317.4 -> It kind of subtracts value
5319.4 -> to the the left hand side from
the value to the right hand side
5323.448 -> and assigns it
to the left hand side.
5325.8 -> So I believe this is pretty much
similar to other programming.
5328.8 -> Languages there's nothing
5330.1 -> different in this we
might have used it somewhere
5333.487 -> or the else should be pretty
much simpler for you guys.
5337.5 -> So let's see
unary operator example
5340.8 -> when X is equal to 10,
5343.1 -> so you could see X
been assigned value 10,
5345.9 -> you have X plus plus
5348 -> as we said it assigns first
and then increments it
5351.8 -> so you could see
value 10 here again.
5355.2 -> So now if you after this
if you print the value of x,
5359.5 -> you should see
the incremented value.
5362 -> That's 11.
5362.8 -> So that's post-increment.
5364.686 -> So, let's see pre-decrement.
5366.8 -> So you have a been assigned
the value of 10.
5370.7 -> All right.
5371.5 -> Now, you do - -
5373.2 -> A which is pre-decrement you
would see the value 9 directly.
5377.3 -> And now if you print the value
of a it would be nine again.
5380.953 -> So basically this is
5382.167 -> like decrement and then assign
this is like a sign
5385.542 -> and then operate this is
like operate and then assign
5388.7 -> Let's see the negation operation
like a has a value of true now,
5393.301 -> we negate it and assign it
5395.207 -> to the variable D
and you could see
5397.7 -> that it's changed to false.
5400.1 -> Now.
5400.4 -> Let's see the
arithmetic operator.
5402.7 -> You have B
which has value of 20.
5405.238 -> We have D which has value of 30.
5408 -> So when you add
it gives you value of 50
5411.2 -> when you multiply it gives
you the value of 613 220
5415.3 -> which is 600
5416.5 -> when you divide it 30
by 20 you get value 1 and
5421.2 -> when you have mod,
5422.953 -> which is like remainder,
5424.8 -> which gives you
value 30 by 20,
5427.107 -> which is equal
to 10 shift operators are
5431 -> so it shifts to the left
so shift left shift, right?
5435.3 -> So basically you have
integer value of 20 and
5439.1 -> if you convert this into binary
5441 -> if you convert the 22 binary
5443 -> which comes out
five digits, right?
5445.6 -> So when you convert this binary
and when you shift,
5448.7 -> To the left you would get
the value of 80.
5451.4 -> So you have value 20,
5453 -> which is nothing but if you
convert this 20 into binary,
5457 -> which would give you
one zero one zero zero right.
5462.5 -> Now, what we're doing here
is kind of Shifting it
5466.3 -> to the left by 2.
5468.026 -> This is what you do and this is
what it shows up as value of DT.
5473.1 -> So this is nothing
but 64 plus 16.
5476.853 -> So that's what this
left shift does.
5479.7 -> Basically it shifting
to the left by 2.
5482.6 -> Again, you could have shifting
to the right by 2 by 3,
5486.6 -> which would give the value
of to just shifting
5489.469 -> to the right by 3 would be
something like this.
5492.6 -> Right?
5493.022 -> So you're basically it shifts it
and you could see that.
5497 -> Yeah, basically it
would end up to 2.
5499.8 -> So now we have
like relational operators,
5502.776 -> which is pretty much simple
like a less than b.
5506.6 -> It gives false a greater
than b equals equals P.
5511.9 -> Since you have a is equal to B.
5514.8 -> In this case.
5515.564 -> We have a equal to B.
5516.726 -> That's why we have a
less than b as false
5519.079 -> and a greater than b as false.
5520.8 -> But whereas a equal to equal
to B is equal to 2,
5524 -> we have arithmetic operators
pretty much similar.
5527.1 -> Basically you have ad you have
5529.139 -> multiplication you have
division you have mod.
5532.4 -> So here we have
a is equal to 20.
5535.9 -> So what we are trying to do
is assignment so a is equal
5540.053 -> to 20 now B is equal
to 40 a plus equal to B,
5543.6 -> which is nothing
5544.624 -> but as I said,
5545.483 -> your left hand side would be
added up to the right hand side
5549.1 -> and would be assigned
to the left hand side,
5551.5 -> which is nothing but 20 plus 40
would be assigned to a so
5555.8 -> when you print a it would print
60 ternary operator,
5559.5 -> which is nothing but if a is
less than b here we can see
5563.344 -> that if a is less
than b then the value
5566 -> of Should be assigned to tr
or the value 200 in this case.
5570.472 -> The value 200 is been
assigned is greater
5573.4 -> than b logical operators
is nothing but anding
5577.1 -> and o-ring of conditions.
5578.9 -> Yeah, here we are saying
5580.4 -> that a is less than B
5581.8 -> and D is less than b
then return false
5585.1 -> and it's like kind of
ending logical conditions.
5589.6 -> Now, let's talk about
the control statement in Java.
5592.7 -> Now again, this one
is pretty much similar
5595.3 -> to other programming languages
5597.493 -> nothing different nothing
different in Java.
5600.576 -> So you have control statements
you have I treat
5604.175 -> if statements you
have jump statements.
5606.9 -> So one is selection
or decision making statements,
5610.377 -> which is like if else
if else ladder you have
5613.504 -> if if this particular condition
satisfies do some things do
5617.502 -> some execute group of statements
5619.708 -> and if it doesn't then execute
other group of statements
5623.5 -> that is about
5624.5 -> if else Which is nothing but
based on the value of a variable
5629.7 -> like you to execute
different step of statements
5633.484 -> like say for example,
5635.1 -> you have you write a switch
5637.9 -> on Integer value
integer variable X.
5641.8 -> Now when X is 1 you do
something or if x is 0
5647.1 -> you do something or you can have
a default statement as well
5650.9 -> when X is either 0
or 1 do something else
5654.5 -> that supports which I tradition
5656.674 -> is you repeat the same set
of statements again,
5659.9 -> and again till the condition
5661.731 -> till a particular condition
is met that's a titration.
5665.131 -> So you have four Loops,
5666.608 -> which is like after every
iteration the value of variable
5670.203 -> or the iterating variables
would be changed
5673.091 -> and would be checked
against a condition and
5675.963 -> if it meets it would come out
5677.9 -> or if it made it
would execute it again,
5680.6 -> and if it doesn't mean
then it would come out.
5683.5 -> So yeah, this is pretty
much similar to other.
5685.952 -> Other programming languages.
5687.6 -> So for for INT I is equal
to Z 0 is less than 10.
5691.8 -> I plus plus
5692.7 -> and you write
something within it.
5695.048 -> So this Loop would go on
for 10 times from 029.
5698.317 -> It would break it would come out
5700.517 -> when eyes greater than 9
which is 10 when it goes to 10.
5704.3 -> It would come out
5705.307 -> while is again pretty
much similar to that.
5707.8 -> You have do while construct
5710.1 -> which is guaranteed
to be executed once
5712.488 -> because the condition is checked
5714.5 -> after the execution is done once
5717.4 -> so basically no matter
what the condition is.
5720.7 -> It has to be executed
once for sure.
5723.5 -> That's when if that's
the behavior you want to put
5726.685 -> into your program you would use
5728.7 -> to Y is equal to once
5730.4 -> for sure jump statements
you have like break
5734.7 -> which come out of for
Loop Komodo for Loop
5738.3 -> or any attractive statements
you have continued
5742 -> which would again continue
and return is again coming out.
5746.215 -> Of a method or are mostly
5748.064 -> from the methods
you written something
5750.8 -> so the control leaves
the method now just to give you
5754.645 -> what if Wells is
if if the condition is true,
5757.849 -> then then execute
the conditional code.
5760.653 -> If the condition is false come
5762.797 -> out of the execution or come
out of the conditional code.
5766.8 -> Skip the conditional code.
5768.5 -> That's what if else is
so here you have int
5772.4 -> I is equal to 10 and
int b equal to 20
5775.6 -> if I is less than b
5777.4 -> so it's pretty much similar to
the ternary operator that we had
5781.4 -> so you could see here
5783.3 -> TR is equal to a plus b
so basically the value
5787.674 -> if a is less than b
which is in this case
5790.853 -> a is equal to 10 and B is equal
to 20 in that case.
5794.7 -> You would have PR as
30 since it is true.
5799.3 -> So basically it checks
the condition and
5801.7 -> if the condition is true it
executes the code with now
5805.3 -> let's talk about If else if it
5808.1 -> if else construct is nothing
5810 -> but you have a is a set
of statements to be executed
5813.5 -> when the condition is
in satisfy succeed.
5816.5 -> So in this case
5818.1 -> if a is less than b TR is equal
to a plus b else TR is equal
5823.5 -> to B minus a so in this case
it was less than a
5827.9 -> is less than b so you
got the value of 30
5831.9 -> whereas if a is greater
than b we have again changed it.
5836.3 -> So if a is greater
than b then TR is equal
5839.5 -> to a plus b else TR
is equal to B minus a so
5844.3 -> in this case a is less than b so
5847.6 -> which means CR
should be B minus a
5850.996 -> which goes into the
else condition statement
5854.4 -> and here you have
20 be as 20 and a as 10
5857.9 -> which is 20 minus 10.
5859.515 -> So you should have PR as 10.
5862.3 -> So here it's pretty much same.
5866.3 -> It does the same thing
nested if-else now,
5869.5 -> we are talking about
the switch statement.
5872.585 -> So you have switch expression
and you would have case written
5877.2 -> against it whatever case
you want to execute.
5880.6 -> So basically you
would have for Value 1.
5884.9 -> So yeah,
5885.4 -> what we are trying to say here
is we have a switch expression
5888.3 -> and we have a value
5890.3 -> for Value 1 as its value then
execute this piece of code
5895.015 -> and then break out
5896.4 -> and if it has value to then
execute this piece of code
5899.9 -> and then break it doesn't match
5901.9 -> with value 1 and value to then
executes the default cases.
5906.2 -> So one thing to note here is
it's mutually exclusive only one
5910.579 -> of it would be executed
out of the cases.
5913.5 -> Make sure you break
5914.961 -> out of all the the conditions so
to the right hand side
5919.2 -> you could see integer
CH has a value of 40 now.
5923 -> We have a switch for 40 now.
5926.1 -> Is when the value of CH
is 20 it would print
5929.5 -> case 20 executor
5930.8 -> when its value is 30 then we
would have case 30 executed
5935.1 -> when its value is 40
5936.521 -> then we would have
case 40 executed
5938.873 -> and then break out and
5940.452 -> if it's neither 20 30 or 40
we would have a default case
5944.4 -> is executed with says
5946.108 -> that 20 30 40 not executed.
5949.2 -> So in this case
5950.6 -> since it has a value
of 40 you would see
5953.5 -> that case 40 executed as
output I'd frisson is nothing
5957.9 -> but it is basically
I treating code
5960.34 -> if a condition is met
the the code would be executed
5964.2 -> until the condition is true.
5966.4 -> The code would be executed
and once once it is false,
5969.634 -> it would come out of the loop.
5971.5 -> So basically it's
a looping statement.
5974 -> So after every Loop
the condition would be checked
5976.576 -> and if the condition
is true it would loop again.
5979.4 -> And if not,
then it would come out.
5981.7 -> There are three types
of for Loop in Java
5984 -> simple for Loop similar.
5986.1 -> See like for INT I is equal to 0
5989.5 -> I is less than 10.
5990.884 -> I plus plus would be
a simple for Loop for each
5994.5 -> or an enhanced for Loop
and labeled for Loop for each is
5999.914 -> basically I treating
6001.453 -> on array list suppose
you have some collection
6004.951 -> or suppose you have a re right?
6007.6 -> You don't have to
manipulate the indexes
6010.7 -> since the typical scenario
6012.7 -> with arraylist is I treating
through all the elements
6016.218 -> within the list.
6017.341 -> So we have an enhanced
6018.886 -> for Loop wherein we don't have
to actually deal with indexes.
6023.1 -> Java has come up
with a enhanced for Loop
6026 -> where and what each iteration
it would assign the value
6029.2 -> of each element
within the array to a variable
6032.4 -> which could be used
within the loop.
6034.568 -> So we don't have
to deal with indexes
6036.8 -> like we don't have
to Loop through
6039.355 -> till the sizes met in the loop
6041.7 -> through in the size
of an array is Matt,
6044.7 -> basically it Done
by Java itself.
6047.7 -> We have an example
which would clarify it.
6050.792 -> So simple for Loop is
6052.6 -> as I mentioned you have
for INT I is equal
6056 -> to 10 is greater than 1 I
6058.2 -> minus minus so it
would print from 10 to 2.
6062.1 -> That's a simple for Loop.
6063.8 -> Now.
6064 -> What's the Syntax for it is
for then open up round brackets.
6069.289 -> Then you have initialization.
6071.6 -> Then you have a condition
and you have increment
6074.408 -> or decrement whatever
you want to do
6076.6 -> or you could even add up like I
6078.695 -> plus equal to 2 even
that is good enough.
6081.4 -> It's like for each even number
not even I would say it's
6085.919 -> like incrementing by 2.
6087.5 -> Now.
6087.766 -> This is what I
was talking about.
6089.9 -> So this is for each Loop
or enhanced for loop.
6093.3 -> We're in a typical
scenario with array.
6095.8 -> You kind of eye to it
through each element
6098.2 -> within the array
6099.4 -> and then do something
within the loop, right?
6102.6 -> So this is what Java
has made it easier for us.
6106.2 -> So basically you don't have
to deal with indexes here
6109.939 -> if we wouldn't have had
for each Loop.
6112.6 -> What you would do is
you would tell the size
6114.982 -> of the array is Matthew
would I trade through and read
6118.1 -> from each indexes right?
6119.7 -> But in this case
6120.93 -> as you could see
there's an array
6123.6 -> and for each Loop the value
6125.6 -> within the array would be
assigned to this variable
6128.316 -> and you could use this variable
6130 -> within makes it pretty
much simpler for us.
6133.2 -> And as I said,
6134.3 -> this is typical thing
6135.915 -> that we do with arrays
6137.9 -> now labeled for loop it's not
recommended to use this often
6142.426 -> but still we have
this construct here.
6145.7 -> So basically it's like go
to we can have a label
6149.8 -> of each for Loop.
6151.2 -> It is useful we
have nested for Loop
6153.892 -> so that we can break
or continue a specific
6157.123 -> for Loop normally break
6158.9 -> and continue keywords continues
the innermost Loop innermost
6163.6 -> for the loop only to give
Behind why I mentioned
6167 -> that this should
be used often is
6169.026 -> because it becomes
very difficult to debug right?
6171.957 -> If you dry run it
if you use this labels,
6174.6 -> it becomes very difficult
to actually understand
6177.1 -> what's happening within so
so we should avoid it
6180.5 -> and all this could be done
by writing a proper construct.
6184.746 -> Sorry using simple
for loop as well.
6187.4 -> So we should avoid it
somehow so basically
6190.235 -> as per my experience is
not a good practice to use them.
6194.02 -> So type of while loop we
6195.601 -> have SIMPLE while loop
we have do-while Loop.
6198.5 -> All right.
6199.088 -> So simple wire Loop is first
the condition is checked
6202.3 -> if it meets then the looping
statements are executed
6205.479 -> whereas do-while Loop is kind of
the statement is executed once
6209.3 -> for sure and then
the condition is checked
6211.855 -> if it is met then
it is looped again.
6214.1 -> If not, then comes out.
6215.619 -> So this is a simple while loop
6217.6 -> so you have conditioned
as you could see here
6220.714 -> while a is greater than 1
6222.2 -> you print the value
of a and you increase
6224.8 -> decremented Within Here
it's a do while loop
6228.5 -> so no matter what you
would have this to printer
6232.6 -> and it would be incremented.
6234.6 -> So it's 2 to 9.
6236 -> So no matter what some value
would be printed for sure
6239.881 -> when you use do I now
we have jump statements,
6243.126 -> which is breaking slyke
coming out of a loop.
6246.3 -> So as we mentioned
it's the innermost Loop
6248.826 -> that it comes out of
so that's what Brave does
6252 -> if a particular thing is met
or you could write a condition
6255.411 -> for a particular Loop
to be broken rather
6257.9 -> than continuing it.
6259.2 -> So basically you could have
like this would be more or less
6263.329 -> like you could have infinite
6265.239 -> Loop say for example
running through and
6268.1 -> if a particular condition
is met you could break out
6271.2 -> of it a typical scenario
6272.731 -> where it would be used.
6274.2 -> So here you could see
that you have a loop from 10,
6277.968 -> which I traits from
6279.394 -> where I is equal to 10 and
where I is greater than V i- -
6283.6 -> which we are
decrementing each Loop.
6286.1 -> Whereas you're saying
6287.394 -> that if I is equal to equal
to 7 we should break out.
6290.6 -> So here you can see though eyes
6293.2 -> greater than 5 you can see the
loop has broken out after 8:00
6298.2 -> since the value
has reached seven.
6300.5 -> It's not printing
the other indexes
6303 -> because it broke
out of the loop.
6304.882 -> So basically this is like
6306.4 -> if a particular condition is met
6308.4 -> and you don't want the loop
to go ahead you can break
6311.7 -> out of the loop
continue is similar
6314.462 -> when you write continue,
6316.2 -> it goes to start
of the loop again,
6318.2 -> it starts the loop again
6319.8 -> and it skips the messages
or it skips the code
6323.164 -> that you have after continue.
6325.394 -> So in this case you could see
6327.625 -> that we have I equal to in case
when I is equal to equal
6332.1 -> to 5 We are continuing the loop
6334.5 -> which means the print statement
6336.884 -> for I when I is equal
to Phi wouldn't get executed
6340.9 -> since you're continuing it.
6342.6 -> So basically as you could see
the News being printed here.
6347.1 -> You can see the 01234
6350 -> and there's no 5 here
then we have 6789.
6354 -> So basically what we
are saying here is
6356.483 -> when I is equal
6357.499 -> to 5 don't execute
the statement within the loop.
6360.635 -> Just continue.
6361.5 -> Just keep it.
6362.4 -> Okay.
6363.3 -> So what a methods
in Java So method is
6368.2 -> if you would have written
6369.9 -> function or if you would have
used any programming languages
6374.4 -> if you want to
perform some operation
6376.517 -> if you want to do something or
6378.287 -> if you want to do something
on some particular data,
6381.3 -> you would write a method.
6382.9 -> So basically in Java methods
are defines the behavior
6387 -> of a class.
6388.23 -> So remember I told
you a class is all
6391 -> about State and behavior.
6393.8 -> So methods are nothing but it
defines the behavior of a class.
6398.834 -> So what are methods or method
has a group of statements?
6403.1 -> Of course, as I said,
6404.4 -> since it defines the behavior
of a class you need to have
6407.8 -> some operations done, right?
6409.6 -> So you define the operations
through group of statements.
6413.523 -> It is much more used to have
reusability of a block of code
6417.984 -> that minimize redundancy.
6419.884 -> So imagine if you
didn't have methods then
6423 -> you have written the same piece
of code again and again,
6426.587 -> Say for example,
6427.605 -> you have a method
which adds to number right?
6430.3 -> And if we write the piece
6431.8 -> of code to add two numbers
directly into the main method
6435.035 -> if you want to write it again,
6436.8 -> or if you want to again
add two numbers,
6439.3 -> you will have to write
the same piece of code again
6441.8 -> in the main method.
6442.9 -> Whereas if you have a method
6444.596 -> what you would do is
you would refactor
6446.9 -> and take this add
method or functionality
6449.7 -> which adds two numbers
6451.109 -> into a method and this method
could be invoked from anywhere
6454.922 -> within the application
6456.343 -> which is nothing
but re usability right
6458.8 -> rather than writing
the same piece of code.
6460.9 -> Now, what you are doing is you
are defining this add method
6463.846 -> into some other method
6464.982 -> which could be called
anywhere within the code.
6467.37 -> So that's about redundancy
6468.9 -> that minimizes redundancy
and increases the reusability
6472.5 -> of a code a class
can have multiple methods
6475.9 -> as you could imagine.
6477.3 -> You could have
multiple behaviors introduced
6480.1 -> into a class which means
6481.7 -> that you would potentially have
multiple methods within a class.
6486.1 -> A method returns a null
6487.876 -> or a value using
the written statement.
6490.8 -> So basically the intent
6492.173 -> of the method is to perform
some operation, right?
6495.3 -> So what method would take
is it would take parameters
6498.99 -> and do some operations
on these parameters
6501.9 -> and it may
6503.1 -> or may not return something back
to the calling program.
6506.6 -> So if you don't want
written anything you
6508.9 -> have to return null or
6510.9 -> if you want to return some value
you could have say for example,
6514.3 -> you want to return string
you would return a string
6517 -> of a method you
could have void as well,
6519.9 -> which means that the method
is not returning anything back
6523.045 -> to the calling program.
6524.398 -> It is doing something
within itself and just
6526.714 -> the control would be back
to the calling program,
6529.3 -> but it won't return anything
out of the method
6532.1 -> that's about method.
6533.638 -> So let's talk about so
what the syntax
6536.484 -> of method So the first one
6539.8 -> that you see so this is a method
6542.261 -> which is public int
at Eureka integer a GB
6546.79 -> and it is just concatenating
the two strings or two numbers
6551.3 -> that we have sent a cross.
6553.5 -> So basically let's
an itemized it
6556.9 -> so what is public
so public is nothing
6560.1 -> but again access modifier
6563.5 -> so public means
this particular method
6565.939 -> could be accessed from anywhere
within the application.
6569.9 -> So that's what public
means similarly you
6571.9 -> could have private.
6573.2 -> You could have default scope or
you could have protected scope.
6577.6 -> So public is accessible anywhere
within the program private is
6582.2 -> within the class default is
within the package
6585.7 -> and the protected is
within the subclass
6588.465 -> and the package.
6590.1 -> Okay.
6590.9 -> What is this int it is nothing
but the return type
6594.479 -> so this particular method
is going to take two.
6597.839 -> Arguments and do something
and written integer,
6601.3 -> right name of the method
is you can see ID Rekha.
6605.6 -> That's the name of the method.
6607.1 -> Okay.
6607.422 -> So what do you see
within the parentheses
6610 -> after the method name is
nothing but the arguments
6613.5 -> that this method takes so
6616.2 -> what this particular method
6618.095 -> is doing is it
is taking two arguments
6620.7 -> which it is acting upon right?
6622.9 -> So it takes integer
a and integer B,
6625.9 -> that's the parameter list.
6628 -> So whenever you want to invoke
this particular method you have
6631.9 -> to pass arguments in this order.
6635 -> Now, what do you see within
this curly braces is nothing
6638.1 -> but the behavior or this is
6640.1 -> how you introduce a behavior
to the class or this is
6643.693 -> how you add functionality
to a method.
6646.3 -> So what you are doing
here is kind of adding
6649.3 -> these two numbers.
6651.4 -> So what is
the written statement?
6653.399 -> What does it do?
6655 -> So written statement is nothing
6656.8 -> but you do something
you take the arguments
6659.3 -> whenever controlled comes
into a particular method.
6662.648 -> It does something
6663.786 -> and you return it back
to the calling program.
6667 -> So the written statement
is a control flow statement
6670.696 -> that terminates the execution
6672.8 -> of method and written
control to its caller.
6676.3 -> So when return type
of any method is void,
6679.9 -> then the method does not return
anything if it is void,
6683.699 -> you won't return anything out.
6685.2 -> But if it is written in string
6686.7 -> or something you
would return string
6688.896 -> or null if you land
not to return anything,
6691.531 -> it could be null as well.
6693.6 -> So here we can see
a method by the name work
6696.68 -> which is returning void.
6698.4 -> So you can see
that it is not taking
6701 -> any arguments as
such or parameters,
6703.9 -> but it is just
printing out saying
6705.841 -> that I do recall welcomes you
6707.6 -> in the second case you
can see it is written integer.
6712.1 -> So it's taking int A
and B. Okay,
6716.7 -> and then it is printing out
6719.028 -> and it's returning
integer as well.
6722.3 -> So let's write a program sample
program to add two numbers
6726.3 -> and we would be writing all
this logic within a method.
6730.6 -> So let's start off
by defining a class.
6734.7 -> All right.
6735.5 -> So we define a class
say calm dot edu,
6739 -> Rica Dot and a typical name for
all arithmetic operation glass
6744.4 -> with all arithmetic operation
would be calculator, right?
6747.6 -> So I would write
it as calculator.
6750 -> For example.
6751.2 -> Alright, so here you can see
the naming convention again.
6754.5 -> There's a package
which is calm down
6756.9 -> at Eureka and you have
a class has calculator
6760 -> and it follows camel casing
6762.1 -> so it starts with upper case
followed by lower case.
6766.5 -> So you can see the class
is being created here.
6769.3 -> Okay.
6769.9 -> Now what we are trying to do is
you are going to have a method
6773.8 -> which takes to number.
6775.8 -> Okay.
6776.7 -> So say I Define
let's keep it public.
6780.3 -> All right.
6780.894 -> So this is access modifier.
6782.538 -> We want to keep it public.
6784.067 -> So you want to access
6785.33 -> this particular method from
anywhere within the application.
6788.876 -> So I'm keeping this public.
6790.6 -> So typically addition
would return results, right?
6794.7 -> You would add two numbers
6796.4 -> and return results
of two numbers.
6798.828 -> So that's your written type
which is integer.
6802.6 -> So you could either write
the return type as primitive
6805.9 -> or you could write it
as a wrapper class.
6808.8 -> So basically wrapper class
is nothing but integer
6812 -> has its own everything
in Java could has to be realized
6816.4 -> in terms of classes.
6818 -> So integer has its own class int
is a primitive data type
6823.3 -> and integer that you see here.
6825.992 -> Is a class corresponding int
so let's put the return type
6830.8 -> as integer and add is
a method name.
6834.5 -> Okay.
6835.38 -> Now this takes two arguments
integer arguments,
6839.1 -> which is arg1 and let's put
the second one as arg2.
6846.292 -> All right, so we start
and ended by curly brace.
6850.2 -> Okay.
6850.7 -> Now we have to write
logic within here.
6852.935 -> So what you see here,
6854.17 -> it's throwing an error
saying that you
6856.395 -> are not returning integer out.
6858.2 -> There is a missing
written statement
6860.278 -> because in the signature this
6862 -> is known as method signature
this particular thing
6865.182 -> that we have defined
here is Method signature.
6867.8 -> So in the method signature
you have mentioned
6870 -> that this particular add method
is intended to return integer
6874.5 -> out of the body,
6875.7 -> but still you
haven't written integer.
6878.434 -> So basically to get rid
of this I could put written null
6882.5 -> which means it's doing
nothing now you can see
6885.605 -> that Got rid of the error.
6888.153 -> So let's do one thing just
to make it more verbose.
6892 -> I will write integer result
is equal to ARG 1 plus ARG 2.
6899.8 -> So this is a method body
that you are defining here.
6903.1 -> So you are adding
a behavior, right?
6905.217 -> You're giving Behavior
to the calculator class.
6908 -> So by defining add method
this certain behavior
6911.1 -> that you are introducing now,
6912.811 -> you could have
a multiplier method as well
6915.311 -> which would take two numbers
and would multiply it
6918.3 -> which is again giving some sort
of behavior to calculator.
6922 -> So that's the reason we say
6924.076 -> that methods add
Behavior to the plus.
6927.7 -> Okay.
6928.7 -> So here it is taken two
arguments arg1 arg2 adding it
6933.3 -> and we will return
the result from here.
6937.8 -> All right.
6938.329 -> So this is a method
that you have defined.
6940.8 -> But so far we are not invoking
this method right?
6944 -> We are not calling
this method you want to call
6946.7 -> and check whether
it's running as expected.
6949.5 -> So that's where we
would have main method right?
6953.6 -> When you type mean it should
give you suggestions saying
6957.479 -> that are you trying
to write main method?
6960.3 -> So if once you click
on it it would this is done by
6962.8 -> IDE by the IntelliJ
similarly in Eclipse.
6965.725 -> You would get an option,
6967.3 -> you know, it would give
you suggestions saying
6969.3 -> that we want to
introduce main method.
6971.4 -> All right, so we have
a main method here.
6974.2 -> So again, it's
public static void Main
6977.4 -> and it's taking arguments here.
6979.8 -> All right.
6980.6 -> So remember I said
static and non-static
6983.3 -> Method you can see
here add is non static method
6986.7 -> when it's a non static method
you have to create instance
6990.2 -> of this class to invoke it.
6992.339 -> So basically first thing
6994.257 -> that I do is I create
instance of Later,
6998.3 -> so how do you create
instance of calculator?
7000.7 -> It's with new keyword.
7002.385 -> All right, you create new
7004.3 -> and it would create
an instance of calculator.
7007.4 -> Now I give a call to add method
7010.8 -> and suppose I want
to add like 10 and 30.
7014.5 -> Okay.
7014.808 -> So these are the arguments
7016.378 -> and it has to be
in order in this case
7018.624 -> since both are integer.
7019.804 -> It doesn't matter but had
it been some other data type.
7023.169 -> You have to ensure
that say for example,
7025.6 -> I write string here
7027.2 -> what this would return
is typically a result
7030.664 -> right addition of two numbers.
7033.3 -> Now, let's print it out
system dot out dot println.
7039.1 -> This is for printing result
7041.7 -> of addition is flits
print out the result
7045.764 -> that we get here.
7047.6 -> All right, and let's end
it by semicolon.
7051.7 -> So basically you have
a package defined here
7054.1 -> within the package
you have calculator
7056.5 -> and actually it's my bad.
7058.4 -> I should have defined
it right here.
7061.738 -> So it gives my it gives
the right package name here.
7066.1 -> So earlier I had defined
7067.9 -> calculator with income
dot Ed u-- Rica again.
7070.347 -> I defined a package computed
Eureka which is not required.
7073.7 -> So yeah, you can see here
packages calm down said Eureka
7076.7 -> which is nothing
but the namespace we
7079 -> have public class calculator.
7081.2 -> So public is nothing
but the access specifier
7084.4 -> for this class
7085.5 -> plus is the keyword used
for defining class
7088.2 -> and calculator is
the name of your class.
7090.5 -> Also one thing
to note is the name
7092.8 -> of the Java file should be same
as the name of the class.
7096.5 -> So that is something
7098 -> that IDE or IntelliJ
would do it for you.
7101 -> You just have to create class
and it would create class.
7104.6 -> So basically if you go
to the source folder
7107.3 -> you would have something
like calculator dot Java right?
7111.3 -> Then you have public method
which is again,
7114.3 -> here's the method
7115.197 -> that we have defined public
is the access modifier
7117.785 -> for this method integer
7119 -> is the return type add is
the name of the method.
7121.8 -> It's taken two arguments
arg1 arg2 within the body
7125.9 -> you are adding two numbers
and you are returning result
7130.002 -> which is integer
7131.1 -> which aligns to the signature
that you have put here.
7134.5 -> All right in the main
method just to check
7137 -> whether this add method
is functioning properly.
7139.9 -> What you do is you create
the instance of calculator.
7143.01 -> You add two numbers you
pass two numbers to it then
7146 -> and 30 and we are going
to print the results and see
7149.2 -> if it returns as expected.
7151.1 -> So here basically it
should print the result as 40
7154.6 -> since adding 10 and 30.
7156.6 -> So remember while it
builds it it would compile
7159.978 -> into a class file.
7161.3 -> Okay, the dot Java file
would be compiled
7164.036 -> if it's properly written
if it's in tactically, correct,
7167.8 -> it would read dot class file.
7170.02 -> All right, let's wait
for it to run.
7175.838 -> Okay, so it's
prompting me errors
7178.3 -> that we have an other methods.
7180.9 -> So let me do one thing.
7184.2 -> Let me delete other classes
that we defined yesterday.
7188.3 -> So I get go to the
source folder Comdata.
7191.199 -> Directa.
7192 -> I So I am just
deleting this classes
7199.1 -> that we defend yesterday.
7201 -> So that we don't spend time in
actually correcting it, right?
7205.6 -> So put it into a backup folder.
7210.6 -> All right, so
7214.7 -> Okay, so we have only
this calculator class
7218.1 -> now I run this.
7225.1 -> So yeah, you can see here.
7226.833 -> It has been tested result
of addition is 40.
7229.788 -> So basically what it
has done is adding
7232.4 -> these two numbers 10 and 30.
7235.2 -> All right, so that's
what we have here.
7237.8 -> So we are adding two numbers.
7240 -> So let's talk about the sequence
of how all this is being carried
7244.5 -> out by Java right
7245.607 -> when you run
a particular program
7247.604 -> how things work out
when you run a class.
7250.546 -> The first thing
7251.5 -> that's been called
is the main method.
7253.989 -> Okay jvm is nothing
but Java virtual machine
7256.98 -> which runs the program for you
7258.988 -> which is part of JRE
Java runtime environment.
7262.3 -> When you run a particular class,
7264.182 -> it would search
7265.05 -> for a main method and
if it doesn't have
7267.3 -> a main method then it
would give you an error saying
7270.3 -> that a class can't be run.
7272 -> So it's pretty much similar
to executable file, right?
7275.117 -> So if you're trying
7276.304 -> to run a class it has
to have a main method
7278.927 -> or you won't be able
to run the class directly.
7281.8 -> So that's where
the execution starts from.
7284.4 -> That's the entry point
for your program.
7287.2 -> Okay.
7287.7 -> So once it encounters Main
7289.7 -> and everything is good
your jvm would start
7292.7 -> executing the statement.
7294.4 -> That are there
within your main method.
7296.6 -> Okay.
7297 -> So in the edition case
7298.564 -> that we saw within the main
method we invoked we created
7302.378 -> the instance of calculator
and we invoked add method right?
7306.5 -> So when we ran that particular
class you could see
7309.6 -> that the addition was done.
7311.388 -> So basically what's happening
behind the scenes is,
7314.7 -> you know jvm would execute
the sequence of statements
7318 -> that you have with a name.
7320.5 -> So again coming back
to the example add example So
7324.5 -> within the main you
invoke the add method
7327.239 -> right when you invoke add
method the control would go
7330.8 -> to the add numbers method
7332.9 -> and it would again
execute whatever functionality
7336.5 -> you have put within
that particular method this case
7339.5 -> it was addition of two numbers.
7341.4 -> So it would execute
once the execution is done.
7344.4 -> It would return whatever
is been written out.
7347.769 -> So in this case,
7348.857 -> I was was addition
of two numbers,
7351.1 -> so it would return addition of
two numbers back to the calling.
7354.5 -> Program so you're calling method
7356.511 -> was the main method wherein you
called this add numbers from?
7360.3 -> Okay, so it would come back
to the main method and that's
7364 -> how it prints it out.
7365.6 -> So following the invocation
of add numbers you could see
7369.308 -> that we have printed
out the visual
7371.6 -> that comes out of
this add numbers and that's
7374.65 -> how it gets printed
onto your console so that
7377.7 -> the sequence of execution
that happens behind the scenes.
7382.8 -> Now what are the ways in which
you could call a method?
7385.8 -> There's call-by-value call
7387.454 -> by value is nothing but instead
of passing the memory location,
7391.398 -> it passes the value
of a particular variable.
7394.397 -> Okay.
7394.9 -> So this is similar
7396 -> to call-by-value and
call-by-name reference
7398.1 -> that we have in see okay,
7400.2 -> instead of passing
7401.4 -> the memory reference or instead
of passing the reference.
7404.808 -> It's just a value
that's been passed.
7407.021 -> So if you change something
within the method or
7409.844 -> if we change the value
7411.242 -> that's been passed
7412.44 -> within the method only
the local copy would change
7415.7 -> whereas the main copy
would remain as is
7418.5 -> but basically call by value
is just passing the value
7422.1 -> but not the actual reference.
7425.336 -> All right,
7425.836 -> so to understand
call-by-value you could so
7429.8 -> this would give you some idea.
7431.942 -> So say for example,
7433.3 -> I have integer ARG
1 which is equal
7437.2 -> to 10 integer ARG 2
which is equal to 30.
7444.099 -> Okay.
7445.4 -> Now I pass ARG 1 comma arg2.
7450.7 -> So what's happening here
is it's passed by value.
7453.9 -> So suppose you change.
7455.8 -> What I'm trying to say is here
7458.107 -> if you change arg1
to something else 300.
7463.6 -> Okay.
7464.3 -> So what we are trying
to do here is we are trying
7467.4 -> to pass this to arguments
arg1 arg2 to add method
7471.934 -> and within the add method we
are changing this arg1 200.
7476.2 -> Basically we would check
7478.046 -> whether this hundred
is been reflected in arg1 here.
7483.6 -> Okay.
7484.3 -> Arg1 here would
change 200 as well.
7488.7 -> Let's see what happens here.
7490.6 -> Okay, so I print it.
7495.3 -> Okay before passing it by value.
7497.8 -> So I print arg1 here.
7500.3 -> Okay, and after I give
7501.992 -> a call I would again printed
printing arg1 after busting
7509.7 -> it a value to a method
add Method All right,
7515.7 -> so let's run this
7518.5 -> so basically since its passed by
value arg1 would remain as 10.
7524 -> Okay, so that's what pass
by value is all over.
7527.3 -> So here you can see arg1
before passing was 10 and arg1
7533 -> after passing was again 10.
7535.8 -> Alright, so the change
7537.314 -> that you made here
doesn't reflect here.
7540.5 -> So that's pass by value.
7543.5 -> All right.
7544.166 -> So this one more concept of
method overloading with in Java.
7548.259 -> You could have same methods
7550.083 -> with different number
of parameters same method
7553.238 -> when I say same method
it has The same method name
7556.519 -> which would take variable
number of parameters.
7559.6 -> Okay, the overloading happens
at the compile time itself.
7563.191 -> So during compile-time jvm
understands to which method you
7566.836 -> are actually giving a call based
7568.956 -> on the actual parameters you
pass on so just to give you
7572.6 -> a fair idea about this I
Define one more method.
7578.4 -> C ad which takes
say integer arg1,
7584.1 -> let's keep this adders.
7588.4 -> So I defend
three parameters here.
7590.6 -> So instead of two I Define
three parameters here.
7593.725 -> This is nothing
but method overloading.
7596.2 -> All right.
7597.9 -> So here I Define ARG
1 plus ARG 2 plus arg3.
7604.9 -> All right, so we sum it up here
7607.8 -> and we return it back
to the calling program.
7613.9 -> So one thing to note here
is it's not giving you
7616.7 -> compile time error, right?
7618.5 -> So you can see
7619.2 -> that it has accepted
this add method as well.
7622.9 -> So you can see here.
7623.9 -> The signature is
pretty much same
7626 -> only thing is we have
one more extra parameter,
7629.3 -> which is a RG3.
7630.6 -> So it is treating this true
methods as a different method.
7634.2 -> That's what method
overloading is all
7636.4 -> about suppose I Define
one more ARG pee I say 40.
7645.846 -> Alright, so we have
three parameters here.
7649 -> I am giving a call
to add arg1 arg2.
7654.8 -> If I put arg1 arg2 the first
add method would be called
7659.4 -> if I have one more ARG 3 now
the second add parameter
7665.4 -> or the second add method
would be called.
7669.3 -> So let's define result
from new add method, right?
7676.2 -> So here we say.
7681.3 -> Okay.
7682.5 -> So as I said,
7684.3 -> we have overloaded
7685.428 -> the add method overloading is
nothing but same method name
7689 -> but different arguments
or different number
7691.6 -> of arguments or it could be
different types as well.
7694.6 -> You could have only
two arguments but one is integer
7697.912 -> and one is something else
7699.59 -> if for example string
7701 -> that also works so basically
different data types
7704.4 -> A number of arguments
7705.638 -> but different data types or
different number of arguments.
7709.2 -> Alright, so here we
7710.661 -> are adding three numbers
and let's run this.
7715.6 -> So it's going
to add 10 30 and 40,
7719.2 -> which is nothing but a tea.
7722.4 -> So this is done
at the compile time.
7724.8 -> As I said this linking is done
by GBM at the compile time.
7729.2 -> So here you can see results
7731.276 -> from new add methods
80 during runtime.
7734.4 -> You can see that it invoked
this particular method
7737.84 -> and not this one.
7739.3 -> Alright now, let's start off
with arrays, right?
7743.5 -> What is the concept of arrays?
7746.4 -> So again, this is similar
to other programming languages
7750.555 -> arrays are nothing
but grouping data
7753.2 -> or grouping values
of same data-type.
7756 -> Okay.
7756.6 -> So arrays are used
to solve the problem
7759.277 -> of storing multiple elements
of the same data type.
7763.1 -> Okay, an array is group
of like typed variables
7767.451 -> that are referred
to by a common name.
7770.3 -> So you define a name
for the array
7772.7 -> and in the future you can use
this name to access it.
7776.8 -> Okay specific element in an
array is accessed by its index
7782 -> as you could imagine
7783.297 -> since we are grouping you
would have multiple elements,
7786.76 -> right you could add
something to it
7789.048 -> or you could delete something
7791 -> or you could add it
7792.347 -> to the end insert it
in the between of the array
7795.54 -> or just so something
7796.905 -> or just search by index rate
you would give some specific
7800.771 -> index and get element
from that particular index.
7804 -> So we would be looking
at the Which would give
7806.749 -> you a clear idea about this
7808.4 -> but basically array
is nothing but group
7810.881 -> of or its multiple elements
7812.662 -> of the same data type
array type is fixed
7816 -> and cannot be changed.
7817.5 -> So in Java when you define
7819.377 -> an array you either give
the number of elements
7822.7 -> that you can store in the array,
7824.6 -> which is nothing
but the array size
7826.6 -> or you have to give the values
7829.2 -> that a particular array
would contain right
7831.816 -> when you define it.
7833 -> Okay, but all in all
you have to make sure
7836.1 -> that when you define an array
you give the size as well
7840 -> which cannot be changed
the feature the size
7842.8 -> of the array has to be mentioned
during the Declaration itself.
7846.7 -> So here's an example
of array this array has around
7850.546 -> for which has four subjects
with stores marks
7854.3 -> of four subjects for a student.
7856.6 -> Okay?
7857.4 -> Here you could see indexes
in the white box,
7860.707 -> which says 0123 it's
always in sequence.
7863.9 -> It starts with 0
and it ends with n minus 1.
7867.5 -> So basically this array is
of size for which starts
7872.9 -> from index ranges from 0 to 3.
7875.9 -> All right the value
that is stored is nothing
7879.4 -> but the that's a marks
in a particular subject
7882.8 -> which is like 87 60 70 and 80.
7886.3 -> That's the value
7887.217 -> that when stored
into this array.
7889.3 -> Okay, we can access any
7892.8 -> of this indexes suppose
you want to access
7895.9 -> at index 1 you could do it.
7898.8 -> Do you need to define a front
you need to Define on the size
7902.733 -> of the array of front?
7904.2 -> This is how it's been done.
7906 -> Okay.
7906.8 -> So this is
how you declare array.
7909.8 -> So we saw how we
usually declare an integer
7913.2 -> and stuff like that in Java.
7915.322 -> But here we are
declaring an array.
7917.9 -> All right.
7918.7 -> So this is an integer array
7921.065 -> and you can see
square brackets here.
7924.2 -> Alright, this tells jvm
7926.352 -> that we are trying
to Define array of type integer.
7930.423 -> Alright.
7931.038 -> So again, we use
the same keyword
7933.412 -> which is nothing
7934.6 -> but Nu new keyword is used
to create a particular array.
7939.3 -> All right,
7939.8 -> and here we are defining
an array of size five.
7943.1 -> So this is one way
of declaring an array.
7945.6 -> The other one would be
who initializer itself
7948.7 -> when you declare it
you give what are the values
7951.6 -> that particular array
is holding up the first case
7954.6 -> you're not giving the values
you are just defining an array
7957.8 -> which Those some some amount
7960.015 -> of memory right jvm would
reserve some amount
7963.399 -> of memory or in this case.
7965.298 -> It's four bytes right array.
7967.343 -> So for integer,
it takes four bytes.
7969.9 -> So it would Reserve 20 bytes
for array of size five.
7974 -> All right.
7974.632 -> So in the second case as I said,
7976.681 -> it's directly initializing
7978.325 -> the array it's putting
these values directly
7981.084 -> into the memory location still
it would be consuming 20 bytes,
7985.1 -> but the second variant
would have values
7987.7 -> directly initialized.
7989.3 -> So when you declare an array
of size 5 the range
7993.3 -> of indexes would be from 0 to 4.
7997 -> If you try to access index 5 you
7999.7 -> would get this exception
exception is nothing
8003.7 -> but a anomalies situation
right which or something
8007.6 -> which is not expected
8009.043 -> as occurred in your program
8010.9 -> and Java expresses such event
by throwing out an exception.
8015.432 -> You can't access index fi.
8017.6 -> So different ways
of declaring an array.
8020.3 -> We saw that it's
with new keyword.
8023.1 -> All right, so you have new int
10 which would declare array
8027.2 -> of size 10 again.
8028.6 -> You could either have
the square bracket
8031.24 -> at the end of the variable
8033 -> or you could have it
in between the type
8035.813 -> and the variable name.
8037.4 -> So behind the scenes it
everything is the same.
8041.5 -> It doesn't do anything
different for both
8044.073 -> but these are different ways in
which erase could be declared.
8048 -> All right, the third one
is similar to the last one
8051.9 -> where in we have
BR initializing it directly.
8055.5 -> Alright, we are putting
this value 12345
8058.484 -> into this array.
8059.9 -> This one is again same you are
so within the square brackets,
8064.8 -> you can see
8065.368 -> that you are not defining
the size of the array,
8067.8 -> but you have an initializer
at the end by which you express
8071.919 -> that you want to put in
1 2 3 4 5 into this array.
8075.4 -> So basically one and two That
you see here does the same thing
8080.1 -> it declares the array of size.
8082.3 -> The first case is 10
the second case is five though,
8085.4 -> but behind the scenes
it's doing the same thing.
8088.264 -> It's nothing different
when it comes
8090.2 -> to actual preserving memory
and stuff like that.
8093.202 -> It's doing the same stuff
8094.9 -> and three and four
does the same stuff
8097.257 -> only thing is syntactically
8099.061 -> it's varying but
what I'm trying to say
8101.6 -> is GBM doesn't do anything
different to actually executed.
8106.4 -> So the length
of the array is set
8108.7 -> when it is declared
8110.1 -> and when an array is declared
array index gets initialized.
8114.761 -> All right,
8115.6 -> so if you define an array and
if you try to print the length
8119.1 -> of it you could see
that it prints out in this case.
8122.67 -> We have declared
an array of size 20 and
8125.413 -> when you do x dot length,
8127.171 -> when you print it out you
could see that it prints 20.
8131.5 -> All right.
8132 -> So what are different types
of arrays that we have
8135.073 -> again similar to what we have
in Programming languages,
8139.5 -> we have single dimensional array
8141.8 -> and multi-dimensional array
single dimensional array
8145.5 -> is what we saw earlier
like you define array
8149.2 -> of integer of size 5 that is
a single dimensional array.
8153.4 -> So in this case,
8154.449 -> you could see a array
been initialized with value
8157.6 -> 2 4 6 8 and 10 that's
a single dimensional array
8161.8 -> since we have just
one dimension one row right?
8165.121 -> Say for example,
8165.921 -> you want to store marks
scored by a student
8169.7 -> or marks towed by a particular
student just one student.
8173.405 -> That would be
a single dimensional array.
8176.2 -> All right.
8177.2 -> So say for example,
8178.8 -> the first one is
the marks code in math.
8182.4 -> The second one is the sign
and so on and so forth.
8185.595 -> All right, so
that single dimensional array.
8189.2 -> So now what's multi-dimensional
array so taking the same example
8193.4 -> of storing marks code
by a student.
8195.9 -> So by a particular
student it would be
8198.2 -> a single dimensional array,
8199.936 -> but suppose you want
to show your marks code
8202.7 -> by all the students
in all the subjects.
8205.9 -> If you want to store it,
8207.317 -> it would be
multi-dimensional array.
8209.376 -> So one particular row
8210.7 -> that you see here would be
a mosque secured by a student
8214.9 -> by just one student
in all the subjects.
8217.7 -> The first row would be
by student won.
8219.741 -> The second row would be
by student to the third row
8222.5 -> would be by student
3 and so on right?
8225 -> So that's where you
have this application
8227.626 -> of multi-dimensional array.
8229.4 -> So how you access it is nothing
8231.7 -> but you want to access
the first element
8234.8 -> the first index it
would be a of 0 0
8238.4 -> and this would be of 0 1
and so on so as I said
8242.171 -> if the First Column is for math
8244.661 -> if it's a marks secured in math
this entire The First Column
8249.4 -> that you see would be
8251.2 -> marks secured by all
the students in math.
8254.5 -> That would be the First Column
8256.6 -> whereas the first row is
the Mach secured by student a
8261.087 -> in all the subjects.
8262.8 -> So basically This
Could Be Imagined as
8264.905 -> a table in a database,
8266.2 -> right you have a table
where in you have rows
8268.9 -> and columns so
columns are nothing
8271.45 -> but you have Fields
within a table and the rows
8275 -> that you have
our different entries
8277.104 -> that you have within a table.
8278.9 -> So This Could Be Imagined
in the same way.
8281.3 -> So you could see
how the index is you could see
8285.3 -> how the indexes
are aligned so X increases
8288.6 -> when you go down and Y increases
8291.009 -> as you go to the right
the memory allocation of array,
8295.7 -> so for single dimensional array
of type integer,
8299.5 -> 1 integer value takes
four bytes, right?
8303 -> So now when you declare
an array of size 5,
8306.2 -> you would have 20 bytes Reserve.
8308.6 -> That's how memories
been allocated right
8311.4 -> if you have a character
array of size 5,
8314.26 -> it would be ten bites
8315.8 -> since each character
takes two bites in Java.
8318.9 -> So you would have
10 bytes reserved up front.
8322 -> All right, so that's
8323.206 -> about memory location a location
in single dimensional array
8326.8 -> and when it goes
to multi-dimensional array
8329.5 -> this case you have
like five elements,
8332.4 -> right you have array of 55,
8335.1 -> which means that you have
25 elements stored
8338.02 -> within the array
8339.158 -> right 25 integer element
stored within the array
8342.5 -> and each integer value takes
four bytes for storage.
8347.238 -> So it would be a hundred bytes.
8349.6 -> All right, so
8350.502 -> if you have array of if you
define a multi-dimensional array
8354.6 -> of 5 into 5,
8356 -> you would have basically a
hundred bytes allocated for it.
8360.759 -> Let's write some programs
8362.682 -> and understand more about
how this arrays operate.
8367.1 -> So we have an array
of five elements.
8370.2 -> All right,
8371.141 -> as you could see here 2 4 6 8
and 10 write a program to access
8375.9 -> element at a specific index.
8379.1 -> Okay, so you have an array
of five elements 2 4 6 8 and 10
8385.4 -> and we want to access it.
8387.323 -> We want to access
particular element.
8390.092 -> All right, so let's write
so I create a class.
8395.1 -> All right, I Define
this as our a demo,
8399.8 -> so I don't give
a package name here
8401.948 -> because I am defining
a class within a package
8404.8 -> so you could see here
the package came directly
8408 -> because I right
clicked here right
8410.288 -> and then created a new class.
8412.3 -> So yeah, you get
this particular class here.
8415.507 -> I Define a main method
8417.2 -> as a type main it
would give me a suggestion.
8420.7 -> So this is the entry point again
for this particular class
8425.2 -> and suppose I Define the jar.
8429.8 -> Ray and suppose
I Define 2 4 6 8 and 10,
8435.3 -> right so you could see here.
8437.8 -> We have an array
defined of size five.
8441.6 -> Okay, and you have
initialized it as well.
8445 -> So what I was trying to say
is you need to have length
8448.4 -> of the array given
up front right?
8450.503 -> If you don't do that,
8451.842 -> it would show you an error
8453.5 -> so you can do something like
array of integers is equal to Nu
8457.4 -> so you could see here
array initializer expected.
8461.6 -> All right.
8462.3 -> So either you will have
to initialize it
8464.9 -> or give some value to it.
8466.8 -> So if you put here
10 you could see
8469.4 -> that it compiled right?
8471.8 -> So either you will have
to mention some indexes here
8475.723 -> or the length size
8477.107 -> of the array or the ways
to initialize this okay.
8482.2 -> Now you could see
the compilation error as gone.
8485.034 -> So what I'm trying
to say is it jvm has
8487.27 -> to know about the size
of the array of And
8489.664 -> if it doesn't know then it
would flag you with an error.
8493.19 -> All right, so we have defined
this array of let me keep it
8497.695 -> as is okay.
8498.8 -> So now we have defined
an array of size here five
8503.3 -> and we have initialized
values as well.
8506.9 -> Now, let's try to print
out values, right?
8510.5 -> So just to keep
it simple suppose.
8513.039 -> It ranges the index
would range from 0 to 5,
8516.346 -> in this case.
8517.4 -> So this value to is stored
8519.4 -> at index 0 value for is stored
at index 1 value 6 is stored
8524.9 -> at index 2 value
8 is stored at index 3
8529.7 -> and then is to that index
for all right.
8533.2 -> So let's try to print
0 by the way.
8537.3 -> I want to copy it.
8544.4 -> Yeah, so I'm just sprinting
0 1 and 4 and let's see
8548.7 -> what it gives up.
8550 -> Right so it should print
2 4 and 10, right?
8557.08 -> So you could see
here to 4 and 10.
8560 -> Now.
8560.204 -> The other thing
that I wanted to show is
8562.7 -> if you try to access
so let me show you
8566.497 -> what happens there.
8568.5 -> All right, so
8570.3 -> if you try to access at index
5 which doesn't exist at all.
8576.1 -> No, it should give
you a exception So
8580.1 -> in Java exceptions could be
8581.9 -> nothing but God and you
could do something with it.
8585.2 -> So here you could see
8586.5 -> that it gives it gave you array
index out of bounds exception
8590.217 -> since five doesn't exist at all.
8592.2 -> The index five doesn't exist
at all for this array.
8595.3 -> Okay.
8595.7 -> Now let's define
multi-dimensional a write code
8599.4 -> to find the length
of rho 0 right.
8602.823 -> So let's define
a multi-dimensional array.
8608.7 -> Alright, so we have
a multi-dimensional array here.
8612.2 -> So how you define
multi-dimensional array is
8615.1 -> something like 1 2 3 4 Alright,
8621.6 -> so this is a multi-dimensional
array that you have.
8627 -> Okay, so we have defined
a multi-dimensional array
8630.4 -> the size of this array
would be 2 by 2.
8633.3 -> Right 2 by 2 is
the size of this array
8636.3 -> since you have two elements here
8638.2 -> or let me put it
to remove the confusion.
8641.5 -> Let me put it this way.
8643.2 -> So right now we
have like 2 by 3,
8645.7 -> right so you have like
two columns and 3 rows.
8649.5 -> All right.
8650.3 -> So now let's print actually
it has to be 3 by 2 rather.
8655.6 -> Okay.
8656.542 -> Now, let's print the size
of this array 0 right.
8660.4 -> So how we do it is
8661.9 -> again println now you
have multi-dimensional array
8667.5 -> and you have 0
8668.8 -> so 0 to 1 refers
to this 0 1 and 2, okay.
8674.7 -> Dot length,
8676.4 -> so as you could see
here that individual row
8679.1 -> that you have
within multi-dimensional array
8681.8 -> itself is an array is
a single dimensional array.
8684.984 -> So multi-dimensional array
is nothing but it's a array
8688.5 -> of single dimensional array.
8690.5 -> Okay.
8691.4 -> So let me print here
size of first array.
8699.7 -> I miss Plus.
8704.6 -> So as you could see here,
8706.273 -> there was an exception
and since there was
8709.5 -> an exception you won't have this
particular statement executed
8713.411 -> since there was exception here.
8715.4 -> So basically to execute
this particular statement,
8718.4 -> you should handle
this particular exception,
8720.971 -> but we are not talking
about handing the exception yet.
8724.2 -> So I'll have to comment
this to pass through.
8727.4 -> So now you could see
8728.8 -> that it has printed out to which
is your size of first array.
8733.9 -> So this is a program
8734.9 -> that we actually did right
now create an array having
8738.7 -> many characters write
a program to copy elements
8742.3 -> from created array
to another array
8744.3 -> and also write a program to
delete an element from an array.
8748.2 -> Okay, so I will just talk
about this right here.
8752.2 -> So we have an array here
of characters, right?
8755.4 -> So basically when you want to
delete something from my array,
8758.9 -> what you will have to do is
8760.369 -> you will have to shift
the indexes, right?
8762.6 -> You can't delete something
directly from an array.
8765.2 -> So what you will have to do is
8766.7 -> if you want to remove
something then you will have
8769.1 -> to shift the indexes
8770.4 -> what happens is suppose you have
an array of five integers
8774.25 -> and suppose you are deleting
the second element right.
8778.015 -> Now.
8778.28 -> What you would do
is you would shift
8780.6 -> if you are deleting
the second element
8782.8 -> within the array you
would shift all the elements
8786.3 -> that follows the second element
to the left, right?
8789.7 -> So the third element
would become the second element.
8793.017 -> What would become third
8794.469 -> and the fifth one
would become the fourth.
8797.006 -> So basically you shift it.
8798.615 -> That's how you delete
something from an array.
8801.45 -> All right.
8802.088 -> So other thing is about copying
elements from the array,
8805.6 -> we have a utility class
8807.324 -> which is nothing but
system system is a class itself.
8811.1 -> So as you could have seen
8812.943 -> that when I'm printing out
something I do system dot
8816.573 -> out dot println, right?
8818.2 -> So this system it's
a utility class in Java
8821.071 -> where an IT exposes lot
8822.644 -> of functions within a lot
of methods utility methods.
8826.619 -> So one of them being our a copy,
8829.3 -> so here you have to give source
8832.146 -> and the starting index
and the destination
8835.5 -> and what we are trying
to do here is copy 5,
8838.675 -> so this is how we copy
8840.3 -> from one array into
another starting from index 0.
8844.8 -> So this is copying
and the other one
8847.2 -> that you see here
is about delete.
8849.9 -> So as I said deleting is nothing
8852.1 -> but we have A logic
written here to shift
8855.2 -> the indexes to the left.
8857.5 -> So here we are trying
to delete one at index 3 and we
8861.5 -> are just shifting elements
after this index 3 to the left.
8866.2 -> That's how we delete
something from an array.
8869.5 -> Now.
8870 -> Let's see what our strings
so string is nothing.
8873.9 -> But again the data type
with in Java.
8877.1 -> So why do we have strings at?
8878.681 -> All?
8878.9 -> Right.
8879.2 -> We have array of characters then
why do we have string at all?
8883.1 -> So here's an example
8884.7 -> where in you have lot
of loads of data?
8887.341 -> So you could imagine
a role of a data analyst
8890.4 -> who has to analyze through lot
of data coming in right?
8893.8 -> So nowadays, it's like petabytes
8895.703 -> of information being processed
throughout a day,
8898.5 -> right which would be
very difficult to handle
8901.4 -> if you had to deal
with character array.
8904.149 -> So that's where that's
8905.712 -> where Java has come
up with strings,
8907.839 -> which is nothing
but a group of characters,
8910.4 -> but you don't have
to deal with it Java
8912.9 -> by Itself has a class
8914.7 -> which would take care
of this strings and
8917.5 -> since strings are widely used
8919.395 -> within a program you could
imagine that name or anything
8923.049 -> that any identify
8924.197 -> that we have is mostly we have
to store it as the string.
8928 -> So one of the data types
8929.729 -> that widely used within industry
or which is widely used
8933.756 -> in programming is string, right.
8936.1 -> So Java has some kind
8937.7 -> of string management
as well to make sure
8939.7 -> that programs run or make
effective use of strings.
8944.2 -> Okay.
8944.7 -> So here what's been mentioned
is James is a data analyst
8948.8 -> and he's finding is really
difficult to actually deal
8952.5 -> with character array to store
patients names every time
8956.9 -> so that's where we have string.
8959.6 -> So string a solving the problem
8961.521 -> of actually dealing
with character array.
8964 -> So Java is actually
8965.461 -> having character array
is touring characters
8969.1 -> or the characters in the string
in a form of character array,
8972.7 -> but It doesn't expose it
to the outside world.
8976.126 -> You can just use
this class to deal with it,
8979.4 -> but you don't have to deal
with character arrays.
8982.4 -> So Java string is nothing
but sequence of characters,
8986.3 -> they are objects
of type string class.
8990.2 -> Once the string
object is created.
8992.41 -> It cannot be changed.
8993.794 -> This is the immutability
functionality of java.
8996.711 -> We're in once you write to it.
8998.614 -> You can change the value.
9000.2 -> So this is specifically
important when it comes
9003.191 -> to multi-threading
9004.406 -> when you have multiple threads
accessing a particular string
9008.487 -> or same string.
9009.5 -> So that's when immutability
9011.5 -> helps us to make sure
that you know,
9013.9 -> multi-threading is it's
9015.473 -> thread-safe we call
it as thread safe
9017.923 -> because multiple threads
can access the same string just
9021.596 -> because it is immutable.
9023.2 -> All right.
9023.788 -> So what are different ways
in which you declare a string?
9026.7 -> So you have string Str
is equal to new string
9029.5 -> which we are not initializing
the value of the string here
9032.8 -> which could Any value and you
have string str1 is equal
9037 -> to Ed Eureka wherein you
are initializing the value
9040.4 -> of the string right away.
9042 -> The other one is
the character array
9044.3 -> similar to the integer array
that we discussed.
9047.4 -> We have character array as well.
9050.2 -> So immutability of the string.
9052.487 -> So why do we have immutability
one is for security.
9056.214 -> So string stores lot
of useful information,
9059.359 -> like even the credentials
and stuff like that,
9062.679 -> which shouldn't be accessed
by external users.
9066.067 -> So this immutability factor
9068.1 -> of string helps us
to keep it secure
9070.8 -> so that no one else
can see it synchronization.
9074.4 -> So this is what I spoke about
9076.4 -> when you have multiple threads
accessing the same string,
9079.967 -> you don't have to synchronize
it Java by itself
9082.832 -> through its immutability
feature would ensure
9085.649 -> that multiple threads
can access the same string
9088.7 -> without hampering it
or it would run
9091.1 -> as it's expected.
9092.8 -> Shing so caching is nothing
but you have a string pool.
9096.7 -> So basically if you have
two strings with the same value,
9100.5 -> it won't store it.
9102.3 -> It won't store
redundant copy of it.
9105 -> There would be just one copy
in the string pool
9108.1 -> and both this references
would be pointing to that value.
9111.9 -> If you happen to change one of
these references it would point
9116.456 -> or it would create a new value
in the swimming pool
9120.2 -> and point the other reference
to it sort of so basically
9124.43 -> what we do is why
caching is required is
9127.5 -> as you could
imagine in application,
9129.9 -> as I said string is
widely used data type
9133.5 -> and you could have
multiple references pointing
9136.807 -> to the same value of a string.
9139 -> So we don't want to have
duplicate values stored.
9142.8 -> That's where this caching comes
into picture to utilize
9146.4 -> memory efficiently.
9148.2 -> So what is shrinking pool
9150.2 -> as I said string pool is
all the constants
9153.5 -> that you define
within the string
9155.4 -> within the application
would be stored
9157.577 -> in the string pull string tool
used in Java is a spool
9160.7 -> of string stored
in Java Heap memory.
9163.5 -> So we have heat memory.
9165.3 -> We're in the objects
are created and that's
9168.236 -> where string pool
resides as well.
9170.507 -> String pool is Possible only
because strings are immutable.
9174.5 -> You can't change
once it is defined.
9176.283 -> You can change it.
9177.2 -> If you change it,
9178.2 -> then you can change
that particular memory location.
9181.415 -> It creates one more entry
in your string pool
9184.8 -> and the reference would point
to the new entry.
9187.9 -> So the actual memory location
is not getting changed.
9191.284 -> That's what immutability is all
about string pool helps
9194.8 -> in Saving lot of space
for Java runtime.
9198.1 -> We are breaking
on the redundancy Factor here.
9201.007 -> So if you have multiple strings
9203.5 -> or if you have multiple strings
holding up the same value,
9206.9 -> it won't create.
9207.8 -> People copies of it there
would be just one value
9210.623 -> in the string pool,
9211.7 -> which would be accessed
by all the references.
9215.6 -> So basically string pool
9217.446 -> as we discussed is
or resides in Heap memory.
9222.2 -> So string is not a
primitive data type
9224.8 -> unlike character character CH AR
9226.966 -> is a primitive
data type string is
9229.261 -> not a primitive data type
9231 -> is the wrapper class
to array of characters
9235.2 -> and this is specifically done
9237.43 -> so that Java has a mechanism
to manage strings.
9241.6 -> Well, which is widely
used it arrived
9244.3 -> within any application
9245.9 -> or any programming language
for that matter.
9249.7 -> Della strings are stored
in string to love Heap area
9253.5 -> which we already discussed
so we can see a string pool.
9257.8 -> So we have stack memory
and Heap memory.
9260.4 -> So when you have
a local variable when you
9263 -> define something locally,
9264.693 -> the reference is created
in the stack.
9267.2 -> All right, and it points
9268.668 -> to the actual object
is created in the Heap,
9271.3 -> but the reference
is created in the stand
9273.75 -> so you could see as pointing
to hello in string pool.
9278.3 -> Okay, so s is nothing
9280.592 -> but a reference reference
to this ring.
9284.153 -> Okay, so here we can see
that we are concatenating.
9288 -> Right?
9288.5 -> So this would give you
fair amount of idea.
9291.836 -> What immutability is
all about, right?
9294.696 -> So here we have string S1
is equal to happy.
9298.5 -> All right,
9299.6 -> and what we are printing
out the original string
9303.1 -> that is happy, right?
9304.624 -> So you could see here
S one is a reference
9307.6 -> that's been created
in the stack.
9309.7 -> You have a string pool
within your HEAP memory
9312.44 -> which would store all
the strings all the constants
9315.485 -> or literals that you
have defined here.
9317.8 -> So you could see happy
been stored in the string pool
9321 -> and S1 pointing to it.
9323 -> Now you are trying
to concatenate S1
9326.136 -> with learning, right?
9327.752 -> So it's happy learning.
9329.6 -> So you could see
9330.861 -> that the memory location
that s one is pointing
9334.6 -> to is not changed right
still pointing to happy.
9338.4 -> But this one more constant
that's been created
9341.4 -> in the string pool
that second category.
9343.9 -> The nation of happy
9345.242 -> and learning so you could see
happy learning also created
9349.2 -> but what's important
to note here is s 1
9352.1 -> is still pointing to happy.
9354.1 -> It's not pointing
to happy learning.
9356.9 -> All right, so
9357.9 -> if you want S1 to actually point
to happy learning this is
9363.2 -> how you do so you have S 1
which has the value happy.
9367.8 -> All right.
9368.7 -> So you do S1 dot concat learning
and you assign it to S 1.
9374.3 -> All right.
9375.1 -> So you are assigning
to the same reference as S1
9378.1 -> and you are printing
out s 1 in this case,
9381.4 -> what would happen is
unlike the previous example
9384.9 -> that we saw there in S1 is still
pointing to happy you would see
9389.2 -> that as one is pointing
to happy learning.
9392.1 -> So here you could see
9393.6 -> that this one is pointing
to happy learning.
9396.9 -> So basically you
9397.8 -> move the reference
from happy to have Peter.
9400.7 -> All right.
9402.4 -> So, let's see what our strings
how do we operate on strings?
9407 -> Right?
9408.1 -> So let me create
a new class here.
9410.7 -> Just ring demo.
9414.3 -> I create a main
main method again.
9416.838 -> All right.
9417.9 -> Now what we do is string
s is equal to and Eureka.
9424.7 -> All right.
9425.445 -> So let's first print
the length of the string.
9429 -> All right.
9429.699 -> So this is how this
utility class or this is
9432.7 -> how this wrapper class helps us.
9435.2 -> So it has all these utility
methods right you just have
9438.6 -> to do else dot length.
9440.2 -> It would give you length
of the string so had we
9442.9 -> not had strings and
9444.066 -> if you want to deal
with the character arrays,
9446.829 -> you would have to print
the size of the array here.
9451.711 -> Alright, so when we run it,
9454.1 -> it should print
it it is the size
9456.7 -> of the string at Eureka.
9459.7 -> Let's have substring.
9463.1 -> So it's a beginning index.
9464.7 -> So suppose we give to
9466.4 -> so it would give you
substring from index 2.
9470.5 -> So basically we
are getting substring.
9472.607 -> We are getting part
of the string substring
9475 -> is nothing but part
of a string right
9477.5 -> from from a particular index.
9479.6 -> So since we have given
to hear it starts
9482.6 -> from index to so you have 0
9486.1 -> he's at 0 and x
9487.6 -> 0 D is at index 1 and U is
at index 2 so it starts from you
9493.3 -> till the end of the string
you have compared to you.
9497.6 -> Could Define two strings
9499.018 -> and you could actually
compare them and see
9501.5 -> the value so basically So
9505.1 -> you could have one more
string defined here
9507.5 -> something of this sort.
9511.4 -> Alright, so here we compare it.
9514.3 -> So we are doing s 1 dot
compared to To him, it's true.
9521 -> So we are comparing S1 with S2.
9524.2 -> So it compares the given string
with current string.
9527.9 -> So here you can see it
as shown minus 1 right
9531.6 -> since B is one ahead of a so
9535.387 -> if you have same string
it would show you zero.
9542.6 -> So if it's exactly the same
it would give you zero.
9547.8 -> You have he's empty suppose.
9550.3 -> You don't have anything
within your spring.
9552.586 -> You could check it
whether it's empty.
9554.8 -> He's empty returns
a Boolean variable which means
9558.2 -> if it's true it is empty
and if it is false,
9561.787 -> it has some value then we
9563.7 -> have to lower case
we have to upper case
9566.4 -> in this case suppose you want
to have could be scenario
9569.889 -> in which you want to change
9571.633 -> or you want to
change the casing.
9573.7 -> So I'll just take one
of that I make it to uppercase.
9578.4 -> Okay, so s 1 is nothing
9580.4 -> but we have Ed Eureka stored
within and we are so
9584.1 -> when I run this
9586 -> you should have said
Eureka printed in uppercase.
9589.9 -> So here we have written camel
casing and let's see the output.
9595.8 -> So here you can see
the string was converted
9599.022 -> or translated into upper case.
9601.7 -> So similarly you
could do lowercase
9603.7 -> which would print
string in lowercase.
9607 -> Now we have value of is nothing
but the value of a string value
9611.9 -> of some of the data type
9613.455 -> so you could pass integer
and you could do value
9616.5 -> of and it would give you
a convert integer into string,
9621.4 -> right so value of is
a method within string
9624.6 -> which takes different data type
and converts it into a string.
9628.3 -> So just to give you
an example you could have
9631.3 -> like teacher I is equal
9634.3 -> to a hundred String dot value
9638.7 -> of and you give I it
converting this I into string.
9644.2 -> So it would print
the same value hundred
9646.583 -> but it's converting
it into spring
9649.1 -> you could replace something
within the string.
9651.047 -> If you want to replace
9652.147 -> particular character
within the string
9653.8 -> which could be done
with replace method.
9655.9 -> So replace method takes
9657.594 -> two parameters replaces
a method within string
9660.902 -> which takes two parameters.
9662.794 -> First one is the character
9664.6 -> that you want to change
and the second one is
9667.624 -> the new character that you
want to change replace to.
9671.3 -> Okay so here to show
9675.2 -> S1 dot replace I could replace
e Within a be alright,
9684.4 -> so we are making it lowercase
and as you can see here,
9689.4 -> it's printed in uppercase E
was changed to lowercase e
9693.5 -> so that's about replace.
9696.4 -> We have contains
9697.7 -> which again gives you
Boolean type result,
9701.3 -> which says whether
a particular value
9703.77 -> of particular character
is present in a string.
9706.9 -> All right.
9707.6 -> So in this case we check
9709.5 -> whether we have
a stew with a TLD.
9713.7 -> Oh and you
replace t with L,
9716.4 -> which becomes hello,
9717.868 -> and now we are checking with
the replaced string contains D,
9722.2 -> which it doesn't contain it,
9724.019 -> right so it would
give you false.
9726.2 -> So that's about contains
equals is basically checks
9730.3 -> for the equality of string.
9732.3 -> It takes one argument
9733.9 -> and it Compares it
against the string object
9736.799 -> against which you invoke
the equals against.
9739.7 -> All right, so to give
you an example,
9742.2 -> so you have S 1 which is at
Eureka Eureka now to print it.
9749.8 -> So here we do S1 Dot.
9756.8 -> printing equality of string So
9760.4 -> since it's the same
it would give you true
9763.3 -> if had it been different
9765 -> it would give you false.
9767.1 -> So you can see here.
9768.7 -> It's printing both
9770.2 -> the strings are the same you
have different methods,
9773.7 -> like compare ignore case
9775.892 -> where in this case we
compared with case, right?
9779.8 -> If you would have had Eureka
in lowercase, right?
9784.1 -> If it would have start
9785.2 -> with lowercase e you
wouldn't have got 0 here.
9788.4 -> All right, whereas this one more
method which is s 1 dot
9792.4 -> compared to ignore case
9794.046 -> when it doesn't consider
the case, right?
9796.907 -> So even if there
is a case change
9799.101 -> if this how one
in uppercase and one
9801.5 -> in lowercase still it
would match all still
9804.3 -> it would give the value as 0
9806.2 -> which means both the strings are
the same we could get
9809.9 -> some character out
from a string.
9812.399 -> Okay.
9813.1 -> There is a method character
9815 -> at there's ends with which again
returns a Boolean value saying
9819.5 -> that That a string ends
with a particular character.
9822.969 -> Alright, so here
9824.2 -> what we are doing
is we are checking
9826.9 -> whether the string P
9828.3 -> which holds the value happy
learning is ending with you,
9832.2 -> which doesn't right.
9833.509 -> That's the reason
it gave you false.
9836.1 -> Had it been G here it
would have given it true.
9840.1 -> Now that's about strings.
9841.822 -> Now.
9842.097 -> Let's talk about different
variant of strings.
9845.188 -> And why do we need it?
9846.9 -> So there are like three variants
9848.9 -> of string one is
the string class itself.
9851.4 -> The other one is stringbuffer
and you have a string Builder.
9854.6 -> So we'll talk about why
do we need this variance
9857.182 -> at the first place?
9859.034 -> So string buffer is nothing
but good for multi-threading
9863.4 -> when you have multiple threads.
9865.597 -> Usually it's good
to have string buffer
9868.368 -> because all the reads and writes
that you do on the string.
9872.6 -> It is synchronized.
9874.1 -> So when I say synchronized
there's only one thread
9877.869 -> that could access a particular
method within a class
9881.807 -> at any given point
9883.2 -> so you can't have
multiple threads going in
9885.678 -> and changing the value
or doing something.
9888.1 -> So basically if you have a
string within your application,
9891.3 -> which is been accessed by
multiple threads it's better
9894.8 -> to go with stream buffer
9896.509 -> or if there is lot
of not accessed as such access.
9900 -> One factor, but of course
9901.5 -> if there are a lot
of modifications done
9903.794 -> and stuff like that
like with stream
9905.792 -> before you could append a pain
to a particular string
9908.8 -> which cannot be done
9909.985 -> in string right
in stream buffer.
9912.141 -> You could actually do lot
of things it cannot be done
9915.2 -> and string and just
to make it thread safe.
9918.095 -> They have made all the methods
that modify the string contents
9922.21 -> as synchronized so
9923.425 -> that only one thread can access
it at any given point.
9927.1 -> So see you can see insert
here right in string.
9930.089 -> You don't have all these methods
you don't have methods
9933.6 -> to manipulate the strings
in string, right?
9936.7 -> Whereas in stringbuffer
you have methods
9939.3 -> to manipulate the strings.
9941.5 -> So when I say strings those
are literal strings,
9944.4 -> right not the string class.
9946.4 -> All right.
9947.3 -> So here we have string buffer
9950 -> and we are trying to append
something to the string buffer.
9958.946 -> So we define a class
we Define stringbuffer.
9966.7 -> So you could have
like S1 dot append
9970.8 -> and when you see
a pendant you could see
9973.8 -> that it appends any data type.
9976.7 -> This is the important factor
in stringbuffer you have lot
9980 -> of utility methods
9981.1 -> within or you have lot of
methods to manipulate the string
9985 -> which you don't have
within string class.
9988.2 -> All right.
9990.6 -> So this is mutable,
9991.957 -> right you are changing
the values suppose.
9994.885 -> I append three exclamation
marks do it, right.
10002.7 -> So what we are doing here
is we are just printing
10005.4 -> out the new string.
10006.5 -> All right.
10007.6 -> So basically you could you
should see at Eureka
10011 -> and the three exclamation marks.
10015.215 -> As you could see
here it got upended.
10018 -> So basically it's a mutable
string change the value
10021.5 -> with them insert is nothing
10023.6 -> but inserts a new character
at the given position.
10027.8 -> So here we are saying
that inside w at position zero.
10033.3 -> You could replace
it replace particular
10037.288 -> or replace substring
with a new string.
10040.9 -> So here what we are saying
is replace index starting
10045.3 -> from 0 till to with
this new character sequence.
10050 -> You could delete something
from it delete sequence of it.
10054.237 -> So here we are saying from
index 0 delete one character.
10058.4 -> So if you have two then it
would delete two characters.
10061.8 -> So basically when you
10063.138 -> say two characters even
this e would have been gone.
10066.388 -> Okay, in this case,
10067.8 -> we are just
deleting one character.
10069.9 -> So basically this delete method
takes the starting index
10073.7 -> and the number of characters
following the starting index.
10077.2 -> Zebras you have like you
could reverse the entire string.
10081.5 -> Okay, so just to show
you again new string dot
10087.234 -> if I reverse it.
10090.3 -> So basically this is a kind
of utility methods
10093.4 -> which we often use right
10095.8 -> so you can see it's
been reversed here.
10099.3 -> All right, you
can see the capacity
10101.175 -> of the string capacity
of the string buffer is nothing
10104.1 -> but I think it reserves
16 characters initially
10107.712 -> when you declare it
10109.2 -> and it keeps on incrementing it
10111.6 -> so it has a growth factor
defined within which
10114.547 -> you did not take care
of at this point,
10116.998 -> which you did not think
about it at this point
10119.9 -> because those are internals
to Java but initially
10123.52 -> when you declare a string
string buffer storage space
10127.5 -> for 16 characters,
10128.915 -> which is 32 bytes.
10130.6 -> If you have stringbuffer by do
we have string Builder, right?
10134.319 -> So string buffer
as I said has some drawbacks.
10137.9 -> What are the drawbacks is more
about string buffer
10141.394 -> is synchronized when I
say synchronized which means
10144.936 -> that only one thread
can enter it only
10147.44 -> one thread can process it.
10149.2 -> So basically if you have
a multi-threaded application,
10152.651 -> you should go
with synchronization
10154.8 -> because synchronization has
some overhead, right?
10158.237 -> It has its own trade offs.
10160.147 -> So when you
when you synchronized
10162.43 -> what happens is
10163.5 -> when you move out of
the synchronized methods
10166.4 -> DVM internally has
to do some operations
10169.213 -> which takes some time.
10170.8 -> So basically it's good
to avoid synchronization
10174.2 -> and which would make
10175.377 -> the application much
more faster and that's
10177.847 -> where stringbuilder
comes into picture
10179.905 -> if it's a
single-threaded application
10181.826 -> wherein you know that you
don't have multiple threads
10184.682 -> which are going to access
a particular string
10187.009 -> in that case.
10187.809 -> You should go with string
Builder as against ring.
10190.499 -> First because stringbuffer
would give you a slightly
10193.854 -> lower in performance
compared to stringbuilder.
10196.7 -> Most of the things
10197.794 -> that string buffer does is done
by stringbuilder as well.
10201.2 -> As far as the functionality
is concerned but it's not thread
10204.782 -> safe stringbuilder is faster,
10206.551 -> but it's not thread safe
10208.016 -> which means that you cannot have
multiple threats accessing it.
10211.8 -> All right, so to keep it simple,
10213.8 -> if you have multiple threads
accessing or string buffer,
10217.035 -> then you should go
with stringbuffer.
10218.975 -> But if you have
a single-threaded application,
10221.4 -> you should go with string
Builder which would make
10224.001 -> the application much more faster
10225.7 -> than stringbuffer again
with stringbuilder.
10228.8 -> The default capacity is 60
when you initialize it stores
10233.5 -> as you could see
it allocated 16 space
10237.1 -> for 16 characters initially.
10240.6 -> So as far as the
demo is concerned,
10243.2 -> it's pretty much
similar to stringbuffer.
10245.416 -> As far as the
outcome is concerned.
10247.315 -> It's pretty much similar to
stream buffer is no difference
10250.5 -> as such but as far as
the performance is concerned
10253.712 -> stringbuilder is faster
than string buffer
10256.4 -> because it's not synchronized.
10258.7 -> Okay, so you define
a string Builder with happy
10262.597 -> and you append learning to it?
10265 -> Okay, and if you
try to print s B1
10268.4 -> which is appended with learning
10270.42 -> you will see happy learning
would see it been upended.
10274.2 -> Okay similar to stringbuffer
10276.016 -> when you delete character
10277.639 -> from index position
zero and one character
10280.3 -> from that position you would see
10281.9 -> that the H which is the first
character has been deleted out
10285.5 -> so you could see
10286.7 -> that at index 1 you
could insert welcome.
10289.9 -> You can see the entire string
10292.8 -> that is welcome being
inserted between okay,
10297.4 -> then you have reverse
Could reverse the entire string
10301.7 -> pretty much similar
to string buffer.
10304.8 -> So again, this one
is very similar.
10308.323 -> You have you are appending
you're deleting then you
10312.169 -> are inserting here you
have reversing here.
10315.4 -> This is pretty much similar to
what we did for stringbuffer as
10318.625 -> far as the syntax
10319.579 -> and semantics is concerned
10321.037 -> and the outcome is
the same as well.
10323.1 -> Just a performance change
in terms of speed right?
10327.2 -> So, when do you stringbuffer
and stringbuilder as I said
10330.946 -> if you have multiple threads you
10333.126 -> should go with string buffer
to make it thread safe,
10336.9 -> but it would be slower
as compared to stringbuilder.
10340.2 -> Okay stringbuilder is
10342.4 -> specifically good enough and you
have single-threaded application
10346.5 -> and it would be faster
10348.04 -> since it's not synchronized.
10350.3 -> So to make it thread-safe
you have synchronization
10353.371 -> which adds over it
10354.5 -> to the performance which takes
tool on the performance.
10357.3 -> That's why stringbuffer
is slower why to use
10361.491 -> object-oriented Concepts?
10364.1 -> So let's talk about
classes and objects.
10367.7 -> So classes are nothing
but it has got a street
10371.161 -> and behavior right
10373.238 -> as you could see
you have a class
10375.7 -> and you have
different objects, right?
10378.5 -> There's a phone
which is a class and
10380.72 -> which has got different types
of phones right rotary phone.
10384.4 -> Then you have a touch-tone phone
and you have a cellular phone
10388.4 -> this are objects
basically, right?
10390.4 -> So you define phone
which is pretty much Jen Rick
10393.591 -> and which has got State
and behavior class is something
10397.137 -> that is generate
10398.145 -> that has got State and behavior
but objects is something
10401.965 -> that is an instance of a class
10403.884 -> which would have
specific State and behavior.
10406.7 -> So phone by itself phone
is a Class by itself.
10410.023 -> Which may or may not have
specific behavior,
10413 -> but you could see
10414.133 -> that the specific phones
will have its own behavior
10417.466 -> to could Define
its own behavior.
10419.7 -> So all these three things
10421.406 -> that you see here
three types of phones
10424.1 -> and nothing but objects objects
of one class state is something
10429 -> that is defined by
instance variables, right?
10432.961 -> It's a class level variable
right at the class level
10435.961 -> you define something
10437.5 -> that gives State and behavior
is nothing but something
10441.249 -> that is defined by methods
like calculator was a class
10445.3 -> where in we had add
method and add method
10448.6 -> basically gave some Behavior
to the calculator class, right?
10453.5 -> So what are attributes
so you have a class
10457.4 -> and you have
attributes attributes
10459.7 -> and nothing but a property
of object and in Java,
10463.323 -> this is defined by your instance
variables basically class
10467.6 -> will have properties
which is nothing but the state
10471.4 -> which would be defined
by instance variables
10474.5 -> and you could imagine
10475.906 -> every instance will have
its own set of properties.
10479.3 -> It won't be the same right
in terms of the phone
10482.686 -> that we saw earlier.
10484 -> There were three different types
of phones you could imagine
10486.95 -> that it would have
different properties right?
10489.4 -> It's not the same.
10490.6 -> So what are the naming
conventions in generally used
10493.5 -> at the industry level for Java.
10495.4 -> So this is not something
10497 -> that is actually taken
care by compiler.
10499.86 -> So even if you follow
10501.4 -> this naming conventions still
the compiler would pass through
10505.2 -> but these are best practices
10507.1 -> or this is good to have thing
in the industry conventions
10511.1 -> is more about to keep On
the same page and make it easier
10514.878 -> for other developers
to understand more right
10517.716 -> or keep things simpler.
10519.2 -> So that's why
we have conventions.
10521.141 -> If you wouldn't have conventions
then people would prefer
10524.1 -> to write in their own way
10525.9 -> which would make
us difficult to understand.
10528.5 -> Alright.
10529.2 -> So for class name it
start with uppercase
10531.9 -> as we saw in all
the examples you would see
10534.9 -> that I have always used
started with the uppercase
10538.3 -> or it's rather camel casing.
10540.3 -> So in this case you could see
stringbuffer demo, right?
10544 -> So it starts with
upper case you have B,
10546.457 -> which is again
upper case you have B,
10548.807 -> which is again uppercase.
10550.3 -> This is nothing but camel casing
it starts with upper case.
10554.3 -> Basically it follows
10555.6 -> camel casing interface name is
again similar to class.
10559.9 -> It starts with upper case
you have method name
10563.38 -> which would be lower case always
10565.5 -> which should start
with lower case,
10567.818 -> but you could have it follows
10569.757 -> camel casing but it has
to start with lowercase.
10572.9 -> So maybe it's a predefined
method with in Java.
10575.4 -> Right?
10576.1 -> So you could see main
starting with lowercase
10579.4 -> or I created a dry Tad
10582.1 -> is again put C uppercase.
10584.692 -> If you would have say
for example at numbers
10588 -> you would have something
of this sort adverse.
10592.8 -> If you want to append
numbers to it,
10594.858 -> it should start with uppercase.
10596.6 -> So basically it's camel casing
but starting with lower case
10600.6 -> where as class name.
10601.925 -> It's a camel casing
10603.187 -> which starts with upper case
variable name is
10606.81 -> again camel casing we
should start with lowercase
10610 -> and constant is always
10611.676 -> like it has to be
everything in uppercase.
10614.9 -> So basically if I Define
a constant final string,
10619.3 -> I would write
something like this.
10624.7 -> okay, so and if you want
to add more words to it,
10628.6 -> it should be
like this underscore
10633.2 -> So it should be separated
out band score.
10636 -> All right.
10636.5 -> So these are the conventions
10637.9 -> that followed in Industry
by Java community.
10640.8 -> So mostly even
if you go to the source code
10643.3 -> if you want to see something dig
into the source code
10645.9 -> of java you would see
10647.209 -> same naming convention being
followed types of variables.
10650.7 -> We spoke about the types
of variables again to brief you
10654.155 -> through we have local variables
local variables are nothing
10657.8 -> but the variables
that are defined in a method.
10660.8 -> So if you define something
within a method
10663.842 -> that's local variable
10665.413 -> so ARG 100 or suppose
I Define and T local
10671 -> where is equal to a hundred.
10673.261 -> So this is
a local variable right?
10675.8 -> If you remember this is
within the scope of a method
10678.845 -> once the control goes
10680.1 -> out of a method your variable
is no longer accessible
10683.9 -> and also it gives space for
the jvm for garbage collector
10689 -> to kick in and clean up
this particular memory space.
10693.2 -> Variables are nothing
but it's defined
10695.5 -> at the instance level so
here for that matter.
10698.6 -> This constant is
also instance variable.
10701.9 -> All right, so I
can Define integer
10707.1 -> variable starts with lower case
and it follows camel casing.
10711.3 -> So this integer is nothing
but an instance variable.
10714.7 -> It's at the class level right
when your class is loaded
10718.3 -> when you refer
to this particular class,
10720.8 -> you will have your instance
variable initialized by Java.
10725.8 -> So instance variables
are declared in a class,
10728.5 -> but outside a method
Constructor or any block.
10731.6 -> Okay class variables are nothing
but static variables
10735.6 -> and it is one copy per class.
10738.9 -> So as against instance variable,
which is one per object,
10743.407 -> whereas static variable
or class level variable
10747.6 -> are it's just one per class.
10750.826 -> So if you define static,
10752.7 -> this is just one per class
and this could be accessed
10757.211 -> directly using calculator
calculator dot constant example,
10761.9 -> you would be able to access it
but for instance variable,
10765.7 -> you need to have
an object created.
10767.867 -> This is non-static basically
non static instance variable.
10772.2 -> So one of the reasons
why you need to access
10775.03 -> instance variable is
10776.311 -> because different instances
might have different values
10779.772 -> for a particular
instance variable, right?
10782.4 -> I could Define
calculator one right?
10786.2 -> Let me put it as calculator
10790.092 -> and we have like
normal calculator.
10795.8 -> You could have
one more class which is
10797.881 -> like scientific calculator.
10800.5 -> It's one more object.
10805.8 -> Now a normal calculator
can have its instance value
10809.8 -> as 10 and scientific
10811.8 -> calculator can have
10813.201 -> its instance value as a hundred
you have different values,
10817.596 -> but whereas in static
since it's one per class,
10820.9 -> it's not at the object level.
10824.1 -> So you have mod is
equal to new demo,
10827 -> which is an instance
of a class demo.
10829.5 -> And you print message right
10831.9 -> d dot print message and it
should print this message.
10835.4 -> So basically there's
a class demo
10837.861 -> which has got
a method print message
10840.7 -> and we are trying
to invoke that message
10843.3 -> from the main method.
10845.3 -> Okay, let's talk about
the constrictor constrictor is
10848.5 -> nothing but when you invoke
new keyword new calculator,
10852.512 -> there is a Constructor implicit
Constructor for each class,
10856.693 -> which is without any parameters.
10859 -> So we'll talk about that.
10860.615 -> But when you do new calculator,
10862.6 -> basically there's a method
10864.322 -> which could be used by
the programmers to initialize
10867.7 -> variables if they want
to initialize something.
10870.72 -> So for each instance,
10872.1 -> if you want the same value
for instance variable,
10875.248 -> you could initialize it
with in Constructor.
10877.9 -> So basically Constructors are
for initialization or
10881.211 -> if you want to do some kind
10883 -> of pre-processing
break on invocation
10885.5 -> if you want to initialize
something or do some kind
10888 -> of pre-processing
10889 -> that could be done through
Constructor Constructor is used
10892.8 -> in creation of an object.
10894.698 -> It is a block of the code
used to initialize an object.
10898.8 -> So when I say
initialize an object,
10901 -> it's nothing but initialize
some property or variable
10904.866 -> within your class Constructor
10906.984 -> must have the same
name as the class.
10909.613 -> It is in and it does not have
any return type.
10912.9 -> So unlike method,
10914.3 -> which has got a return
type Constructor won't have
10917.282 -> a return type at all
10918.5 -> because what we are trying to do
10920.389 -> through Constructor is
just to initialize objects
10923.224 -> within but you can't return
something out of it.
10926 -> So basically you Constructor
is a special method
10928.8 -> which you don't have control
10930.2 -> over you are not doing anything
within it you're not trying
10933.377 -> to actually return
something out of it,
10935.6 -> right?
10936.1 -> You don't have control
over its invocation.
10938.9 -> It's done by jvm itself jvm
calls this special method
10942.901 -> when you invoke knew
10944.7 -> or when you create an instance
of it by using this new keyword
10949 -> Constructors are of
two types default Constructor
10951.7 -> and parameterised Constructor.
10954.6 -> So when I say
default Constructor
10957.2 -> and parameterised Constructor,
10958.999 -> this is nothing but
so I am defining
10961.4 -> a Constructor now calculator
10964.4 -> as I said, it has to have
the same name as the class.
10968.1 -> Okay.
10968.8 -> So this is a Constructor.
10970.8 -> And as I said,
10971.8 -> this could be used
for initialization of variables.
10975.1 -> Say I initialize this 200.
10977.5 -> So for all the objects
you would see this
10980.7 -> being initialized to 200.
10984.3 -> That's the initialization.
10985.9 -> Okay, so I have created
two instance of it to instance
10989.174 -> of calculator class
10990.348 -> that is normal calculator
and scientific calculator.
10993.8 -> Let me do normal calculator
dot instance variable.
11002.715 -> Okay.
11003.1 -> So here we are printing the
value of the instance variable.
11006.9 -> Let me copy
the same thing again,
11009.3 -> but in this case.
11012.6 -> the second case I would be
As you could see here.
11024.9 -> We have a Constructor.
11026.2 -> I defined a Constructor
here Constructor for a class
11029.326 -> which is initializing
the instance variable
11031.9 -> to Value 200.
11032.706 -> So as in when you call this new
calculator a new instance
11036.049 -> of calculator would be created.
11037.9 -> The first thing
that would be called.
11039.905 -> Is this Constructor
and which would initialize it.
11042.788 -> So basically what we are trying
to do here is we are right
11045.999 -> after the construction
of this particular object.
11048.601 -> We are going to print the values
of instance variable to see
11051.8 -> if it assigned 202 it.
11056.076 -> So here you can see the value
200 being printed out.
11060 -> So basically if I wouldn't have
11062.3 -> Constructor then the value
wouldn't have been 200.
11065.257 -> So let me comment out this one.
11067.228 -> This is how we comment in Java.
11069.191 -> By the way.
11069.9 -> This is a block comment
which starts with Slash
11073 -> and asterisk and which ends
with asterisk and smash.
11077.2 -> So I commented out that one I
comment out the Constructor
11081.2 -> and you would see the value
being initialized to 0
11085.1 -> so you could see value
been initialized to 0.
11088.5 -> All right, so that's what
Constructor is all about.
11092.3 -> Now.
11092.575 -> This is a default Constructor.
11094.643 -> You could have
parameterised Constructor,
11097.4 -> which is like integer
you provide some value right
11102.1 -> and you assign
this value to variable.
11105.6 -> So instead of hard-coding
this value of 200
11108.336 -> for the instance variable
you could pass on some value
11111.789 -> during the construction
of the object.
11114.2 -> So basically what we are doing
here is I pass 30 here
11120 -> and bypass 40 here.
11122.361 -> Alright, so I am passing 30
11124.592 -> and I'm passing
42 the Constructor.
11128.1 -> And as you could see here,
11130.2 -> we are initializing
the instance variable
11133.861 -> to that value.
11135.2 -> So basically for
normal calculator,
11137.815 -> it should be 30
and for scientific.
11141.356 -> It should be 40.
11144.6 -> Yeah, as you could see
here you have 30 and 40
11148.2 -> min printed out and this is
the parameterised Constructor.
11151.3 -> That's what this default
and parameterised Constructor
11155.29 -> and that's what it is all about.
11157.7 -> So default Constructor
is you don't even have
11160.847 -> to specify any Constructor.
11162.753 -> So I commented this calculator
constructed still implicitly.
11166.8 -> There is the Constructor
put in by jvm,
11169.4 -> which is the
default Constructor.
11171.2 -> So it's not mandatory
to have Constructor each time
11175 -> unless you want
to initialize something.
11176.95 -> So what's the difference
between Constructor
11179.168 -> and Method constructive
must not have a return type?
11181.8 -> Whereas method may
or may not have a return type
11185.3 -> here you could see that
unlike the methods add integer,
11189.5 -> which return something.
11191.048 -> This doesn't say anything.
11192.6 -> This doesn't return anything
11194 -> because we are not doing
anything within it.
11196.3 -> You're just initializing
11197.9 -> it initializing some instance
variables right Constructor name
11202.147 -> must be same as the class
11203.888 -> so that This is a contract
this has to be followed
11207.246 -> Constructor has to have
same name as the class,
11210.4 -> since you are not invoking
the Constructor by yourself.
11213.886 -> It's done by the jvm.
11215.254 -> You don't have control
over invocation of Constructor
11218.714 -> and you have to follow
the naming pattern that Java
11222.1 -> recommends to or Java forces us
to you have to make sure
11225.9 -> that instructor is given
the same name as the class name.
11229.719 -> Whereas method can have any name
11231.873 -> as we saw the add method you're
free to use whatever method name
11236.039 -> that you want to Constructor
11237.813 -> is used to initialize
the state of an object.
11240.6 -> We saw the instance variable
being initialized
11243.4 -> within the Constructor method
is basically it gives
11246.9 -> some Behavior to a class right
11249.4 -> we saw add method
11250.8 -> which is giving some Behavior
to the calculator method,
11254.062 -> which is nothing
but adding up two numbers.
11256.7 -> Similarly.
11257.2 -> You could have multiplied
you could have divided
11259.5 -> and stuff like that
11260.5 -> which adds more Behavior
to it Constructor is invoked.
11264.601 -> Implicitly so you
11266 -> don't have control
over invocation of Constructor,
11269.3 -> which is done by Java itself.
11271.2 -> When you try to
instantiate a class
11273.569 -> or when you use the new keyword,
11275.803 -> it's implicitly invoked
by Java by jvm.
11278.869 -> Whereas method you have
to invoke it manually.
11282.4 -> So basically when you
11283.9 -> do this Constructor
is called by itself.
11286.678 -> Whereas when you want
to call add numbers,
11289.6 -> you have to
invoke it explicitly.
11292.3 -> How does Constructor work
the moment object of a class
11295.748 -> is created The Constructor
of the class is called
11298.6 -> which initializes
the class attributes, right?
11302 -> So we saw about this.
11303.315 -> So when you use the new keyword
jvm by itself would give a call
11307.2 -> to the Constructor
11308.32 -> which could be
used for initializing
11310.5 -> initializing instance variables
within your class.
11314.6 -> So type of Constructors
11316.3 -> this default Constructor and
this parametrize Constructor,
11319.683 -> which we already spoke
about the Constructor,
11322.298 -> which is created by the compiler
11324.2 -> without any parameters is
the default Constructor
11327.3 -> and the Constructor
with specific number
11329.914 -> of parameters is called
parameterized Constructor.
11333.5 -> So here we spoke
about this already.
11336.2 -> So we have integer value, right?
11338.7 -> This is a
parameterised Constructor,
11340.694 -> since you are passing parameters
to the Constructor,
11343.6 -> whereas if you don't Define
anything Java by itself,
11347 -> so in this case you could see
that we didn't have
11350 -> a Constructor for
this class straight.
11352.105 -> I read them all we don't have
Constructor for this class.
11355.5 -> So Java by itself puts
her default Constructor
11359.5 -> for array demo,
11361.1 -> which is known as
default Constructor.
11363.5 -> So it's not mandatory
11365.2 -> that you need to have
Constructor every time
11367.864 -> since Java takes care of it.
11369.6 -> That's the differentiation
between default Constructor
11373.084 -> and parametrization.
11374.9 -> We use parameterised Constructor
11376.957 -> for passing values
to the Constructor
11379.3 -> and initializing something
based on the value
11382.197 -> that's been passed
out past in brother.
11385.6 -> So the default Constructor
is used to provide
11388.509 -> the default values
11389.7 -> to the object like 0 null
depending on the type right
11394.1 -> when I didn't have
any Constructor at all
11396.3 -> for a moment.
11397.108 -> I am going to comment this.
11398.788 -> So this is a line comment
when you put two slashes.
11401.9 -> It's a line comment.
11404.1 -> Okay, it's commenting just
11405.57 -> this particular line This
is a block comment
11408.1 -> and this line comment block
comment is slash asterisk
11412.2 -> and ends with asterisk.
11414.5 -> / whereas line comment is
two slashes forward slashes.
11419.7 -> Okay.
11421.2 -> So basically a comment
or disc instructors as well.
11428.1 -> Alright now we have this
calculator class now lets me.
11434.4 -> Let me print the value
of the instance variable.
11439.7 -> value of instance
variable initialized
11445.7 -> by default Constructor.
11450.5 -> All right, so we don't have
a Constructor at all.
11452.6 -> So that's what I
am trying to say here.
11454.5 -> I commented out
this Constructors, right?
11457.5 -> So we don't have
a Constructor at all.
11459.84 -> And when you create
a new calculator jvm
11462.404 -> by itself would have
a default Constructor
11465.1 -> which is used by jvm
to initialize variables within
11469.3 -> so you would see
11470.6 -> this instance variable has
zero value as 0 because that's
11475.1 -> what the default
Constructor does.
11477.5 -> It assigns some value
to it has like specific values
11482 -> for integer it 0
11483.919 -> if it's a class it would be null
11486.8 -> so you could see the value being
printed as 0 if it's a class
11490.593 -> it would assign value null.
11492.3 -> So in this case you have string
right and you could see 0 null
11497.5 -> depending on the type
of instance variable
11499.718 -> that we are dealing.
11501.1 -> We saw how we pass parameters
and initialized it.
11505.3 -> Constructor overloading is just
like method overloading
11508.554 -> without written type
Constructor overloading
11511.455 -> in Java is a method of having
more than one Constructor
11514.723 -> with different parameter lists.
11516.9 -> Like we defined add we had
11519 -> to add methods and now I have
renamed this to add numbers,
11523.484 -> but basically this
was add method right
11526.3 -> so you could have multiple
methods with the same name
11529.7 -> but different parameter lists,
11531.521 -> which is known as overloading
similarly for Constructor.
11535.358 -> You could have
the same Paradigm.
11537.3 -> So basically what we
are trying to do here is
11539.94 -> we have a Constructor
with 1 parameter
11542.241 -> that sing teacher I'll Define
one more Constructor here
11545.6 -> with two parameters.
11548.5 -> So we Define one more parameter
here and I say for example,
11552.961 -> I put something like this.
11556.4 -> So we are adding up
these two parameters
11559.324 -> and putting it
into instance variable.
11562.6 -> Okay, this is
Constructor overloading.
11565.5 -> So here you have single
parameter been passed here.
11568.779 -> You have multiple parameters
being passed So
11571.6 -> based on whatever you pass
here suppose I say 10 and 20.
11577.2 -> Or say I say?
11580.1 -> So on construction you
11582.2 -> should C-130 as the value
of the instance variable.
11592.1 -> Okay, as you could see here,
11594.2 -> you have the instance variable
initialized to 130,
11597.5 -> which is nothing but edition
of hundred and ten and twenty
11600.894 -> and you could have something
like this just hundred and ten,
11604.386 -> which is also K
11605.302 -> because you have
a single distinct defined
11607.806 -> as well Constructor taking
a single value as well.
11610.9 -> And in this case,
11611.958 -> it would be just a hundred
and so Constructors are nothing
11615.4 -> but methods which helps
in construction of object.
11620.4 -> All right, so you get
a hundred and ten here?
11624.5 -> So Constructor overloading is
in Java is a technique of having
11628.149 -> more than one Constructor
with different parameter lists.
11632.476 -> So we had a demo about it
11634.5 -> as I showed there were
multiple Constructors
11637.3 -> one with one parameter
11638.628 -> and the other one
with integer parameters
11641.145 -> and during runtime
based on whatever you
11643.6 -> pass a particular instructor
would be called in this case.
11647.345 -> You could see
11648.2 -> that in the first case
11649.99 -> which is shop s 1 you
could see the first Constructor
11653.99 -> been called which has
two integers as being passed.
11658.2 -> Whereas when you create
11659.9 -> object S 2 which has
two integer parameters
11662.8 -> and one string you could see
11664.555 -> that second Constructor
is being called.
11668.3 -> What's Constructor chaining
so Constructor chaining
11671.5 -> is the process
11672.2 -> of calling one Constructor from
another Constructor with respect
11675.605 -> to the current object?
11676.9 -> The real purpose
of Constructor chaining
11678.75 -> is to pass parameters to a bunch
of different Constructor,
11681.8 -> but the initialization
11683 -> should be done at a single place
Constructor chaining can be done
11687.5 -> in two ways within the same
class from the base class
11691.3 -> and Constructor chaining
occurs through inheritance.
11695.2 -> So basically for
Constructor chaining,
11697.2 -> there are two key words
that we have.
11699.4 -> So one is this this
itself is a keyword
11702.5 -> in Java this pH is
this is a keyword
11706.035 -> and the super keyword.
11707.953 -> Let's see how we how we do it
for this particular Constructor.
11714.8 -> I have this Constructor
which has this value, right?
11720.1 -> So instead of
doing this directly,
11722.41 -> what I could do is so here.
11724.3 -> I was initializing
this value directly
11726.567 -> to the instance variable.
11728.1 -> What I could do
through Constructor chaining
11730.8 -> as I could do this
11733.2 -> and I could pass
the value comma zero.
11738 -> So basically you're
chaining here, right?
11740.1 -> You could see
11740.87 -> that what I am trying
to do here is I am trying
11743.6 -> to invoke this Constructor
from this Constructor.
11747.1 -> That's what the chain
is all about.
11749.3 -> So when you say this it
tries to find Constructor
11753.327 -> within your class
11754.7 -> which takes two parameters
to integer parameters
11757.9 -> and this is the one
it finds out, right?
11760.3 -> It has two parameters.
11762 -> And basically what we
are doing is we are keeping
11765.222 -> the second parameter is 0
11766.9 -> which means it would initialize
the instance variable
11770.342 -> to whatever value you have here,
11772.6 -> right?
11772.9 -> This is what Constructor
chaining is all about.
11775.3 -> It's more about calling
Constructor of the same class
11779.5 -> within the Structure
of the same class.
11781.6 -> So basically from
this Constructor you are giving
11784.188 -> a call to this Constructor
that is constructive change.
11788.238 -> Super should be the first
11791.011 -> it gives a call to
the super Constructor.
11794.6 -> So you have a subclass
and superclass, right?
11798.05 -> What do you do here is
you give a call to superclass?
11802.8 -> For Constructor chaining.
11804.049 -> I think they
should be good enough
11805.7 -> where and you use this keyword
to call Constructors
11809.311 -> within the same class.
11811.7 -> You basically chain
them together, right?
11814.3 -> We have demonstration
on Constructor chaining here.
11818.3 -> When you create student you
could see there's a Constructor
11822.1 -> without any parameter
11824 -> and we could see
this Meghan been called.
11828.7 -> So basically what we are trying
to do here is the default name
11833.2 -> would be Meghan, right?
11835.923 -> So and again we have
one more Constructor,
11839.1 -> which is overloaded Constructor,
11840.8 -> which takes name
11841.925 -> and in that case it would give
a call with the specified name
11846.2 -> and Mark as 70.
11847.4 -> So basically 70
is a default marks
11850.2 -> that we are signing and you
can is the default name here.
11854.4 -> If you don't provide name,
it would be Meghan.
11858 -> All right.
11858.8 -> So this is what Constructor
chaining is all about.
11864.1 -> Static keyword
static keyword again,
11867 -> we have spoken about
in couple of instances,
11869.675 -> but I'll just walk you
through this slide again.
11872.6 -> The static keyword is used
for memory management static
11876.6 -> is non access modifier used
in Java accessible applicable
11882.2 -> for blocks methods class
variables static keyword
11887.5 -> is used to refer the common
properties of an object.
11891.109 -> So as we spoke it's
at the class level,
11893.8 -> it's not at the object level.
11895.8 -> We have it common
across all the objects right
11899.7 -> when the static keyword is used
to declare any parameter.
11903.45 -> Then memory is allocated
only once for that parameter.
11907.4 -> So in this example,
11909.2 -> we could see that
since it is one per class.
11912.8 -> So you would have
this constant example
11915.934 -> Define just once right
it would be allocated.
11919.2 -> Just once whereas the non-static
ones like this in.
11924.1 -> This variable you
would have memory allocated
11927.646 -> for each and every instance.
11929.8 -> So basically for this instance,
11931.7 -> you would have memory allocated
for this instance variable
11935.1 -> for again this normal calculator
11936.992 -> that we had earlier
you would again have
11939.3 -> a memory allocated
for instance variable.
11941.8 -> All right, so it's
one per object
11944.4 -> whereas the static ones
are one per class.
11948.9 -> So yeah memory is allocated
only once for that parameter.
11953.4 -> All right.
11954.1 -> So here we can see
11955.3 -> that this we have
a static string company
11958.7 -> which has some company
named put in there
11961.4 -> and we are just displaying it
11963.9 -> right we can see
11965.3 -> that we are displaying ID salary
and Company and you could see
11969.8 -> that for both the instances
for even and E2
11973.4 -> you have two employees here
11975.4 -> with ID 25 and salary
25,000 and we have employee
11981.8 -> to with salary 30.
11984.5 -> Sorry with ID 30 and
salary 3000 right?
11988.5 -> So we are defining
two instances of employees
11991.681 -> and you can see here.
11993.2 -> We are not passing
the company name as a parameter
11997.3 -> to the Constructor right still
11999.9 -> when you display it look
at the output at the right side.
12003.8 -> You can see
12004.487 -> that it has displayed
twenty five twenty five thousand
12007.8 -> and SRT Traders
the company name came by itself
12011.7 -> because it's one per class.
12014.3 -> So what we are assuming is
12016.5 -> this class is basically designed
just for one company,
12020.9 -> right that is SRT creators.
12023.3 -> So all the instances
12024.6 -> of the class are
all the employees
12026.7 -> that you create here.
12027.9 -> All the instances of employees
12029.4 -> that you create here will have
the same company name
12032.4 -> that is defined here
12033.921 -> since it is one per class.
12036.3 -> Whereas their ID
and salary would be variable
12040 -> which would differ as
12041.3 -> per the value that you
passed to the Constructor.
12043.9 -> here we can see that company is
12045.6 -> a static variable little
allocates memory only once So
12049.467 -> here it could be seen
12051.005 -> that you as I mentioned earlier
you have reference variables
12055.328 -> being created out in the stack.
12057.6 -> And in the Heap memory,
12059.325 -> you could see
values being stored.
12061.9 -> So ID is tri-five salaries
25,000 for E2 ID is 30
12068.9 -> and salaries 3000 and you
can see the static variable.
12073.9 -> So basically static variable
is stored in a different space
12077.478 -> which is permanent
generation memory.
12079.7 -> That's where the static
variables are stored.
12083.2 -> So method could have
static as well.
12086.2 -> When a method is static
you did not create instance
12089.683 -> of a method to call
that method instance
12092.4 -> of a class to call that method
pretty much similar
12096 -> to static variables, right?
12098.7 -> So basically I can have
one more static method here.
12104.3 -> So say for example I have
private static all right,
12110.8 -> so So what I was trying
to say here is you
12119.9 -> could have calculator. .
12124 -> And you could directly
call the display method.
12127.9 -> So you do not have instance
12129.845 -> of a class created its
at the class level.
12132.861 -> This is at the class level
rather write one per class.
12137.8 -> Let's talk about this keyword
12140.03 -> that this keyword is used
as a reference variables
12143.8 -> to the current object.
12146.2 -> So basically what what it
is trying to say here is so
12153.6 -> if I want to
print something here,
12155.963 -> let me print
the instance variable, right?
12161.4 -> So within the add method
12162.9 -> what I am trying to do is
I am printing the value
12165.8 -> of instance variable
Within add numbers, right?
12175.6 -> So I'm trying to print the value
12177.2 -> of the instance variable
within add numbers
12180.7 -> which would be
basically this is
12183.084 -> where we are calling at numbers.
12185.2 -> So basically it should be
a hundred and ten, right?
12189.3 -> When we have such scenarios
12190.888 -> where and we refer
to an instance variable
12193.5 -> within a method we could see
here printing the value
12196.7 -> of instance variable
within add numbers gives
12199.547 -> you a hundred and ten
right the implicitly
12202.2 -> what happens is
12203.3 -> it puts this dot here
this dot instance variable.
12208.2 -> All right.
12208.7 -> So what we are trying
to say is the instance
12212.001 -> on which the add numbers
was called on the same instance,
12216.3 -> whatever the value of
instance variable is just print
12219.9 -> that thing out.
12220.9 -> So this is implicitly
put in here you
12223.2 -> need not use this keyword.
12225.1 -> This keyword is usually used
12227.2 -> when you have something
like this right when you
12230.7 -> have instance variable suppose.
12233.6 -> You have something of this sort.
12235.2 -> Right?
12235.8 -> One of your parameters
is same as
12238.2 -> as the instance variable, right?
12240.3 -> So you want to differentiate
which is the instance variable
12243.8 -> and which is
this variable right?
12246.2 -> So that's when you
12247.8 -> use this When you say
this dot instance variable,
12252 -> this is referring
to this instance variable
12254.1 -> and this instance variable
12255.7 -> to the right hand side
is referring to this one.
12259 -> Alright, so that's
12260.4 -> when you have to explicitly
put this or in other cases.
12264.746 -> It's done by the jvm itself.
12266.9 -> You did not take care of it.
12269.7 -> All right, so So,
12272.6 -> this can be passed
as an argument
12274.942 -> in the Constructor call.
12276.9 -> This can be used to invoke
current class method.
12280.453 -> This can be passed as
an argument the method call
12284.4 -> and this can be used to invoke
current class Constructor.
12289.965 -> This could be past basically
if there is one more.
12300.6 -> so say for example,
12302.2 -> you have something of this sort
which is pretty big though,
12305.1 -> but Admitted taking
calculator as its parameter.
12314.6 -> Okay, so I'm just trying
to demo you could actually take
12319.3 -> calculator as an argument
for any of the methods within.
12323.9 -> All right.
12325 -> So you have ADD method
12326.75 -> which takes calculator
as its parameter.
12330.3 -> Alright, so here say for example
within this method don't think
12334.6 -> about the logic it's
not logical though.
12336.9 -> I'm just trying to show
you it could be done.
12339.5 -> Right?
12340.6 -> So I have ad and I put this
within your method
12347 -> you could have you could pass
as an argument you could pass
12350.8 -> this as an argument.
12352.11 -> So basically you
are invoking this one.
12355.1 -> So now if I print it
12357 -> you can see in add numbers you
have this method being called.
12365.5 -> So yeah here you
can see printing out
12368.3 -> the add method taking calculator
has its parameter.
12372.1 -> So basically it's calling
this on by passing this.
12377.1 -> So here we spoke
about the Constructor earlier.
12379.891 -> We saw how this could be used
in The Constructor and one
12383.204 -> of the use cases
12384.102 -> as I said here you could see
that similar to the example
12387.337 -> that I spoke regarding
the instance variable.
12389.9 -> You could see
the parameter the name
12392.323 -> of the parameter is rule number
12394.342 -> which is same as the name
of the instance variable.
12397.6 -> This one is pretty
much similar to that.
12399.9 -> You could see
that the name of the parameter
12402.8 -> that is passed to
the Constructor is same
12405.017 -> as the instance variable name
the rule number two.
12408.6 -> The left hand side is nothing
but instance variable
12411.6 -> within the class info
whereas to the right hand side.
12415.394 -> It's a rule number
12416.5 -> that is passed as an as
an argument to the Constructor
12420.2 -> similarly for the name
you have this dot name,
12423 -> which is referring to the name
the instance variable
12426.2 -> in the class info
and to the right hand side.
12428.4 -> It's a parameter that's passed
to the Constructor.
12431.752 -> That's a typical use of this.
12434.5 -> So we are creating a message
here and you can see
12437.4 -> that we are giving a call
within the Constructor.
12440.2 -> This is within
the Constructor actually,
12442.438 -> so we saw this
in the previous example.
12446.2 -> Basically, this is
12447.41 -> what it does write
this value of 0 that is
12450.251 -> what this is doing within
the Constructor you have this
12453.861 -> and you are giving a call.
12455.7 -> So in this case this Annie would
give a call to message string n
12461.076 -> and would print it out.
12463.5 -> So how does it work
the main function is executed.
12467.7 -> So again, this is a sequence
in which the things execute
12471.2 -> behind the scenes.
12472.507 -> The main function
is executed first,
12475.2 -> when an object of the class
is created a default Constructor
12478.7 -> is called okay,
12479.723 -> in this case, the one
without parameter is called
12483 -> right then you have this dot any
12485.5 -> which is nothing
but you're giving a call
12488 -> to the Constructor
within the same class,
12490.6 -> but with the parameter
any so the jvm would check
12494.4 -> whether you have a Constructor
with parameters as string,
12498.6 -> so it finds it and it would give
a call to that Constructor,
12502.868 -> which is nothing
but the Constructor
12505.4 -> that you see here
in a Blue Block right,
12509 -> then it would similar
to any method
12511.8 -> after the method
invocation is done.
12514.027 -> It comes back
to the calling method, right?
12516.7 -> So after this and is called it
comes back here then it prints.
12521.067 -> Welcome to edu Rica.
12522.8 -> And once this is done,
12524.4 -> it would go back
to the main method in general.
12527.5 -> What happens is whenever
a method is invoked
12530.066 -> the local variables
12531.274 -> and everything is pushed
12532.8 -> onto the stack similar
to C. Write in C.
12535.343 -> Also you have a calling stack.
12537.3 -> So your local variables
go into the stack.
12540.114 -> The calling method is invoked
12542.111 -> after the method
is being invoked
12544.199 -> and is completely done.
12545.7 -> It would come back to the stack
12547.5 -> and start off from
where it had left earlier.
12550.8 -> So typically how the subroutines
12552.4 -> and everything work
in programming language.
12554.7 -> That's how it's done
in Java as well.
12556.9 -> So that's why we
have calling stack.
12560 -> So that's the sequence
of execution that happens.
12563.8 -> So let's start off
12564.989 -> with object-oriented
programming Concepts.
12567.8 -> This is pretty much generic.
12569.574 -> This is not something
that is just for Java.
12572.3 -> So this is object
oriented programming concept,
12575.4 -> which usually all
12576.4 -> the object-oriented
programming languages use it
12579.9 -> or adhere to it.
12581.453 -> So we have Which we'll
be covering up in the topics
12585.3 -> to come polymorphism,
12587.3 -> which is we have
like static polymorphism
12590.2 -> and we have Dynamic polymorphism
cover it up in details.
12594.4 -> The coming slides
12595.7 -> will talk about what is
abstraction and also
12598.504 -> how Java has encapsulation
12600.2 -> or how Java is aligned words
the encapsulation feature
12603.48 -> of object-oriented programming.
12605.4 -> So let's start off
with inheritance just to give
12608.7 -> you an analogy you could think
of inheritance anything
12611.9 -> that is derived have
some super class
12614.5 -> or you have something from which
other subclasses are derived
12618.6 -> when you have some feature
of your parents.
12621.202 -> We say that you inherited right
12623.109 -> because you have got it
from your parent.
12625.462 -> So you have a parent
12626.615 -> so this could be an illogical
to something of that sort.
12629.8 -> Maybe you are looks is inherited
from your parents sort
12633.1 -> of that is exactly
what inheritance is all about.
12636.4 -> You have a parent class
12637.997 -> and you could have
subclasses out of it
12640.576 -> and this subclass
is would inherit.
12642.922 -> Features or inherited State
or the behavior?
12645.891 -> I would say
of your parent class.
12648.085 -> So to give you an example
12649.8 -> as you could think of vehicle
right vehicle is generic thing
12653.8 -> which could be a super class
12655.3 -> so vehicle could be thought
of as a superclass.
12658.462 -> Now, there are subclasses
to Vehicles you have bike
12661.9 -> which is a type
of vehicle you have car
12664.5 -> which is a type
of vehicle you have buses,
12667.2 -> which is again a variant
of vehicle and truck
12669.912 -> of course is again a vehicle.
12671.7 -> So basically this defines
easier relationship by
12675.2 -> if you read it out
you could Clearly say
12677.4 -> that bike is a vehicle
car is a vehicle
12679.715 -> but it's a vehicle
and similarly truck is vehicle.
12683.102 -> So basically this is something
like it defines.
12686 -> He's a relationship.
12687.568 -> So let's see about
how actually this classes
12690.9 -> or the sub classes inherit
12692.501 -> from the parent classes just
to read out inheritance
12695.746 -> is a powerful feature
object-oriented programming
12698.8 -> through which one
object acquires some
12701.625 -> or all properties.
12703.006 -> Behavior of parent object.
12705.3 -> So as I said,
it's an easy relationship.
12708.3 -> So he's a relationship
is represented in Java
12711.22 -> through inheritance.
12712.604 -> It could also be seen as
a parent child relationship.
12716.2 -> So subclasses are actually
child of parent classes
12720.8 -> in the previous case you have
by which is a subclass
12724.9 -> of superclass vehicle.
12726.8 -> So vehicle is a superclass
12728.438 -> and henceforth we
would be talking in this terms
12731.48 -> of we would be using
this terminology is so
12734.2 -> just wanted to be sure you get
it so vehicle is nothing
12737.73 -> but a superclass
12738.84 -> and by could be
henceforth referred
12741.2 -> as subclass child classes
would be referred as subclass.
12745.3 -> So you have method overriding
12747.3 -> what do you achieve
by inheritance is more
12750 -> about method overriding
to achieve runtime polymorphism.
12753.922 -> And the second thing
is code reuse ability
12756.867 -> as I mentioned
the subclass would inherit
12759.644 -> properties and behavior
from your superclass.
12762.7 -> Your parent class so there
could be some method defined
12766.2 -> in your super class
12767.7 -> which need not be redefined
in your subclass.
12770.7 -> It inherits by itself.
12772.3 -> That is the property
of inheritance.
12774.2 -> If it has got a common Behavior
like say you have two kinds
12777.3 -> of calculator different types
12778.75 -> of calculated the example
that we spoke about yesterday.
12781.5 -> There could be
a parent class calculator,
12783.5 -> which is adding numbers
as is you provide two numbers.
12786.9 -> It adds up and it gives
you maybe this add
12789.718 -> Behavior could be added
12791.3 -> into the calculator
Claus now Suppose there is
12794.299 -> a subclass of calculator
12795.7 -> where in you
12796.5 -> have this scientific
calculator or something
12799.049 -> which is modifying
this behavior of our
12801.3 -> which is using the same behavior
12802.9 -> of add right basically
a normal calculator
12805.6 -> or a scientific calculator
will have the same add
12808.1 -> Behavior adding up two numbers.
12810 -> Whatever you send
it as a parameter,
12812.181 -> it would add it up
and give you the result.
12814.8 -> So basically you would Define
this ad in the calculator
12818.2 -> in the scientific calculator.
12819.905 -> That would be the subclass
12821.3 -> of your calculator you need
Redefine this add method.
12824.558 -> It would inherit
from the calculator method.
12827.2 -> So that reduces would redundancy
12829.407 -> or it helps you
in code reuse ability.
12831.9 -> You need not redefine
the add method we have lot
12835 -> of slides to come
about method overriding
12837.521 -> and Method overloading
12838.908 -> so I won't talk it right away.
12840.8 -> This is inheritance.
12842.243 -> You have a manager class
and you have like employee
12845.937 -> which is extending manager.
12847.806 -> So what we are trying
to show here is e dot salary
12851.2 -> as you could see here.
12852.494 -> There's a salary property
in a manager and this employed
12855.8 -> to is extending manager
12857.472 -> and we could see here
12858.989 -> that employee to in
Harrods salary property though.
12862.6 -> It doesn't have
a salary property.
12864.453 -> We are able to access
the salary property
12866.7 -> from employee to let
me give you an example.
12870.2 -> You just have to click
on create new project
12872.999 -> and give some project name.
12874.845 -> I'll give a dude
12875.927 -> a car modules 3 so it opens
up a new window you could go
12879.5 -> to the source folder
12880.8 -> and you could right click on it
and Create a new class.
12884.076 -> So basically I'll do one thing.
12885.835 -> I'll create an employee class.
12887.622 -> I'll follow the same example
that's been mentioned here.
12890.9 -> I create calm down
at Eureka dot manager class.
12895.1 -> So calm down Eureka is nothing
but the package name
12898.2 -> and manager is your class name.
12900.5 -> So now I Define a property
here say salary in that case,
12904.6 -> right suppose.
12905.8 -> I say maybe I will put
it as wrong salary.
12909.3 -> So I Define a property
within your manager,
12912 -> which is salary.
12913.2 -> Now I Define one more class.
12915.5 -> So you could either Define it
with in the same file
12918 -> or you could create
a new class for Simplicity.
12920.7 -> I create a new class.
12922.1 -> It will create employee.
12924.3 -> So it created an employee class
within calm down Eureka package.
12928.9 -> Now, let's do main
12931.1 -> which is your entry point
for the program.
12933.7 -> Now as you could see
I haven't defined
12936.5 -> salary within employ.
12938.6 -> The first thing
that I'll have to do is we
12941.082 -> are talking about inheritance.
12942.9 -> So employ extends.
12944.938 -> This is a keyword
used for inheritance.
12947.962 -> So employ extends manager.
12950.1 -> So now you could see
there is a property
12952.4 -> which is salary
12953.276 -> which is defined in the manager
and this employee
12956.2 -> which is the subclass
of manager and let's see
12959.2 -> if salary is
accessible to employ.
12962.1 -> This is a place of manager.
12964.1 -> So I Define employ EMP is
equal to Nu employ.
12967.7 -> This is how we create instance
of the class using new now.
12972 -> Let's see if
just for Simplicity.
12974.6 -> I will give this e MP dot salary
you could see that right just
12979.5 -> to be sure I print out so
12981.5 -> as we can see
here salary though.
12984.3 -> It's not defined in employ.
12986.5 -> It has been inherited
from rather from your manager.
12990.131 -> We can have one
more instance created
12992.606 -> which is like manager is equal
to new manager.
12995.7 -> This is instance
of manager class.
12997.9 -> Now, I do manager dot salary
is equal to salary of manager.
13003.1 -> Is it just printing it out?
13005.6 -> So what we have done
here is again,
13008 -> I repeat the same thing.
13009.2 -> So we have
a manager within manager.
13011.588 -> We have defined a field salary
and we have employee
13015.1 -> which is extending manager
and the employee class.
13018.498 -> We don't have the field
13020 -> or we don't have the property
salary defined here,
13023.111 -> but we could see here
13024.4 -> in this example wherein we
created the instance of employ
13027.8 -> and we are accessing salary
property from here though.
13030.917 -> It's not defined
specifically in employee.
13033.287 -> It's been inherited
from the parent class
13035.6 -> that's manager and manager
of course has salary field
13038.8 -> which is been access of here
13040.2 -> and we could assign
some value to it.
13042.3 -> I run the program
it should compile
13044.447 -> and create a class file
13045.9 -> out of it and it runs
the class file using jvm.
13048.9 -> So yeah, as you could see here,
13050.785 -> it's printing out values
for salary of employee
13053.593 -> and manager as well.
13054.834 -> So that's about inheritance
it see inheriting
13057.455 -> the property salary
from parent loss.
13059.6 -> Now, what are different
types of inheritance
13061.7 -> that we have this Bill
inheritance wherein you
13064.507 -> have a parent class
13065.751 -> and you define a subclass
out of it so similar
13068.7 -> to what we spoke.
13070.007 -> We had a manager class
and we had employee class
13073.6 -> which was inheriting manager.
13075.549 -> That's about single inheritance.
13077.7 -> You can have hierarchical
inheritance wherein you
13080.976 -> could have multiple classes
inheriting from a same class.
13084.8 -> So you could have a
13086.123 -> and be inheriting
from a single class.
13088.7 -> You could have multi-level
inheritance wherein you
13091.4 -> have one class inheriting
from another and again,
13094.357 -> you could have subclass
of the subclass parent class
13097.5 -> you inherited or you subclass it
or extended whatever you say
13101.378 -> so there is one level.
13102.8 -> So you have a child class.
13104.45 -> Now, you could have
one more sub class
13106.8 -> of this child class.
13108.2 -> That's what multi-level
inheritance is all about.
13111 -> So as we go through the example,
13112.618 -> it should give you a clear idea
about what I'm talking
13115.3 -> about so single inheritance,
13117.461 -> so we have vehicle
and we have bike
13120.2 -> which is extending vehicle.
13121.991 -> So this Similar to
what we defined here.
13124.605 -> So what we did here
is single inheritance.
13127.347 -> You had a manager
and you subclass debt
13129.889 -> and this is just single
inheritance one level.
13132.9 -> So what is
hierarchical inheritance?
13135.7 -> So you have a vehicle
13137.3 -> and you have two subclasses
created out of vehicle.
13140.941 -> So there are two child's
of a parent class.
13144 -> So this could be
pretty much similar
13145.9 -> to a parent having two kids
right there could be two cats
13149.194 -> and they inherit some property
from your parent.
13151.958 -> So it's pretty much
similar to that.
13154.053 -> So you have a vehicle class
13155.735 -> which is the super class
and you have subclasses to it.
13159.2 -> So, let's see how this works.
13161.204 -> So I create a vehicle class
which is the super class.
13164.798 -> I have a vehicle class
13166.399 -> and civically class
has a property
13168.8 -> which says integer say
number of Wheels.
13171.9 -> This could be one of
the property of a vehicle class.
13174.9 -> You have say for example,
you have the mileage.
13178.6 -> So these are common properties
that you have in vehicle.
13181.6 -> Say you have Motion
just to add a behavior
13184.8 -> to this particular class.
13186.4 -> I Define method move
13187.757 -> and I just print
this thing out here.
13190.2 -> I defend two properties here
for vehicle class,
13192.986 -> which is number of wheels
13194.5 -> and the mileage and add
a behavior to the class
13197.589 -> by introducing method
13199 -> which is move which is nothing
but I'm just printing it out.
13202.7 -> So ideally you would have
some functionality written
13205.35 -> within or you would have lines
of code written within just
13208.426 -> because we are talking
about inheritance just
13210.8 -> to show the properties
13212.011 -> and behavior is been
inherited by the subclass
13214.529 -> for Simplicity sake we
13215.761 -> don't have any logic
written within move.
13217.8 -> It's just printing it out saying
13219.4 -> that just to indicate
that you know,
13221.3 -> there's a move method
within the vehicle class
13223.947 -> is being called.
13224.774 -> We're just printing it
out there but in reality
13227.2 -> as I said there would be
actual logic written with them.
13230.1 -> So now I Define car class
and I defined by class.
13234.6 -> So now I say
13235.8 -> that car is extending
which is nothing
13238.604 -> but sub class of vehicle.
13240.5 -> So remember we said
easy relationship.
13242.8 -> Chip car is a vehicle.
13244.3 -> So what we are
saying is subclassing
13247.1 -> or we are inheriting properties
of vehicle into car suppose.
13251.7 -> I change the property
13253.4 -> of any you method within or say
I can have its own moment
13257.8 -> when car cross.
13259.5 -> So basically we
are overriding it.
13261.7 -> What we are trying
to do is we are trying
13263.7 -> to whatever method you had
within your car class
13267.6 -> or the vehicle class.
13269.105 -> You are overriding it
for the car class.
13271.908 -> You are trying to change
something similarly
13274.912 -> in your by class.
13276.1 -> You could overwrite the move.
13278.055 -> So first thing
13279 -> that we'll have to do is bike
should extent your vehicle.
13283.032 -> So bike is a vehicle we
are extending it now.
13286.2 -> We are again overriding
this move method to say
13290.4 -> move in by class.
13292.3 -> So now basically we
can have seven more just
13295.316 -> for simplicity's sake we have
just a class wherein you
13299.138 -> would write the main method.
13301.041 -> So this is generally
13302.4 -> Practice were in such classes
are called as client classes
13306 -> where in you have a main method
and you do something with it?
13309.6 -> I just call it as
automobile management class.
13313.1 -> So you have a main method
so suppose you want
13316.29 -> to change the number
of wheels for a car.
13319.1 -> So what you would do is
car car is equal to Nu
13322.46 -> or it won't be carved would be
13324.7 -> like suppose I put
Mercedes is equal to new car
13329.169 -> by create Mercedes.
13330.7 -> I create BMW is equal
to new car.
13333.9 -> So now what we do is I want
to overwrite the property
13337.5 -> that is number of wheels
for Mercedes to for similarly.
13341.449 -> I could have a bike class say
r 1 is equal to Mu
13344.8 -> by something of this sort you
could have Ducati is equal
13348.518 -> to Nu by so this is just
to give you an idea of
13351.625 -> how we have classes
and objects right now.
13354.443 -> You could imagine
what objects is all about.
13357.4 -> So Mercedes is object
of car BMW is object of car.
13363 -> Arvin is object of bike
13364.8 -> and Ducati is again an object
of by so now I could overwrite
13369.4 -> the properties here
say number of vehicles
13372.426 -> as to so yeah,
13373.459 -> this is what it is all about.
13375.6 -> This should give you some idea
13377.1 -> about how we use Java you have
a class you have subclasses,
13381.6 -> then you kind of create objects
13383.8 -> and you could override
the properties with them
13386.8 -> and you could change
13388.2 -> when I say override is
nothing but you could modify
13391.3 -> the values within
your subclasses and similarly,
13395 -> you could change
the behavior vehicle
13397.1 -> by itself would have
some Behavior defined
13399.8 -> but Mercedes and BMW,
13401.308 -> which is a car would have
its own kind of behavior,
13404.9 -> which is not
inherited from parent
13407 -> you're overriding it
when you say
13409.347 -> this this could be
an illogical to something
13412.1 -> like kid kid doesn't have
the same features as a parent.
13416.6 -> It is something
like it's been overridden right?
13419.1 -> It's peculiar to
that particular kid,
13421.3 -> and that's what this is.
13422.696 -> About so you could override it.
13424.5 -> Now.
13424.7 -> Let me print move or let
me call the move method on BMW
13429.1 -> so you could see a move method
13431.5 -> and when I run it it should show
move method in car class
13436.3 -> since it's a movement
13437.7 -> that called on car BMW
is instance of car.
13440.8 -> So this should give
you some idea about
13443 -> how are we inheriting properties
and behavior from parent class.
13446.9 -> So here we can see
that move in car class.
13449.726 -> So again, you could
Define your own method
13452.552 -> within your subclass,
13453.8 -> which is not something
13454.9 -> that is inherited
from your parent class.
13457.1 -> So BMW by itself
13458.915 -> or car by itself could have
something like sector board
13463.2 -> which is not in vehicle.
13464.4 -> Maybe this is specific to car.
13467.238 -> So this is what we spoke about
is hierarchical inheritance.
13471.7 -> Now, let's talk
about multi-level inheritance.
13474.8 -> So basically it's
nothing but say you have
13477.519 -> a super class category.
13479.039 -> So let me use the same example.
13481.088 -> You have a vehicle class
you Have a car
13483.6 -> which is extending vehicle.
13485.676 -> Now I Define one more class,
13487.83 -> which is nothing
but superclass Supercar
13491 -> which is extending car.
13493.3 -> Basically, I can put this turbo
in Supercar rather
13496.459 -> that would make more sense.
13498.2 -> This is like
kind of multi-level.
13500.585 -> So I am putting this turbo
here in supercars.
13503.8 -> You have a vehicle class
you have a car
13506.5 -> which is surplus of vehicle.
13508.4 -> You have a Supercar
which is a subclass of car.
13511.708 -> So all the properties
13513.254 -> that you have in vehicle class
could be accessed
13516.586 -> in car as well as Supercar.
13518.5 -> That's what we want to see here.
13520.3 -> So you could have something
like say change Wheels
13524.305 -> which is void which is
not returning anything here.
13526.9 -> I just want to show you
13528.443 -> that we can still access number
of Wheels here though.
13532 -> It's not defined
in car or Supercar
13534.6 -> but in vehicle class
13536.004 -> you could actually it
is still visible here
13538.951 -> and you can modify it.
13540.421 -> That's the beauty of it again.
13542.415 -> Brief, you have a vehicle class
you have a car class,
13545.888 -> which is extending
vehicle class.
13548.026 -> You have a Supercar class,
which is extending car class.
13551.7 -> So basically there
is a multi-level
13553.7 -> of inheritance and all
the properties and behavior
13557.089 -> that you have in vehicle class
would be visible to car class
13561.2 -> as well as Supercar cross
13563.1 -> and Supercar class can access
properties and behavior
13567.6 -> that is there specific
to car class.
13570.1 -> What I'm trying to say is
if you define a new method here,
13573.6 -> so I just mention here Behavior
specific to class to car.
13578.9 -> So there's some behavior
that is specific to car
13582.051 -> that we have defined
within the car class.
13584.9 -> Now Supercar class
can access this one as well.
13588.9 -> So you could see here
you could access Behavior
13591.66 -> specific to car as well.
13593.1 -> If you look it as a tree.
13594.6 -> This is a leaf node.
13596 -> This is super car class
can access everything
13599.384 -> from vehicle and car class.
13601.7 -> Whereas.
13602.3 -> Our class can access everything
from vehicle class,
13605.8 -> but it's not the other way
around car cannot access
13608.9 -> something that is
specific to Supercar.
13611.445 -> There's a turbo method
13612.919 -> that we have put in
into the Supercar class.
13615.8 -> Now.
13616 -> If you try to access
Turbo from here,
13619.1 -> you won't be able to access it.
13620.6 -> All right, so it's
not the other way round.
13622.8 -> So you cannot access something
13624.3 -> that is specific
to your subclass
13626.7 -> in your super class.
13627.8 -> Whereas you can access anything
13629.84 -> that is there in your superclass
into your subclass.
13633.2 -> So it's a one directional flow
from superclass to subclass.
13637.1 -> Now, let's talk about has
a relationship has
13639.629 -> a relationship is nothing
13641.005 -> but you have properties
within your class,
13643.417 -> which is has a relationship.
13645.031 -> All right.
13645.599 -> So say for
example employee, right?
13647.65 -> We defined the employee class
13649.4 -> and employee would have
an ID specific to employ
13652.7 -> and it can have salary
and stuff like that
13655.3 -> which is has a relationship
13656.9 -> which is nothing but employ as
ID sort of right so a department
13661.476 -> in a class Let's talk
13663.032 -> about this example
a department in a college
13666.433 -> has several professors without
existence of departments.
13670.4 -> There is good chance
13671.752 -> for the professor's to exist
hence professors and Department
13675.852 -> are loosely associated.
13677.447 -> And this loose Association
is known as aggregation.
13680.962 -> So one can exist without other
which is loose Association
13684.901 -> and such thing is
nothing but aggregation.
13688.2 -> So here you could
see employ here.
13690.8 -> You could see name
name class itself,
13693.356 -> which has got first
and last name.
13695.7 -> So basically you
have a name class
13697.641 -> which has got property as first
13699.532 -> and last and which is nothing
but the first name
13702.4 -> and the last name of any entity.
13704.464 -> It's not associated
with anything right now.
13707.332 -> It's a different entity name is
a different entity
13710.6 -> which would have first
and last name now
13713.7 -> this employee info class,
13715.577 -> which has got ID and
which has got name
13718.5 -> so you can see name hear
this name property is nothing
13722.3 -> but The instance of name class
13724.6 -> that is there
the left hand side.
13726.6 -> So this is has a relationship.
13728.9 -> This says that
employee info has name.
13731.9 -> So basically this is what it is
13733.905 -> when you talk about has
a relationship its containment.
13737.4 -> Basically you have class
as a property in a class.
13741.2 -> So in this case
name is a property
13743.703 -> within your employee info
13745.6 -> and similarly this name could
be used somewhere else as well.
13749.3 -> It's not that it has to be used
just in employee info.
13752.5 -> That's a kind of Detachment
they have right.
13754.9 -> It's not tightly coupled.
13756.536 -> It's Loosely coupled
or decoupled.
13758.585 -> So basically you have name
13760.2 -> which is altogether a different
entity defined as a class
13763.088 -> which would have first
and the last name
13765.1 -> and you would have an employee
in for which is containing name
13768.6 -> which has name.
13770 -> So this is has a relationship
13771.8 -> and also to give you idea
about has a relationship.
13774.9 -> It's not just
it has to be object.
13777.1 -> Right so vehicle has number
of Wheels vehicle has Uh,
13783 -> this could be thought
of as a relationship.
13785.47 -> So let's talk
about polymorphism.
13787.3 -> Now when one task is performed
by different ways,
13791.053 -> then it is called as
polymorphism Polly is multiple
13794.899 -> of ism is forms.
13796.1 -> Basically, that's
the meaning behind it.
13798.4 -> So multiple forms.
13799.9 -> That's what polymorphism means
13802.092 -> and when one task is performed
by different ways,
13805.6 -> then it's called as
polymorphism this person
13808.509 -> which is the super class.
13810.2 -> You have a subclass student is
again person millionaire is
13814.812 -> a person these
are super classes.
13817.3 -> So you have a person class
you have super class student
13820 -> and millionaire you
have a behavior,
13822.058 -> which is nothing but P Bill
13823.607 -> and which would be specific
to both of them.
13826.075 -> So as we move on you
would get much more idea
13828.6 -> about the different kinds,
13829.9 -> but basically you
have multiple forms.
13832.1 -> That's what polymorphism
is all about.
13834.3 -> So, what is Method overloading
so we spoke about this yesterday
13838.5 -> if you remember we spoke
13839.977 -> about Constructor
overloading we're in you
13842.5 -> Had multiple Constructors Define
one was integer integer,
13846.6 -> and the other one was
13847.842 -> like it was taking
three parameters integer integer
13850.783 -> n 3 integers, right?
13852.025 -> So basically this is what method
overloading is all about to have
13856 -> the same name of a method
13857.622 -> but you have different number of
parameters passed to the method
13861.57 -> or you have different type
13863.2 -> of parameters passed
to the object to the method
13865.964 -> and based on that.
13867.034 -> It would understand
which is a method
13869.2 -> that needs to be called.
13870.741 -> So suppose you have ad with
two integer parameters Define
13874.334 -> and you have ADD with three
integer parameters defined now
13878.06 -> when you invoke add method
on a particular instance
13881.319 -> of calculator and you
pass two parameters to it,
13884.293 -> it would appropriately call
add method with two parameters
13888 -> and if you pass
three parameters to it,
13890.326 -> it would call one
with three parameters
13892.653 -> or it would resolve it
13894 -> during the runtime which one
to be called rather.
13896.4 -> It's not overloading
doesn't happen during runtime.
13898.9 -> It's done during the linking
of the resolving operation.
13902.5 -> Ben's during the
compile time itself.
13904.937 -> That's why it's
static polymorphism method
13907.6 -> overloading is nothing
but static polymorphism.
13910.184 -> So return type is not taken
into consideration when it comes
13913.5 -> to Method overloading.
13915.1 -> It's just the parameters
that a particular method takes.
13918.986 -> So Alex wants to write a code
13921.111 -> which can be used to find
out the area of triangle
13924.7 -> as well as of circle.
13926.4 -> So generic code which
would have area of triangle
13929.9 -> and circle so such are
the instances wherein you
13933.1 -> could use method overloading.
13935.116 -> So what's the thought behind
is I want to find area
13938.533 -> of both the shapes here
area is the common method.
13941.924 -> It's there for both the shapes.
13943.959 -> It's therefore rectangle.
13945.6 -> It would be there for square.
13947.2 -> It would be there for Circle
and so on and so forth.
13950.441 -> So basically you
would have a shift method
13952.936 -> which would have area
which is a common method.
13955.829 -> So instead of writing
two methods of different names.
13959.1 -> I will write area as
the method name for both shape.
13962.4 -> And a path different
13963.758 -> arguments according to
the respective shape.
13966.579 -> So instead of defining
multiple area methods
13969.5 -> you would have just
a general area method defined
13972.3 -> in your shape class
13973.6 -> and your subclasses
would overloaded as
13976.45 -> per the type of shape.
13978.1 -> So here we can see that this
area class there's area method
13982.54 -> which is taking integer
13984.3 -> since it's a triangle
its base and height.
13987 -> So it's taking base
and height as parameter.
13990.1 -> So Java doesn't understand
base and height.
13992.457 -> This is user defined by the way.
13994.34 -> It understand.
13995.089 -> There are two integer parameters
passed through the area Whenever
13998.54 -> there are two integer parameters
passed to area method.
14001.52 -> This one would be called.
14002.9 -> The other one is again,
14004.4 -> we have one more method
14005.9 -> which is area which is
by the same name
14008.711 -> and which is taking just
one integer parameter,
14012.115 -> which is radius.
14013.3 -> So this is supposedly
for circle Pi R square.
14016.7 -> So during runtime
when you call it,
14018.7 -> so I'm not repeating
this exercise again,
14021.052 -> because we did the same.
14022.4 -> Yesterday if you remember we
14024.118 -> kind of had multiple add methods
in the calculator and we saw
14027.8 -> that it was getting resolved
to the proper one
14030.447 -> based on the number
of actual parameters
14032.7 -> that you pass.
14033.4 -> So I will just read
14034.7 -> through the slides to make you
give more explanation on this
14038.201 -> but it's pretty straightforward.
14040.1 -> So here you have area method
which is ticking for six
14043.9 -> which is nothing but
it would get resolved
14046.8 -> during compile-time
14047.805 -> this particular area method
invocation would get resolved
14051.276 -> to this one
14051.937 -> since it is taking
two integer parameters.
14054.482 -> Second one is taking just
one integer parameter,
14057.4 -> which is 5 so it understands
14059.1 -> that it has to call
this area method
14061.2 -> the second area method
that's been defined
14063.458 -> in method demo and it
would call it accordingly.
14065.824 -> So here you could see
14067.1 -> that when you run this
particular program you could see
14069.8 -> that the first one resolved it
to Triangle and it said
14073.5 -> that the area of triangle is
nothing but 4 into 6
14076.921 -> into point five,
14078.078 -> which is nothing
but 12 the second one
14080.718 -> goes 2 pie R square.
14082.116 -> And it gives answer as
seventy eight point five.
14085.4 -> So you could see there are
two different invocations
14088.252 -> done based on the number
of actual parameters.
14090.907 -> Now, let's talk about type
of parameter the method
14093.8 -> overloading can happen
on type of parameter as well.
14096.906 -> So you could have multiple
methods with the same name
14100.097 -> taking same number of arguments
14102 -> but different data types
14103.418 -> one could be taking
integer as a parameter.
14105.9 -> The other one could be taken
string as a parameter
14108.7 -> and during runtime ordering
compile time itself.
14111.8 -> It would resolve that, you know,
14113.498 -> this one should be resolved
to this invocation
14115.887 -> and the other one should be
resolved to the other one.
14118.7 -> So basically it tries to resolve
based on the parameter based
14122.547 -> on the data type
of the parameter
14124.6 -> that you pass.
14125.5 -> So here's the example wherein
you have two different methods.
14129.796 -> I will take this one.
14131.3 -> Say for example,
I Define public integer.
14134.911 -> So it's a dummy value
to be printed one
14138 -> of the best practices
14139.6 -> when you write Java code is
to express it, right.
14142.4 -> So you can have
a big variable name you
14144.6 -> shouldn't be restricting
on variable name
14146.688 -> which makes it difficult
14148.099 -> for other programmers
to understand.
14150.1 -> So it's good to have big
variable name versus small one,
14153.635 -> which is not that expressive.
14155.5 -> So here I said dummies
string value to be printed.
14159.8 -> I'm printing integer value is
nothing but dumb integer value
14163.7 -> and here I am printing
14165.2 -> so we have two methods
with the same name
14167.284 -> but it's taking different
data types as argument
14169.8 -> and we are just printing it out.
14171.6 -> So I Define a main method here
and I Define manager.
14175.8 -> So we have instance
of manager senior manager grade
14179.1 -> 2 dot display I
pass integer to it.
14182.8 -> I pass hundred to it and I pass
14186.1 -> so I have to Method
invocations here.
14188.217 -> One is first one.
14189.244 -> We are passing
hundred the second one.
14191.358 -> We are passing a string to it
and it gets resolved.
14194.41 -> You could see
14195.142 -> that the first one would go
to this display method
14197.9 -> which says printing
integer value the next one
14200.8 -> would go to this.
14202 -> Display method which
print string value
14204.6 -> so you could see here.
14205.847 -> Right?
14206.2 -> So first one is
printing integer value.
14208.277 -> The second one is
printing string van.
14210.3 -> So based on the type
of the parameter
14212.176 -> that you pass through are passed
to the method particular method
14215.5 -> would be called This
is static polymorphism.
14217.9 -> Now what's runtime polymorphism.
14219.8 -> So since it is resolved
during the compile time,
14222.6 -> it is static polymorphism.
14224.2 -> There are few things
14225.2 -> that gets resolved
during the runtime
14227.5 -> or the compiler cannot judge
it up front what the instance
14231.2 -> would be and that's
14232.355 -> when it does it
during the runtime
14234.328 -> and that is nothing
but dynamic polymorphism
14236.9 -> or method overriding so
method overriding is mostly used
14240.5 -> in an easy relationship.
14242.3 -> So in one of the methods or we
saw in vehicle and car example,
14247.453 -> we have a move method here
and here we overrode it.
14251.4 -> You can see override annotation
here for the move
14254.7 -> because you're overriding
it overriding the behavior
14258 -> of vehicle in car class.
14259.753 -> So that's where it says
14261.454 -> that this Easy relationship
method overriding must be used
14265.751 -> in case of inheritance
14267.323 -> that is easy relationship method
must have the same name as
14271.47 -> in the parent class.
14272.894 -> We saw in the move
in the example move.
14275.631 -> We have the same name as
in this super class.
14278.8 -> So huichol has a method move
and car has a method move
14282.838 -> as well method must have
the same parameters as
14286.3 -> in the parent class as
against method overloading
14289.8 -> which has different
parameters method overriding
14292.9 -> you have to be sure
14294.166 -> that it takes the same parameter
if I change this to integer
14298.3 -> if I add an integer
parameter to it,
14300.7 -> so it's not taking it as
overriding you could see it.
14304 -> It's not been taken as
14305.347 -> overriding because you have
integer parameter to it.
14308.5 -> So basically it has
to have same number
14311 -> of or it has to have the same
signature as your parent class.
14315.4 -> So that's about
method overriding.
14317.8 -> Let's have a demo on this so
which we already saw
14321.069 -> but I will again A trait on that
14323.257 -> so basically this example you
could see there's a man class
14327.084 -> which has got a pay method
14328.875 -> which is adding Behavior
to the man method
14331.7 -> and you could see
it's a dummy printer
14334.7 -> and you have a millionaire is
a man and you could see
14339 -> it overrides the pay behavior
14341.5 -> and you run this program.
14343.268 -> One thing to note here is you
can assign me linear to man.
14347.229 -> You can assign
unlike all the examples
14349.8 -> that we saw we are creating
instances of the same class
14353.2 -> or assigning the instance
of a class to the same class.
14356.7 -> But in this case you
could see the instance
14359.1 -> of millionaire is being assigned
to reference of man.
14362.5 -> This is something
14363.6 -> that happens only in Easy
relationship or inheritance.
14367.49 -> So what I am trying
to say here is a go-to
14370.5 -> automobile management I have car
14373 -> I have a new car
14374.155 -> which is Mercedes I could assign
this Mercedes to vehicle
14378.2 -> since Mercedes is a vertical it
14379.6 -> should be a sign you
should be able to assign it.
14382 -> This is something
14383.213 -> that you need to keep in
mind your subclass object
14386.835 -> could be assigned to superclass.
14389.123 -> So here we have Mercedes
being assigned to vehicle.
14392.7 -> But one thing to note here
again is the tricky part is
14396.3 -> vehicle itself has
its own move method, which
14400.2 -> Moving vehicle class
14402.1 -> and Mercedes which is car
itself has its move method
14407.046 -> with this move in car class.
14409.2 -> So the tricky part here is
14410.977 -> when you would do something
like vehicle dot move just
14414.6 -> give a thought about it
which one should be called.
14417.631 -> So you have two variants
of move method here.
14420.3 -> You have one in car
and one in vehicle.
14423.4 -> So the one in vehicle
is printing out moving
14426.4 -> vehicle class and one
14427.9 -> in car is the overridden version
14430.5 -> of vehicle with says
move in car class.
14433.8 -> Now, what we are doing
here is we are creating
14436.905 -> an instance of a car class
14438.7 -> and we are assigning
that instance to vehicle
14441.9 -> and we are calling
the move method.
14443.9 -> So just give a thought
14445.016 -> whether the move method
on the vehicle class
14447.2 -> would be called or a move method
14448.959 -> on the car class
would be called.
14450.895 -> So this is
14451.5 -> where method overriding comes
into picture so method
14454.784 -> overriding is nothing but
it's a runtime polymorphism
14458.132 -> which is done at the runtime.
14460 -> So during the runtime
jvm would see
14462 -> that Mercedes is nothing
but the instance of car though,
14466 -> it's assigned to vehicle
14467.419 -> which is super class still
an instance of class.
14470.2 -> So during compile-time jvm
wouldn't have a friend knowledge
14473.611 -> that which move are you calling?
14475.476 -> Is it on vehicle class or is
it on something else
14478.3 -> or some sub class of vehicle?
14480.1 -> So it doesn't decided during
the compile time it delays it
14484.4 -> or there's a lazy binding
14486.103 -> that happens delays it
till the time you run it.
14489.2 -> So when you run it,
14490.48 -> it understands that this vehicle
is actually pointing to car.
14494.364 -> That's Mercedes.
14495.4 -> So when you run
this you could see
14497.379 -> that I will comment
out this piece of code.
14499.9 -> So this is how we comment out
that's a block comment.
14502.5 -> So when I move
this you could see
14504.58 -> that move glass
14505.529 -> on car has been called
and not vehicle that is what is
14508.981 -> if you get this concept,
14510.5 -> you're pretty good in terms
of object oriented.
14512.8 -> By the way.
14513.533 -> This is an important Concept
in object-oriented Paradigm.
14517.3 -> So you could see here move
in car classes.
14520.1 -> Called similarly vehicle
14521.881 -> could have I call it
as vehicle one, right?
14525 -> I Define one more vehicle here,
14527.492 -> which is like new vehicle
14529.6 -> and I invoke the method
14531.254 -> on vehicle to so
the second variant
14533.7 -> would call the move method
in your vehicle class.
14536.9 -> The first one calls
14538.3 -> on the curved glass the second
one calls on the baker was
14542.242 -> since its object
of vehicle itself.
14544.9 -> So basically you have to see
on the right side,
14547.301 -> which is the object
14548.299 -> that's been assigned
since its object of vehicle.
14551.2 -> It's vehicle.
14551.977 -> But since this one
is object of car,
14554.111 -> that's the reason you have
car class being called.
14557.1 -> So we had some discussion
on this keyword yesterday.
14561 -> So super keyword is similar
to that super keyword is just
14565 -> that it is called on superclass.
14567.7 -> This is called on the same
class super is called
14570.702 -> on the immediate subclass
14572.3 -> immediate parent class you
could have multi levels, right?
14575.652 -> But this one is calling
the immediate parent used
14578.4 -> to refer immediate parent.
14579.745 -> Us instance variable used
to invoke parent class method
14583.9 -> and there's one more
Super keyword one more form
14587.065 -> in which you could use is
to have class Constructor.
14590.5 -> So basically whenever
you create a class
14592.848 -> whenever you call a class
whenever you call Constructor
14596.1 -> of a class by default jvm
14597.959 -> by itself would give a call
to the superclass Constructor,
14602.2 -> which we would be looking
at the further slides.
14605.2 -> So here we have vehicle leaven,
14607 -> which is a super class
14608.1 -> which defines string
Wheels vehicle moves
14610.744 -> because of wheels
so that the string
14613.345 -> that the property
of a vehicle you have a truck
14616.43 -> which extends vehicle
and then within truck
14619.477 -> you have your overriding
the wheels property saying
14622.933 -> that truck has four wheels.
14624.8 -> This is kind of your
overriding the property.
14628.1 -> It's not called
overriding though
14629.7 -> when it comes to properties.
14631.4 -> But basically you
have changing the values
14633.8 -> within your truck class print
wheel is nothing but a method
14638.315 -> that's defined in.
14639.7 -> Truck which would bring
the number of wheels
14642.3 -> in your truck class
and it has got super dot Wheels
14645.7 -> which would print the number
of wheels in your
14648.17 -> or print the value of the Veals
not number of Wheels value
14651.5 -> of the wheels property
within your vehicle class.
14655.046 -> So we will look at this one.
14657.2 -> So we have a vehicle class
and we have string Wheels
14660.6 -> which is a property
within a vehicle class
14662.851 -> which has some value
put in right?
14664.7 -> We have a truck class again,
14666.347 -> which has got wheels
and it is overriding the value.
14669.313 -> It is just changing the value
14671 -> as truck has four wheels
14673 -> with interrupt class you
have print will method
14676.103 -> which is printing
the wheel or the value
14678.66 -> that this particular
Wheels property holds
14681.3 -> it would print it first
one would be the value
14684.1 -> that this particular truck class
would hold and the other one
14687.629 -> that you see here
the second print statement,
14690.211 -> which is doing super dot Wheels
is actually printing the value
14693.8 -> of wheels in vehicle class.
14696.3 -> So, let me show you
a quick demo on this thing.
14699.401 -> So we Have a vehicle class
14701.215 -> which were in we are defining
the default number of Wheels as
14705.4 -> for say for example,
14706.937 -> and now we have a bike class,
14709.071 -> which is overriding
vehicle class.
14711.5 -> And what we are going
to do here is we are going
14714.6 -> to change the value
of number of Wheels.
14717.3 -> I have a method to print
number of fields,
14720.2 -> which would give suppose
I change your number
14723.7 -> of Wheels to say to so here we
print number of Wheels first
14728.9 -> and I would have
one more print statement
14731.821 -> which would be printing
super DOT number of Wheels
14735.389 -> within a by class.
14736.7 -> We have a print number
of bills method first.
14739.288 -> We are changing the number
of Wheels to 2
14741.8 -> and then we are printing
the number of wheels for bike
14745.119 -> and number of wheels
on the superclass.
14747.5 -> All right, and by default we
have set the number of wheels
14751.053 -> in the vehicle class
14752.3 -> to before so we have
a bike class now I remove this
14756.5 -> to so now I print
the number of Wheels.
14760.1 -> So I create the instance
14761.8 -> of bike and I invoke
print number of Wheels.
14764.6 -> Now you could see
14765.641 -> that first it would print
to and on super dot.
14768.4 -> Basically.
14768.988 -> This is what it's going
to call so first it
14771.4 -> will print to so basically here
14773.5 -> we need to have one more
teacher number of fields
14776.834 -> when it comes
to instance variables.
14779.282 -> It's not overridden as
such so I have like number
14782.767 -> of Wheels defined here again
14784.799 -> and here I change number
14786.464 -> of Wheels to to so
let me run it again.
14789.1 -> So when it comes
to instance variable
14791.041 -> when you define one more field
here of the same name,
14794.1 -> it's not overriding it.
14795.3 -> It's rather creating
a new instance variable.
14798.2 -> So now you could see
14799.2 -> that when you print number
of Wheels it's printing out
14802.371 -> to which is nothing
14803.499 -> but the value here value
of this instance variable.
14806.468 -> Whereas when you do
super DOT number of Wheels,
14809.2 -> you have a default value of 4
here which is been printed out.
14813.2 -> So on super it gives
a call to superclass.
14816.6 -> So here you are creating.
14818.229 -> It's at the Constructor level.
14820.2 -> And we can see
that so it's more about
14822.9 -> as I mentioned
within your Constructor.
14825.4 -> The first thing that is called
14827.2 -> when you create an instance
is a super Constructor
14830.362 -> is called first
14831.3 -> and then your sub class
Constructor or I mean to say is
14835.2 -> when you create instance of car.
14838 -> So your first thing
14839.3 -> that would be called
is the Constructor
14841.2 -> of vehicle and it would do
all the initialization
14843.824 -> that's required in vehicle.
14845.3 -> And then it would call
the cars Constructor.
14848.908 -> So what I mean to say
is for example,
14851.8 -> I create a Constructor here
and I print saying
14855.561 -> that we are within Constructor
of fecal of superclass vehicle.
14861 -> Now we have this car class
and say we have Constructor
14865.707 -> for car class as well.
14867.4 -> Remember we said
14868.4 -> that there's a default
Constructor implicit Constructor
14871.1 -> that's already been
put by GBM itself.
14873.7 -> You don't have to
take care about it.
14875.6 -> So I don't do anything here.
14877.397 -> So basically you
need not create you do.
14879.9 -> Right Constructor jvm
by default right Constructor,
14882.841 -> unless you want to write
14884.053 -> something or you want
to initialize something.
14886.432 -> That's when you would
write explicitly you
14888.557 -> would write Constructor.
14889.862 -> But in this case since we
are not initializing anything
14892.8 -> as such I won't put
a Constructor car.
14895.3 -> What I'm trying to say
is we are creating
14897.4 -> an instance of car here.
14898.966 -> And let's see when we
create the instance of car.
14902.1 -> There is a super Constructor
that's been called.
14904.697 -> That's what I wanted to show.
14906.3 -> So that's why we created
a Constructor here for vehicle.
14909.5 -> This is not a method.
14910.627 -> This is constructed by the way,
14912.3 -> since it has got
the same name as your class
14914.8 -> and it doesn't have
any written value.
14917.284 -> So so I have printed
it out saying
14919.5 -> that we are in the Constructor
when we call this now
14922.562 -> when we create the instance
of car you could see
14925.2 -> that this Constructor
of superclass that's vehicle
14928.73 -> that's been called.
14930.053 -> So this is done
implicitly by compiler.
14932.7 -> You don't have to care about it.
14934.49 -> So here you could see whenever
14936.255 -> you create the instance
of car you would see
14938.526 -> that we are in construction.
14940.173 -> Of superclass vehicle
and the second print statement
14943.1 -> that you see is directly
for the vehicle sensation.
14946.946 -> So even for car you could see
14949.3 -> so this will get
rid of confusion.
14952 -> So there's only one instance
of car being created
14954.832 -> and we can see that it
is calling vehicle Constructor
14957.891 -> and it's implicitly put
14959.273 -> we don't have to explicitly
put it jvm by itself
14962.1 -> operates that way
14963.3 -> and how it calls is nothing
but by Super Final keyword we
14967.3 -> again touch based on this one
earlier in the session.
14970.6 -> Number one final keyword is non
access modifier applicable only
14975.2 -> to variable method or a class
when it's applied to a variable.
14979.705 -> We say that the variable content
cannot be changed usually use
14983.911 -> final when you want
to define a constant
14986.6 -> within your application.
14987.8 -> So that's final a method
could be defined as
14990.747 -> final you define a method
as final when you say
14993.9 -> that your subclass
cannot overwrite it
14996.5 -> that's when you define it
as final you define a class.
14999.916 -> As final when you say
15001.284 -> that there cannot be
any subclass of that class.
15004.4 -> So you cannot subclass it like
15006.371 -> if you try to extend
on a final class you
15009 -> would get an error
compile time error saying
15011.2 -> that you cannot extend it.
15012.7 -> So just to show you maybe
15014.2 -> if I make this as final your car
would show an error saying
15019.1 -> that you cannot inherit
from final class.
15022.029 -> That's Comdata recorded pickle.
15024.273 -> So that's about final class.
15026.3 -> And if you make
this method final you
15028.6 -> would again get an error
in the class saying
15031.274 -> that you cannot overwrite
this the car class you
15034.258 -> are trying to override
the move method
15036.688 -> since its final it showing
you an error saying that move
15040.3 -> cannot overwrite move
in calm dot Ed u--
15043.058 -> recorded vehicle overridden
method is final.
15046.1 -> Let's remove this finer
15047.382 -> and you should see
the error is gone.
15049.7 -> And also if you want to see
at the instance level
15052.86 -> if you define this as for number
15054.878 -> of Wheels as for now
within this vehicle,
15057.492 -> if you're trying to modify
this number of Units
15060.5 -> to to it would throw
you an error saying
15063.131 -> that cannot assign a value
to final variable.
15066.1 -> All right, so that's
what it does it.
15068.217 -> It's not access modifier,
15069.765 -> but it regulates it in a way
15071.5 -> that you can't change the value
in case of variables you
15074.9 -> can change the value
in terms of class.
15076.8 -> You can't subclass it
15078.397 -> or you cannot create
a child class of a final class
15082.3 -> and in terms of methods,
15084.4 -> if you have final method
you cannot override
15087.048 -> that particular method
in your subclass.
15089.5 -> So final modifier can be applied
to class method instance
15093.1 -> variable class variables local
variable and Method parameters.
15097.8 -> So final variable is used
15099.532 -> to create constant variables
when it comes to variable
15103.675 -> as I said,
15104.356 -> usually you use final variable
15106.4 -> when you want to
have constants, right
15108.576 -> and it would be final static.
15110.4 -> By the way.
15111.2 -> If you have a constant
usually final and static
15114.2 -> static final final methods
is used to prevent method
15118.2 -> overriding in terms.
15119.7 -> Method the demo that I
showed you previously we saw
15123.2 -> that we cannot override it
in terms of class.
15126.2 -> When you have a final class,
15127.807 -> you won't be able to create
subclass of it which we saw.
15131 -> All right, it gives you
an error some examples
15133.7 -> of final clause in string class.
15136.2 -> So system class
15137.9 -> in Java dot Lang dot package
is final as well string class
15142.3 -> that we have been
using string class
15144.8 -> that's been exposed by
or Java itself has
15147.591 -> or Java by itself defines it
that class is final as well.
15151.6 -> If you try to
extend string class,
15153.6 -> it would show you an error
it would give you an error.
15156.4 -> So system is kind of
putting a contract
15159.6 -> or Java by itself is putting
a contract or is saying
15163.8 -> that cannot extend
the string class.
15165.9 -> You cannot extend Its Behavior.
15167.611 -> You can't change anything
any of the behavior
15170.142 -> within your string class by yo,
15171.978 -> that's why they have marked
it as final if a method
15174.948 -> is declared as final then
it cannot be overridden
15177.8 -> in your child class.
15179.3 -> If a Variable is declared
as final then you
15182.1 -> cannot change the value
of that particular class
15184.85 -> or cannot change the reference
of that particular class
15188.027 -> when it comes to objects.
15189.497 -> So we will see
15190.3 -> that later a Constructor
cannot be declared as final.
15194.4 -> So that's the rule you cannot
declare the constructors final
15198.3 -> and blank final variable should
be initialized in Constructor.
15203.3 -> So maybe in this case
15205.2 -> if you wouldn't have
any value here,
15207.508 -> you declared this as final if
you don't have any value here.
15211.38 -> It has to be assigned
an Constructor right now.
15214.4 -> It's giving an error saying
15216.15 -> that it's not initialized
if you mark it
15218.839 -> as for it should be gone.
15220.5 -> So it's mandatory
15221.675 -> that if you put instance
variable as Final in class,
15225.2 -> it's mandatory that you assign
some value in the Constructor.
15228.905 -> If you don't then compiler
15230.309 -> would throw an error so
here you can't override it.
15233.44 -> So basically you have
a final method void run
15236.125 -> and you have a sub class
15237.652 -> of vehicle and you're trying
to override Run method,
15240.899 -> it shows you an error.
15242.3 -> So this is what we saw
in case of was Final
15245.1 -> and when we try to override it
in car we got an error
15248.4 -> and it's all compiled sign
15250.1 -> if you declare
15251.089 -> any class as final you
cannot overwrite that class
15254.55 -> which we saw it gives
you a compile-time error.
15257.8 -> So when it declared a vehicle as
final and when you try to extend
15262.275 -> when you try
to create car class,
15264.432 -> which extends vehicle class
it gave you an error
15267.9 -> because vehicle class was
fake lettuce final again.
15270.879 -> This is a compile time.
15272.232 -> Now what's Dynamic binding
15273.762 -> which is also known
15274.8 -> as runtime polymorphism is
nothing but during runtime it
15278.603 -> decides which instance
of which instance
15281.3 -> of a method should be called
15283.213 -> or which method
should be called.
15285.4 -> So this is in case
of again inheritance
15288.443 -> and when you override
the method in your subclass,
15292.3 -> so we saw this earlier
again to just to show
15296.279 -> you we had this move method here
15299 -> and in I have this move method
and in automobile management,
15304.1 -> we did this thing
we have a Mercedes
15307 -> that is assigned
15308.046 -> to vehicle class class reference
rather vehicle class reference
15312.1 -> of reference named by vehicle
1 and in the second thing we
15316.386 -> have vehicle itself.
15317.9 -> So first one is pointing
to an object of car,
15321.284 -> which is Mercedes
15322.592 -> and the second one is referring
to the object of vehicle itself.
15327.3 -> So this is what dynamic
polymorphism is all about.
15330.34 -> The first one gives
a call to the move method
15333.122 -> in car the second one
second one gives a call
15336.104 -> to the move method in vehicle.
15338 -> So yeah, you could see here.
15339.8 -> So move in car class
15341.3 -> and then it calls
a moving vehicle class
15344.5 -> and it happens at run time.
15346.171 -> That's why it's
runtime polymorphism.
15348.4 -> So abstraction is a mechanism
15350.7 -> of hiding the implementation
details from the user
15354.6 -> and only providing
the functionality of a user.
15357.6 -> So basically you
could have abstraction.
15359.634 -> We're in on the first day.
15360.996 -> We spoke about the shape class
and the circle class
15363.8 -> and Wrangle and square
and stuff like that.
15366.3 -> Right?
15366.747 -> So basically shape is a class
which is abstract class,
15370.5 -> which doesn't know all
the functionality up front door.
15373.2 -> It doesn't have all
the behavior of front.
15375.809 -> It doesn't know
15376.722 -> what would be the behavior
of a circle class
15379.481 -> or it doesn't know.
15380.7 -> What is the behavior
of a square class
15383.225 -> when I see Behavior.
15384.611 -> It's nothing but calculation
of area calculation
15387.962 -> of area is nothing but it
adds Behavior to the class
15391.6 -> and calculation of area
15393.9 -> in your Square class would be
different calculation of area
15397.7 -> in your circle class
would be different.
15400.137 -> So shape by itself doesn't know
15402.074 -> what the implementation
of area method I would say.
15405.2 -> So that is what is attraction.
15407.4 -> There are two ways
in which you could provide
15409.6 -> abstraction in Java one is
by abstraction class,
15413 -> which is not hundred
percent abstract,
15415.4 -> which could have
15416.416 -> like abstract methods like area
in this case is about Track
15420.1 -> but there could be some methods
15421.876 -> which is same throughout
or common throughout all
15424.7 -> the subclasses of shape say
for example printing area.
15428.1 -> You just have to have
a print statement
15430.139 -> which is printing area
for a particular shape
15432.5 -> from the implementation per se
15434.235 -> it's same throughout
all the classes area method
15437 -> would be something
that is abstract.
15438.9 -> Whereas display area
could be something
15441.268 -> that is not an abstract method.
15443.2 -> So in such cases wherein
15444.882 -> you have blend of abstract as
well as non abstract methods,
15448.821 -> that's where you
use abstract class.
15451.2 -> So it's not hundred
percent abstract.
15453.468 -> Whereas in interface it has
to be interface is something
15456.9 -> which says that it has to be
a hundred percent abstract.
15460.337 -> So interface is
altogether a new construct
15462.866 -> that we have in Java
15464.16 -> when it comes to abstract
class abstract is just
15467.2 -> a modified to a class.
15468.696 -> So you write class and you
just prepend it by abstract
15472.3 -> which makes that class
and abstract class.
15474.8 -> Whereas interface is something
that is a new construct
15477.8 -> that we are going
to see in the coming.
15479.9 -> Slides upset class
15481.181 -> and Abstract methods
so abstract method is
15484.3 -> as I said area
would be abstract method
15486.8 -> in this case wherein you don't
have a concrete implementation
15490.6 -> of area in your shape class.
15493.3 -> That's the scenario
in such cases wherein
15496.1 -> you don't have a complete
concrete implementation
15499.188 -> of a particular method
you would declare it
15501.949 -> as abstract method and
if you have an abstract method,
15505.5 -> if you have at least
one abstract method
15508.2 -> in your class,
15509.157 -> you have to declare
that class as abstract class
15512.37 -> or else compiler
would throw an error.
15514.9 -> So whenever you have
a abstract class,
15517.5 -> it means that there is
at least one method
15519.709 -> within that particular class
which is declared as abstract.
15522.952 -> So when you suppress
this abstract class so
15525.3 -> shape for that matter
15526.621 -> when you subclass shape shape
has got a area method
15529.699 -> which is abstract.
15530.835 -> Now when you subclass it
when you create Circle,
15533.8 -> which is nothing
but class Circle
15535.995 -> which extends shape now you
are creating surplus of it.
15539.7 -> That case you have to ensure
that you implement area.
15543.3 -> If you don't Implement area,
15545.026 -> it is still kept as abstract
and you will have
15547.8 -> to make circle class
as abstract as well.
15550.5 -> If you don't give
the actual implementation.
15552.93 -> So an abstract method is
a method that is declared
15555.7 -> without implementation any class
15557.649 -> that contains one or
more abstract methods
15560.06 -> must be declared
with abstract keyword
15562.266 -> and abstract class is a class
15564 -> that is declared
with abstract keyword
15566.3 -> and abstract class may
15567.992 -> or may not have
all abstract methods.
15571 -> So as I said,
15571.901 -> it's a mixture of abstract
and on abstract methods
15575.3 -> and abstract class
is mostly used for inheritance.
15579 -> So let me take the same example
of shape and shapes.
15582.923 -> So we Define a shape
which would have abstract area.
15586.8 -> This is what I was saying.
15588.05 -> So when you have at least
one abstract method the compiler
15591.048 -> will throw an error.
15592.131 -> So in this case it is saying
15593.7 -> that you have abstract method
but your class is not abstract.
15597.1 -> So we have to make
this one as abstract.
15599.537 -> And as I said abstract class
is nothing but a modifier you
15603.1 -> just have a modifier
15604.1 -> that you need to prepare
into the class.
15606.2 -> This is abstract method
and you say you have a method
15610 -> which is public void.
15611.9 -> It's not returning anything.
15613.3 -> We are just displaying area now
rather than defining it here.
15616.8 -> Maybe I will put something
like So we have a shift method
15626.7 -> and now I declare
Circle method now,
15630.1 -> this circle method
is extending shape now.
15633 -> It's throwing an error and it
says you have to implement
15636.666 -> the abstract methods shape
15638.4 -> as got abstract method
15639.604 -> if you don't implement it
as I mentioned earlier,
15642.445 -> if you don't implement it
15643.823 -> if you choose not to implement
the area method then you
15646.806 -> will have to make this abstract.
15648.511 -> If you make this abstract
error would go off.
15651.1 -> But in this case
15652.199 -> since we know the concrete
implementation of area
15655.5 -> for Circle will have
to implement it
15658.011 -> when I say we will have
to implement it we say area
15661.481 -> and we override it.
15662.8 -> So for Simplicity reason,
15664.27 -> I'll just put
some value here for now
15666.3 -> since we are talking
about abstraction.
15668.29 -> I'll just keep it simple.
15669.6 -> So basically what we
are trying to do here is we
15672.504 -> have implemented area
15673.8 -> which would be nothing
but your Pi R square actually,
15677 -> so here we have a shape class
15678.914 -> and we are overriding
the idea method here.
15681.614 -> And this is how you abstract it.
15683.666 -> When you run it,
15684.753 -> so basically you
could have something
15687.2 -> like suppose I create
a shape utility class.
15690.127 -> So this is pretty much
like overriding methods.
15693.3 -> So you could have a shape
class shape circle is equal
15697 -> to New Circle and you
could call Circle dot area.
15701.5 -> So basically what you would get
is nothing but a float value,
15705.6 -> which is your area area
15707.338 -> of let me put it
this way area of circle
15710.338 -> when I want to print it.
15712.184 -> What I would do is
circle dot display area
15715.7 -> and I print area of circle
15717.4 -> what we have seen here is
there was abstract method area
15720.7 -> which was implemented
15721.981 -> in your subclass that Circle and
when I give a call to it
15725.4 -> and here you could see
15726.72 -> that again similar
to vehicles that we spoke
15729.249 -> about instance of circle
is being assigned to shape
15732.19 -> and when you give a call to
it you could see that method
15735.203 -> on circle is being called
and not on shape
15737.449 -> because shape by itself doesn't
have any implementation of area.
15740.9 -> So one thing to note here is
when you have Class.
15744.1 -> So here you could see this value
being printed operate abstract
15747.7 -> class would have one or more
abstract methods for sure.
15750.514 -> And when you subclass it,
15751.985 -> you have to ensure
that you give implementation
15754.5 -> of your abstract methods.
15756.1 -> If you choose
not to implemented,
15757.864 -> then you will have
to make the subclass
15760.1 -> as abstract as well.
15761.46 -> So execution of abstract method.
15763.643 -> This is very much similar
to normal exhibition
15766.626 -> that we have.
15767.516 -> So the main method you have
instance of mobile class created
15771.6 -> this case then there's
a default Constructor
15774.584 -> of mobile class gets
created gets executed.
15777.5 -> So pretty much similar
to normal execution
15780.194 -> when you create
an instance of Nokia,
15782.5 -> which is subclass of mobile.
15784.2 -> As I said the first statement
15785.8 -> that you have the Constructor
of subclass is nothing
15788.8 -> but super or it calls
the super Constructor.
15791.34 -> So here we can see
15792.4 -> that the default Constructor
for super is being called
15795.5 -> when you try
to instantiate Nokia
15797.5 -> as we are running run method,
15799.419 -> but in Mobile class run
is an abstract method so
15802.615 -> run method from Nokia class gets
executed similar to the example
15806.9 -> that we saw so shape
area class area method
15810.3 -> on Circle got executed
and not on shape.
15812.8 -> What is the encapsulation
15814.313 -> that encap solution is
the methodology of binding code
15817.639 -> and data together
into a single unit.
15819.9 -> So basically everything
it's a encapsulation.
15822.898 -> It's put as one so you
could imagine class
15825.6 -> being put as one right classes
called this for that matter.
15829.08 -> You see everything
been encapsulated as one right
15832.093 -> you group these together
15833.6 -> you group this integer and long
15836.2 -> which is a property of vehicle
and it has got some Behavior as
15839.8 -> through this move.
15840.927 -> It's all encapsulated as one
15842.605 -> or it's all put
together as one entity
15844.8 -> that is nothing
but encapsulation.
15846.619 -> So basically you could
imagine a capsule right
15849.1 -> which has got
multiple ingredients
15851.26 -> which has multiple made sense
or chemical components
15854.6 -> which are put together
into one capsule
15856.917 -> and you have you think
capsule has one mixing
15859.613 -> but it's basically combination
of chemical components
15862.786 -> Within Thing is
for encapsulation.
15864.802 -> There is access modifier comes
15866.683 -> into picture you have
this access modifiers
15869.345 -> or private and you have public
15871.309 -> you have protected
you have default
15873.512 -> this access modifiers restrict
15875.556 -> or it restricts the visibility
15877.6 -> of regular component
of a class say method
15880.312 -> or variable or anything.
15881.9 -> So that's encapsulation feature
of object-oriented programming.
15885.8 -> You can't see everything.
15887.05 -> It's not that everything
is open for everyone.
15889.3 -> So you can have
restriction you have
15891.156 -> different levels of restriction
15892.8 -> when it comes to visibility
of this components
15895.447 -> that is a part
of encapsulation as well.
15897.7 -> So to achieve encapsulation
15899.7 -> in Java declare the variables
as private usually
15903.3 -> the best practices
not to expose everything
15906.53 -> because once you expose
something as public or once you
15910.9 -> expose it for the application
to access you have to ensure
15914.305 -> that you maintain it right
because anyone can access it.
15917.65 -> So your class is becoming
much more fragile
15920.173 -> a I won't talk about
this topics right now
15922.716 -> because fragile D is something
that is related to code quality
15926.5 -> or coupling we say
15928 -> so I don't want
to touch on that.
15929.6 -> But basically the best practice
15931.762 -> is to have less
visibility restrict visibility
15934.9 -> or different visibility
as much as possible.
15937.7 -> Try to make it as much less
as possible make it private.
15941 -> Basically if you could make all
15942.669 -> the variables as private
it would be good thing.
15945.2 -> So basically all non private
15947.2 -> or public variables are
liability for application.
15950.352 -> So it increases the maintenance
of the application
15953.429 -> and it's easy to break that way
15955.425 -> if you make some changes
to a class it becomes
15958.397 -> very difficult the future
to maintain it.
15961.064 -> So usually the general practice
is to keep the methods variables
15965.265 -> as private not methods variables
as private and we have Getters
15969.554 -> and Setters method
15970.8 -> which exposes which are public
methods or mutator methods
15974.735 -> which would expose
15976 -> this variable to the outside
world through public.
15978.9 -> So usually we don't
have Setter methods.
15981.352 -> We restrict
Setter methods again.
15983.364 -> Usually you have a private
15985 -> since variable and you
have a getter method
15987.1 -> which is a public method
15988.5 -> which is nothing
but Returns the value
15990.249 -> of the instance variable
to the outside world.
15992.5 -> So data hiding the user
will have no idea
15994.715 -> about the inner implementation
of the class.
15996.929 -> What are the advantages
of data hiding user
15999.426 -> need not know the core
implementation of the class.
16002.4 -> It increases flexibility.
16004.058 -> We can make variables
and methods read only
16006.8 -> and right only as
per the requirement.
16009.1 -> So imagine if you didn't have
all this access modifiers,
16012.5 -> there's only one that is public
which is exposed to everyone
16015.97 -> so it would create a Havoc.
16017.6 -> So this is basically based
on your requirements.
16020.2 -> You could have
different patterns
16021.8 -> of this access modifiers used
within the application.
16024.6 -> It makes testing easy.
16026.227 -> So basically Hotpoint is
reuse ability easy to reuse
16030.01 -> and easy to change
with the new requirement.
16033.143 -> So with reusability,
16034.6 -> even the maintainability
16036.066 -> of the particular
application is improved
16038.502 -> when you have this encapsulation
and easy to reuse in the sense
16042.619 -> if imagine The way around
16044.2 -> where in you have
only private methods
16046.7 -> so a class could access
only the instance variables
16050.158 -> within a class nothing
from outside world.
16052.927 -> It cannot be accessed
from outside as well.
16055.7 -> Imagine such a scenario
right in that case.
16058.4 -> You would have a lot of code
redundancy right everywhere.
16061.235 -> You would write the same code.
16063 -> It might be the same thing.
16064.588 -> We have already implemented
in some other class,
16067.174 -> but you will have
to re-implement it
16069.1 -> since it's not accessible
outside the class.
16071.7 -> So that's how encapsulation
increases the reusability of who
16076.8 -> and it makes testing easier.
16078.6 -> Of course.
16079.238 -> So here you could see
that employ one.
16081.6 -> So this is the encapsulation
mutator method that
16084.371 -> I was talking about.
16085.589 -> So basically you
have employee one
16087.559 -> which has got string name,
16089.179 -> which is private
you could see here.
16091.287 -> It's defined as private when I
say private this name property
16094.9 -> would be used only
within this class.
16096.9 -> If you try to access it
16098.177 -> from outside class
you would get an error
16100.6 -> but there might be scenarios in
which you want to Says this name
16104.567 -> from outside class you
want to understand what
16107.4 -> its value is in that case.
16109.3 -> You would have something
like this right?
16111.689 -> You would have
getter method get name,
16113.912 -> which is nothing but
it's written type is string
16116.677 -> which is the data type for name
16118.525 -> and it's returning the name.
16120.233 -> Now one thing to observe
here is this is public.
16123.1 -> This one was Private name was
private but get name is public
16126.8 -> which means it could be accessed
from outside as well.
16129.5 -> Similarly.
16130 -> You could have Setters
which is not a good practice.
16132.5 -> By the way, you
shouldn't have Setter methods.
16134.983 -> So again Setter is something
like you pass the value
16137.983 -> that you want to set
this particular name variable.
16140.7 -> So basically you are saying
that whatever you send
16143.3 -> through this method is going
to set to the name variable.
16146.1 -> So we are referred
16147.4 -> to this particular
example in Maine.
16149.447 -> So you create an instance
of employee one
16151.8 -> who have edad set name
you're sitting at well X
16154.968 -> and when you access it
you do e dot get name.
16158 -> So basically what we
are trying to say here is
16160.8 -> a demo end caps is a Glass
16164 -> it's not the same class.
16165.6 -> So you have employee one and you
16167.483 -> have demo end caps as
a different class though.
16170.2 -> It's a different class
16171.3 -> till you are able to access
your name employee name
16175.3 -> from this class.
16176.4 -> This is again,
16177.164 -> a private instance variable you
are able to do this just
16180.486 -> because you have
this Getters and Setters,
16183.055 -> let understand interfaces
interfaces are nothing
16186.2 -> but could imagine
interface as a blueprint
16189.5 -> or it is something that
it's a specification rather,
16192.6 -> right and interface could be
thought of as a specification.
16195.8 -> This is how it should be.
16197.4 -> So basically it could be
a company manufacturing bottles
16201 -> or remote rate.
16202 -> It would say that this is
16203.5 -> how it should be basically there
should be so-and-so buttons.
16206.5 -> There should be
this button should be here.
16208.6 -> This button should be there
and something of that sort.
16211.458 -> So basically through interphase
16213.1 -> what we do is we specify
the contract we say
16216.155 -> that this is
how it should be now.
16218.5 -> For example,
16219.4 -> you could have specification
mentioned in a piece of paper.
16222.9 -> This is how Remote should be
16224.6 -> and there could be different
vendors for this remote
16227.6 -> who would be actual
manufacturing remote
16229.9 -> and which would be aligned
16231.2 -> to this particular
remote specifications.
16233.5 -> Then you could check that.
16234.9 -> Okay, so and so specifications
are met which means
16237.677 -> that this this particular thing
could be used as a remote.
16240.741 -> So basically these are nothing
but the specifications
16243.8 -> for the system so
through interphase you say
16246.171 -> that this is
16246.839 -> how it should be and you
would have different vendors
16249.898 -> or you would have
different implementations
16252.3 -> that align to the specifications
16254.316 -> and if they match up
to the specification,
16256.9 -> it means that it's
a correct one.
16258.5 -> So hence an interface contains
all the specifications
16261.966 -> and can be used
for creating a new remote.
16264.802 -> So all you see here,
16266.119 -> there's a joystick
this AC remote
16268.2 -> this TV remote and everything.
16270 -> It has got different things
16271.51 -> but there's something
in common and that's
16273.73 -> what you specify
16274.638 -> through interface and interface
contains variables and methods
16278.1 -> but the methods declared
16279.8 -> inside interface or by
default abstract methods.
16283.2 -> As we saw in the earlier
slide interface is
16285.958 -> hundred percent abstract.
16287.6 -> So all the methods that you have
within interface is abstract
16290.6 -> and interface is used
to achieve abstraction.
16293.188 -> It is used to achieve
16294.461 -> loose coupling when I
say loose coupling.
16296.886 -> It's like you are not binding
everything into a class.
16300.1 -> Basically you say
that fits a remote.
16302.6 -> It has to have
this features, right?
16304.9 -> So basically your kind
of decoupling it or you can see
16308.498 -> that all the implementations
16310.4 -> of remote will have
so-and-so specifications,
16313.489 -> which is been introduced
by interface also in Java,
16317 -> you cannot have
multiple inheritance.
16319.135 -> You cannot have a class
16320.5 -> which extends multiple
classes cannot have car
16323.787 -> which extends vehicle and
which extends the for example
16327.7 -> locomotive locomotive is
one of the classes
16330.6 -> if for example,
16331.642 -> so, you cannot have a class
16333.45 -> which extends to classes
that is multiple inheritance.
16337.3 -> Do you could have levels
16338.71 -> and you could have
hierarchical inheritance,
16341.047 -> but you cannot have
multiple inheritance.
16343.4 -> But through interfaces you
can have multiple inheritance
16346.8 -> you could parlament
multiple interfaces,
16349.3 -> but not multiple classes again,
16351.413 -> since this is
16352.3 -> inheritance interface is
hundred percent abstract class.
16355.993 -> And basically you
create sub classes
16358.38 -> from or you implement
an interface is nothing
16361.268 -> but it follows
he's a relationship.
16363.5 -> So what's the difference
between interface and a class
16366 -> and interface can
never be instantiated
16368.052 -> just to give you an example,
16369.7 -> I'll show you what interface is.
16371.604 -> So instead of this class.
16373.141 -> I will make this interface.
16374.8 -> So this is how we Define an
interface we Define interface,
16378.734 -> but as I said,
16379.7 -> the interface is
hundred percent abstract.
16382.111 -> Everything has to be attract.
16383.7 -> You cannot have methods
something of this sort.
16386.9 -> You cannot have a concrete
implementation of method though.
16389.8 -> You could have a default method
which we would be looking
16393.1 -> at in the in the slides to come
but at this point,
16396.289 -> let's imagine that you have
a ship class and
16399 -> whatever methods you
have you declared
16401.4 -> within your ship class has
to be Track a by default.
16404.5 -> It is abstract.
16405.464 -> You did not even mention it
16407.134 -> by default jvm puts
it has abstract.
16409.3 -> Even if you mention it abstract,
it's not a problem.
16412.1 -> It is abstract.
16413.2 -> So now when I unlike extends
16415.6 -> that we do on glass
or for the face you implement it
16421 -> so you implement shape class.
16423.4 -> So you'll have to make it public
by default the access modifier
16427.2 -> for a method the face is public.
16429.155 -> So here you can see
16430.352 -> that we have implemented
it we could see
16432.756 -> that it has a hundred
percent abstract.
16435.1 -> So with this you could see most
of this differences
16438.153 -> being listed here and interface
should contain abstract methods,
16441.958 -> which we saw class can contain
only concrete methods.
16445.1 -> We are talking
16445.873 -> about normal class here
not the abstract class.
16448.579 -> The members of the interface
are always public
16451.1 -> which we again saw
16452.2 -> when I didn't implement
16453.688 -> this one as public Circle
it gave me an error.
16456.563 -> So by default it is public
16458.298 -> the members of the class
can be private public
16461.3 -> or protected and interface
can I have a Constructor
16464.9 -> since we are not
creating instance.
16466.9 -> The first point you
can see that interface is
16469.4 -> cannot be instantiated since we
cannot instantiate interface.
16473.2 -> There's no need of Constructor
a class can have constructed
16476.566 -> to initialize the variables
16478.1 -> which we met yesterday
implements keyword is used
16481.3 -> for inheritance and whereas
in terms of class,
16484.829 -> we have extends
16486.1 -> which we saw now right
for interfaces you we
16489.163 -> changed it to implements
rather than exchange
16492.188 -> after extends keyword.
16493.7 -> Any number of interfaces
can be given this
16496.169 -> is multiple inheritance
that we spoke about
16498.7 -> whereas after extends
16500.5 -> you can have only
one and only one class.
16503.097 -> You cannot have multiple classes
cannot contain instance Fields.
16507.38 -> The only field
16508.311 -> that can appear in our interface
must be declared
16511.423 -> both static and final
can contain instance Fields.
16514.676 -> So only the constants
would be declared
16517.169 -> when your interfaces
whereas with in class.
16519.9 -> You can have all levels
of all the instance variables.
16523.4 -> Classes have implementation
16525.2 -> whereas this is between class
and abstract class.
16528.4 -> So classes have implementation
abstract classes have
16531.628 -> no implementations or they
can have implementation as well.
16535.3 -> So it's a mixture
16536.3 -> of abstract methods
and non abstract methods
16539.32 -> as we saw.
16540 -> So abstract class is
not hundred percent abstract
16542.5 -> right unlike interfaces.
16544.034 -> You could have
concrete implementation
16546.4 -> as well concrete classes
are instantiated to create
16549.718 -> object abstract classes
16551.198 -> cannot be instantiated
similar to interfaces
16554.15 -> abstract classes cannot be
instantiated a concrete class
16557.8 -> can be final and abstract
class can never be final
16561.646 -> as it has no defined functions
16564.1 -> for abstract class
to be a complete.
16566.531 -> It has to be extended.
16568.1 -> That's what the focus
is abstract class
16570.9 -> and interface is an abstract
class can be extended
16574.738 -> with class using keyword extends
16577.3 -> and whereas interface
16579.2 -> can be implemented
to a class using implements
16582.3 -> which we saw.
16583.2 -> Abstract class can extend
only one class at a time
16586.6 -> and interface can extend number
of interfaces at a time.
16590.4 -> So yeah, this is one thing we're
in your interface can extend
16594.148 -> other interfaces, right
16595.423 -> and you could have
multiple interfaces
16597.8 -> extended abstract class can have
private default protected
16601.5 -> and public members
16602.7 -> and interface members are
default or by default public
16607.3 -> in abstract class keyword
abstract is mandatory
16610.723 -> to declare a method
as an abstract method
16613.8 -> which we saw okay in interphase.
16616.039 -> It's not mandatory
16617.265 -> because by jvm by default put
set abstract classes
16620.6 -> are to achieve zero to
hundred percent of abstraction,
16623.453 -> which means that you
16624.535 -> could have some concrete
implementation as well.
16627.3 -> Whereas interfaces
or hundred percent abstract.
16630 -> You cannot have anything you
cannot have any implementation
16633.2 -> within but you could have
a default methods abstract class
16637 -> can have abstract
16638.1 -> and on abstract methods
again here abstract class
16641.7 -> can have Constructors.
16643.2 -> Interface cannot have
Constructors which we
16645.979 -> saw earlier abstract class
16647.694 -> can have abstract
and non abstract methods
16650.5 -> since it's not a
hundred percent abstract.
16652.8 -> Whereas interface can have only
abstract methods by the way
16656.97 -> from java it as I said,
16658.624 -> there's a default
method being introduced
16661.3 -> which is nothing but
16662.434 -> you could have a concrete
implementation written
16665.1 -> within interface class interface
relationship you have class
16669.525 -> which extends other class
16671.42 -> you have class
16672.6 -> which implements interface
you have interface
16676 -> which can extend other interface
16678.2 -> if there's an interface already
defined and you want to inherit
16681.847 -> some methods or you want
to inherit the methods
16684.332 -> that you have within
the other interface
16686.6 -> would do it using extends
a class extends another class
16690.2 -> while implements an interface
16692 -> and interface extends
another interface class
16694.992 -> cannot extend multiple classes,
16697.1 -> but can Implement
multiple interfaces.
16700.2 -> So here you could see
that this one class.
16703.054 -> Which is extending
the class on the top
16705.8 -> and this one at the right side.
16707.878 -> It's time to extend it.
16709.343 -> If you try to extend
multiple classes,
16711.7 -> it would give you
a compile-time error.
16713.9 -> It won't allow you to inherit
from multiple classes.
16717 -> Whereas in this case,
16718.416 -> you could see it's implementing
multiple interfaces on the top.
16722.6 -> You could see one interface
been implemented by this class
16725.952 -> and there's one more
interface to the right
16728.3 -> which is being implemented
by this class class
16730.9 -> cannot extend multiple classes,
16732.7 -> but it could Implement
multiple interfaces
16735.451 -> which gives an opening
for multiple inheritance
16738.624 -> when any interface gets compiled
compiler automatically adds
16742.875 -> access modifiers to the members.
16745.072 -> So this is done by default
its internal Edition.
16748.44 -> So here you could
see interface demo
16750.834 -> which has got one variable
16752.7 -> that is int count is equal to 10
16755 -> and it has got a method
which is output now
16758 -> when this demo dot Java,
16759.773 -> which is an interface,
16761.4 -> which gets compiled you See
that by default.
16764.676 -> It has put it as public static
final so count 10 would be given
16769.4 -> access modifier public static
final so four variables jvm by
16773.595 -> itself puts public static final
16775.8 -> and four methods it would put
it as public abstract.
16779.5 -> So that is the reason
when we had the area method
16782.3 -> when we try to override
it it gave an error saying
16785.182 -> that it has to be public.
16786.8 -> So John went to a bank he
wants to credit some money
16790.7 -> to his account.
16792 -> So let's see this one.
16794.1 -> So basically here you could see
to implementation of it you have
16797.9 -> money interface and you have
operation as its method.
16801.7 -> So now you could see
two implementations of it
16804.506 -> one is debit and the other one
is credited with in debit.
16808 -> We are just saying
16808.9 -> that we are writing
a dummy statement.
16810.7 -> They're saying that we are
debating money from this account
16813.6 -> whereas credit is nothing.
16814.99 -> But again, we
are printing saying
16816.743 -> that we are crediting
money to this account.
16819.1 -> So now when you create
instance of money
16821.8 -> or you create in It's off credit
16823.913 -> and assign it to money
and money dot operation.
16826.988 -> You would have operation method
16829.01 -> on credit being called
in this example.
16831.687 -> We can see that there's
a shape interface
16834.4 -> which has abstract area
and there's a circle
16837.83 -> which returns this value right
and say I declare one more class
16842.8 -> which is square
16844.2 -> which implements shape and its
again three main error saying
16847.8 -> that you will have
to declare it.
16849.73 -> You will have to
implement the method
16851.9 -> so I will read this and say
I written some dummy value
16855.7 -> like hundred you have a square
and said Circle say circle area.
16861.4 -> We are just hard
coding it right now.
16863.517 -> We don't have to implement it.
16865.1 -> So it gives you two hundred.
16867.1 -> It's returning 200 as float.
16868.936 -> And this one
is returning hundred.
16871.1 -> So what we can do here is
we have this shape utility.
16874.9 -> So here we have this thing
called on Circle.
16878.032 -> So I will just print
it out here saying
16883.6 -> And now I have one
more say for example,
16886.493 -> I create one more shape
16888.2 -> which is square nothing
but Nu Square now
16891.4 -> what we are doing is we
are going to print out
16894.861 -> where dot area so instead
of assigning to a variable
16898.8 -> you could do it this way
as well area of a square.
16902.7 -> What we did is we
have interface shape
16904.612 -> and we have a area method
which is abstract.
16906.941 -> We have two concrete
implementations of
16909 -> it Circle and square
16910.4 -> and we are instantiated circle
16912.5 -> and square here and we
are calling area method on it.
16916.281 -> By the way,
16917.049 -> you could see here that this is
dynamic polymorphism Circle
16921.1 -> and square is been assigned
to the shape reference.
16924.3 -> It's not directly to the circle.
16925.9 -> You would see hundred and
two hundred mean printer know
16928.6 -> so Circle was 200
and square was hundred
16931.179 -> and you could see two hundred
16933.1 -> and hundred so it's basically
Dynamic polymorphisms followed
16937.008 -> in interface as well.
16938.4 -> You could extend an interface
with another interface.
16941.7 -> So suppose you have
one more Switch is
16944.5 -> for now just too.
16948.7 -> So I create
an interface test interface
16951.3 -> which has like test method.
16953.1 -> So you have a test interface
which has void test
16956 -> and you could have shape which
is extending test interface.
16960 -> Now your circle and your Square
would give an error
16963 -> because there is one more method
that you need to implement.
16965.95 -> If you don't implement
it you will have
16967.85 -> to either make this abstract.
16969.331 -> If you make it abstract,
16970.535 -> it should go off
but in this case suppose
16972.829 -> we want to implement it
then you will have to ensure
16975.5 -> that you implement test method
as well once implemented
16979.1 -> the error should be gone
similarly in square.
16981.888 -> You will have to find it.
16983.358 -> So that's what is extending one
interface with another right?
16986.7 -> So basically here you
could see there's walkable.
16989.2 -> There's a runnable
and when you do it
16991.313 -> when you implement runnable,
16992.923 -> you will have to ensure
that you implement Walk and Run
16996.1 -> both the methods.
16997.423 -> It's a class extending one class
17000 -> and implementing more
than one interface.
17002.702 -> There's two interfaces
Walk and Run
17005 -> so you could see animal
17006.675 -> which implements walk and So
then it will have to implement
17010.958 -> both the methods Walk and Run
17013.1 -> whereas there's a human glass
which extends animal.
17017.5 -> So this is basically
there's a class
17019.459 -> which is implementing
multiple interfaces
17021.812 -> and which has to ensure
17023.1 -> that it implements
both the methods.
17025.448 -> So in this case walk and run
it has to ensure
17028.4 -> that it implements Walk and Run
and this one class
17031.971 -> which is extending
from this particular class
17035.1 -> and you could see here
17036.807 -> that you could assign human
which is extending
17040.269 -> which is a subclass of animal
17042.5 -> we could see
17043.1 -> that human could be assigned
to walk and run as well since it
17047.216 -> is implemented from there.
17049 -> So you could have H 1 dot walk
17051.2 -> and H 2 dot run sort
of you have given a call
17054.32 -> to this methods.
17055.46 -> So basically this is again
17057.241 -> if you understand the idea
of runtime polymorphism
17060.6 -> or dynamic polymorphism,
17062.127 -> which is nothing
but assigning the instance
17064.8 -> of subclass to superclass
you should get idea of me.
17068.6 -> All this thing we are pretty
much talking the same thing
17071.9 -> all this is talking
about Dynamic polymorphism.
17074.9 -> If you get that thing,
right you have good enough.
17077.8 -> So we are talking
about default method right
17080.7 -> since Java it you could
have default implementation
17084.236 -> within your interface.
17085.732 -> You could say that you
cannot have a concrete method
17089.2 -> but you could have
17090.258 -> if you put a concrete methods
something like this,
17092.749 -> it would give you an error.
17094.2 -> Okay, it gives you
an error saying
17096 -> that it's not allowed but you
could have it as default.
17099.196 -> Once you define is default.
17100.794 -> It's good enough.
17101.8 -> So all this methods are all
these classes circle square
17106.3 -> and all these classes
would get would inherit
17109.05 -> this they can't override it.
17110.8 -> They can't do anything with it,
17112.497 -> but they would inherit this we
can give a call though,
17115.4 -> but he can't override it.
17116.926 -> So basically I'll
just show it here.
17119.163 -> So basically you
have default method
17121.4 -> which is say say and
which is printing out.
17124.2 -> Hello.
17124.602 -> Welcome to edu Rekha, right
17126.6 -> and you can see here.
17128.5 -> Flash interface demo,
17129.735 -> which is implementing welcome
and you could see here.
17132.602 -> Hello bean concrete
implementation of L,
17134.897 -> which is nothing but
it's printing out the message
17137.665 -> that is passed
to the hello method so
17139.7 -> though default class
interface demo doesn't declare
17143.1 -> say method it
inherits from welcome.
17145.779 -> When you do out dot say you
could see the default method
17150 -> being invoked here.
17151.2 -> We could see that you know,
17152.605 -> hello welcome to edu
Drake has been printed out
17155 -> which is nothing but the output
of default method so
17157.77 -> basically default methods
are not but method
17160.406 -> which cannot be overridden
17162 -> but is available
for all the classes
17164.799 -> that implements a
particular interface
17167.6 -> or implements that interface
17169.616 -> so rules for using
private methods in interfaces
17173.021 -> following all the rules
for using private methods
17176.5 -> in interfaces private interface
method cannot be abstract
17180.809 -> private method can be used
17182.809 -> only inside interface
private static method
17186.152 -> can be called from other static.
17188.614 -> Non-static interface methods
private non static methods
17193.115 -> cannot be called
from private static methods.
17196.5 -> This might look confusing
at this point,
17198.701 -> but you could think that first
of all private interface method
17202.289 -> cannot be abstract
17203.194 -> because we want it
17204.134 -> to be implemented in some
other implementation, right?
17206.9 -> We cannot keep it
private since interface
17209.3 -> by itself doesn't have
the implementation of it.
17211.743 -> You want to implement
that method in some other class.
17214.5 -> So it cannot be private
private method can be used
17217.5 -> only inside interface.
17219 -> So if we Define a private method
within an interface,
17222.119 -> it can be used only
within the interface.
17224.519 -> So basically you
could have a default method
17227.049 -> which is private, right?
17228.569 -> So basically default method
itself cannot be private
17231.8 -> but within default method,
17233.673 -> so what I am trying
to say is so here
17236.268 -> you could have private void
which is doing nothing
17239.8 -> but here your default method
would call this private method.
17244.1 -> So private method can only
be used within the interface
17247.5 -> and it's usually used 24
get private static method
17250.8 -> can be called from other static.
17252.755 -> This is pretty much similar
to other classes normal classes
17256.3 -> private non static methods
cannot be called
17259.4 -> from private static methods.
17261.3 -> This is a common rule
17262.6 -> that we have private non
static methods cannot be called
17265.611 -> from private static method.
17267.2 -> So if you have a static method
within the static method,
17270.3 -> you cannot call
a non static method.
17272.381 -> Remember we mentioned it earlier
17274.139 -> unless we create
the instance of it.
17276.246 -> We can't call it.
17277.299 -> But in this case you
cannot call it at all.
17280 -> So it's not on a class
you're invoking it basically
17283.286 -> within an interface.
17284.6 -> So private methods is
specifically you could call
17287.6 -> Private methods from within
your default method in interface
17291.262 -> and since private methods are
not accessible from outside.
17294.8 -> That's the only reason you
could have private method
17297.3 -> near interface static methods
in an interface.
17301.1 -> So you could have
something like this
17303.651 -> where in you have
interface one and you
17306.287 -> have a static method display?
17308.3 -> You remember static
methods are more
17310.52 -> of a class level method, right?
17312.593 -> You need not have to create
17314.4 -> instance of a class
to invoke a static method
17317.4 -> if an interface has
a static method you could call
17320.4 -> it directly by interface dot
the name of the interface
17323.517 -> does the name of the method
17325.3 -> so we can have a static
method like static.
17328.5 -> So this method could be called
17330.6 -> so you could have something
like this method
17333.013 -> and you could call it directly
using the interface name.
17336.1 -> So we have this so now
17338.2 -> within shape utility
you could wreck akahl,
17341.5 -> like as you could see here,
17343 -> you could call the static method
17344.6 -> directly by the name
of the interface.
17346.9 -> You cannot have
normal methods within it
17350 -> unless it's a default
one interface features
17352.311 -> four different jdk version.
17353.9 -> So interface has evolved
throughout the versions
17356.9 -> of JD case.
17357.7 -> So just to brief on that.
17359.4 -> We have jdk 121 .7
17362 -> having normal interfaces
with constant static variables
17366.1 -> as we said the variables
17367.511 -> that you would have in a The
freezer typically constants
17370.5 -> which is public static final
and with abstract methods,
17374 -> of course in Java 8 it evolved
and we have a default method
17378.8 -> as I said,
17379.6 -> there would be
one default method
17381.482 -> which would be inherited by
all the interfaces extending
17384.6 -> that interface and you have
static methods as well,
17387.807 -> which was not there earlier
in Java 9 and later versions.
17391.7 -> So in Industry right now,
17393.746 -> it's mostly Java 8
that's been used across
17396.844 -> very few have gone to Java
9 all the big data Frameworks
17401 -> and everything we have
is supporting Java it
17403.9 -> at this point.
17404.878 -> So with the latest version
17406.761 -> that's Java 9 and above we
have static constant static
17410.6 -> variables abstract methods
default method static methods
17415.1 -> and they have come up
with this two methods
17417.253 -> which are nothing
but private methods
17419.1 -> and private static method,
17420.484 -> which was not there earlier.
17422.018 -> Now you could have
this things as well.
17424.1 -> It makes very little sense to
have all this scope variables,
17427.57 -> but maybe they might Have
17428.92 -> or something as
a part of evolution,
17430.979 -> but at this point,
17432.064 -> I believe since this private
methods cannot be called
17435.195 -> from outside it just
17436.425 -> that you have control
over the default method.
17439.186 -> So basically maybe
17440.292 -> if you have a big
logic to be written
17442.476 -> within your default method
17444.136 -> just to modularize
it just to break it
17446.5 -> into multiple methods not to
have one monolith big function
17450.348 -> or big method you could have
this private methods.
17453.6 -> That's what I can think.
17455.1 -> What is the package we have been
using package since day one.
17458.961 -> So package is nothing
but it's a namespace
17461.6 -> it's for avoiding Collision.
17463.9 -> So basically I could write
a name class with name shape
17468 -> and maybe someone else
17469.495 -> within my team would
write the same thing.
17471.999 -> Right?
17472.36 -> So basically at the end
when we archive it together
17475.495 -> like we have a jar file,
17476.991 -> which is Java archive
17478.3 -> when we archive this files
together there is going
17480.814 -> to be named Collision, right?
17482.311 -> You wouldn't know
which shape class.
17484.179 -> Are you referring to?
17485.3 -> So basically namespace
is nothing but it adds.
17488.356 -> Stewart and it avoids
Collision classes
17490.936 -> in the same package can access
each other's members.
17494.4 -> So basically you can have
within a package.
17497.5 -> So we'll talk about
the import statements
17499.572 -> that will give you
a clearer understanding
17501.814 -> of what we are talking about.
17503.4 -> But basically within a package
as you could see here,
17506.4 -> we have not done anything
to refer any of these classes.
17509.815 -> So it's within a package
we have calmed said Eureka
17513 -> and we have all these classes
within this package
17516.1 -> so you could see that employ
or maybe manager
17519.3 -> which is a different class
in the same package.
17521.814 -> We are accessing it directly.
17523.4 -> We are not doing anything
different for it.
17525.5 -> But when you want to access it
17527 -> from a different package you
have to do something else
17529.4 -> which is nothing
but importing the package
17531.8 -> the normal living convention
is usually domain name here.
17535.44 -> You could see we
wenshan calm down at Eureka.
17538.411 -> So it's usually something
17540.1 -> of that sort dorji dot
example dot hyphenated name.
17543.6 -> It has to be lower
case usually written
17545.9 -> in lower case companies
use their reversed.
17548.488 -> Net domain name to begin
their package names.
17551.2 -> So basically if you have
my package or example.com,
17555.15 -> you would have it
in reverse order.
17557.4 -> This is typically a one of
the best practices of practices
17560.5 -> that's been followed
across industry to define
17563 -> the package but it
doesn't have any constraints
17565.801 -> from the Java side
17566.835 -> as such you could do anything.
17568.682 -> So for example,
17569.564 -> if I make it uppercase,
so basically it's saying
17572.529 -> that it's not showing error
because of its in uppercase,
17575.769 -> but basically you don't have
a directory starting
17578.576 -> with uppercase Aspire Java
or from the Java side.
17581.4 -> You don't have any constraints.
17582.9 -> For example, I could do
17584.2 -> something like So basically it
does convert it into lower case,
17589.3 -> even if you give uppercase.
17591 -> I don't know whether this is
a feature in IntelliJ IDE,
17594.176 -> or it is of course it has
to do something with the ID
17597.319 -> because Heidi is converting it
into lower case as
17600.213 -> far as the Java naming
convention is concerned.
17602.919 -> This is what we do
17604.048 -> but it doesn't have constraint
Java predefined packages.
17607.5 -> So Java itself
has many packages.
17610.1 -> So you could imagine
the entire language been written
17612.7 -> in Java source code.
17614 -> So basically all this you
would find in the source code
17617.333 -> when we refer to the string
17619 -> when we refer
to string string is a class
17621.615 -> which resides in Java dot Lang.
17623.642 -> There is Java dot language is
nothing but Java dot language.
17627.5 -> So string is something
17629.1 -> that resides in Java dot
Lang object is a class
17632.236 -> which is a super class
for all the classes.
17635.1 -> So, you know,
what super classes are
17637.388 -> after we went through
the inheritance thing.
17640.2 -> So you have super class
and you have subclasses.
17643.579 -> So the superclass All
the classes no matter
17646.6 -> what class you use with in Java.
17648.79 -> All the classes are inherited
from a class called object.
17652.6 -> There is a class object
17654.09 -> in Java from which all
the classes have inherited
17657.257 -> from our all the class inherit
17658.8 -> from this particular
class thread is used
17661 -> for multi-threading.
17662 -> Java dot length of thread
17663.5 -> is used for multi-threading
multi-threading is nothing
17666.442 -> but 2 lightweight processes in
order to leverage the potential
17669.6 -> of your processors.
17670.782 -> So if you have multi-core,
17672.4 -> then you could have
multiple operations happening
17675.035 -> at the same instance of time.
17676.62 -> That's what thread is all
17677.994 -> for you make it faster
you have exception class
17680.899 -> you have system class
Java dot language system.
17683.8 -> This package is used to achieve
the language functionality
17686.65 -> such as conversion
17687.5 -> of data from string
17688.677 -> to fundamental data display
the output on the console
17691.9 -> and many more the package
is quoted by default.
17694.8 -> So you don't have to
specifically explicitly import.
17697.8 -> This particular package is
17699.414 -> by default voted into
your application Java dot util.
17702.537 -> This is like utility classes
you have Elections
17705.554 -> and stuff like that
into your Java dot
17707.8 -> util this package is used
for developing quality
17710.765 -> or reliable applications
in Java or J2
17713.1 -> ee this package contains
various classes and interfaces
17717 -> which improves the performance
of j2me application.
17720.294 -> So basically these
are utility classes.
17722.8 -> It does something
in terms of performance
17725.152 -> or does some conversions
or something of that sort.
17728.094 -> Java dot IO is a package
which contains something
17730.629 -> like file input stream
file output stream
17733 -> and stuff like that,
17734 -> which is basically
17735.142 -> for interacting with
your files with your I/O.
17738 -> So basically if you want to load
something into your memory,
17740.602 -> if you want to read
something from your file
17742.5 -> or write something go file
in your local directory,
17745 -> you would use something
like Java dot IO package
17748.1 -> if you want to do some kind of
socket networking or some kind
17751.965 -> of network programming
you would use java.net
17755.099 -> which has something
like socket datagrampacket
17758.076 -> datagram socket Etc.
17759.4 -> We have applet tablet is
nothing but application
17762.249 -> that gets loaded
into your browser.
17764.359 -> It's not you.
17765.133 -> So as of now earlier
it is to be used
17767.251 -> but now there are a lot
of other technologies
17769.7 -> that have come up
but this is something
17771.917 -> like an applet is a Java program
17773.8 -> which runs in the context of
w WR world wide web for browser.
17777.9 -> You have Java dot e WT
which is like event-driven
17781.285 -> like you could
have UI applications.
17783.7 -> If you click on your checkbox
17785.6 -> or button there
would be even triggered
17787.8 -> and you would have
an event handler handling it
17790.2 -> if you click on a mouse
17791.298 -> or something you would have
a even triggered.
17793.4 -> So basically all these classes
are grouped into this package,
17796.7 -> which is Java dot AWD
17798.398 -> so you could see
the Java dot w dot even
17801.398 -> which has like Mouse listener.
17803.7 -> This is specific to event
without this classes.
17807.022 -> It is impossible to handle
17808.9 -> events generated by
G UI components.
17811.8 -> So as far as the front end
17814.1 -> is concerned as
far as all this a WTF
17816.5 -> that is concerned.
17817.718 -> It's not in use basically.
17819.412 -> Java is much more useful
in terms of back and program
17822.8 -> which means you take data
and Do something with your data
17826.41 -> and stuff like that,
17827.7 -> but it's not well suited
for UI applications
17831.4 -> and it's not used to that extent
in Market or industry.
17835.2 -> You have Java dot SQL
17836.813 -> which is nothing
but your database related stuff.
17840.5 -> So we want to connect
17841.862 -> to your post gray or if you
want to connect to Oracle.
17845.3 -> You have all the stuff
written in Java dot SQL.
17848.5 -> So mostly in Java data skill,
17850.175 -> you have interfaces
and this interfaces
17852.411 -> as I said,
17853.017 -> it's nothing but specifications
17854.9 -> and this specifications are
implemented by database vendors.
17858.75 -> So it's nothing
but interface is just
17861.1 -> an abstract method it would have
like four five abstract methods
17865 -> within so all
this concrete implementation.
17867.753 -> Someone will have two women
to use this interfaces
17870.837 -> or someone will have a class
17872.6 -> which will implement
this interface has and we
17875.3 -> as developers can
use those classes
17877.3 -> to interact with databases.
17879.3 -> So Wenders like Oracle will have
its own set of implementation
17884.2 -> to the Patients
17885.4 -> that are mentioned
in Java dot SQL
17887.893 -> as I said most of the thing
in Java dot SQL or interfaces.
17892.2 -> So about the access modifier.
17894.096 -> We have spoken earlier.
17895.593 -> We have public we have protected
private and default modifier
17899.5 -> public is nothing but
it could be accessed
17901.6 -> from anywhere within
your application.
17903.807 -> So you could have your methods
as public you could have
17906.512 -> your class as public
17907.688 -> you could have your instance
variables as public
17910.234 -> which means that particular
method could be accessed
17913.054 -> from anywhere within
your application.
17915.1 -> You could have protected
modifier protected modifier is
17918.276 -> nothing but your subclass
is can access it
17920.7 -> and your current package
whatever the package
17923.488 -> in which a particular method
17925.184 -> or particular class resides in
which you have protected method.
17929 -> You could access it
from that class
17931.2 -> or any class from
that particular package access
17934.191 -> the protected methods defined
within a class that package
17937.7 -> so I will give you an example
17939.534 -> since we have spoken
about inheritance now,
17942.238 -> so I will give you a demo
on protected private.
17945.2 -> Modifier is basically
it's private.
17947.5 -> It's within a class.
17948.7 -> You cannot access
it from outside.
17950.368 -> If you try to access it,
17951.499 -> you would get a compile
time error saying
17953.5 -> that it's not visible default
modifier is package is public
17957.8 -> within package So within package
any class can access it.
17961.712 -> So basically it's
17962.9 -> like protected right
protected can be accessed
17966.025 -> within the package
plus it has like
17968.219 -> if a sub classes are
outside the package,
17970.9 -> even though subclasses
can access it
17972.859 -> whereas in default.
17974.062 -> It's just within the package.
17975.9 -> So protected has wider scope
then default modifier.
17979.574 -> This is kind of public so public
has almost like everything so
17983.953 -> why didn't scope then comes
protected then comes default
17987.9 -> and then comes private so access
modifiers public word Republic.
17991.855 -> So when you have
17992.811 -> Public Access modifier
within a class in this case,
17995.8 -> you have two packages.
17996.962 -> Are you Ricardo back one
17998.23 -> and a new record out back to
and you have some public members
18001.6 -> within your class one,
18002.7 -> which we can see here
that all this public.
18005.19 -> Members could be accessed
by Class 2 class 3,
18007.807 -> which is there in the same
package as class 1 that is
18010.866 -> at Eureka dot Pack 1.
18012.174 -> So now there are two classes
in a do record back
18014.938 -> to one is a class
18015.922 -> which doesn't have
any relationship with glass
18018.569 -> one but still it
can access it though.
18020.597 -> It's there in
a different package.
18022.5 -> But still it can access
the public members of class one.
18025.9 -> You can see class for which
is a child of last one
18029.9 -> since it extends class one,
18031.7 -> but it's there
in a different package
18033.961 -> but still it can access
the public members of class 1 so
18037.3 -> protected protected is nothing
18039.1 -> but it could be accessed
within the package in which
18042.1 -> the class is defined and it
could be accessed by members
18045.614 -> that are outside the package but
child of that particular class.
18049.5 -> So in this case we can see
18051.1 -> that there are few protected
members in class one
18053.938 -> which could be accessed
by Class 2 and class 3
18056.6 -> since they are in the same
package as class 1 plus 3
18059.982 -> and class two are defined
in Eddie cannot pack 1
18063.1 -> we have class 5 Is not related
18065.7 -> to class 1 which means
it's not a subclass
18068.8 -> or it doesn't have
18070.018 -> any relationship with class
1 in that case class
18073.2 -> 5 cannot access any protected
members within class 1.
18076.8 -> So here we have class for which
extends class 1 which is nothing
18081 -> but plus 4 is a subclass
of class 1 which is there
18084.6 -> in a different package
at your record back
18087.273 -> to but it can access
the protected members
18089.693 -> of class one
18090.4 -> since it is there
in a different package
18092.585 -> private member is nothing
but it can be accessed just
18095.5 -> within the class
in which it is Define.
18097.9 -> So in this case you could see
that this is private members.
18101.6 -> So you have class one
which has got private members
18104.7 -> and you can see
that class to contacts
18106.896 -> is it class three contacts?
18108.5 -> Is it either class 4 or
plus 5 no one can access it.
18112.001 -> It's just that class
one can access private members.
18115.481 -> So we have seen this in examples
18117.61 -> that we took in session
one default package.
18120.4 -> So default package is nothing
18122.2 -> but only within the package
in which it is defined.
18125.1 -> It so in this case
you have class one
18127.72 -> which has got default members
with default scope
18131.047 -> and you can see that class 2
and class 3 can access it
18134.8 -> but not class 4 and Class
5 since they are
18137.533 -> out of this package
18138.8 -> since Class 2 and class 3 are
defined in the same package
18141.5 -> as class 1 that is
a deal-breaker DOT back one.
18143.875 -> That's the reason you
could access from there.
18146.2 -> This is same for
attribute or method.
18148.7 -> There's a table here,
18149.949 -> which is summarizing whatever
we discussed so far you
18153.007 -> have modified public.
18154.167 -> So yeah, it's within the class.
18155.813 -> Yes.
18156.052 -> It's within the package.
18157.427 -> Yes, if it's
within the subclass.
18159.309 -> Yes and within the world days
18161.093 -> so everywhere it
could be accessed right?
18163.638 -> That's why you have public
protected is within the class.
18167.3 -> Yes, within packages
within subclass.
18170.099 -> Yes, but not within world.
18172.06 -> So just within
package and subclass,
18174.7 -> but if you have
18175.553 -> different package or
if you have different package,
18178.4 -> but it's not a subclass.
18179.6 -> Then you can't access it.
18181 -> No modifier,
18181.7 -> which is a default scope
within the classes
18184.3 -> within the Yes,
18185.242 -> but we saw
18185.838 -> that it cannot be accessed
within the subclass
18188.623 -> if the subclass is
in a different package
18191.1 -> when we save world world
is nothing but any package
18194.324 -> and they are not related in
this case the previous example
18197.973 -> that we should saw
last five is something
18200.622 -> that could be thought of as laws
that are unrelated.
18204 -> But reside in a different
package private is just
18207.2 -> within the class you can see
18208.9 -> that it's not with package
within the package.
18211.3 -> It's not within the subclass.
18212.822 -> It's not within the world.
18214.2 -> So I think we have spoken
18215.7 -> about private public
and default scope earlier.
18218.806 -> Let's start off with protected.
18220.9 -> So in the meanwhile
when it starts,
18223 -> let's talk about this.
18224.4 -> So here we can see package demo
18226.443 -> which shows public it
has got a public method
18229.198 -> that is message.
18230.2 -> There are three ways to access
the package from outside.
18233.004 -> So let me talk about
how we actually recorded.
18235.318 -> So there are three ways to
access the package from outside.
18238.3 -> The package one is
with import this case
18241.2 -> like you had a direct a 1
and enter a car to right there.
18245 -> Sample that we saw earlier.
18247 -> I do record Pack 1 and add
18248.544 -> you taken right back to these
are the two packages you have
18252 -> if you want to access
something you want to access
18255.1 -> class 3 from class 5 you
would have to import
18258.9 -> a new record Pac-12 class 3,
18261.5 -> since it is outside the package
18263.691 -> of back one if it's
within the package so far
18266.8 -> the examples that we
were taking was all
18269.094 -> within the same package,
18270.337 -> so we didn't have
to import it now.
18272.1 -> I will just show you an example
wherein you would have something
18275.3 -> that is outside the package
and I will show you
18278.2 -> how to access it.
18279.236 -> So we have to import it.
18280.7 -> So whenever you have it
in different package,
18283 -> then you have to input
that particular package
18285.4 -> within one thing is importing
the entire package.
18288.496 -> The other one is importing
a particular class.
18291.4 -> So in this case you
have a package demo,
18293.708 -> and we can see
that within package demo.
18296.006 -> There's a pack demo,
18297.186 -> which is nothing but a class
defined within it.
18300 -> So, let's see
18301 -> how to access package
from another package
18304.1 -> you have a Demo here
18305.9 -> that's a class that is defined
within the package demo
18309.017 -> as you could see here.
18310.5 -> There is one method
which is MSG and
18313.1 -> which is taking two parameters
as input TJ Ryan integer J.
18316.6 -> So what are the ways
18317.76 -> in which you could access
this particular class
18320.588 -> that is packed demo
from outside the package.
18323.4 -> So the first thing
18324.566 -> that you could do
is you could import
18326.908 -> the entire package itself.
18328.6 -> So demo dot star
or demo dot asterisk
18331 -> as you could see here,
18332.408 -> which says that all the classes
within this particular package
18336.43 -> can be accessed
from this particular class.
18339.2 -> So you have a package
demo class defined here,
18342.9 -> which says import demo dot star
18345.4 -> and which would input everything
all the classes within demo.
18349 -> So in this case back
the more you could see
18351.7 -> that pack demo class
could be accessed
18354.129 -> from within package demo class
18356.1 -> that's there in
different package.
18358.2 -> So basically this
package demo class
18360.533 -> that you see here is defined
18362.428 -> in some other package
other thing is See
18365.174 -> if you want to import
just a class
18367.498 -> and not the entire package.
18369.4 -> You could do that thing as well.
18371 -> So here what we are doing is
import demo dot pack demo.
18374.823 -> So we are importing
a specific class
18377.3 -> and not the entire package
that could be done as well.
18380.5 -> And the third one is
instead of importing you
18383.4 -> can do one thing you can have
fully qualified path name
18386.714 -> or fully qualified name
like demo dot pack demo.
18389.659 -> That's your class name.
18391.062 -> You can access it
within your class.
18393.2 -> So basically you would use
the fully qualified name
18396 -> who might use it.
18397.3 -> You did not do it,
18398.6 -> but you might use it in case
where you're just using it once
18402.277 -> within your class,
18403.4 -> but you would go with
this options demo dot pack demo
18407.169 -> or demo dot star in which you
class has multiple is referring
18411.539 -> to the class in different
package multiple times.
18414.928 -> So in that case,
18416.119 -> you just do it once
and could be used
18418.706 -> within your class.
18420 -> You need not do it
again and again,
18422.4 -> so I create a new class
18424.169 -> which is Calm down
at Eureka new DOT.
18431.6 -> So I created a new package.
18433.6 -> So there is one
that is calm down Eddie Rekha,
18436.286 -> and the other one
18437.3 -> that is calm dot ed
u de canoe this are
18439.535 -> different packages you have
18441.1 -> if you want to use something
within this package
18443.7 -> Comdata Rekha suppose I want
to use Vehicles, right?
18447.5 -> So this is what I
was talking about.
18449.9 -> When you try to access it.
18451.6 -> You can't do it you
can access vehicle from here
18454.4 -> because it's there
in a different package.
18456.617 -> Now you are not able
to access it
18458.5 -> because you haven't imported it.
18460.7 -> So what I do here is
import calm dot Ed u--
18464.4 -> Rica dot vehicle
18466.6 -> once I do this I am able
to access it now.
18469.6 -> Now what I was saying is
18471.239 -> if you are accessing multiple
classes from multiple classes
18475.206 -> within the package
18476.44 -> like car also you
18477.566 -> are accessing so instead
of writing it like this.
18480.871 -> So what you would do is calm
18482.8 -> down at Eureka the car now
the compilation error has gone.
18487.5 -> So basically instead of doing
this like instead of writing.
18491.54 -> Multiple times the other option
18493.7 -> that we have is like calm down
at Eureka dot star.
18499.1 -> So now if I get rid
18500.676 -> of this 2 inputs
still it would work.
18503.7 -> I don't need these two inputs
18505.4 -> because we have putted all
the classes within the package.
18508.9 -> So it's able to access
both the classes vehicles
18512.1 -> and Ed Eureka from
calm dotted Eureka.
18514.8 -> The other one was you
18516.4 -> could get rid of this now
it's showing up error.
18520 -> What you could do is calm
down Eureka dot vehicle.
18524.2 -> You could access it directly
with the fully qualified name
18527.7 -> so you can see
the error has gone.
18529.4 -> So these are the three ways
in which you could access
18531.8 -> different packages
18532.9 -> or access classes
from different packages.
18535.4 -> Now, let's understand.
18536.569 -> What is the regular expression
18538.146 -> so regular expression pretty
much similar to other languages
18541.314 -> that you have regular expression
is nothing but an expression
18544.6 -> through which you
could extract some sequence
18547.1 -> of characters from your string
18549.037 -> or you could check
18550.222 -> whether a specific Fake
regular expression or
18553.035 -> whether a string is aligned to
a particular regular expression.
18557 -> So you could Define
a regular expression saying
18559.2 -> that if for example email ID,
18561.113 -> right one of the use cases
of regular Expressions could be
18564.774 -> like you have email IDs and you
might have seen on websites
18568.5 -> where in you do some kind
of registration or something
18571.7 -> and if you don't give
a proper syntactic 1 then
18574.6 -> what it would do is it
would give you an error
18577.26 -> at the red gmail.com.
18578.553 -> If you don't give
18579.6 -> that it would throw
you an error showing
18582.005 -> that it's not proper.
18583.345 -> So it's not checking
against the Gmail server to see
18586.6 -> whether your email ID
is proper or not.
18589.218 -> So it is just
checking syntactically.
18591.708 -> You might have seen it.
18593.264 -> So if you give a wrong
syntactic email ID and
18596.366 -> if you go to the next tab,
18598.2 -> if you tap to the next
column or to the next space
18601.9 -> what it would show is you
haven't entered it correctly.
18605.5 -> So basically what it's doing
18606.9 -> is its checking it
against a regular expression.
18609.4 -> It has got a regular expression
saying that This is
18611.9 -> how an email ID
could be it should end
18614.8 -> with so-and-so characters.
18616.7 -> It should be at the rate.
18618.1 -> It should have at the rate.
18619.549 -> It should have Gmail
18620.725 -> or it should have
some characters in between then
18623.4 -> add followed by.com
or something of that sort.
18626.248 -> So basically to have
18627.456 -> this syntactic this thing
done just to ensure
18630.11 -> that you have given it properly
you have a regular expression.
18633.999 -> So yeah, one of the use cases
could be to have this pattern
18637.1 -> Checker usually to see
18638.6 -> if you're giving value
18639.7 -> which aligns to
what is expected.
18641.798 -> So maybe other thing could be
18643.7 -> if you're typing something or
18645.33 -> if you have been asked
to put some amount
18647.683 -> and if you type characters
18649.285 -> there it would give
you an error saying
18651.52 -> that it's not allowed those type
18653.4 -> of checks could be done
through regular expression or
18656.032 -> if you want some value to start
18657.549 -> with a particular character and
end with a particular character.
18660.7 -> You can check it
against a regular expression
18663 -> regular expression is
a pattern used for searching
18665.5 -> and manipulating strings.
18666.917 -> It could be used for
manipulating strings as well.
18669.8 -> So one of the use cases is Ching
18671.823 -> and the other one
is for manipulating
18674.1 -> the regular expression
either matches the text
18677.334 -> or fields to match.
18678.726 -> So basically it
would validate and say
18681.436 -> whether it's a match
or it's feeling
18683.9 -> so we call regular
expression as Rex which is
18686.1 -> nothing but abbreviation
for regular expression.
18689.4 -> So Java supports
regular expression,
18691.772 -> and these are the pluses
18693.4 -> that we have with in Java, which
is in Java dot util package.
18698 -> So remember we spoke
about Java dot util package
18700.8 -> which has got utility classes.
18702.9 -> So these are among them.
18704.935 -> So here you can see
a pattern class you
18707.958 -> have mature class
18709.3 -> and you have patterns
in tax and tax exception.
18712.6 -> So basically if you
have some exception
18715 -> if it's not proper,
18716.171 -> then you would get
some exception as well.
18718.7 -> So we would be taking an example
clarify what this is all about.
18722.7 -> So here are some
matching patterns used
18724.805 -> in regular expression.
18726.1 -> So it just about
to read through it.
18729.3 -> So you have like ABC It
means it has to exactly
18733.1 -> match ABC if the string
18735 -> that you are matching it
against has the content
18738.1 -> ABC it would match
18739.5 -> when you put it
into square bracket,
18741.4 -> which is any letter a b
or c should match any character.
18746.1 -> And again if there's a negation
if within the square bracket,
18749.548 -> if you have this negation Mark,
18751.288 -> which says that any character
except these three characters
18754.7 -> should be matched.
18755.9 -> So if you put D it
will match the second case
18759.4 -> if you put a or b
18760.723 -> or c it will match and here
it would be from D to Z.
18764.8 -> If you put anything it
will match not just alphabets.
18768.4 -> It could be anything
any character A to Z.
18771.639 -> So when you say A to Z,
18773.4 -> it says that we are giving
a sequence of it, right?
18777.06 -> So we are saying from a
it's a range basically
18780.6 -> so it understands range as well.
18783 -> So when you say a -
18784.7 -> Z which means that it is from A
to Z here we are saying that
18789.238 -> any one letter or digit.
18791.3 -> Ben sequence so basically
you could have uppercase
18794.888 -> and lowercase as well.
18796.5 -> Basically it is saying
it should be in sequence.
18798.952 -> It should end with basically
18800.709 -> digit at the N dot is some kind
of a wild-card character saying
18804.6 -> that any one character
18806.249 -> except line Terminator
must be in sequence.
18809.4 -> This one indicates
beginning of line.
18812.4 -> So we say that line
should begin with so
18814.858 -> and so you could put
some character here
18817.274 -> and we can say
18818.11 -> that if a line begins when Sue
18819.805 -> and Sue character sequence
or whatever regular expression
18823.3 -> that we have put in then
the entire line matches.
18826.6 -> The other one is end
of the line with check
18829.4 -> if any character present
18830.8 -> at the end of the line
other thing is word boundary.
18833.939 -> We have an example about this
18835.726 -> so which would give you
a clear idea about it,
18838.5 -> but it's more about it
cannot be part of a word here
18841.93 -> when we put slash B to the front
and the end or to the start
18845.9 -> and the end of a particular
character sequence,
18848.5 -> which means that it has
to be separate word, but it
18851.6 -> I'd be part of some other
word /b to verify
18854.884 -> that any character is
18856.464 -> not present at the word
boundary /g to check
18859.7 -> that the character is present
18861.646 -> at the end of the previous
match metacharacters.
18864.8 -> So we have /t instead
of writing 029.
18867.9 -> You could use metacharacters.
18869.7 -> /d to define DJ
18871.5 -> when you want to Define
on digit which is
18874.2 -> like you can see here
negation of 029 set,
18877.049 -> which is non digit
18878.3 -> which could be like
alphabets peace or anything
18880.9 -> which could be grouped as /t /
s is a whitespace character
18887.3 -> who space tabs and stuff
like that could be enter
18890.7 -> for that matter
is whitespace character
18893 -> /s is a non whitespace character
18895.372 -> which means the actual character
rather than white space /
18899.6 -> W is a word character
and / uppercase
18903.2 -> W is a non word character
you have quantifiers,
18906.761 -> which is a quantifier defines
how often an element can occur.
18912 -> So star, which means
18914.4 -> that zero or more times
plus which means
18917.533 -> that it has to occur one or more
times question mark is it
18922 -> could be no or just one time you
could mention the number
18925.4 -> of times you want
a particular sequence to occur,
18928.2 -> which could be put
into your curly braces
18930.8 -> occurs X number of times x
18932.8 -> you could put a range
18934.267 -> within within your curly
braces X comma Y which means
18937.9 -> that it should occur
somewhere between X and Y.
18941.1 -> So it's a range you have
asterisk question mark
18944.7 -> it tries to find
the smallest match.
18947.3 -> This makes the
regular expression stop
18949.4 -> at the first match.
18950.6 -> So as and when it finds
the first match it would stop
18954.015 -> so we will have a quick demo
on regular expression.
18957.3 -> So here before we start off
we Define a pattern here.
18960.9 -> Basically, then you could see it
is basically saying from A to Z
18965.099 -> and followed by character
18966.697 -> one or more character
then we have a check here,
18970 -> which is nothing
but a string again.
18971.755 -> Which we are going
to check first.
18973.405 -> We compile the pattern.
18974.513 -> This is a regular
expression pattern
18976.2 -> that you have you're going
to check against.
18978.35 -> So the first thing
18979.366 -> that we have to do is we have
to compile this pattern to see
18982.7 -> if it's properly done or not.
18984.6 -> So first thing is to compile it
against patent and
18987.7 -> if it's correct up to the mark
you would get the instance
18991.2 -> if it's wrong then
there would be some kind
18993.6 -> of exception thrown then
there is a matcher.
18996.1 -> So once you have the pattern
you do pattern matcher
18999.381 -> and you provide the string
against which you want to check
19003 -> in this case you have
19004.3 -> happy learning welcome
to Eddie break is the string
19006.9 -> that spin past and
when you do see dot find
19009.506 -> if this is fine,
19010.5 -> it would return the result true
19012.2 -> and if you remember the while
construct it would get in only
19015.8 -> if this is true,
19016.987 -> so it's a loop
19018 -> so it would basically
I trait through
19020.5 -> and you could see here
19022.014 -> that it's displaying
all the characters.
19024.753 -> I'll quickly run this.
19026.5 -> Let's name the class has
pattern Checker now,
19029.596 -> I write a main method
now if Remember,
19032.4 -> we had a pattern there
19034.3 -> which was like a to z
followed by actress.
19037.8 -> Then we have string
against which you want to check
19041.646 -> or you could say
simple string to check.
19044.876 -> So we just put this one.
19046.9 -> So once you have
this string to check now,
19049.4 -> what we want to do is we want to
compile this particular pattern.
19054 -> So what we do patten.com pile,
19056.6 -> so one thing to see here is
that's the beauty of using
19060.9 -> the IntelliJ or Eclipse.
19063.4 -> So you could see here.
19065.1 -> This package is already
been imported when you use it.
19068.548 -> Unless you have multiple classes
with name patterns,
19071.976 -> it would ask you
to specifically explicitly
19074.732 -> mention which one you opt for.
19076.7 -> But in this case there was
just one pattern class.
19079.8 -> So it imported it automatically
then we give the pattern here.
19083.9 -> So basically if this
pattern is correct,
19086.6 -> if it's rightly formed
syntactically you would get
19090.24 -> a pattern here or so.
19091.8 -> Pat and I believe we have
a compiled pattern now now
19095.583 -> what we do is we take
this compile pattern
19098.513 -> and I think we
have matured here.
19100.8 -> We get the matcher.
19102.1 -> No so matcher would
check again string.
19105.4 -> So you have a string to check
which would give you matcher.
19109.7 -> So here it's asking me
19111.246 -> which mature do I want
I'll select this one
19114.4 -> and you see this one getting
in put it here.
19117.2 -> So this is what we have done.
19118.65 -> We have compiled the pattern and
we have provided the argument
19121.9 -> against which we have
to check as a part of nature.
19125.117 -> We get the instance of matcher.
19127.016 -> So everything is
in terms of class.
19129.1 -> This is what object oriented
programming is all about.
19132.008 -> You have a pattern
which is a class.
19134.067 -> You have a method
19135.067 -> within pattern which is
compiling your pattern.
19137.652 -> So this is what object oriented
programming is all about.
19140.8 -> Everything is realized in terms
of classes and objects.
19144.6 -> This is nothing but the object
of pattern class company.
19148.4 -> So now what I do
is matcher Dot Find
19152.623 -> I just print this one
match her dot check.
19156.1 -> So basically what we
are trying to do here is once
19159.5 -> the entire string passes
19161 -> through we are trying to get
the substring out of it.
19164.1 -> So when we get
the substring from matcher,
19166.9 -> you would get the string indexes
begin index and you would get
19171.7 -> matched end as well.
19173.225 -> So when we run it,
you should get a PP y
19176.2 -> n so the first character
would be trimmed off
19179.4 -> so you could see first character
being trained of each line.
19183.3 -> So I'm putting
regular expression.
19185.551 -> We saw that Java dot util
don't reg ex gets imported.
19189.1 -> Then you have patent then
you have string to be checked
19192.417 -> against the pattern
and the sentence
19194.638 -> which is to be matched are given
A 2 Z means any character from A
19198.68 -> to Z and plus means one or more
the sentence check is checked
19202.914 -> whether it matches the pattern
or not the strings
19205.901 -> from the sentence which match
the pattern are printed.
19209.2 -> So basically here we could see
19211.352 -> that Echizen uppercase and we
don't have uppercase here.
19215.3 -> So that's the reason I dreamed
of the first character.
19218.9 -> So basically if I add H hear
you now eh would match as well
19223.221 -> and it won't cream H
or it won't remove edge.
19226.5 -> You should be able
to see H as well.
19228.6 -> So yeah,
19229.4 -> as you could see here
you have H appearing as
19232.7 -> with previous case.
19233.966 -> It was getting primed
of so this one is
19236.5 -> for the word boundary.
19237.798 -> As I said,
if you want to have something
19240.092 -> like you want to be sure
it's a separate word
19242.458 -> and it's not a part
19243.48 -> of any word you could put
something like this.
19246 -> So basically what we
can do here is
19249.6 -> so we can mention here something
like special are we
19253.523 -> and then in so
19254.8 -> what we are trying to do
here is you could see here.
19258.5 -> What we are saying is
we want to separate word
19261.5 -> as in we don't want it to be
a part of any other word.
19265 -> So here in learning
do you have iin?
19267.8 -> It didn't pass it
because it's word boundary
19270.8 -> whereas Just a
separate word here.
19273.2 -> It just passed this one.
19274.9 -> So if and I remove this one
you could have seen two ions.
19279.8 -> That's what I mean to say.
19281.366 -> So now what's exception
exception handling is nothing
19284.8 -> but typically so here
you could see two ions
19288.3 -> when it's / / be it
would be just the ones
19291.6 -> that are complete word instead
of matching the word boundary.
19295 -> Let's talk about
what are exceptions
19297.029 -> and exception is an event
19298.589 -> which occurs during
the execution of a program
19301.4 -> that disrupts the normal flow
of the program instruction.
19305.166 -> So to give you
an example yesterday,
19307.643 -> we spoke about arrays,
19309.2 -> right if array size is 5
19311.6 -> and if you try to access
something more than four like
19315.5 -> if array size is 5 which means
19317.7 -> that the index is
range from 0 to 4,
19320.7 -> if you try to access
something more than four like
19323.5 -> if you try to access
Sixth Element within the array
19326.5 -> it would give you an error
saying array index out of bounds
19330.328 -> or if a particular Their object
is assigned null value.
19333.779 -> And if you're trying
to access that method
19336.4 -> within that particular object,
19338.141 -> you would get
null pointer exception
19340.2 -> since it's not
instantiated as yet
19342.6 -> when you instantiate it that's
when the object gets created.
19346.3 -> But if your reference
is pointing to null
19348.611 -> and if you're trying to access
something within that reference
19352.253 -> or a class you would get
null pointer exception
19355 -> similarly you have like / 0
and stuff like that.
19358.357 -> It's basically something
that is not expected
19361.5 -> or something that would
disrupt the normal flow
19364.7 -> of program execution.
19366.17 -> When an exception occurs the jvm
creates an exception object
19370.3 -> to identify the type
of the exception
19372.611 -> that has occurred.
19373.8 -> So basically within itself,
19375.675 -> it would create it
or the gold would create it
19378.9 -> so I can create my own
custom exception tomorrow.
19381.8 -> If I am writing an application
usually in applications.
19385.146 -> That's how we do.
19386.2 -> We write our own
custom exceptions.
19388.4 -> I can Define my own exception as
19390.685 -> well if My application
something is not working
19394.084 -> or something is not running
19396.051 -> as I would expect it
to I would throw an exception
19399.517 -> so that within my application
it properly logs
19402.8 -> or it properly prints out
in my console saying
19405.5 -> that this is the exception
19407.029 -> that's been triggered
due to so-and-so condition.
19409.7 -> So an exception is often
referred to as runtime error.
19413.12 -> So here we can see divide
by zero exception as an example.
19416.8 -> Now there are different types
of exceptions first one being
19419.903 -> checked exception the other one
being unchecked exception
19422.9 -> and the third one being error.
19424.7 -> So checked exception is
something that happens
19427.429 -> in the compile time.
19428.694 -> What happens is when you have
a checked exception when you
19432.3 -> are invoking some method,
19433.913 -> which is throwing
a checked exception and okay.
19436.774 -> I don't want to get
into the catch block
19439.2 -> as yet because we
haven't covered it.
19441.4 -> So this is also called
as compile-time exception.
19444.4 -> It means if a method is throwing
a checked exception then it
19448.141 -> should handle the exception
using the try Clash block.
19451.5 -> It should declare the exception
using throws keyword.
19454.6 -> Otherwise, the program will give
19456.482 -> a compilation error whenever
there's a checked exception
19459.6 -> that's been thrown out
thrown out in the sense
19462.2 -> not at the runtime.
19463.387 -> There could be methods
which is throwing an exception.
19466.7 -> So whenever there is a checked
exception you have to ensure
19470.5 -> when you give a call to
that particular method say
19473.526 -> there is a method X
19474.7 -> which is throwing
some checked exception
19476.785 -> which is throwing some checked
exception from your application.
19480.1 -> You are trying to
access this method X
19482.4 -> when you try to access
this method X you have to ensure
19486.158 -> that you are taking care
of the checked exception
19489.478 -> that is thrown from X.
19491 -> If you don't take care of it,
19492.829 -> it would give you
a compilation error
19495.1 -> when I say when you
don't take care of it.
19497.7 -> How do you take
care of exception?
19499.7 -> That would be the first question
19501.176 -> that would have come
to your mind.
19502.7 -> So when I say you have
to take care is nothing
19505.539 -> but you have to catch it.
19507.129 -> You have to
handle that exception.
19509.223 -> So try and catch is a mechanism
19511.184 -> through Which you
handle the exception.
19513.679 -> So what you would do is
Method call or the call
19516.8 -> to X you would put
it into a try block
19519.7 -> and the catch block.
19521.2 -> You would say that
19522.498 -> if this particular
exception occurs execute
19525.524 -> this block of code,
19526.888 -> that is a Handler
for exception X
19529.144 -> or checked exception
that is thrown from method X.
19532.6 -> So basically you write a Handler
for in the catch block saying
19536.6 -> that this is what I want to do
when this exception occurs.
19539.8 -> Once you have that
when your program runs even
19542.734 -> if the exception occurs,
19544.23 -> it won't stop
at that point it would go
19546.6 -> and check whatever is written
and whatever piece of code
19549.935 -> that you have written
and it can continue from there
19552.893 -> on it's basically a decision
made by the developer
19555.776 -> whether to carry from their own
19557.396 -> or whether you want to break
it there whenever there's
19560.284 -> a checked exception
you have to ensure
19562.4 -> that you handle it
19563.471 -> either handle it or you say
19565.022 -> that I'm not going
to handle this.
19567.019 -> I am just going to throw
this off from my method
19569.963 -> or throw this off from the Well,
19571.924 -> I'm executing this method
X method X which we spoke
19574.988 -> about which is throwing
checked exception.
19577.5 -> I can choose not to handle it
and just to throw it off
19580.827 -> to the calling program wherever
the execution initiated from.
19584.45 -> So if you don't do that,
19585.9 -> you would get a compilation
error unchecked exception
19588.958 -> unlike checked exception.
19590.429 -> It's not mandatory
19591.489 -> that you catch
it's not mandatory
19593.43 -> that you handle it.
19594.548 -> So runtime exception basically
it could occur any time
19597.694 -> and it's not mandatory
19599 -> that you go
and actually handle it.
19601.029 -> So even if you don't handle
it jvm would be okay with it
19604.1 -> and it won't give you
compile time error.
19606.452 -> So basically these are nothing
19608.1 -> but runtime exception
so divide by 0
19611 -> that we spoke about his nothing
19612.788 -> but a runtime exception
it's not mandatory
19615.474 -> that you go and actually,
19616.976 -> you know handle it
during the compile time.
19619.5 -> You can either handle it
or you can leave it
19621.825 -> as is and during the runtime
you would get an exception.
19624.8 -> So compiler doesn't check
for the unchecked exception.
19628 -> It's done at the
runtime now error.
19630.379 -> These are Conditions that are
external to the application
19634.462 -> and that application
usually cannot anticipate
19637.563 -> or recover from it.
19638.995 -> For example,
19639.9 -> if stack Overflow occurs
and error will arise
19643.5 -> they are also ignored
during the time of compilation.
19647.2 -> So even the error condition
cannot be anticipated
19650.2 -> during the compilation time.
19652.048 -> It's done during runtime.
19653.649 -> Right?
19654.019 -> So one of the classic example is
the stack Overflow,
19657.241 -> we're in see for example,
19658.812 -> you call the same methods
19660.381 -> like thousand times not
thousand time is too less
19663.279 -> for the stack to get overflowed.
19665.327 -> But suppose you call it
19666.8 -> like million times you call
same method right in that case.
19670.9 -> Remember when I said
19671.9 -> when you give a call
to the method it goes
19674.229 -> to the call stack, right?
19675.789 -> We have a call stack.
19677.1 -> So it would push something
it would push state of class
19681.7 -> or it would push the properties
19683.806 -> that's been passed as
19685.175 -> an argument the class or to
the method to the stack.
19688.5 -> I treatable if you call it
like million times,
19691 -> what would -
you would get stack Overflow
19693.4 -> because basically everything
would get into the stack and it
19697.1 -> would basically, you know,
19698.7 -> give you a memory
or float or even memory
19701.2 -> for the Heap memory
for that matter
19703.2 -> if you create lot of classes
19704.727 -> if you create a lot
of instances of classes,
19707 -> you are Heap memory
would get overflowed
19709.309 -> and you would get
out of memory error.
19711.6 -> Those are classic
examples of error.
19714.2 -> So what the hierarchy
of exception in Java
19717.3 -> when it comes to classes
you have a stable interface
19720.922 -> and then you have error
19722.511 -> and you have exception.
19724.1 -> So exception is further.
19726.1 -> It has got runtime exception.
19728 -> The other ones are
the checked exceptions.
19730.5 -> So ioexception SQL exception.
19732.8 -> These are the checked exception.
19734.746 -> This has to be handled
19736.041 -> if there's a method
which is throwing one
19738.394 -> of these checked exceptions.
19739.9 -> You have to ensure
19741.2 -> that when you give a call to
such methods you handle it
19744.569 -> or you throw it from your method
19746.611 -> to the right side
its runtime exception,
19749.095 -> so it need not be handled
as I said.
19751.354 -> Divide by zero and stuff
like that would be
19754.16 -> runtime exception even
array index out of bounds
19757.3 -> and Class cast exception
arithmetic exception.
19760.5 -> Then you have
null pointer exception
19762.687 -> that we spoke
19763.5 -> about all these exceptions
are unchecked exception
19766.9 -> and you need not actually handle
it during compilation time.
19771.165 -> So why to use exceptions
19772.9 -> when we execute a given program
will get an exception exception
19776.789 -> handling is performed
in order to get the output.
19779.8 -> So basically,
19780.7 -> why do we handle
exception is nothing
19782.9 -> but to get the program going
rather than breaking it
19785.9 -> at that point use
19787.083 -> of exception handling
process exceptions
19790.1 -> from program components handle
exceptions in a uniform manner
19795.4 -> in large projects.
19797.1 -> So basically, why do we do it?
19799.176 -> So it's done basically
19800.7 -> to get the process going rather
than stopping it at that point
19804.47 -> and you could handle
it the way you want
19806.927 -> to that 's the reason
you have this exception
19809.761 -> handlers give you a simple.
19811.5 -> Example suppose 29 by zero
19815.4 -> what I am trying
to print here result
19817.7 -> after dividing 29 by zero.
19819.6 -> So basically when you run this,
19821.298 -> it's not showing up
any compile time error.
19823.6 -> It's compiling fine.
19824.9 -> Now when I run it
19826 -> since it's a runtime exception
it's compiling fine.
19828.6 -> But when I run it,
19829.72 -> let's see if it
throws an exception.
19831.875 -> So as you could see here it
throws arithmetic exception
19835.264 -> which is divided by 0
and this is happening
19837.795 -> at the runtime.
19838.7 -> That's why it's
a runtime exception
19840.7 -> or unchecked exception
19842.166 -> when a runtime exception
occurs program gets crashed
19845.566 -> and control comes
out of the program
19847.9 -> as we saw here when we ran it.
19849.9 -> It didn't run this part of it.
19851.853 -> You could see
19852.7 -> that it broke out
just right from here.
19855.2 -> So whenever there
is an exception
19857.3 -> if you haven't handled it
program control would come out
19860.261 -> from there exception handling
is done to execute the program
19863.478 -> without getting an exception.
19865.184 -> So handling is done basically
to handle the exception
19868.2 -> whenever the exception
occurs do some action it.
19871.4 -> It's flexibility to
the developer to handle
19874.571 -> it the way they want to and get
it going mainly try catch
19878.8 -> and finally our keywords
for exception handling.
19882.6 -> So we have a trike at as I said,
19884.753 -> there's a try block
19885.981 -> where in all the suspicious one
or wherever the exception
19889.6 -> you think that there
could be exception occurring
19892.423 -> could put it into a trike block
and in the catch block,
19895.5 -> you would say that if
a particular exception occurs,
19898.1 -> this is what I want to do.
19899.5 -> All right, that's
the catch block.
19901.259 -> The finally block is nothing
19902.83 -> but no matter the exception
is thrown or not.
19905.211 -> A finally block is going
to execute at the end.
19907.7 -> So basically finally
block is usually used
19910.375 -> to release resources,
19911.719 -> right when you
deal with databases
19913.789 -> and stuff you create
connections against database
19916.8 -> or you create some socket
connections and stuff like that.
19919.7 -> When you do some socket
programming finally
19922.1 -> would be a place
19923.041 -> where in once the execution
of the method is done
19925.864 -> or execution of something
is done you say
19928.2 -> that we can release these
resources of rather than Still
19931.4 -> establishing the connection,
19932.8 -> right which picks up some
of your resources CPU resources
19936.394 -> or which takes up memory.
19938 -> So basically it's to release of
the memory exception handling.
19942.4 -> So let's talk about try try
block is nothing but code
19945.47 -> that could generate
so suspicious could
19947.676 -> as I said that could generate
an error is written
19950.5 -> into the try block.
19951.796 -> So the cache block could be
19953.607 -> more about catching
a specific exception
19956.178 -> and doing something with it.
19957.958 -> So you could opt
out to just break
19960.094 -> at that point or do something
19961.9 -> with it say for example want
to profile an application
19965.2 -> or you want to have
some instrumentation set
19967.7 -> for the application to see
19969.433 -> how much time
19970.3 -> what are the exceptions
that occurring during runtime,
19972.8 -> right if you want to see
19974 -> that may be a typical way
19976 -> in which it is done is
you write all this exceptions
19979.6 -> into a database
19980.9 -> and we're in later could apply
some analytics to see you know,
19984.6 -> what kind of Errors
have occurred in the application
19987.319 -> you could see
that later on so that
19989.319 -> one of those cases
19990.378 -> where a new Let Whenever there
is a particular exception you
19993.477 -> put it into a database you make
an entry in the database saying
19996.766 -> that this is the exception
19998.258 -> that was caught
in so-and-so time.
20000.2 -> And you could later on
have some analytics to see
20003.2 -> how it could be improved
20004.4 -> how the application
could be improved.
20006.5 -> So finally block is nothing
but with a successful
20008.9 -> or unsuccessful the block
is going to get executed
20011.6 -> as I said,
20012.1 -> this is nothing but mostly
it's used to release
20015.206 -> resources such as connections
and stuff like that.
20018.608 -> Let's see a demo of
20019.982 -> how we can handle exceptions
to give you an example
20023.8 -> of try catch us with this was
this is a suspicious code
20027.6 -> which we are running.
20028.823 -> Maybe you could put this in
to try catch block and save
20031.911 -> and there is any kind
of arithmetic exception
20034.5 -> that occurs just
20036 -> printing It Out Printing
any kind of rhythmatic.
20040.7 -> So what we are doing
here is nothing
20043.141 -> but we are catching exception
20045.1 -> and we are printing it
20046.643 -> so everything is
in terms of classes
20049.1 -> again see exception itself.
20051.124 -> A class so you could click
on it control click
20054.5 -> and you could see it as a class.
20056.459 -> This is source code
for arithmetic exception.
20059.2 -> So you could see extends
runtime exception which means
20062.472 -> arithmetic expression is
a runtime exception.
20065.33 -> So it's a subclass
20066.499 -> of runtime exception
you could see super
20069.052 -> and everything being used here
whatever we discussed about.
20072.7 -> So arithmetic exception is
nothing but it's a Constructor
20076.129 -> right and you could see
super been called here.
20078.839 -> So that's how you could get
20080.403 -> into exception and you could
read through it to understand
20083.441 -> how the source code
is being written
20085.5 -> that would give you a good idea
20087.3 -> about how flexible Java
is it's very much
20090.096 -> when it comes to flexibility
20092.092 -> and when it comes
to object-oriented Paradigm,
20095.3 -> it's very much
cleanly followed code
20098.1 -> so you could go
20099.1 -> and actually see at the the way
the programs are being written.
20102.4 -> If you remember
20103.2 -> when you'd we did 29
by 0 the program bro,
20106.038 -> it came right from there
20107.636 -> and it didn't execute
the following code.
20110.3 -> Now we have Handled it.
20111.8 -> We are saying that
20112.7 -> whenever there is
an arithmetic expression
20115.403 -> in this piece of code.
20116.76 -> That's here.
20117.5 -> We are saying that
20118.415 -> whenever there is
an arithmetic exception.
20120.5 -> We are going to just print it
and we are going to continue it.
20123.5 -> Don't stop at that point.
20124.897 -> So you could see here
20126.105 -> the program didn't break right
it give you an opportunity
20129.4 -> for you to actually
handle it and it
20131.53 -> didn't break it continued.
20133.178 -> So you could see this statements
been executed as well.
20136.6 -> That's why you
have this results.
20138.7 -> So we had printed here.
20140.4 -> So as a part of handling
exception handling,
20143.3 -> what we did is we just printed
out saying that what kind
20146.762 -> of exception had occurred.
20148.4 -> So exception dot get message
20150.367 -> that gave like divide
by zero this divided by 0
20153.6 -> that you see here is nothing
20155.36 -> but is printed out
by this message.
20157.5 -> So it give you an opportunity
20159.291 -> to handle it and get
the program running
20161.7 -> as is so try
catch finally block.
20164.6 -> Basically.
20165.1 -> What I can do here is
20167.5 -> let me Define integer
denominator is equal to So
20171.9 -> as I said finally block
is going to execute no matter
20175.738 -> of pot is going to get executed.
20178.1 -> So I just print the message
here saying I will say here.
20183.361 -> I'll put denominator
20184.9 -> when the denominator is
0 we would get exception
20187.909 -> and it would come
to the exception block here
20190.858 -> or the catch block here
20192.343 -> and it would print it
20193.7 -> and then it would come
to the finally block.
20196.2 -> So let me run this and see so
as you could see here,
20199.7 -> it came to the exception Handler
it caught arithmetic expression
20204.102 -> that is divided by 0
and then we printed out saying
20207.2 -> that printing the typical
message or the actual exception
20211.1 -> that we got and it came
to the finally block here.
20214.5 -> Let me put a scenario
20215.771 -> which is not going to throw
exception in this case.
20218.8 -> My denominator is 1
20220.2 -> which means 29 by one we
shouldn't throw any exception.
20224.1 -> So what I want to show
is still it would execute
20226.9 -> the finally block
20228.033 -> so you could see here
29 been printed out
20230.7 -> which this got executed
successfully this time
20233.159 -> because the denominator is not
20234.8 -> 0 it's one it got successfully
executed still the finally block
20239.6 -> is been executed why to use
multiple Catch blocks
20243.1 -> so you could have
multiple exceptions
20245.577 -> and you could write
multiple catch blocks.
20248.4 -> There are different exceptions
that we spoke about it could be
20251.605 -> like a pointer exception as well
which you want to handle right?
20254.871 -> So it depends
20255.491 -> upon your program logic or
what you are trying to do here.
20258.441 -> So there could be null pointer
exception then you have finally
20261.6 -> so you have multiple
catch blocks here.
20264.1 -> So you usually don't handle
null pointer exception
20267.4 -> but this is just
to give you an example.
20269.694 -> So basically you have
this arithmetic exception
20272.4 -> here been handled then you
have null pointer exception
20275.46 -> being handled here
20276.5 -> then you have finally so
20278 -> if you want to have different
exceptions to be handled
20280.776 -> within your application,
20282.036 -> you could have multiple
cache blocks since all
20284.446 -> the exceptions are derived
from exception catch exception.
20287.5 -> He should be placed at the end.
20289.3 -> So basically if you put
the exception this exception,
20292.6 -> right if you
remember the hierarchy
20294.517 -> that we spoke about all
the exceptions are derived
20297.6 -> out of exception class
20299.2 -> so you could have
something of this sort.
20302.1 -> So if it is
20302.9 -> not an arithmetic expression
not a null pointer exception
20306.1 -> then is of course going
to be some kind of exception
20309.03 -> which is going to be handled
in this exception block.
20312.089 -> So basically we are catching
all the exceptions
20314.6 -> here first is specific
to edit mattock exception.
20317.668 -> The second one is
null pointer exception
20320.127 -> if it's not a null
pointer exception
20322.411 -> or arithmetic exception then
this particular cache block
20325.926 -> is bound to get executed
20327.45 -> and it has to be last
you cannot place it first
20330.321 -> because if you place it first
this two blocks exception
20333.809 -> Handler blocks will
never get executed
20336.2 -> because even this two
exceptions are a subtype
20339.369 -> of exception class itself.
20341.2 -> So it has to be it is mandatory
that you place it at the end
20344.691 -> or else it would be be
compiled time exception
20347.457 -> so you could have something
like array index
20350.1 -> out of bounds and stuff.
20351.8 -> So just to give you
this is integer array.
20355.3 -> I put one two three
I Define an array now
20359.5 -> I say integer array
of Three elements right
20363.2 -> and if I try to access
or just choose so
20366.212 -> when there are three elements
the index ranges from 0 to 2.
20371.1 -> So now I put three here.
20373.2 -> So this is generic exception
Handler for all the exceptions.
20377.6 -> We would have this Handler
when you run it.
20380.1 -> This is going to give you
a rain dicks out of bound
20382.7 -> because you are trying
to access element
20385 -> at index 3 which doesn't exist.
20387.2 -> So you would see
a generic exception
20389.892 -> and so it came here.
20391.8 -> What I was trying to say is
20393.5 -> so you could have arraigned X
Out of bound here, right?
20396.676 -> So instead of null
pointer exception now,
20399.169 -> I have arranged index
out of bounds now,
20401.6 -> it would be handled
by this block
20403.6 -> and it wouldn't come to
the generic exception Handler.
20406.4 -> So here you saw it came to
the generic exception Handler.
20409.6 -> Now what you would
get is array index
20411.9 -> out of bounds exception Handler
20413.8 -> because it's been handled by
this particular cache block
20417.1 -> and not the last catch block.
20418.9 -> So this one is
20419.8 -> as you go down
it becomes generate.
20421.8 -> So here you could see
it's been handled by array index
20424.611 -> out of bounds exception
as you go down.
20426.688 -> It becomes generic more.
20428.1 -> Generally it is
multiple catch block.
20430.517 -> So this is pretty much similar.
20432.6 -> We have re we have
arithmetic exception
20435.6 -> that occurred array
has four elements 023
20439.1 -> and you are trying
to access the 10th element.
20441.4 -> That's when you would get array
index out of bounds exception
20444.4 -> as we saw there could
be nested try the rain.
20449 -> You could have try
and inside try.
20451.318 -> So basically when you
have prai inside try
20454.2 -> if there's an exception
that occurs in the nested one
20457.8 -> or the innermost one,
20459.283 -> it would try to see
if there's a catch Handler
20462.432 -> for that particular
exception innermost one.
20465.37 -> If it doesn't find then
it goes to the outer one.
20468.6 -> So in many cases it may happen
20470.5 -> that a part of the block
may cause an error
20473.1 -> and the entire block
may cause another such cases.
20476.409 -> You're going s to try block.
20478.3 -> So what I was trying to say
is you have this one.
20482 -> We have one more like exception
or shouldn't be done.
20485.7 -> So you have a nested one within
this try you have one more wire.
20489.018 -> This thing with says array index
which is handling
20491.901 -> null pointer exception sending
just the null pointer exception.
20495.4 -> It's not handling
array index out of bounds.
20498.148 -> So what I was trying to say is
if such scenario occurs,
20501.508 -> it would check the innermost one
20503.5 -> if it finds
the exception Handler,
20505.5 -> it would execute it.
20506.5 -> If it doesn't find then it
would come to the outer one.
20509.4 -> So basically though this try
doesn't have Handler
20512.819 -> for arraigned X Out of pound
still it would be taken care of
20517 -> so you can see here.
20518 -> It came to the outer one.
20519.9 -> So if you would have some piece
of code right after this,
20524.053 -> it won't get executed.
20525.745 -> So this piece of this code
will not execute
20528.976 -> if inner try so basically
20531 -> if there's a reception
which occurs in the inner block
20533.993 -> and if it's not handled it
would come to the outer block
20537.1 -> but this piece of code whatever
you have in between this catch
20540.717 -> and this catch would At x
20542.243 -> equal to Y to use throw keyword
the Java through keyword
20545.6 -> is used to explicitly
to throw an exception
20548.359 -> while executing the program.
20550.2 -> So if you want to throw
something as I said,
20552.349 -> you could create
your own custom exception and
20554.6 -> if you want to throw something
you could throw it out you
20557.2 -> could throw an exception
from your program.
20559.699 -> It can be used to throw checked
or unchecked exception any kind
20563.5 -> of exception could be thrown
using throws up using through
20567 -> and the Java through keyword
is used inside a method
20570.493 -> so you could see here.
20572 -> Basically if B is equal
to 0 you throw new exception /
20576.569 -> 0 causes an exception.
20578.4 -> So before it goes to actually
dividing it by a by B,
20583 -> you are kind of handling it
prior to that you are checking
20586.1 -> whether denominator is 0
if the denominator is 0
20589.2 -> you're throwing Exception
by yourself, you are creating
20591.8 -> a new exception.
20592.659 -> This is kind
of your own exception,
20594.559 -> right you are you're creating
your own exception and saying
20597.8 -> that it's divided by 0
so for any condition
20601.036 -> so basically Denominator
is equal to equal
20604 -> to 0 you could throw it from
you're saying or denominator.
20608.3 -> So basically if I keep
this denominator has zero
20611.5 -> and this should be prior
to this just cut this
20614.8 -> and this should be done prior
20616.633 -> to this event to use throws
throw this something as I said,
20620.3 -> when you have
a checked exception,
20622 -> you can either handle
it using prai catch
20624.6 -> or you have to throw it
out of the method saying
20627.364 -> that I am not going to handle
20629.1 -> this let the collar
handle it you could do
20631.58 -> that using throws keyword.
20633.15 -> The method is not taking
the responsibility to handle
20636.415 -> a checked exception and it is,
20638.3 -> you know, asking the collar
20640.187 -> of the method to
actually handle it.
20642.542 -> This is in terms
of just checked exception
20645.3 -> when you have
a checked exception.
20647.176 -> So basically since you're
throwing it from there,
20650.2 -> but since you have Handler
here is coming to this
20654 -> so you have this denominator you
through an exception from here,
20658.064 -> but this exception
is been handled here,
20660.58 -> so it came here saying
That generic exception Handler.
20664 -> All right.
20664.5 -> So if I remove this
20665.8 -> that's the reason you have
generic exception Handler here.
20669.1 -> So I remove this Handler
I'm not going to handle
20671.9 -> exceptions whenever you
throw an exception.
20674.881 -> It has to be handled
20676.232 -> since exception is
a checked exception.
20678.8 -> So basically you could
have run time exception
20681.6 -> which need not be handled.
20683.244 -> So basically the Handler
that you see here,
20685.9 -> we just have two handlers
20687.37 -> which is for arithmetic
exception and array index
20690.056 -> out of bounds exception,
20691.4 -> but we don't have a Handler
for runtime exception.
20694.8 -> So that's the reason
it gave you an error
20697.3 -> saying denominator is 0 so,
20699.1 -> this is an exception that we
through here using throws.
20702.4 -> So it's giving you
an error right here
20704.441 -> because this is
a checked exception.
20706.394 -> The exception itself is
is a checked exception.
20709.105 -> Now, you could either handle it
20710.939 -> like the way we
had handled it here.
20713.033 -> You could write catch exception
and you could handle the way
20716.704 -> you want to so you
have two options now
20719.008 -> when you get into this scenario
into this situation,
20722.1 -> You have two ways to handle
it either right exception
20725.803 -> and handle it.
20726.8 -> This would be a Handler.
20728.2 -> If you see the compilation error
has gone or this is one thing
20731.7 -> that you could do
or the other thing
20733.6 -> that you could do is you
could ask this method
20737.012 -> this method can say
I'm not going to handle it.
20740.5 -> I'm going to throw it
for my collar to handle it.
20743.9 -> So the main method is saying
I am not going to handle it.
20747.506 -> I'm just throwing it off
from my side from my code
20750.718 -> or the caller to handle it.
20752.416 -> So see the exception has
again the error has gone.
20755.5 -> So basically Whenever there
is a checked exception
20757.768 -> you have to option
20758.633 -> and this is happening
at the compile time,
20760.683 -> by the way,
so you have to ensure
20762.4 -> that you either handle it
or you throw it throw
20764.817 -> in the sense throws
its through throws me anything
20767.7 -> that I am not going to handle
this at the collar handle him
20770.7 -> as you could see
20771.735 -> the throws keyword was added
in the method signature.
20775.1 -> We saw how we Throw exception.
20777.159 -> We throw exception
from here you check
20779.7 -> for some condition
you throw exception
20781.7 -> from Why uvu's throws throw is
basically to throw an exception
20786.3 -> and a method saying
20787.6 -> that I am not going
to handle the exception.
20790.004 -> So what's the difference
between through and throws
20792.8 -> the throw keyword is used to
explicitly throw an exception.
20795.7 -> The throws keyword is used
to declare an exception.
20798.9 -> The through keyword
is followed by an instance.
20802.176 -> The throws keyword is followed
by throwable class.
20805.686 -> Alright, so here you
could see this is throws
20808.699 -> keyword is actually
20810 -> by instance you create
an instance of exception.
20812.8 -> Whereas throws is the class
20814.432 -> itself through keyword
is used within a method
20817.154 -> and throws keyword is used
with the method signature.
20820.3 -> So you could see through
is used within a method
20823.581 -> within the method body
20825.054 -> and you could see throws
at the signature level.
20828.441 -> So you have throws
20829.694 -> and throw so throw is nothing
but whenever you want to check
20833.8 -> whether there is an exception
and you want to throw it out
20836.6 -> you want to actually
trigger the exception that's
20839.2 -> when you would right through
and you would This exception.
20842.3 -> So basically here we
are checking for a condition
20844.7 -> if denominator is equal to zero,
20846.3 -> which is potentially
20847.3 -> which would cause error
further down the line.
20850.455 -> So we are checking
it up front saying
20852.9 -> that if the denominator is 0
20854.69 -> then we are not passing it
further write in such scenarios.
20858.4 -> We could throw
the exception right away.
20860.7 -> That's how you figure
the exception from the program
20863.898 -> Rose is nothing but it's
at the signature level
20866.767 -> of the method
20867.577 -> that you could see
20868.7 -> and what you mention
out by throws this
20872 -> that main is saying here
20873.4 -> that I'm not going
to handle the exception
20875.507 -> and just going to throw it off.
20877.1 -> So this are unchecked
exceptions, by the way.
20879.7 -> So whatever is not
been handled here
20882 -> if there's some exception
handled here it would get
20884.5 -> to the exception Handler
or the catch block.
20887 -> But if there is something
20888.2 -> that is not been handled
here would be thrown
20890.4 -> out of this main method
main method won't handle it.
20893.4 -> That's the reason
why we have throws
20895.733 -> through keyword is used
within the method
20898.4 -> and throws keyword is used
with the method signature.
20902 -> Through keyword can throw
only one exception
20905.262 -> whereas throws keyword
can be used to declare
20908.57 -> multiple exception.
20910 -> Basically, you could have
20911.5 -> something like this one
exception say ioexception
20914.8 -> so you could have
multiple exceptions here.
20917.247 -> So the main is saying I'm
not going to handle ioexception.
20920.642 -> I'm not going to handle
exception or something of that
20923.8 -> so you could have
multiple exceptions after throws
20927.2 -> user-defined exceptions.
20929 -> You can create your own
exception and it is called
20931.629 -> as user-defined exception
20933.1 -> or custom exceptions
user-defined exception class
20937.133 -> can be created by creating a
class child class of exception.
20941.6 -> So basically create exception.
20943.907 -> I create a clasp
which is SE custom exception.
20947.369 -> Now, this custom exception
is extending exception
20951.1 -> so you could have
your own classes defined
20953.9 -> and it would have like this.
20956.1 -> So what you exception
20957.455 -> you get you go you could pass
that exception directly here.
20961.2 -> So this is See,
20962.171 -> what I'm trying to do here
is overloading of Constructor.
20965.8 -> So you could see
if you are passing string.
20968.288 -> It would come to this.
20969.588 -> If you are passing exception
to come to this Constructor.
20973.2 -> So you could create
your own exception here.
20976.093 -> So basically to give you example
of this instead of exception.
20980.2 -> What I throw is I can have
a new custom exception.
20984.2 -> So initially I
was throwing exception.
20986.364 -> Now what I am saying is
new custom exception.
20989.022 -> This is the exception
that I have created.
20991.5 -> It's my own exception
when I run this now,
20994.464 -> you can see that it
should throw custom exception
20997.603 -> so you can see here exception
20999.524 -> in thread main thread main is
nothing but your main method
21003.3 -> where your program is executing
and it shows the exception type
21007.5 -> which is custom exception
which is created by me
21010.5 -> and I have passed the strings
in the denominator is 0
21013.8 -> and at what point
21014.9 -> or at which line this particular
exception occurred can see it
21018.6 -> in the stack trace.
21019.792 -> This is a stack Trace basically.
21021.8 -> Whatever you get here
21023.112 -> when an exception occurs
is nothing but stack Trace.
21027.1 -> So hi everyone,
21028.115 -> welcome to module number four
before I start off L.
21031.9 -> Just briefed on what we covered
in module number 3,
21035.1 -> so we covered on Hoops
Concepts in general.
21038.2 -> What are the Hoops Concepts
21039.665 -> what are different
concepts or terminologies
21042 -> that we have in oops?
21043.5 -> Then we saw how Java is aligned
to those Hoops Concepts
21047.4 -> how Java is known as
object oriented program,
21050.9 -> right or how Java
is aligned to object
21053.6 -> oriented programming Paradigm.
21055.8 -> Then we spoke
about abstract classes,
21058 -> which is a different
modifier all together,
21060.2 -> right and then we spoke about
a hundred percent abstraction,
21063.376 -> which is nothing but interface
which is a construct in Java
21066.5 -> which helps you
to specify something
21068.8 -> and you could have
different implementations as
21071.7 -> per the specifications
21073.2 -> then we spoke
about exception, right?
21075.8 -> What are different exceptions
21077.7 -> and why do we have
exceptions at all?
21080.1 -> And how do we catch exceptions
21082.2 -> or what is the need
to catch exception
21084.6 -> and what are different types
of exceptions right?
21087.1 -> Have like checked unchecked
exceptions checked exception has
21090.536 -> to be caught by your application
21092.4 -> or a particular method my top
to just throw it off rather than
21096.4 -> actually handling it through
the throws keyword, right?
21099.74 -> We touch base on regular
expression as well.
21102.4 -> And why do we need
regular expression and
21105.006 -> what are different classes
21106.7 -> that Java has to support
regular expression?
21110.3 -> Alright.
21110.7 -> So today we would be
covering file handling
21113.691 -> and Java Collections framework.
21115.9 -> All right.
21116.4 -> So file handling is nothing
21118 -> but you have external files
you might have something
21121.245 -> on your network
21122.2 -> or it could be
21122.9 -> on your local machine
itself and you want to access it
21125.938 -> and do something on it
21127.2 -> or you might want to have data
21128.98 -> that's been coming
to your program.
21130.923 -> You might want to
write it into a file
21133.1 -> so that you could kind
of analyze it later.
21135.637 -> I spoke about exception right?
21137.45 -> If you get an exception,
21138.9 -> you could write it into a file
21140.4 -> so that you could later
on go through it
21142.497 -> and understand at what time
a particular exception occurred
21145.7 -> and you could act upon it.
21147.2 -> It's a kind of profiling
21148.673 -> and instrumentation turn on
application to understand more
21152.3 -> on the behavior
of the application
21154.4 -> and to improvise on it.
21156.1 -> Such activities could be done
using file handling
21159.2 -> will talk about
Java Collections framework.
21161.68 -> Java Collections framework
is nothing but you have
21164.6 -> a re array list and everything.
21166.467 -> That is we spoke about arrays
in the previous topics.
21169.6 -> But Java Collections framework
itself exposes array list,
21173.17 -> which is a dynamic list.
21174.5 -> You don't have to manage it.
21175.9 -> So remember in list we said
21177.745 -> that when you take Claire a list
or declare an array,
21181.4 -> you have to mention
the size of it
21183.599 -> whereas array list is dynamic.
21185.6 -> You don't have to mention it.
21187.176 -> It keeps growing.
21188.2 -> So these are the topics
21189.4 -> that we are going to cover
file input output of operation
21192.2 -> in Java wrapper classes in Java.
21194.7 -> We are going to talk about
Java collection Frameworks.
21197.5 -> We are going to talk about list
and its classification in Java Q
21201.7 -> in Java and sets and
their classification in Java.
21205.2 -> So as you could relate all
this Action all this components
21208.6 -> within the collection
Frameworks are nothing
21210.7 -> but data structures in general.
21212.284 -> That's you straight.
21213.46 -> So maybe in see you might have
used different data structure
21216.5 -> and whereas in
different languages,
21218.135 -> you have different
data structures, right?
21220 -> This is just to handle
data data structures are nothing
21222.7 -> but to store data efficiently
21224.7 -> and you could select one
of them based on the use cases
21227.62 -> that you're handling
within your application.
21230.1 -> So let's start
with file I/O file
21232.4 -> I/ O is nothing
21233.308 -> but you have a file on your disk
and if you want to do something
21237.123 -> if you want to write to that or
21239 -> if you want to read
from that file,
21240.9 -> you would ideally
use file I/O API.
21243.8 -> All right.
21244.716 -> So file I/O is used
to process the input
21247.8 -> and produce output
for a specific file.
21250.5 -> All right, so you
could access some file
21252.7 -> within your local
disk do something
21254.8 -> and you can write it on
to a different file as well.
21258.3 -> Write Java dot IO package
21260.6 -> contains all the classes
required for input
21263.764 -> and output operation for a Phi.
21266.1 -> All right,
21266.9 -> so As we said package is nothing
but namespacing right?
21270.5 -> So everything is grouped.
21272.431 -> All the I/O classes are
all the classes in Java
21276 -> that is handling.
21277.3 -> IO is grouped into
Java dot IO package.
21280.3 -> Okay, that makes it easier
21281.995 -> for programmers to
understand as well.
21284.408 -> Right?
21284.8 -> So if you're doing a lot
of I/O operations,
21286.9 -> you could directly say
import Java dot IO dot star
21290.126 -> which would in put
all the classes
21292.3 -> within your Java dot IO package.
21294.6 -> All right, the files
can be text file or it
21297.823 -> could be binary file, right
21299.9 -> so you could imagine not always
you deal with a text file,
21303.971 -> right you have
other files as well.
21306.4 -> So nowadays.
21307.4 -> There's a lot
of things going on
21309.3 -> on iot right internet of things.
21311.4 -> So you get data
from different systems.
21313.8 -> It could be like
your mobile phones.
21315.8 -> It could be from the car sensors
or elsewhere, right?
21318.9 -> You have a real-time
raw information coming in
21321.919 -> into your system for analytics.
21324 -> So such data
cannot be a text file.
21326.8 -> Txt file as such is
a heavy file,
21329.3 -> right so such iot applications.
21331.7 -> What is been passed between
systems our intercommunication
21335.246 -> between systems is done
through a binary file,
21338.055 -> which is kind
of lightweight right
21340.028 -> compared to text file
txt files are heavier.
21342.7 -> So you could imagine this files
not being just the text file.
21345.8 -> It could be binary files and so
on when I say binary files,
21348.7 -> it could be it could be images
21350.7 -> as well write different images
21352.7 -> that could be shared
among system or some image
21356.2 -> that is there
on your local disk,
21357.8 -> which you want to read into Java
21359.4 -> and do something on it some kind
of graphical processing
21362.6 -> on it right stream is
a sequence of data.
21365.267 -> So you convert this file
21366.866 -> into a stream and you
use it with in Java.
21369.6 -> Okay, we'll look at example,
21371.5 -> which would give you a clear
idea of what I'm talking about.
21375.14 -> Okay, so here you
can see an example
21377.252 -> where in you have a file
21378.7 -> which is student dot txt
into your local system
21381.807 -> into your local disk
21383.1 -> where you are running
this program right then you
21386.2 -> have a pretty Traitor
21387.37 -> this is nothing
but a printwriter is a class
21389.93 -> that is exposed by Java
21391.341 -> which is there
21392.2 -> in Java dot IO package you
would pass on this file.
21395.387 -> So initially you have new file
21397.3 -> and you pass on
the path of this file
21399.393 -> that you are going
to read or do operations
21401.872 -> on not just read it could be
right operations as well.
21405 -> So basically you have new file
21407.158 -> and you specify the path name
or initialize the file.
21411.2 -> The next thing that you do is
you have printwriter wherein
21415.024 -> you pass this file.
21416.22 -> All right.
21417 -> Now what we are trying to do
here is we are trying to write
21420.7 -> into a Phi, right?
21421.915 -> We are trying to write the name
or the some ID or something.
21425.9 -> We're trying to write
this content into a Phi right
21429.5 -> into your local file
will write a program on this
21432.64 -> which would give you
a clear idea and the next step
21435.6 -> that we are doing here is kind
of we are reading it from a Phi.
21439.229 -> Alright.
21439.7 -> So the first step
21440.593 -> that you do is write it
into a file The Next Step
21443.278 -> that you do is read
from the same file
21445.294 -> and print the contents of it.
21447 -> All right, so it's not mandatory
21448.882 -> that you have to specify
the same file for reading right?
21452 -> This is for just
for the convenience
21453.944 -> or just to demo it.
21455 -> We are using the same
file you could have
21457 -> different file as well.
21458.3 -> All right, so let me show you
how this is done.
21462 -> So again, I create
a new project for today,
21464.9 -> which is All right,
21469.8 -> so we create a new
project and Eureka.
21475.9 -> module 4 Alright,
so we have this project now.
21483.158 -> Let's create a new class.
21486.1 -> Calm down daddy.
21486.9 -> Rekha is nothing
but the package name
21489.7 -> and I give up.
21495.2 -> input output demo Alright,
21498.1 -> so before we start off
I can do one thing.
21502.9 -> I can create a folder here.
21505.3 -> Say said, Eureka.
21509.8 -> All right, so we'll put
all the files here.
21512.5 -> So this is the empty folder
21514.3 -> that I have created right now
or let me put it here.
21520.5 -> So for Simplicity,
21521.837 -> I'm going to put it
on C drive itself.
21524.505 -> Alright, so on see have created
a director IO directory
21528.4 -> where in we are going
to dump all the files, right?
21530.819 -> Whatever we are going
to do is going to come
21532.9 -> into this particular directory.
21534.8 -> Alright.
21535.2 -> So the first thing
21536.2 -> that we are going to do is so
now we are thinking of writing
21540.251 -> into a file first right?
21541.9 -> So I create a main method right?
21544.361 -> The first thing
that I do is create a file.
21549 -> All right, and I
create a new file.
21552.3 -> Which is nothing,
21553.3 -> but I am calling the Constructor
of a class of the class file,
21556.661 -> which is with in Java.
21557.8 -> Right?
21558.3 -> It's not something
that we are writing.
21560.3 -> So Java itself has
this internal file class,
21563.317 -> which is file.
21564.357 -> All right.
21565.1 -> So now a point
to this particular directory.
21568.9 -> All right, calm down
Ed Eureka IO and we say
21576.4 -> so I call it
as employee info dot txt.
21579.7 -> Alright, so we are going
to write into this file now
21582.699 -> from java program.
21583.681 -> So now it's showing
up an error saying
21585.7 -> that which file I
want to refer to
21588.238 -> as we said the all
the I/O related files
21591.3 -> all the all the I/O
related classes are placed
21594.2 -> in Java dot IO package.
21595.9 -> So I select this package
21597.424 -> once selected you can see
an import statement here.
21601.4 -> Being up.
21601.9 -> So why do we
have input statement
21603.8 -> because file is a class
21606 -> which resides in a different
package then calm down
21609.152 -> Eureka had it been
within calm down Eureka.
21611.8 -> You need not import
it it's outside.
21614.396 -> So you have to put it right
21616.5 -> then there are different ways
in which you could write it,
21619.3 -> but now we'll follow
the same example.
21622.1 -> So I write
printwriter printwriter.
21625.2 -> Is there within Java dot IO
21627.3 -> and you could see
it imported here.
21629.9 -> All right employ
info writers if example,
21635.5 -> okay now we create
21636.811 -> a new printwriter and if you see
the Constructor of printwriter,
21641.4 -> so we spoke about Constructor
overloading and stuff like that.
21645.405 -> Right?
21645.8 -> So you could see
if you go into the source code.
21649.084 -> If you want to Deep dive
more you could go
21651.6 -> into the source code
and see it takes file.
21654.4 -> Alright, so here you
could see an option
21656.917 -> which is nothing
but it consumes file.
21659.305 -> So the file
which we created above.
21661.9 -> I can put it as
e employ info file.
21668.8 -> All right.
21669.523 -> So there's a file
that's created here.
21671.7 -> So I put the same
file here right
21674.7 -> since the Constructor
supports file itself.
21677.5 -> Now this is checked exception.
21679.541 -> All right, you could see here.
21681.493 -> It is saying Java
is explicitly saying
21683.947 -> that you are not
handling this exception.
21686.6 -> All right.
21687.3 -> So ideally the better practice
21689.1 -> is we shouldn't be writing
everything into the main
21691.771 -> because it would become
cumbersome to understand
21694.316 -> later on right you
shouldn't be dumping everything
21696.973 -> to the main method.
21698.07 -> So as a good practice,
21699.437 -> what you should do
is you should create
21701.8 -> a new method right to file.
21705.7 -> All right.
21706.404 -> So this is best
practices, right?
21708.6 -> It's not mandatory.
21709.8 -> Java is not going to tell you
there is an error or something.
21713.1 -> But as a part of best practices,
21715.2 -> this is how you
should write programs
21717.4 -> which would make
it readable for others
21719.5 -> because tomorrow some other
developer is going to handle
21722.1 -> this particular class.
21723.109 -> It's not that you
have going to be there
21724.9 -> throughout right so basically
21726.529 -> so that other developers
can easily read It
21729.042 -> and maintain it.
21730 -> Well, this is how we write it.
21732.6 -> I move this content.
21734.1 -> Whatever the writing part is.
21736.194 -> I move this content here.
21738.1 -> Alright, so now it's showing
up an error saying
21741.3 -> that it's not been handled
right file not found exception
21745.1 -> is not been handled because it's
a checked exception.
21748.6 -> So remember in the checked
exception we said
21751.14 -> that there are two options one
is to handle it
21753.8 -> within your method all
this right to file method
21756.851 -> can hop to throw it off saying
21758.8 -> that I am not going to handle
it let the caller handle it.
21761.9 -> So when I say caller caller is
nothing but this method alright,
21766.1 -> so I am going to create
say here input demo.
21771.934 -> Sam trading in instance here.
21774.2 -> Alright and demoed right to file
and I'm going to pass the file
21778.859 -> that we created here.
21780.3 -> All right, so there was one file
that we created here
21783.382 -> which is pointing
to an employee info Dot txt.
21786.873 -> And we are calling
this method to write it
21790.5 -> if you think about
the reusability part of it.
21793.5 -> So this is how you make
the method reusable.
21796.5 -> If you put it into Maine
you cannot reuse it.
21799.4 -> If you're taking the right logic
outside the main and refactoring
21802.7 -> and putting all the code
21803.9 -> that is specific to writing
to a file do particular method.
21808.1 -> You could reuse
this method you're making
21810.1 -> it generic right now.
21811.9 -> I opted to throw it off
or let's handle it.
21815.9 -> All right when I
say let's handle it.
21818.424 -> It's nothing but you
have try catch block.
21821.3 -> All right, so I say Catch
so what exception was that?
21826.1 -> It was filenotfoundexception.
21827.964 -> So you need to have
file already in place.
21831.1 -> Alright, so here I print saying
21833.8 -> that given file was not found
on the local disk.
21839.2 -> All right, and once that file
Maybe we can print the name
21844.057 -> of the file as well.
21847 -> Alright, so here we
have chosen to handle it.
21850.4 -> Okay, so we remove this.
21852.2 -> Alright, so we have
21853.6 -> a try catch block written now
and we say that Okay,
21859.5 -> so we are handling this error.
21861.8 -> So we say that it
just print a message saying
21864.9 -> that given file was not found
on the local disk.
21868.5 -> And as a good practice,
21869.9 -> I don't want
further processing right
21872.068 -> if I don't have a file I don't
want to process it further.
21875.7 -> So I say through
runtime exception
21879.2 -> and I so runtime exception
is unchecked exception.
21883 -> It won't give you error even
if you don't handle it,
21886.2 -> right whereas this was
a checked exception.
21888.81 -> That's why you
are getting error.
21890.8 -> Basically.
21891.372 -> What I'm doing is I'm catching
the checked exception
21894.372 -> and wrapping it
into unchecked exception.
21896.7 -> All right, because I don't want
this to be processed further.
21900.864 -> So once we have
this printwriter set,
21903.6 -> so I'll have to take
this print right outside
21905.8 -> or I'll get here.
21907.2 -> Alright, so what I do
is employ Dot println
21910.6 -> and I write some content
21912.4 -> to it and say in this case
I am writing vinod.
21920.1 -> I write some ID to it as well.
21924 -> Anything you could write.
21925.7 -> Okay one side right
into the file.
21928.588 -> I have to ensure
that I close the file.
21932.1 -> So basically you
could have finally block
21935.7 -> so you would do this.
21937.576 -> I'll have to take so this
21939.46 -> if this is within try
so it's not accessible
21942.8 -> within the finally block.
21944.6 -> So to make it accessible
21946.239 -> what you will have to do is
you'll have to take it outside.
21951.9 -> All right.
21952.4 -> So I Define it outside Dry block
21955.707 -> so that it gets
accessed in finally.
21958.4 -> Alright, so now
21959.553 -> what I do is employ
info dot writer Dot close
21963.4 -> I close it.
21964.2 -> So that's one of the use cases
of finally as I said,
21967.899 -> it's basically for
closing the resources.
21971.1 -> So this finally
would execute even
21973.8 -> if this doesn't throw
21975.14 -> or don't throw any exception
and it would get executed even
21979.141 -> if it throws an exception.
21981 -> All right, so
21982.1 -> that's what the use
of finally block is.
21985.2 -> So let me quickly run
this program to see I have
21988.6 -> to create a file here.
21992.7 -> If I create a text
file here Dot txt.
21996.9 -> All right before I create a file
21998.871 -> maybe I will I would want
to show you what happens
22001.89 -> if we don't have a file, right?
22004 -> So if you don't have
a file I run it
22006.515 -> so we don't have anything
in to see at Eureka
22009.9 -> I oh, all right.
22013.4 -> Basically, you're trying
to write into a file
22015.6 -> which doesn't exist at all.
22018.896 -> So it's building.
22021.392 -> And it's running now.
22024.3 -> Even if you don't have a file,
22026.29 -> it doesn't throw file
not found exception rather.
22029.475 -> It creates one on its own.
22031.2 -> So remember we
didn't have anything here.
22033.6 -> Now.
22033.8 -> Let's see the content
of this file.
22035.9 -> You could see whatever we rode
right the employee name
22039.3 -> and you could see
the employee ID,
22041.742 -> which is hundred.
22043.9 -> So whatever you wrote
here came into that file.
22046.846 -> All right.
22047.486 -> Now, let's write
a program to scan
22049.8 -> or read through this file.
22052.169 -> All right, so maybe I
can use the same file
22055.4 -> or I can use something
like All right.
22058.9 -> So I write something
like BMW cities howdy.
22063.8 -> All right, I I write
something like this.
22066.4 -> It's a vehicle info and say
22068.9 -> you have something
like let's keep it
22071.499 -> as is okay.
22072.3 -> So you have
vehicle info in here.
22076.1 -> So now we are writing
a program to read from a file.
22080.3 -> All right, so we pass on
the file parameter here.
22083.123 -> There are different ways
in which you can do.
22085.9 -> All right, so we create
scanner now scanner takes
22090.6 -> if you see instructor you
could see that scanner takes
22094.665 -> file as a parameter.
22096.2 -> All right.
22096.963 -> So I put scanner file again.
22099.1 -> It is saying
22099.865 -> that file not found
exception is to be handled.
22102.8 -> So in this case,
22103.935 -> you have to be sure
the file is present, right,
22107.6 -> since you are reading
the file the earlier case
22109.9 -> it was writing to the file
22111.2 -> which can create a file
22112.259 -> but reading to the file
you have to be sure
22114.359 -> that the file is present
22115.5 -> or else you would get
a file not found exception.
22119.1 -> So in this case,
I choose to throw the exception.
22123.6 -> The read file is saying
22125.133 -> that I don't want
to handle this exception i
22128 -> instead threw it off.
22129.401 -> All right, you
could see throws here.
22132.1 -> Okay.
22132.8 -> Now what we do is we read
lines from it, right?
22136.6 -> So we have like Okay,
22142.502 -> so we read line from it
and we just print it out.
22147.1 -> basically, you would have
something like So let
22152.3 -> me just print line read
from the input file, right?
22157.3 -> So this is nothing
22158.302 -> but we are just printing
whatever we read from there.
22161.4 -> Basically, this should have
something like it should Loop in
22165.2 -> until it's end of the file.
22169 -> Alright, so this is
22170.162 -> how you use the while loop
similar to what you do
22173.4 -> in C and C++ right till the end
22175.431 -> of the file till yo F character
22177.463 -> is encountered you kind of read
the Lines within the file.
22181.6 -> All right.
22182.095 -> So this is a method
22183.095 -> that we have written but we
haven't invoked this method yet.
22186.2 -> So I create file
22187.3 -> since it's a different file
we have to create
22190.2 -> a file vehicle info
is equal to new file.
22194.4 -> We give the path of it,
22196 -> which is nothing but a Eureka
IO vehicle info dot txt.
22202.1 -> All right, we
created a file here.
22205.199 -> Now, what we are going to do
is we are going to call
22208.3 -> read file on this file
22210.1 -> or vehicle info file
22212 -> and we should be able
to see the contents of it.
22214.9 -> All right.
22215.4 -> So now one thing here is
22217.031 -> since you have thrown
exception it's saying
22219.885 -> that exception has
to be handled here.
22222.315 -> All right, I can choose
to not handle the exception
22225.6 -> here as well and I am adding it
to the method signature.
22229.1 -> Sure, so main
would throw as well.
22231.2 -> So basically what
would happen is
22233.082 -> if you don't have a file
22234.287 -> which is being read your program
would stop at that point
22237.149 -> because you're not handling
it anywhere, right?
22239.5 -> You're just throwing
it off up the ladder.
22241.8 -> So basically at the end
22243.1 -> if you don't have a file
you're going to get
22245.4 -> an exception your program
is going to stop there.
22249.123 -> I run this file and
let's see what we get.
22254.4 -> All right, so you
could see BMW Mercedes
22257.4 -> and Audi being read out
from vehicle info.
22260.9 -> This was the content
that we had within the file
22263.388 -> and which you could
see it's been bred.
22266.5 -> So file writer and file reader
22269 -> so similar to print this one is
a different way of writing it.
22273.3 -> So what's written
within this program is nothing
22275.923 -> but we create an instance
of file writer
22278.1 -> and we pass the string the path
of the file rather as an input
22282.513 -> to the file writer
now file writer
22285.6 -> is nothing but
it's character-oriented
22287.873 -> right print was not
as such character oriented.
22290.7 -> This one is character oriented
22292.2 -> which means two bites
right character is nothing
22294.7 -> but two bite-sized with in Java.
22297.1 -> So this one is not
like it doesn't work
22300.105 -> at the byte level.
22302.1 -> Basically, whenever
22303.264 -> you're dealing with
character-oriented file,
22305.9 -> you could use this one rather
than printwriter.
22309 -> All right, objectify
lighter is being created
22312.034 -> which is a character
oriented file or which is
22315.012 -> a character oriented place.
22316.8 -> All right, and you write
to a file you're writing
22319.975 -> to the file here.
22321.2 -> All right, and similarly
when you use file reader,
22324.269 -> it's a character oriented reader
reads character one character
22328.058 -> at a time from the file
that you have mentioned here.
22331.7 -> So maybe I will take just
an example of writing it
22335.1 -> because it's going to be
pretty much similar.
22343.4 -> So quickly write this program.
22345.512 -> You have a main method
you create a method
22348.485 -> to say you have public
or it could be a private method
22352.2 -> as I said,
22352.825 -> the best practice
would be to restrict
22355.1 -> as much as possible rate.
22356.506 -> If you don't want this method
to be called from outside,
22359.6 -> you could have private method
22361.7 -> so it's going
to be right to file.
22365.6 -> So you need to give string
or you can have file as well.
22369.826 -> Whatever you prefer
to would have file
22373 -> and file to write to okay.
22376.8 -> So basically we were talking
about file right?
22380.1 -> All right, so I create
file right to object.
22383.5 -> Okay, and again say
it's a bike info.
22389.553 -> And I pause this file
to which you have to write.
22394.5 -> All right.
22395.299 -> So again, you could see now you
could see a checked exception
22398.6 -> that is nothing but issuing
that ioexception has
22401.979 -> to be handled now I
choose to throw it off.
22405.8 -> I'm not handling it here.
22408.45 -> Bike in four thought
I write to the file
22412.7 -> and I write some content.
22416.1 -> Basically, this should be writer
just to make it more elaborate.
22420.3 -> All right, I say
right Road close close
22423.5 -> this particular file.
22425.009 -> Okay.
22425.394 -> Now I give a call to this method
22428.4 -> which is nothing
but file writer demo is equal
22431.1 -> to Nu we are creating
instance of it.
22433.6 -> Okay, let me create a file
22435.8 -> which is nothing
but file bike info file
22441.4 -> and which is new file
and within the same directory,
22446.407 -> which is nothing
but calm dot Ed u--
22449.1 -> record at I/O.
22451.2 -> I create by info Dot txt.
22454.6 -> Alright, so what we are doing
here is using file writer.
22457.57 -> We are going to write
into biking for DOT txt.
22460.023 -> And we are going
to write this content
22462.2 -> that is Ducati and maybe
22463.767 -> after this we could have
whatever you have in buffer
22468.1 -> that that would be flushed
off to or disc.
22473.2 -> Alright, so when I
run this basically we
22475.787 -> don't have a file now bike info
and I think it should create it
22480.2 -> so you could see here.
22481.569 -> We don't have a bike info file.
22484.615 -> Okay.
22485 -> So again, let me talk
about this program.
22487.666 -> So what we have written
is we have a file.
22490.4 -> So what we are trying to do
is we are earlier the program
22493.976 -> we wrote using printwriter.
22495.7 -> Now we are going to use
five writer which is
22498.3 -> a character stream based I/
O so we are going to write
22501.5 -> into bike info dot txt file
22503.7 -> and we have a method
right to file
22506.34 -> in which we are creating
a file writer object
22509.738 -> which is taking
up this parameter
22512.115 -> or taking this pile,
22513.6 -> which we are going to read
through as the input.
22516.5 -> All right and not read
through its rather, right?
22519.6 -> So the file to which
we are going to write
22522.033 -> is taken as an input parameter
22523.85 -> to the file writer and we
are writing into this file.
22527 -> So right now we are just
writing to cart either.
22530 -> All right.
22530.6 -> So I invoke this method
like file writer demo dot right
22536.2 -> to file and I pass
on this file here.
22540.169 -> All right shows up an error
that you have to handle iOS.
22544.4 -> Option which is been thrown
from right to file.
22547.7 -> So I choose not to handle
it here as well.
22550.8 -> Which means if you
don't have that file
22553.6 -> or if there's some ioexception
22555.512 -> that's been triggered you
would program would stop.
22558.719 -> All right, so I
run this program.
22562.6 -> So basically, it
should create file
22564.848 -> and should write to it as well.
22566.9 -> All right, so I go
to the directory.
22569.1 -> So you see bike info file
has been created here.
22572.19 -> We didn't have it earlier.
22574.1 -> It got created
after we ran this program now,
22577.4 -> I just open it up
22578.5 -> and you should see the value
Ducati been written there.
22581.9 -> All right, so that's
about file writer
22583.812 -> and similar to that.
22584.874 -> You have to just
read through it.
22586.598 -> You have to pass the file
22588.068 -> that you want to read
as a parameter
22589.992 -> and you just have while loop
to iterate through
22592.5 -> till the end of the file
and you can print the character.
22595.5 -> So basically it's pretty
much similar to what we did
22597.7 -> for the printwriter,
22598.8 -> but I just wanted to demo
for one of these cases
22602.635 -> so we took an example
of why writer.
22605.669 -> Alright, so now let's move
towards stream stream based I /O
22610.2 -> so Java streams are used
to perform input
22613.105 -> and output operations
on eight bits.
22615.739 -> A bite right screams
is basically operating
22618.9 -> on a bite input stream.
22620.8 -> It is used to read the data
22622.241 -> from The Source it could be
file it could be keyboard
22625.477 -> or it could be anywhere across
across the network,
22628.5 -> right?
22628.859 -> It could be a socket as well.
22630.6 -> So basically it is used to read
the data from the source
22634.2 -> that is input stream
and output stream is nothing but
22637.9 -> if you want to write
something from your program
22640.7 -> to any resource on a network,
22642.9 -> that would be nothing but write
22645.1 -> that would be nothing
but output stream.
22647.8 -> All right.
22648.3 -> So with output stream you
would typically write data
22651.508 -> to a destination
and with input stream.
22654.1 -> You're going to read
it from a source.
22656.4 -> All right, just to walk you
through so we have object
22660.3 -> as I said all classes
22662.4 -> or every class in Java
is inherited from a class.
22666.4 -> That is object.
22667.6 -> All right.
22668.364 -> This is a super class
22669.6 -> for all the objects all
the classes in Java.
22673.1 -> Okay.
22673.7 -> So you have object
and you you could see
22676.612 -> that this input stream
and output stream.
22679.6 -> So let's talk
about the input stream.
22681.582 -> There's file input.
22682.7 -> Beam, there's byte array input
stream this filter input stream
22687 -> and this object input stream.
22688.9 -> So we'll talk about this
in the coming slides.
22691.265 -> Why do we have
object input stream
22693 -> and stuff like that.
22694.1 -> But right now you could imagine
22695.8 -> that we have multiple classes
or you could think
22698.338 -> that there are multiple classes
with it input stream,
22701.147 -> which are used
for different use cases.
22703.2 -> Like you have
buffered input stream,
22705.258 -> which is nothing
but it buffers it.
22707.2 -> It doesn't read
or write it in one go.
22709.47 -> It's sort of buffers it
and then it flushes it over.
22712.7 -> All right output stream
similar to input stream.
22715.5 -> We have an output stream.
22717.016 -> It's an interface.
22718.165 -> I believe which has got
several implementations
22721.1 -> like file output stream.
22722.91 -> You have byte
array output stream.
22725.4 -> You have filter output stream.
22727.427 -> You have object output stream
22729.462 -> and filter output stream
is further categorized as
22733 -> or has further sub classes
as buffered output stream
22737.6 -> and data output stream.
22739.5 -> All right, so in further slides,
22740.95 -> we are going to discuss
22742.1 -> file input Stream file output
stream object input stream
22746.087 -> and object output stream.
22748.1 -> Okay, so file
output stream class
22750.4 -> and file input stream class.
22752.131 -> Let's talk about it.
22753.451 -> The file output stream class
22755.3 -> is used to write
to a file right you
22757.6 -> you could take a bite array
and you could write to a Phi.
22761.3 -> All right, so you
could take something.
22763.3 -> If you have a string
you could convert it
22765.3 -> into a byte array
and you could pass it
22767.2 -> and it would write to a file.
22769.298 -> So remember we said it's
a byte oriented, right?
22773.1 -> So basically it's going
to write take array as input
22777.6 -> and it's going to write to it
22779.472 -> write to the file that you
have mentioned in there.
22782.7 -> Right so you could take
integer as well.
22785.6 -> It is used to write
the specified bite
22788.3 -> to the file output stream.
22790.103 -> So you could provide
integer as well.
22792.8 -> There's a close method
which is nothing
22795.302 -> but closing the Stream
So streams are nothing
22798.2 -> but it is hooked up
to the resources.
22800.388 -> It is taking up resources
22801.955 -> and there is a Action
between your program
22804.442 -> and the file established rate
when you create three times.
22807.9 -> So when you close it you close
that connection and it is free
22811.429 -> for garbage collector
22812.8 -> to remove that particular
object from memory.
22816.2 -> So basically freeze
memory as well right
22819.1 -> unless you close it.
22820.4 -> It's going to stay
in the memory.
22822.1 -> So it's a good practice
to close it right
22824.877 -> after you use it.
22826.068 -> Okay rights, you could write
to a particular offset,
22829.754 -> which could be done
using right method.
22832.5 -> So right length bites,
22834.6 -> whatever length you have
mentioned in as third argument,
22837.647 -> it would write it
to a particular offset.
22840 -> It would write the bite
that you have even
22842.4 -> or bite that you
have passed in as input.
22845.2 -> It would write that bite do
22847.4 -> a particular Offset
you have flush method,
22850.7 -> which is nothing
but flushes the output stream
22853.4 -> and forces any buffered
output bytes to be written out.
22857.036 -> All right, so it
could be buffered as I said,
22860 -> so not writing it each
22861.8 -> and every time You have bite
basically it buffers it
22865.1 -> and you could have flush method
to flush it off to the Phi.
22869.3 -> So basically we
have buffered stream,
22872.3 -> which is this Method All right.
22874.961 -> So here we have
file output stream
22877.5 -> and using file output stream.
22879.505 -> We rewrite it to the file
and then we close the file.
22883.4 -> All right, as far as
the syntax is concerned.
22885.988 -> It's pretty much similar
to file writer example
22888.8 -> that we took but just to give
you a demo just to show you
22893 -> how it is.
22893.9 -> We'll have fun demo done here.
22896.7 -> All right, so I
create a new class
22899.1 -> which is nothing
but file output stream demo.
22907.1 -> Alright, so we
have a main method
22910.4 -> and I create a new method
22913.361 -> which is like file
write to a file.
22917.5 -> Which could be
like private method
22919.934 -> private void write to a file?
22924.8 -> Alright, so we are going
to write to this file using
22928.4 -> what using file output Stream
So it showing up this
22932.7 -> so I select Java
dot IO dot fight.
22935.238 -> All right.
22936.365 -> Okay now I create
file output stream.
22944.3 -> Create an instance
of it right similar to
22946.814 -> how we did for other programs.
22948.7 -> Now, it says file not found
exception has to be handled.
22952.1 -> I choose not to handle it
22954 -> and I throw it back
to the calling program.
22956.6 -> All right.
22957.4 -> So now what I do is I do file
dot right file output stream.
22964.903 -> I am going to write
it to this file.
22971.6 -> So I just write a text here.
22975.4 -> All right.
22976.7 -> So write a text here.
22978.1 -> Hello folks.
22978.7 -> Hope you're enjoying the session
and I just closed it off again
22984.9 -> it throws ioexception
when you close it.
22987.5 -> So remember we said there
could be multiple exceptions
22990.7 -> that could be thrown
out of a method.
22992.6 -> So I again I choose
to throw this one as well.
22996.5 -> So basically what I'm trying
to do here is I throw
22999.9 -> IO exception as well.
23003.1 -> Okay, so it doesn't take
a string as a as an input.
23007.1 -> So what I have to do is
I have to do not get bites.
23011.3 -> As we saw the Constructor
of it constructed
23014.4 -> isn't takes string as input
23016.9 -> in case of output stream or in
case of file output stream.
23021.6 -> It interacts in terms
23023 -> of byte array
and stuff like that.
23025.2 -> So I converted this string
into byte array.
23028.43 -> So when you see get bites get
bites method is a method
23032.507 -> on a string class
23033.819 -> which converts the string
into array of bytes.
23037.4 -> All right.
23038.093 -> So now what I do is I give
a call to this particular.
23049.9 -> I'm writing to a file
23051.405 -> and I'm going to take
create a new file.
23055.9 -> So I can take
the same file, right?
23057.9 -> I am going to take a b
or else I will create a new one.
23064.6 -> All right, so I create a file
which is like message dot txt
23069.2 -> or you need not even create it.
23071.103 -> It will create by its own.
23072.7 -> I will delete it may be okay
23074.7 -> on the thing is I love
to create see a Eureka yo.
23080.2 -> All right.
23081 -> And here we say message dot txt.
23085.5 -> All right, so I call a method
to write to the file using
23090.124 -> file output stream night
choose to throw it off
23093.663 -> from here as well.
23095.9 -> Alright, so we have a method
23097.766 -> which is going to write into
a file using file output stream.
23101.766 -> All right, so I
run this program.
23106.8 -> Okay, it ran successfully.
23108.8 -> Let me open this message and see
23111.1 -> if we have the
message written there.
23113.2 -> All right, so you
could see here.
23115 -> Hello folks.
23115.646 -> Hope you're enjoying the session
23117.369 -> which is written
from your program.
23119.7 -> All right, so this file
input stream as well,
23122.288 -> which is pretty much similar
it again operates
23125.07 -> in terms of bytes.
23126.039 -> As you could see the signatures
of the methods within it
23129.047 -> would read the contents
of the file into the byte array
23132 -> that you have passed
as a parameter.
23134.1 -> The second one is to read
23135.8 -> from a particular
offset the length
23138.1 -> that you have mentioned
23139.452 -> or passed as a parameter close
is pretty much similar.
23142.202 -> It would close the connection
23143.79 -> that's been established
23145.1 -> and it would make
the class available
23147.4 -> for garbage collector
to clean it off.
23150.2 -> Okay garbage collector
is nothing but unlike see
23153.4 -> where in you have to delegate
the memory location
23156.471 -> that's been used garbage
collector is parallel thread
23159.8 -> that is run by jvm to remove the
or to free up the memory space
23164.4 -> that's been acquired by classes.
23166.9 -> So it runs sporadically it's
not within your control.
23170.062 -> It runs per radically and it
clears of the memory locations.
23173.7 -> We have a reed method
which is nothing
23176.046 -> but reads the next bite
from the input source.
23178.9 -> So on the file input stream
instance on which you read it,
23182.619 -> it would read out the next bite
and if it's end of the stream,
23186.6 -> it would return -1.
23187.898 -> So the return value is integer
23190 -> as you could see here you
could skip specified number
23193.7 -> of bytes from the input stream
23196.7 -> and available Returns
the number of bytes
23199.2 -> that can be read
from the currents tree,
23202 -> right?
23202.5 -> So maximum number of bytes
that could be read out.
23205.4 -> So I'm just going to read
through this light
23208.41 -> or if you want.
23209.46 -> Yeah, I can take
an example maybe
23211.8 -> since we didn't take
example on reader.
23214.5 -> I'll take one example
and reader as well.
23217.3 -> Okay, so here I to file
input stream demo All right,
23225 -> so we create a class here
23228.4 -> and I have a main method here.
23231.8 -> Okay.
23232.43 -> I have a private method
23234.2 -> which is void and it's
not returning anything
23238.1 -> and I said read from file.
23240.7 -> All right.
23242.7 -> which takes file Again,
I'll have to import file.
23250.6 -> Okay, so Java dot you could see
23252.9 -> the input statement
coming up here.
23255.18 -> So now I create
file input stream.
23260.5 -> Okay.
23262.8 -> I create a new instance of it.
23265.7 -> Which would typically take
23267.557 -> for that matter it
would take string as well.
23271.8 -> Just to show you
a different variant of it.
23274.551 -> It's not that you have
to always pass file it you
23277.696 -> could pass string as well.
23279.8 -> Alright, so we are
passing a string here.
23282.4 -> It says file not found
exception has to be handled
23286.2 -> since its read you
have to ensure
23288.6 -> that you have the file there.
23290.2 -> Right?
23291 -> So I choose to again
throw off this exception.
23294.6 -> So I'm not handling it.
23296.6 -> So typically you
would handle exception
23298.8 -> when you want to do
something on it.
23300.8 -> Right when file not found
23302.449 -> if you're trying to read a file
and that file doesn't exist
23306.285 -> in your drive.
23307.131 -> I wouldn't handle it.
23308.412 -> I would just throw it off.
23310 -> I want program
to break right there.
23312.219 -> Right?
23312.6 -> I don't want it to proceed
23314.149 -> because our program
23315.28 -> at this particular method
is trying to read from a file
23318.626 -> and if it doesn't exist it,
23320.3 -> it doesn't make sense
to proceed further.
23323.094 -> All right, so I
have input stream.
23325.4 -> Now what I do is not read and
23327.861 -> as you could see it's written
in integer, right
23331.4 -> so This has to be looped.
23335.7 -> All right.
23336.4 -> This has to be looped
until you get minus 1 right.
23340.3 -> So basically you would have like
say teacher and you have like
23348.8 -> so this is integer
read from file.
23351.4 -> All right, and I
keep this as integer,
23354.7 -> which is so whatever you read
I need to assign this because I
23360.223 -> want to write that as well.
23362.3 -> All right, so I'm assigning
23364.2 -> to this and unless this
is minus 1 you are going
23369.1 -> to read through write it
again shows exception,
23372.9 -> which I need to handle.
23374.6 -> So this time it's ioexception
23376.817 -> and I'm going to throw
this one as well.
23380 -> All right, so you have a reed
method you are going to read it
23383.247 -> and basically till the time
its minus 1 it's going
23385.9 -> to be red right now.
23387.222 -> What I'm going to do
is within the loop.
23389.8 -> I'm going to just type.
23393.657 -> So basically I'm going to just
type cuz this to character.
23399.6 -> It's read as integer.
23401.2 -> So you have to convert
it into character.
23403 -> If you want to see
in terms of character.
23405 -> If or else you would get
the ASCII value of it.
23408.661 -> Alright, once this is done.
23411.3 -> Basically I need to close
off the stream as well.
23415.5 -> Okay.
23415.833 -> Now what I do is
I create the instance
23418.3 -> of file output stream demo.
23422.3 -> Just nothing, but creating
instance of it.
23425 -> Right demo dot read from file.
23428.069 -> But remember this time we are
not creating a file instance.
23432.6 -> We are just passing the string.
23434.491 -> All right, so you
could take any of this file
23437.261 -> since we are reading it we could
take like let me take bike in
23441.1 -> for it just got valued Ducati.
23443.7 -> So I'm passing this
as a string this time.
23446.3 -> All right, and it's
a different variant.
23448.5 -> You could pass it
as a file as well.
23450.347 -> You could pass it
as a string as well.
23452.4 -> But since I have been passing
as a file in previous examples
23456.5 -> this time I choose
to pass it as a string.
23459.7 -> Alright, so now I
am throwing it off
23461.9 -> from here as well since I
don't want to handle it right.
23465.2 -> So if I get an error,
I want the program to break.
23467.9 -> So that's the reason
I am throwing it off
23469.9 -> from here as well.
23473.7 -> So coordinator, let's see.
23475.7 -> What's it?
23476.664 -> Okay, so I have to put
double slash here.
23479.826 -> All right.
23480.769 -> I miss that one.
23484.5 -> So basically if you
don't put double slash it
23487.1 -> would take it as a regular
expression sort of again.
23490.1 -> It's not bike
in Foods dot txt,
23492.851 -> which I missed I believe
23494.8 -> so it says that bike
info file doesn't exist.
23499.3 -> Right since it's
a text file, right?
23501.326 -> You have to provide
the extension as well.
23506.4 -> All right, so you
could see it read in terms
23508.9 -> of characters, right?
23510.3 -> So you could see the first
character read as D then then
23514.16 -> you could see it followed till
till it red Ducati.
23518.1 -> All right, so that's
about file stream
23520.9 -> or file input stream.
23522.4 -> That's how you write programs.
23525.1 -> Now what serialization
23526.2 -> and deserialization I
will quickly cover on this one
23529.2 -> since this is something
23530.5 -> that's been used widely
in big data when it comes
23533.6 -> to Big Data or when it comes
to distributed computing.
23537.2 -> Just not to if you
understand it's good.
23539.288 -> If you don't understand you
don't have to think much
23542.1 -> but I'm just talking in terms
of distributed computing.
23545.247 -> Right?
23545.616 -> So when it comes to Big Data,
23547.4 -> it's not that you have
server farms and everything.
23550.8 -> Your program doesn't run
on server Farm anymore.
23553.7 -> It's more about you
have commodity Hardware
23556.9 -> on which a program is run
23558.7 -> and that's what
Big Data Frameworks are good
23561.6 -> about the investments
in terms of infrastructure
23565.3 -> by having server Farms
has been reduced a lot
23568.7 -> has been cut down a lot
23570.4 -> and you could have
commodity Hardware
23572.6 -> on which you could have this
distributed Frameworks running.
23576.081 -> So say for example,
23577.2 -> you might have heard
about Hadoop or Apache spark,
23580.4 -> which could actually run
on normal Hardware right
23584.2 -> or you could Need
to on cloud as well.
23586.413 -> So you have like
Amazon web service
23588.633 -> which is cloud like you
you have Google as well
23591.5 -> Google services,
23592.6 -> which exposes as a cloud
you have a seizure,
23595.5 -> which is nothing
but Microsoft's Cloud.
23598.06 -> So all these are kind of not big
Hardware not server Farms
23601.9 -> that you have.
23602.693 -> It's a normal Hardware
that you could configure
23605.3 -> and you could run
through your chunks of data
23608.1 -> or petabytes of data
23609.404 -> that comes in from cloud
or from elsewhere, right?
23612.6 -> So that's the beauty of it.
23614.339 -> That's the beauty
of java and one
23616.356 -> of the main things
are main feature
23618.5 -> that Java has
got a serialization
23620.755 -> and deserialization
23622.094 -> which helps in having this
distributed framework going.
23626 -> Okay.
23626.6 -> So serialization is nothing
but you have class
23630 -> right and you you create
instance of a class,
23633.257 -> which is nothing
but object right now
23635.803 -> this instance of a class
23637.5 -> if you want to pass it over
to some other computer
23640.382 -> or some other computer
on your network,
23642.4 -> right?
23642.9 -> This could be done just
23644.178 -> because this Serialization
there's a concept
23646.6 -> of serialization right suppose.
23648.5 -> I create some object
of a class today on my computer.
23652.5 -> And if I want to pass
the same state,
23655.2 -> right it's about
passing the street
23657.38 -> not the behavior behavior is
of course just methods, right?
23661.1 -> So it's about passing
the state of the object.
23663.8 -> So whatever state my object is
23665.843 -> or whatever properties
my object bolts
23668.243 -> at some particular point
23669.8 -> if I want to pass it over
to some other computer
23672.564 -> on the network.
23673.463 -> This could be done just
23674.816 -> because you have
serialization was
23676.83 -> what you would do is basically
23678.661 -> if you remember the object stays
in Heap right Heap memory,
23682.075 -> which is protected
23683.177 -> which no other process can get
into that particular.
23686.3 -> He process Heap memory, right?
23688.656 -> That's a security
that Java provides
23691.6 -> if you remember in the first
slide we covered it, right.
23694.8 -> So what Java does
23696.061 -> by serialization is whatever
contains of a particular object
23700.6 -> or whatever contains
a particular object whole
23703.4 -> set any could be written.
23705 -> To your disk as a binary file
23707.469 -> and you could send it over
to some other computer via wire,
23712 -> or you could take
it plug in your USB drive
23715.4 -> and you could just take that
particular file the binary file
23719.1 -> that's created and you
can go elsewhere
23722.03 -> and just play that file
23723.8 -> or just deserialize it
to see the contents of it.
23727.492 -> Right?
23727.845 -> So you could imagine
this is something
23730.021 -> that is needed in terms
of distributed computing
23732.705 -> since not everything
is been carried out
23735 -> on a single computer you
you would process something
23738.108 -> on your computer you would you
would write it to a file
23741.4 -> and you need to pass
on this file toward
23744.1 -> or transport this file
23745.585 -> to different computer right
or typical example in which you
23749.6 -> would think of serialization
is more about you.
23752.754 -> Could you could have say
23754.4 -> for example one operation
carried out on one computer
23758.262 -> and same operation
23759.6 -> or different operation
on a same file carried out
23762.423 -> on some other computer now you
23764.103 -> want to move Just them
together and that's
23766.307 -> where you would
have serialization
23768.052 -> and deserialization coming into
picture basically to understand
23771.7 -> the concept serialization
23773.164 -> is nothing but writing the state
of the object to a file
23776.4 -> and deserialization is nothing
23778.4 -> but again taking
the state of the object
23781.4 -> that's been written to the file
again putting it back
23784.2 -> to a class format
23785.379 -> or when you want to use
this serialized class.
23788.5 -> You would basically
deserialize it use it.
23791.1 -> So serialization is a process
of converting an object mrs.
23794.6 -> To sequence of bytes,
23795.9 -> which can be persisted
to a disk or file
23798.9 -> and can be sent through streams
or can send across wire
23803.6 -> or could be you could actually
take it on your drive
23807 -> and transport it elsewhere
the reverse process
23810.1 -> which will convert
data bytes into object
23812.1 -> is called D serialization.
23814.3 -> All right.
23815.2 -> So how do we have
this serialization
23817.572 -> and deserialization done
23819.18 -> or what classes we have
for supporting it.
23821.9 -> Let's talk about that.
23823.321 -> All right in this example.
23825 -> You have a student info
23826.735 -> which is having ID
and name, right?
23829.3 -> And basically you could see
23830.978 -> that we have created
an instance of student info
23833.9 -> which which has value
of 9 and John.
23836.7 -> All right.
23837.319 -> And now what we are doing is we
are writing the state state is
23841.173 -> nothing but the value
23842.535 -> that this particular
object holds right
23845 -> which is nothing but ID
of 9 and name value
23848.5 -> of John, right?
23850 -> So we are writing this
into a do a file
23853.3 -> which is nothing
but student Dot txt.
23856.7 -> And and we are just writing
that to a particular file.
23859.999 -> Okay, and this is nothing
but the student dot txt file
23863.3 -> that you see it should be txt.
23864.8 -> Actually.
23865.31 -> It's it's a binary file.
23866.647 -> So you should I would rather
prefer to have student dot Pi
23870.2 -> n or binary and you
would write it to that file
23873.243 -> using right object.
23874.5 -> So the supporting class
23876.3 -> for serialization is
object output stream
23879.237 -> and object input stream.
23881 -> All right, so I will quickly
take a demo of this.
23887.3 -> So the first thing that we do
is serialization serialization
23890.8 -> is done by object output stream.
23895.1 -> All right.
23895.9 -> So again, we have
a main method suppose.
23900.1 -> I want to serialize it.
23902 -> So I would do something like say
23904.5 -> I have a private method
which is void,
23907.1 -> which is serialize.
23909.8 -> Okay.
23910.2 -> So the first thing I
would want to create
23912.7 -> is nothing but Java class
which will hold the state right.
23917 -> So this is a class
23918.058 -> which you want to serialize
or which you want to send it
23921.2 -> across two different computers.
23923.1 -> So such losses are known
as model classes, right?
23926.196 -> Basically such classes
are nothing but classes
23929.073 -> which holds chunks of data.
23930.808 -> So for Simplicity,
23931.904 -> we have taken small data
like ID and name,
23935.007 -> but in general you would have
like chunks of data.
23938 -> They're all right.
23939.4 -> So here I say Vehicle info.
23943.5 -> Maybe this is the class
that I have here.
23946.2 -> Alright, and now
23947.43 -> what I do is suppose
I have Suppose I have
23954.853 -> two parameters here.
23958.7 -> All right, so I have
two parameters here,
23960.9 -> which is nothing but integer
23963.2 -> and suppose I have
like string name of equal.
23970.2 -> Alright, so now I Define
a Constructor for vehicle info
23974.3 -> which takes T three parameters
for Simplicity number of Wheels.
23979.7 -> First.
23980.2 -> Say for example,
I take name of vehicle.
23984 -> then it's number of wheels and
say I have one more parameter,
23988.2 -> which is mileage.
23991.1 -> All right.
23992.6 -> Remember we use of this keyword
23995.8 -> since the name of the arguments
23997.713 -> and the name of the instance
variables are the same
24000.8 -> we need to use this
this DOT number of Wheels.
24006.6 -> Is equal to number of Wheels?
24008.9 -> All right, and this dot mileage
is equal to mileage.
24013.8 -> All right.
24014.409 -> So this is a simple model class
24016.325 -> which is supposed
to hold values.
24018.207 -> Basically in reality.
24019.419 -> This would be holding
like chunks of values.
24021.9 -> Okay.
24022.28 -> Imagine like could
be like megabytes
24024.862 -> of information or even
huge gigabytes of information.
24028.7 -> All right, but
for Simplicity here,
24030.95 -> we are taking
this simple class right.
24033.4 -> Now.
24033.6 -> What we want to do is we want
to see realize this into a GFI.
24037.342 -> We are going to
create an instance
24039.283 -> of this particular class
24040.7 -> and we are going
to dry this state
24043.057 -> or whatever values we have
that particular instance.
24046.9 -> We are going to
write it to a file
24048.897 -> so that it could be read
from somewhere else
24051.5 -> or it could be used by
any computers on the network.
24055.03 -> All right, so I
have vehicle info.
24060.3 -> Again suppose I write BMW is
equal to new vehicle info.
24065.1 -> Now, what I have to pass
is name of the vehicle,
24068.2 -> which is BMW right number
24070.7 -> of and I pass some value
like Like 10, all right.
24077.9 -> Okay.
24078.224 -> Now we have created
instance of vehicle info
24080.753 -> and we have passed the values
24082.459 -> that we want to pass it and now
we want to see realized this.
24086 -> Okay.
24086.349 -> So how do we see realize
is nothing but we use
24089.5 -> object output stream, right?
24096.8 -> So what does it take?
24100.3 -> So basically you could go
into the source code and
24103.414 -> if you want to deal
more you could actually
24106.205 -> see what other Constructors
24108 -> that it takes.
24110.1 -> You could see it
takes output stream.
24114.302 -> So one is output stream
as a Constructor.
24120.2 -> If it takes output stream,
24122.2 -> then I'll have to create
file or stream.
24125.8 -> Basically.
24126.3 -> I will name this as
24127.8 -> object stream and this one
would be filestream.
24132.6 -> Okay, I create a new
file output stream
24136.4 -> and you could pass the file
on which you want to write it.
24139.972 -> All right.
24140.599 -> So in this case the file
24142.14 -> on which I want to write
a particular class.
24144.9 -> I will pass it as file
24146.529 -> and I'll be passing
it over here.
24148.9 -> All right.
24149.7 -> So what I am trying to do
here is resolve this okay.
24153.6 -> So you take the file or to which
you want to see realize
24157.4 -> so basically this vehicle info
would be serialized
24160.511 -> into this file
24161.4 -> and this file would
be transported anywhere
24163.5 -> across your network.
24164.8 -> So it shows file
not found exception again,
24167.999 -> I choose to throw it.
24169.8 -> It shows my exception now,
24173.12 -> I've passed this
file stream here.
24176.3 -> Alright, so this is
how we usually write programs.
24179.9 -> You have file input
stream file output stream,
24183.2 -> which is nothing but the file
24184.995 -> to which you want to write write
the state of the object
24188.4 -> and you instantiate
object output stream.
24191.8 -> Okay.
24192.4 -> Now let me write to it.
24195.7 -> Okay.
24196.8 -> So basically what are you
going to write is nothing
24199.8 -> but vehicle info just
instance of okay.
24204.6 -> So you're going to you
want to write this instance
24207.1 -> of vehicle info particular
instance of vehicle info
24210.7 -> into your into the file?
24212.546 -> Okay.
24213.1 -> So I write something like this.
24216.4 -> Okay.
24216.8 -> So so basically
24219.015 -> what we'll have to do here is
whenever you have this thing
24223.531 -> whenever you want to write
24225.5 -> or whenever you want
to write the state
24228.1 -> of a class to a file you need
to implement one interface,
24233.202 -> which is serializable.
24235 -> All right.
24235.646 -> It's a do-nothing interface.
24237.8 -> It's just used by it's
a mock-up interface as
24240.7 -> well marker interface rather.
24242.65 -> It is just used by jvm to say
24244.6 -> that this particular class
could be serialized
24247.194 -> but it doesn't have
any methods within it
24249.5 -> as you could see if it would.
24251.5 -> I've had some methods it
would have shown an error saying
24254.3 -> that you should implement it.
24255.935 -> But in this case it didn't
because it doesn't have
24258.7 -> any methods within right?
24262.4 -> So basically when you
have object streamed, right?
24267 -> Okay, so it takes all right.
24270.3 -> So we we create objects stream
24272.7 -> and we pass the file
that we want to write to
24276 -> and we have right object method
which would take the instance
24279.869 -> of the class that you
want to write and we have
24282.836 -> like we flush it
and we close it.
24284.9 -> So one thing to note here
is vehicle info class has
24288.9 -> to implement serializable.
24290.9 -> That's a marker interface
serializable is nothing
24294.023 -> but a marker interface
24295.443 -> and it doesn't have any method
within it is just an indicator
24299.292 -> as you could see it's
an empty interface.
24301.858 -> All right.
24302.5 -> This is the source code of it.
24304 -> You could see it's
an empty interface.
24306.2 -> It is just a marker
24307.5 -> or it is just a notification
to the jvm saying
24310.9 -> that this class is something
that could be serialized.
24314.6 -> Alright, so we have this class
24317.5 -> and we are going
to serialize the state
24320.5 -> of BMW object into a Phi.
24323.6 -> Alright, so now
24324.753 -> what I do is I create
Object output stream demo
24330.2 -> and I call serialized
24332 -> within it now this serializes
taking two parameters.
24336.5 -> So if the first parameter is
this is other way of passing it.
24341.3 -> We are not actually
creating instance.
24343.5 -> We are passing it directly.
24345.3 -> All right, so I pass this
and I say serialized file.
24352.5 -> Okay, maybe dot bin
and the other parameter
24356.6 -> that it's taking is nothing
but the instance of class
24360.5 -> that you want to serialize.
24362.4 -> Alright, so here we
are again getting exception
24365.7 -> which needs to be thrown off.
24368.5 -> Alright, so this is
a simple class that we
24370.7 -> have we have vehicle info
24372.6 -> which carries BMW instance
24375 -> or we have created instance
of vehicle info with BMW values
24379.4 -> and we are trying to serialize
this to the to a file
24383.148 -> which is serialized
file dot bin.
24385.6 -> Okay.
24386.435 -> Let me see if it runs.
24391.6 -> Alright, so I hope it ran now.
24394.3 -> This is a binary file.
24395.4 -> If you see you are not going
to understand everything
24398.156 -> that you have within this file.
24399.8 -> Okay, so I
24401.9 -> just Okay, so here you could see
it's not something that could be
24410.7 -> completely readable,
24411.987 -> but you could get
some idea about it.
24414.3 -> It's during game W.
24415.6 -> All right, and this is not meant
24417.3 -> for you to read it writes
not in a human readable form.
24420.826 -> This is basically for passing
this over a network
24424.012 -> and at the other end you
would deserialize it.
24426.973 -> Alright, so this is
how we see realized it now.
24430 -> We will check on
how we deserialize it.
24432.345 -> All right.
24432.986 -> So you you saw
the contents right?
24435.1 -> It's something that
is not readable.
24437.6 -> Okay again, I'll open it up.
24442 -> Not everything would make sense.
24443.6 -> But you could see
that this is for BMW.
24447.7 -> So basically you could see
the value BMW here, right?
24451.8 -> So now what I do is I want
to see see realize this right.
24456.3 -> So this is
how you see realize it.
24458.6 -> We spoke about it
24459.7 -> how we see realized it now we
are going to deserialize this.
24463.4 -> So basically this
deserialization won't happen
24466.263 -> on the same computer.
24467.596 -> It might or might not
or it could be saved
24470.4 -> different application within
the same computer as well.
24473.217 -> So if you have
two applications running
24475.22 -> and want to interact
between the two applications
24477.9 -> running on the same computer
could use serialization
24481.2 -> and deserialization or you
could majority of the use case
24484.718 -> for this feature is more
24486.145 -> about passing it
over the network.
24488.241 -> All right.
24488.893 -> So, let's see
how we deserialize it.
24491.3 -> Okay.
24491.672 -> So when you easy realize it
you use object input stream.
24495.789 -> Okay, so in the same class
or I'll just for Simplicity sake
24501.15 -> I'll change this
to object stream demo
24503.997 -> because this is
not just all right,
24509.9 -> so I Defector it
24511.396 -> and I change we name this too.
24515.5 -> Okay, so this is been renamed
to object stream demo now
24519.6 -> create a private method,
24521.3 -> which is nothing
but void deserialize.
24525.5 -> Again First DC realization you
need to have the file right
24529.6 -> you could imagine of you
having the file and file
24533.8 -> should be okay.
24536.8 -> Okay.
24537.2 -> So now what we do is
24540.8 -> basically we could have
this as a file rather
24545.4 -> since we are going
to send the same file.
24550.061 -> Same file for DC
realizing as well.
24552.676 -> So it's better to have
it defined here.
24555.6 -> And you pass it as CD list.
24558.5 -> Okay so far we have serialized
24560.6 -> it now we are going
to deserialize it.
24562.77 -> So what you do in D
serialization is nothing
24565.5 -> but you use object.
24567.8 -> So the first thing
24568.874 -> that you will have to create
similar to be created
24571.8 -> file input stream about now,
24573.611 -> we are going to file output
stream in the serialized case,
24577.3 -> but here we are going
to create a file input stream.
24582.2 -> And a provide the fight here.
24584.421 -> Alright, so we have file
input stream created now
24588.1 -> we have object input stream.
24594.1 -> Alright, we are creating
instance of it and it
24597.372 -> would be new object input stream
24599.7 -> and you would be passing
the fill input stream
24602.593 -> that you created the step
24604.2 -> above all red showing
you for exception.
24607.1 -> You have to could either throw
it or you could handle it.
24611.6 -> So this case I'm
throwing it off.
24614 -> Alright, so we have
24616.53 -> so here you could see
we had bright object now,
24620.3 -> I'll have read object.
24622.2 -> So read object throws
filenotfoundexception or class
24626.3 -> not found exception
24627.502 -> that you need to handle
right again through it.
24630.871 -> So here you could
see IO exception
24633.053 -> and class not found
exception right single method
24636.227 -> can choose to throw
multiple exceptions from within.
24639.7 -> All right, so we have chosen
to throw it now we
24643.5 -> have vehicle info
or we don't know
24648 -> whether it's BMW at that point.
24650.384 -> So I say d serialized object.
24656.1 -> All right, so object streamed
read object by default.
24660.2 -> It returns object type.
24662.3 -> So we need to we
need to type casted.
24665.4 -> This is how we typecasted
one form to the other.
24668.464 -> So basically we know
that object streamed
24671 -> or read object is going
to give us vehicle info object.
24674.832 -> That's why we can
actually type cast it.
24677.6 -> All right.
24678.287 -> So now what I do is
24679.593 -> once I get this D
serialized object,
24682 -> I'm going to print out
the values that I have within.
24685 -> All right, so I'm going to print
the name of the vehicle.
24688.5 -> So I say All right put us.
24700.4 -> Right, so name of the vehicle
the serialized file similarly.
24705.038 -> I just copy paste.
24706.423 -> It will print number
of Wheels Alright
24713.4 -> and we'll print mileage
of we go I need this one.
24718.5 -> Alright, so basically
we are serializing it
24720.999 -> and then DC realizing it
after deer is realizing it.
24724.1 -> We are printing the value
of the contents
24726.3 -> or we are printing the contents
of a particular object to see
24730 -> if it is what we expect.
24732 -> All right, so maybe
I can do one thing.
24734.596 -> I can delete this off.
24736.2 -> Let me close this and let
me delete this off.
24740 -> Okay.
24740.352 -> I'm deleting serialized info.
24742.4 -> I'm going to run
this program again
24744.2 -> and this program will serialize
and deserialize it.
24747.9 -> Okay, it will see realize it
in the first case.
24750.8 -> And now I'm going to write would
be serialization deserialized
24754.675 -> and the serialized file.
24756.211 -> All right now here as well.
24758.3 -> I am going to throw away.
24760.7 -> Okay.
24761.5 -> So first we are going
to serialize it
24763.6 -> and then we are going
to deserialize it and see
24766.5 -> whether we get the contents
that we expect.
24769.4 -> All right, so it's running.
24771.3 -> Let's see if the file
has been created.
24773.6 -> So we deleted the files.
24775.085 -> It's not yet come.
24777.1 -> So we can see
that a file was created here.
24780.011 -> Right which is a serialized file
and we printed the value
24784.391 -> from be serialized file as
well after DC realization.
24787.9 -> We printed the value
of the contents
24790 -> in the serialized file just
24792 -> like we got the expected value
which was BMW 4 and 10,
24796.738 -> which you had said.
24798.2 -> So basically what we
are doing here is we
24800.2 -> are storing the state of a class
24802.1 -> or state of the object
24803.502 -> to a disk and this
could be transported anywhere
24806.5 -> when I say it could
be transported is nothing but
24809.323 -> this is just a binary file,
24810.823 -> right so you could take it
into your text file
24813.47 -> or you could take it
into your pen drive
24815.775 -> and you could take it anywhere.
24817.6 -> All right.
24818.199 -> So that's the
beauty of serialization
24820.015 -> and deserialization.
24821.029 -> I spent more time on this
24822.335 -> because this is something
that is very important
24825.1 -> for Big Data
24825.9 -> since big data is nothing
but all the big data Frameworks
24829.194 -> that we have they follow
distributed computing
24831.918 -> and this is one
of the important internals
24834.4 -> of distributed computing
24836 -> though you need not.
24837.111 -> Take care of it.
24837.991 -> It's all taken care by
the Big Data framework.
24840.394 -> But this is an important
concept to understand.
24843.1 -> All right, so let me quickly
talk about wrapper classes.
24846.766 -> It's not an important topic
24848.5 -> to but I will quickly
cover on this thing.
24851.1 -> So wrapper classes are
nothing but you have
24853.283 -> primitive data types
24854.269 -> that we discussed
the first day, right?
24856.26 -> So initially we didn't have
this wrapper classes in picture
24859.3 -> when the initial version
of java was created.
24861.9 -> So data types were dealt
24863.67 -> in terms of primitive
data type itself.
24866.4 -> Then since Java is
object oriented, right?
24869.3 -> It has to be completely
object-oriented so they
24872.2 -> came up with a concept
24873.3 -> that we shouldn't be
dealing data types as
24876.1 -> a primitive data type rather.
24877.989 -> We should be having
some sort of object to it
24880.8 -> which is rapper,
24881.825 -> right which is wrapping
this primitive data type.
24884.9 -> So in order to make
it completely object-oriented
24888.3 -> they have come up
with this wrapper classes,
24890.6 -> right so int when you
define int right
24893.6 -> if you define int
something of this sort,
24896.621 -> it's Native whereas you
would have something like this.
24901.6 -> Inti is going to be
primitive data type
24904.7 -> and whereas you would have
something like this
24907.472 -> which is nothing
but wrapper class, right?
24910 -> So if you go into
the wrapper class,
24911.75 -> you could go into the source
code and see it's nothing
24914.4 -> but it's doing the same thing.
24915.9 -> It has got some utility methods
as well on the top of it,
24919.002 -> but basically it
storing your value.
24922.4 -> So for now they have changed
the source code quite a bit.
24925.6 -> Basically, it's touring in terms
of characters, I believe.
24928.9 -> All right, so you
need not take care of this.
24931.099 -> But what I am trying to say
is wrapper class is nothing
24933.8 -> but a rapper built
upon the primitive data type
24937 -> so that everything is taken care
in terms of classes since it's
24941.368 -> completely object-oriented
programming language, right?
24945.077 -> So Java has a class dedicated
to each of the Primitive types.
24949.2 -> These are known
as wrapper classes
24950.9 -> because they wrap
the primitive data type
24952.9 -> into the object of that class.
24954.5 -> All right, so you could see for
bite you have a wrapper class
24957.8 -> corresponding wrapper class as
bite with starts with capital.
24961.5 -> Be all right,
24962.7 -> since it's a class it has
to start with uppercase
24965.8 -> or it has to follow
camel casing short
24968.8 -> has again short int has
integer long has long float.
24973.9 -> You could see
a corresponding wrapper class
24977.1 -> with name float double
24978.9 -> will have double character
CH AR will have character
24983 -> which starts with a bouquet
see again Boolean again has
24987.021 -> camel cased Boolean
as its wrapper class.
24990.1 -> All right, so
24990.927 -> when it comes to classes
you could have hierarchy.
24994.176 -> So basically you could see
24995.9 -> that all this byte short integer
long float double.
25000.33 -> Everything is subclassed
from number.
25003.1 -> So basically in the source code
25004.9 -> that we saw for integer
you could see
25007.437 -> it's extending number right?
25009.1 -> So that's what it is saying
here is a subclass
25011.7 -> of number integer is
a subclass of number.
25015.2 -> So how do we
reduce wrapper class?
25017.8 -> It's basically you just have
to pass value to it.
25021.3 -> You could have as
a part of Constructor,
25023.8 -> you could pass some kind
of value to it.
25026.8 -> So you could either assign value
of hundred right
25030.492 -> or you could have something
like Something like this.
25036.6 -> Okay.
25036.8 -> So you have different
variants of it.
25038.6 -> You could either create
it directly assign
25040.898 -> literal value to it,
25042.099 -> or you could have
something like this but
25044.752 -> as you could see
this is deprecated.
25046.811 -> This is no longer required.
25048.4 -> Actually.
25049 -> It is still accepting it.
25050.512 -> It's not throwing
compile time error,
25052.659 -> but it's deprecated.
25053.836 -> Which means if you're
writing a new code,
25056.2 -> you shouldn't be
writing it this way.
25059.1 -> So there's also concept
of Auto boxing
25061.696 -> which is nothing but
25063.1 -> if you have like integer a could
be assigned value K directly.
25068.6 -> All right, or could be assigned
value J directly.
25071.9 -> So it could be converted
from wrapper class
25074.9 -> into your primitive type
without any kind of conversion.
25078.7 -> That is known as Auto boxing.
25080.846 -> It does it by itself?
25082.4 -> What is generic in Java generic
is nothing but template in C C++
25087.3 -> in C++ rather you have
you define a template
25090.748 -> which is which is a general.
25093 -> Thing you're not putting in
25094.7 -> a specific data type
you are saying
25096.4 -> that this is what it is.
25097.6 -> It's a template
25098.64 -> and you could have
any data type during runtime.
25101.9 -> So basically what you're trying
to say is this particular method
25106.1 -> or this particular class
is a generic class,
25109.4 -> which could handle any data type
that is passed.
25112.799 -> So it's not specific.
25114.4 -> All right.
25115.392 -> So generics in Java is similar
25117.7 -> to templates in C++ generique
enabled type parameters
25122.2 -> when defining classes interfaces
and methods, right?
25126.3 -> So the type parameter is nothing
25128.265 -> but a generic type
and it's not saying
25130.7 -> that it's going to deal just
with integer or with character
25134.4 -> or with string.
25135.445 -> It is saying that it
could handle anything
25138.249 -> that comes anytime
that you would send it any type
25141.7 -> that you would instant.
25143.265 -> She ate that class with.
25144.9 -> All right.
25145.935 -> So when we take example,
25147.834 -> you should get some more idea
about this generate
25151.484 -> provide compile time.
25153.1 -> Type safety allowing programmers
25155.391 -> to catch invalid types
at the compile time.
25158.4 -> So generics work
on type Erasure,
25161 -> which is nothing
but which is done
25162.9 -> at the compile time itself.
25164.5 -> Basically, it's done
at the compile time.
25166.563 -> It can catch exhibitions
during the compile time itself,
25169.4 -> or it could prompt you during
the compile time itself, right?
25173.092 -> We can specify the type
the angular brackets.
25175.8 -> So whatever type you want to do,
25177.4 -> whatever type is
that class going
25179.8 -> to handle we can put it
into angular brackets,
25183.2 -> which makes it generate right?
25185.2 -> So here you could see
25186.554 -> that this is a method
which is print array
25189.2 -> which is taking e as type.
25190.92 -> So as you could see
he is the type here.
25193.7 -> All right, he is a type here
and we are not mentioning
25197.343 -> that it is going to take
print integer array
25200.1 -> or string array
or something of that sort.
25202.683 -> We are seeing that it generates.
25204.624 -> So whatever you pass
25205.912 -> or whatever you
instantiate it with
25208.1 -> it's going to take that array
and print elements within it.
25212 -> All right, so this Method
could be thought
25214.411 -> of as a generic method,
25215.798 -> right you could think
25217.065 -> of this printer as
a generic method not a method
25219.9 -> which is just taking integer
and printing it.
25222.1 -> It could be string array
or it could be anything else.
25225.5 -> So that's what
generic means advantages
25228.184 -> of generics type safety objects
25230.33 -> or single type can
be stored in generics.
25233.1 -> We would be looking at it
25234.662 -> in the next example
typecasting is not required.
25238.2 -> There is no need to type casters
25239.8 -> because it knows
that what kind of objects
25242.3 -> that particular data
structure would carry
25244.8 -> or hold compile time checking
it checks type mismatch error
25248.5 -> in compile time,
25249.518 -> which avoids runtime errors.
25251.3 -> All right.
25252 -> So imagine a list
25253.7 -> which we are going to talk
in further slides what is list,
25257.1 -> but imagine a list
which is a collection.
25259.9 -> All right, and you have
like imagine a list
25262.982 -> which is holding strings.
25264.866 -> All right, so you have list
25266.907 -> dot add and you you
add a direct cut to it.
25270.4 -> Now when you get 0 typically
25272.6 -> get Zero would have object
the return type would be object
25277 -> since it doesn't know
25278 -> that it is just carrying string
know where you have mentioned
25281.1 -> that it is a string of
25282.662 -> it's a list of string right?
25284.651 -> It's a generic list
25286.006 -> so it could hold
integer value as well.
25288.674 -> Alright, so in that case,
25290.361 -> what you need to do is
when you do list dot get 0
25293.6 -> you have to Typecast
to the string here.
25296.145 -> The next element
could be integer.
25298.273 -> We don't know right
25299.5 -> since we haven't said
that it's a list of string.
25302.3 -> So that's that the reason you
need to have typecasting done.
25305.8 -> All right now using
generics you could Define
25308.789 -> that this list is
a list of string.
25311.1 -> All right, it's going to carry
only string nothing else.
25314.5 -> It's going to hold now.
25316.1 -> It makes it simple right
you add either a car now.
25319.142 -> If you try to during
the compile time itself,
25321.992 -> if you try to add
integer to it,
25324 -> like list dot add hundred.
25325.8 -> It would throw an error saying
25327.3 -> that it cannot pulled integer
because it's meant for string.
25330.8 -> So that's the advantage
that you get over.
25333.1 -> Rick's you could hold it
you could catch errors
25336.266 -> during the compile time itself.
25338.6 -> All right, so it
won't allow you to add
25342.2 -> or it won't allow
you to put a hundred
25344.746 -> in to your list of string.
25346.573 -> All right, and
25347.538 -> since we know it's going to hold
only string there's no need
25351.607 -> of typecasting it as well.
25353.46 -> You can see here.
25354.582 -> It's not typecasting it
25356.1 -> in this case you had to put
this string here, right?
25360 -> So basically in this case,
you need not type custard.
25363.3 -> There's no type
question required
25364.9 -> because we know it's
a list of string now
25367.3 -> what a collection Frameworks
collections framework is nothing
25371.2 -> but you have data structures
in terms of classes.
25375.2 -> Again, it's a wrapper
for data structure.
25377.7 -> All right, it's nothing
25379.1 -> but like you have array which is
normal primitive arrays,
25383.1 -> but this one would be
sort of growing array.
25386.2 -> So basically you need not take
care of actually,
25389.5 -> you know adding
up indexes to it.
25391.7 -> It would automatically It's
a self growable array.
25395.3 -> So you could imagine
25396.7 -> when it comes to array you
could imagine collection.
25399.9 -> You could imagine
one of the classes
25402.295 -> within collection is list,
25404 -> which is nothing but growable
array of any data type.
25407.8 -> All right,
25408.3 -> so Java Collections framework
provides an architecture
25411.9 -> to store and manipulate
a group of objects
25414.9 -> or Java Collections framework
includes the following it
25418.1 -> has interfaces classes
25419.615 -> and algorithm interfaces is
nothing but again specification.
25423.678 -> This is how it should be.
25425.371 -> So Java says that you know,
25427.2 -> when you have a list it
should have so-and-so methods
25430.4 -> like adding to the list setting
25432.269 -> to the list removing
25433.455 -> some elements to the list
something of that sort.
25436.4 -> So it defines collection
you have a collection you
25439.708 -> should have so-and-so methods
25441.6 -> and list should have so-and-so
methods and so on and so forth.
25445.4 -> So basically it's for
specification classes is nothing
25448.682 -> but concrete implementation
25450.354 -> so list by itself would have
Would have all the methods
25454.511 -> that you just the it's
an interface, right?
25457.123 -> So it would have all the methods
25459.1 -> that you want
without any implementation.
25461.705 -> But this classes
would be actually
25463.8 -> implementing it or rather.
25465.568 -> It would be
implementing this interfaces
25468.222 -> and would be giving a concrete
implementation for methods.
25472.2 -> Right?
25472.7 -> So as you could read here,
25474.7 -> it's concrete implementations
of collection interfaces
25478.579 -> in essence.
25479.379 -> They are reusable
data structures,
25481.7 -> right algorithm is nothing
but there are utility algorithms
25484.905 -> that you have like
25485.903 -> if you want to sort
a particular collection or
25488.4 -> if you want to sort a list list
of string you could do it using
25492.589 -> using your algorithm using
a predefined algorithms
25495.9 -> that already comes
pre-loaded with Java.
25498.4 -> All right when I say algorithms
25500.525 -> and where are
these algorithms residing?
25503.183 -> It is a class
which is collections.
25505.5 -> So you have a collection
25507.057 -> which is an interface
top level interface
25509.879 -> and you have a collections class
which is class.
25513.094 -> Which is holding all the
utility methods or algorithms,
25516.596 -> whatever you call
25517.7 -> who basically you could just
read through this hierarchy.
25520.77 -> These are different types
of data structures
25523.3 -> that has been supported by Java.
25525.4 -> You have a collection.
25526.9 -> So the top level interface is
25528.9 -> as you could see
there's collection,
25531.038 -> which is extending
I treble all right,
25533.372 -> extending iterable interface
collection itself is
25536.5 -> an interface you have
a list as interface,
25539.6 -> which is extending collection.
25541.3 -> All right.
25542.1 -> So list is extending collection
Q is extending collection set
25546.8 -> is extending collection.
25548.417 -> So we have three distinct type
25550.4 -> of data structures
Year's list queue
25552.757 -> and set list is nothing but you
could say it's a ordered one,
25556.8 -> right it maintains
the insertion order write
25559.9 -> the order in which you
inserted data into the list
25563.3 -> Q is nothing but
first in first out
25565.849 -> and whatever you push in
first would come out first
25569.6 -> and set is nothing but To sit
in mathematical form right over
25575.4 -> in you have unique values.
25577.2 -> You cannot have
duplicate values.
25578.8 -> So that's what set is
but it's it need not be ordered.
25582.5 -> It need not maintain
the insertion order, right?
25585.8 -> So you have the concrete
implementations for list
25589.4 -> our array list,
25590.6 -> which is nothing
but again similar to array
25593.432 -> that we have right
the normal primitive array
25596.4 -> that we use.
25597.304 -> So it's a wrapper class for it.
25599.524 -> We have a linked list.
25601.1 -> Alright, so this linked list is
nothing but doubly linked list.
25605.259 -> All right, so you could insert
from you could Traverse
25608.815 -> the either direction you
have Vector as well
25611.7 -> which is which is Legacy Forum,
25613.833 -> which is not used
to that extent yet as of now.
25617 -> So we have vector
and we have a stack
25619.845 -> which extends this Vector
redstack is nothing
25623.4 -> but last in first out
25624.9 -> and it adds some more capability
on the top of this Vector,
25628.8 -> which is nothing
25629.808 -> but it's a subclass of Victor.
25631.7 -> All right, so these
are Implementations
25634.1 -> of list we have a Q and
as you could see here,
25637.638 -> there's one interface
here DQ which is nothing
25641.1 -> but it is extending Q. Alright
25643.9 -> and we have an array D Cube
which is implementation of TQ.
25648.3 -> All right.
25648.931 -> It's a class which is
implementing DQ interface.
25651.9 -> All right, this is
a priority queue as well,
25654.3 -> which is a class
which is implementing Q
25657.163 -> when it comes to set
we have a sorted set
25660.211 -> which is again an interface
which is extending set
25663.8 -> and as you could see
there is a tree set,
25666.311 -> which is a concrete
implementation of sortedset
25669.2 -> and it sorts the element
that you put into a set.
25672.4 -> It sorts it into
a specific order.
25674.6 -> All right, again,
25675.7 -> the concrete implementation
of set f is our hash set
25679.3 -> which is nothing but
which does some kind of hashing
25682.46 -> which is a default
implementation of set
25684.8 -> and which doesn't
maintain insertion order
25687.627 -> as set is nothing
25688.8 -> but it is indexed
to for fast reversal
25692.3 -> or Want to go get
something out of a set,
25695.174 -> its kind of indexed set.
25696.9 -> You could say right it has
buckets and everything.
25700.148 -> It follows hashing algorithm,
25701.936 -> right which is
25702.8 -> which is basically for indexing
25704.6 -> or which is basically meant
for retrieving data faster
25707.8 -> from the hash set from the set
and that implementation.
25711.3 -> That's the default
implementation which is
25713.533 -> has said, all right,
25714.598 -> there is a linked hash set which
maintains the insertion order.
25717.864 -> All right.
25718.488 -> This has said doesn't maintain
the internet insertion order.
25721.6 -> So if you put X & Y
into your hash set
25724.4 -> and if you retrieve it or
if you Traverse through it
25727.743 -> and print the values,
25729.166 -> it's not mandatory
25730.327 -> that you would get X
and Y in the same order
25733.1 -> whereas in the linked has set
its pretty much you could be
25736.956 -> a hundred percent sure
that X would come
25739.339 -> before why all right.
25740.541 -> So it maintains insertion order
what is less list has
25743.8 -> nothing but an ordered
collection of elements
25746.3 -> which can contain
25747.397 -> duplicate son like sect
it can contain duplicates,
25750.672 -> but it has ordered an unlike say
State has ordered write lists
25754.7 -> are further classified into
following arraylist linked list
25758.3 -> and vectors, right?
25759.6 -> So based on the use case,
25761.9 -> you could select one
of these data structures.
25764.883 -> Let's talk about array
list arraylist is nothing
25768 -> but similar to arrays
25769.4 -> that we had and here you
could see element stored
25772.728 -> within of size 5-a released
25774.6 -> of size 5 and you could see
value stored within right.
25778.687 -> So this is how you instantiate
25781 -> an arraylist array list object
is equal to new arraylist
25784.996 -> and you have an arraylist
created one of the main things
25789.142 -> about arraylist is
25790.5 -> as I said itself growable
25792.422 -> or its Dynamic you unlike array
the normal primitive array
25796.8 -> where in you had to
within your square brackets,
25799.798 -> you had to mention
the size of the array
25802.193 -> during the Declaration itself.
25803.9 -> Whereas in Array list,
25805.4 -> you need not have
to mention this sighs.
25808.1 -> All right, it grows
by itself as then
25810.421 -> when you insert data
into it, it would go
25813.1 -> So basically you
could imagine a normal
25815.9 -> in general scenarios or in most
25818.2 -> of the programming cases or in
most of the real use cases.
25822.8 -> You don't know up front.
25824.459 -> What is the size of data
25826.05 -> that a particular array
is going to hold right.
25829.1 -> Now the number of elements
that a particular array
25831.708 -> is going to hold you
cannot know it up front
25833.981 -> because things
are Dynamic right?
25835.663 -> So suppose you are reading
from the database.
25837.975 -> You don't know what that size
25839.5 -> of the data or what what
are the number of elements
25842 -> that a particular database
is going to have.
25844.5 -> So typically you
25846.8 -> could imagine real cases
you would go with arraylist
25850.859 -> and not primitive arrays.
25852.9 -> All right.
25853.527 -> So also you could imagine
this is this is this is saving
25857.092 -> us in terms of memory
25858.5 -> because we are not hard
coding the values of it.
25861.7 -> So by default,
25862.8 -> it starts with 10 size of 10
and then it keeps growing as
25866.6 -> and when you insert it.
25868 -> So again, it has a logic it
doesn't keep going for each
25871.4 -> and every That you do
25873.4 -> but it has a logic
within to grow it
25876.057 -> by particular size.
25877.598 -> So which is all optimized
25879.521 -> which is good for your
for your cases use cases.
25884.7 -> So these are the methods
that we have within our A-list.
25887.5 -> It's very straightforward.
25889.1 -> When you do add it
appends the specific.
25891.792 -> It's usually add and
not collection for collection.
25895.3 -> You have a doll methods.
25896.957 -> So it's a typo here
you have ad and
25899.504 -> you you mention an element
25901.3 -> that you want to
insert into a list
25903.5 -> if it's a string you would have
25905.695 -> string string element or
if it's something else
25908.9 -> if it's an integer,
25910.1 -> you would have integer element
you could add it
25912.729 -> to a particular index you
25914.2 -> could clear it removes
all the elements
25916.4 -> from the list you
could have last index
25918.7 -> of a written the index of
this list of the last occurrence
25922.426 -> of the mentioned object.
25923.963 -> So if you have multiple
25925.444 -> as we said they could be
duplicate values within but
25928.684 -> when you give last index of
it's giving you the last index
25932.871 -> All right last index
of the object
25934.912 -> that's been passed
you could clone it.
25937.7 -> So it's basically coming
clone is nothing but a method
25940.9 -> that they're within
your object class
25943.7 -> and it would shallow
copy the array list.
25946.3 -> So whatever list you have
there would be a clone of it.
25949.7 -> Right so clone is
as we could see it's
25952.276 -> it's it's from the object class.
25954.42 -> So any class that you
create could be clone.
25957.3 -> All right, then
you have to array
25959.287 -> so you could have
an array list and
25961.406 -> if you want to convert it into
a primitive array and use it
25965.038 -> in some form you could do
that thing as well
25967.795 -> by doing two array you
could trim to size.
25970.5 -> So trim to size is nothing
but prims the capacity
25973.7 -> of this array list instance
to the list current size.
25977.3 -> All right.
25977.931 -> So whatever is the size
25979.32 -> it would trim to that so
moving on let us understand
25982.4 -> how we can Traverse
through a list of collection.
25985.4 -> So travel cell is done
through I traitor interface.
25988.945 -> Okay.
25989.3 -> So basically you have
a nitrate interface and that's
25992.3 -> how you Traverse it.
25993.7 -> Basically you have
implementations of it
25996.057 -> since it's an interface
it is it is just
25998.455 -> the specification you would have
an implementation of it.
26001.9 -> So I traitor is an interface
that I traits the elements.
26006.053 -> It is used to Traverse
The Collection access
26009.494 -> the data element
26010.7 -> and remove the data elements
of the collection.
26013.187 -> All right, it's used
for traversal as well
26015.517 -> as removal of data elements
within the collection.
26018.4 -> Okay.
26018.703 -> So what are the methods
26020.1 -> that we have within I
traitor first is has next.
26023.2 -> So it's it's nothing
26024.376 -> but as you could imagine
it is written in Boolean.
26027.1 -> So if it has a next element
it would return you true.
26030.8 -> Okay, and if it doesn't then
26032.8 -> if the arraylist
is already exhausted
26035.402 -> then it would give you false.
26037.5 -> So you would I basically
26038.9 -> would have a loop
wherein you would see
26041.1 -> if it has a name next right
26043.116 -> and if it has next you could
This is the next element
26047.2 -> using next Method
26048.6 -> All right, so next
would return the actual object
26052 -> and to remove it you
could do I treated or remove
26055.5 -> which removes the last element
written by the I traitor.
26059.8 -> Alright, so here you could see
26061.3 -> how I treat her
is being used you
26063.56 -> have you declare an array list
26065.676 -> and you you I trade through it
26067.791 -> and you print the elements
so quickly we can take this.
26074.2 -> So basically I do
calm dot edu Rekha dot I
26080.5 -> create one more package
now for arraylist.
26083.4 -> Okay, Isaac collections,
demo dot array list.
26092.5 -> All right, so I have this
particular class created now.
26096 -> I create a main method
and I create private void.
26105.2 -> I write a method
26106.5 -> which is create
array list for demo.
26110 -> All right,
26110.769 -> as you could imagine
when I see create it's going
26113.8 -> to return an arraylist.
26116.4 -> All right, we want
it to return list.
26119.8 -> Okay, what I do here
is I would create list
26124.1 -> and this list is going
to be list of string.
26127.9 -> Okay, imagine generic
26129.5 -> that we spoke
about you are saying
26131.5 -> that it is going to be
list of string now,
26133.8 -> it's three mirrors saying
which list I want it's going
26137.186 -> to be Java dot util
26138.4 -> so you could see Java
dot util doll wrist here.
26141.5 -> Now.
26142.2 -> I say it's strings dot new.
26145.661 -> I didn't list.
26149 -> You're saying that here
26150.642 -> what we are doing is
we are instantiated.
26153.9 -> So we have a list of strings
and we are instantiated it
26157.602 -> since we want arraylist.
26159.277 -> It's going to be a release.
26161.161 -> So here you could see array list
being imported as well.
26165.3 -> All right.
26165.8 -> Now what we are going
to do here is we are going
26168.2 -> to add some values
to it strings dot add
26171.8 -> or maybe I will put again
26174.9 -> since we have been
talking about cars
26177.6 -> and bikes I will cars right?
26179.961 -> So we are creating
here cars list of car.
26183.1 -> All right, so I
put BMW But what?
26193.2 -> all right, so all German cars
and then we Then we written it.
26199.8 -> We are returning this.
26200.9 -> So we are creating a collection.
26202.3 -> Right and we are
inserting data into it
26205 -> and we are returning it.
26206.2 -> All right, so this would create
a list for me right now.
26209.6 -> I want to I trade
this list, okay.
26213.788 -> So I create a private method
which would return void
26217.8 -> and which food print
arraylist or demo.
26224.3 -> All right.
26225.043 -> So as you could imagine
26226.788 -> this is going to take
a list as parameter.
26229.9 -> All right list list
to be printed
26233 -> or it's pretty much implicit
26235.8 -> or implied that list is
whatever list you pass
26239 -> as a parameter is going
to be taken for printing.
26242.199 -> Okay.
26243 -> So here what I would do
is list dot I traitor
26247.3 -> I take the I traitor.
26249 -> Okay, so I get
the list I traitor
26252.2 -> I say I traitor and it's a list
26256.6 -> I traitor All right.
26258.7 -> So I take this list I traitor
26260.9 -> and I say list right
26262.9 -> while while it has
any elements within so,
26266.9 -> how do we check with
26268.017 -> whether it has elements
within is nothing but dot
26270.7 -> has next if you remember
26272.2 -> while it has any elements
within what we are going
26275.3 -> to do is we are going to print
out print the value the list.
26281.7 -> Alright, we are going to print
it using I traitor dot next.
26287.7 -> Okay.
26288 -> So I've created two methods one
is create a released for demo
26291.036 -> and the other one
is print arraylist
26293 -> for demo create arraylist
is doing nothing,
26295.5 -> but it's creating a list
26297.1 -> and it is returning the list
26299.012 -> and printer a demo
is printing the list
26301.76 -> that you have passed
as a parameter.
26304.2 -> Okay, so I create
26305.9 -> a new element of array list
demo dot create arraylist.
26313.2 -> All right,
26314.2 -> and whatever I realize
that I get over.
26317.5 -> Will is that I get I
would be putting it here.
26323.4 -> Right now I create
one more this and I print it.
26329.5 -> All right.
26330.1 -> Now when I print it
I am going to pass
26332.546 -> this returned array list.
26334.2 -> All right, I think
it's pretty clear now.
26336.513 -> So we have created
a released in this method
26339 -> and we have returned it
26340.241 -> and in the second case we
are just going to print it.
26343.3 -> We are going to take
any array list
26345.35 -> and we are going to print it.
26347.056 -> All right.
26347.8 -> So let's see.
26349.3 -> So rest of the collections most
26351.248 -> of the collections you do
it pretty much similarly.
26354.356 -> It's just that you know,
26355.848 -> it's used for
different use cases.
26358.092 -> All right, I am getting
some error I think okay.
26361.876 -> Yeah, you could see here.
26363.8 -> It has printed BMW Mercedes
26365.853 -> and Audi which we had put
into the arraylist.
26369.2 -> Alright, so that's
26370.273 -> how you kind of
I trade through it.
26372.4 -> Similarly.
26373.2 -> You could just remove it.
26374.9 -> You could use list I traitor
26377.3 -> Don't remove will remove
the current element
26380.331 -> that's penetrated.
26381.7 -> All right.
26382.5 -> So yeah, this is I
don't need to actually
26385.1 -> create one dot remove
you could remove it.
26388.6 -> All right Drew.
26390.5 -> So that's how you remove it
if you want to so you
26393.59 -> you have the same syntax.
26395.2 -> So basically we don't use
I traitors nowadays more.
26398.578 -> It's more about we have Java 8
there are different constructs.
26402.7 -> Like we have Lambda
expressions and stuff.
26405.3 -> We have screams
stream processing,
26408 -> which is you have I traitors.
26411.1 -> All right.
26414 -> So this is what we have
we have a hydrator,
26416.707 -> which is I creating
through all the elements right
26419.59 -> and you could remove
it as well using
26421.6 -> the I traitor usually nowadays.
26423.6 -> We use Java 8 streams
26425.5 -> which helps us to I'd rate
through which is pretty much
26428.676 -> like the underneath is I traitor
26430.558 -> and stuff but there
are some some kind
26432.735 -> of abstractions done
26433.82 -> so that we don't
actually deal with
26435.67 -> I traitors there's
some kind of abstractions
26438.2 -> are it's less verbose
in this case.
26440.222 -> You have to write a lot of code
to print through and everything.
26444.123 -> Whereas in streams.
26445.3 -> It would be just one method call
26447.4 -> which would do lot
of things right.
26449.4 -> So that's what has
been used as of now,
26452.2 -> but this should be good enough
to start off with to understand
26455.5 -> the basics of it.
26456.6 -> Alright other thing
is I was talking
26458.658 -> about the best practices.
26460.1 -> So it's good to have things
broken down in methods.
26463.1 -> So that could reuse it rather
than putting everything
26466.158 -> into the main method
which makes it difficult
26469 -> for any other developers
to understand mode.
26471.885 -> So basically it's
a good practice.
26474.1 -> Make it modular,
26475.23 -> right and which enables
reusability as well
26478.2 -> which reduces the lines
of code within your program.
26481.7 -> So tomorrow if I
have some other list,
26484.032 -> which I want to I trait I
can just pass the list to this
26487.5 -> and it would right fit
and give me the results.
26490.002 -> So I don't have to write
the same piece of code again.
26492.864 -> Alright, so moving on
26494.1 -> so we have a released arraylist
is nothing but abstraction done
26497.656 -> on a primitive array.
26498.923 -> So what are the advantages
of using array list?
26501.7 -> It's more about it's faster
26503.5 -> in terms of retrieval right
index based retrieval suppose.
26507.379 -> If you want to get
to the index to just write
26510.374 -> like arraylist get
26511.6 -> to and it would give
you the one at the end x
26513.8 -> 2 or the element
at the index to whereas
26516.481 -> when it comes
to insertions and deletions.
26519.3 -> If you want to insert
a particular object
26522.4 -> at index 2 what it has
to do is it has to move
26526.4 -> that was there at the index
to to the index
26529 -> 3 and it has to increment
the entire array by one
26532 -> or move to the right by Position
which is pretty cumbersome,
26535.917 -> right which takes a lot
of time so insertions
26538.585 -> and deletions are not good
when it comes to arraylist,
26541.752 -> whereas when it comes
to retrieval it's faster.
26544.5 -> So based on the use case
you have to decide
26546.9 -> which data structure
you should go for right?
26549.849 -> So simply put we think
of Big Data applications.
26553 -> It's mostly about you don't have
insertions and deletions
26556.455 -> as such it's not transaction,
26558.2 -> right but typical
online transaction processing
26561.5 -> this thing would be
application or say,
26564.1 -> for example, you have Amazon
right Amazon or something
26567.217 -> where in you have a lot
of transactions happening
26569.8 -> which needs insertions
and deletions right
26572.4 -> in that case arraylist
is not a good option.
26575.333 -> Whereas in terms of big data,
26577.244 -> which is like analytics right
online analytical processing
26581 -> which doesn't have
transactions as such right.
26583.447 -> It doesn't have
insertions and deletions.
26585.8 -> It is one-time load
you have data you load it
26588.335 -> into your data structures and
you do some kind of processing
26591.6 -> or you do some kind
of analytics on This data,
26594.9 -> but you don't
manipulate this data.
26597.2 -> You don't actually have
26598.8 -> insertions or deletions
done in such cases.
26601.599 -> It's better to go
with a realist.
26603.7 -> All right, so
26604.448 -> which is a variant which is good
for insertions and deletions
26607.978 -> that is linked list.
26609 -> All right, when it comes
to insertions and deletions
26611.7 -> and you want to maintain
26612.9 -> the order of the list
insertion order of the list.
26615.662 -> That's when you would go
with linked lists.
26618.196 -> All right.
26618.8 -> So linked list is
a sequence of Link's
26621.1 -> which contain items
each link contains connection
26624.105 -> to another link and that's
26625.678 -> how insertions and
deletions are simpler.
26628.1 -> You don't have to shift
elements to the right
26630.3 -> when you insert it
26631.3 -> or you don't have
to shift elements the left
26633.588 -> when you delete it.
26634.6 -> There are two types
26635.563 -> of linked lists to store
element singly linked list
26638.1 -> and doubly linked list singly
linked list is nothing
26640.9 -> but it has pointers
26642.017 -> in One Direction
doubly linked list is
26643.911 -> like it has previous
and the next its stores.
26646.586 -> Both each node would store
previous element pointer to
26649.807 -> the previous element
and the next element.
26652.7 -> So yeah, this is a singly
linked list wherein you see
26655.3 -> that it has pointed to the next.
26657.5 -> It doesn't have pointed
to the previous one, right?
26660.3 -> It's a one directional
traversal, right?
26664 -> Whereas in doubly linked list,
26665.5 -> you could see
that it is looping back
26667.3 -> to the previous element as well.
26668.925 -> So it has a pointer to the next
26670.5 -> and it has pointed
to the previous one.
26672.8 -> It's a bi-directional traversal.
26675.3 -> So linked list has
pretty much similar
26678 -> to arraylist you have ad you
could add a particular object.
26682 -> You could check
26682.779 -> whether a particular object is
contained within the linked list
26686 -> and that object has to be passed
as a parameter to contains.
26689.3 -> You could add a certain element
at a particular index.
26692.8 -> You could add it to the
to the head of the list you
26695.3 -> could add to the last you could
check the size of the list.
26699.048 -> You can remove the element
from the list and you
26702.011 -> could get the index
of a particular element
26704.624 -> so you could pass some element
and get the index of it
26707.811 -> since linked list is again,
26709.458 -> it can have duplicate elements.
26711.387 -> If you want to get
the last index
26713.353 -> of a particular element you
could do that thing as well.
26716.607 -> So if you have
multiple elements,
26718.5 -> you would get the last one
right the index of the last one.
26722.1 -> So linked list example
here you could see
26724.311 -> that a linked list
of string is being created
26726.9 -> and you add values to it,
26728.8 -> which is fragile Rahul
26730.441 -> and Richard you
add things to it.
26732.853 -> And and yeah,
26733.832 -> this is just about adding
elements to the list.
26737.3 -> All right.
26738.8 -> So arraylist versus linked List
released internally uses
26742.2 -> Dynamic array to store
the elements since I said,
26745.158 -> it's Groove able it grows
26746.764 -> on its own linked list
internally uses doubly
26749.582 -> linked list to store
the elements to add an element
26752.815 -> in between or to
remove an element
26755.064 -> from the array list slow
26756.7 -> because it internally uses array
26759 -> if any element is removed
from the array list,
26761.7 -> then the rest of the elements
should be shifted to the left.
26765 -> All right, similarly
26766.193 -> when you add something
to the list you have
26768.7 -> to move everything
to the right adding an element
26771.6 -> in between or removing
26772.7 -> an element with linked list
is faster than arraylist
26775.7 -> because it uses
doubly linked list.
26777.588 -> So no element shifting
is required, right?
26780 -> You don't have
to shift any address.
26781.822 -> Or something.
26782.5 -> It's just about
moving the pointers.
26784.4 -> Right?
26784.9 -> So you would just move
it skip one element
26787.498 -> and move to the next in
terms of deletion.
26789.982 -> Whereas in terms of insertion,
26791.8 -> you would insert a node
26793.1 -> and you would manipulate
26794.3 -> the pointers according
T. Alright arraylist
26797.4 -> can act as a list only
it is normally for list
26801.8 -> but linked list could be thought
of as a list as well as Q right
26806.3 -> since it's a doubly linked list
you could have like first-in
26809.5 -> first-out arraylist is better
for storing and accessing data.
26814.9 -> All right.
26815.557 -> So as I said,
26816.389 -> this is pretty much good enough
for analytical sort
26819.5 -> of application analytical
nature of application.
26822.4 -> Whereas when it comes
26823.635 -> to transactional linked list
would be better.
26826 -> So linked list is better
for manipulating data
26828.8 -> and it is slow
in searching an element
26830.829 -> because it needs to compare
the elements from the first note
26834.3 -> when it comes to you know,
26836.299 -> index based search.
26837.761 -> It is slower
26838.523 -> because it has to start
all the way from the start.
26841.7 -> Was it goes through links?
26843.4 -> Right?
26843.762 -> It has links to next
element and that's
26845.941 -> how it traverses through
vectors are similar to erase
26850.1 -> but the Legacy form of it.
26851.9 -> It's a dynamic array again
similar to arraylist.
26855.3 -> All right, it could be
visualized very much
26858.2 -> similar to array list,
26859.999 -> but just that it's
a legacy of java.
26862.8 -> It's not used to that extent
26864.7 -> or I would say it's not used
at all at this point.
26868 -> But what is important to note
is Vector is synchronized
26871.491 -> when it comes to multi-threading
it's better to go with Vector,
26875.6 -> but nowadays we have
concurrent arraylist arraylist
26879.095 -> that is supporting concurrency.
26881.3 -> So there are a lot
of optimized versions of it
26884.248 -> which gives lot
of performance Improvement.
26887 -> So vectors are no more used
as such an industry.
26890.4 -> It's a Legacy form of arraylist.
26893.3 -> There are concurrent
versions of arraylist
26895.931 -> that that has been evolved
26897.6 -> which could be used
in multi-threaded applications.
26900.4 -> All right, Victor.
26901.759 -> Contain many Legacy methods
26903.8 -> that are not part
of collections framework.
26906.442 -> So it doesn't even fit
into collection framework
26909.4 -> because it contains
some Legacy methods
26911.912 -> which are no longer used
26913.5 -> or which are not part
of collection framework at all.
26917.4 -> Now Vector is again taken
into collection framework
26921.246 -> and it implements list
26923.4 -> and that's the reason it
has the implementation
26926.4 -> for this methods
26927.4 -> because this methods are
typically coming from collection
26930.3 -> and list collection interface
26932 -> and list interface and all
the concrete implementations
26935.425 -> have to implemented.
26936.638 -> And since Victor is
26937.756 -> one of the concrete
implementations of list.
26940.352 -> They have to ensure
26941.5 -> that they Implement
these methods as well.
26944.4 -> All right.
26944.953 -> So these are the methods
pretty much similar to
26947.5 -> what we spoke earlier
add clear and add
26950.3 -> to a particular index remove
26952.05 -> and then you could have size
26953.8 -> and you could have last index
of and last index of object.
26957.6 -> So it's a vector of string
then you add element you add.
26961.7 -> Issued fun and Kumar and you
just write great
26964.822 -> through it to print out
the message from a chiffon
26968.3 -> and Kumar would be the output
of this application
26971.6 -> or this program.
26973.4 -> All right, so you could see
I traitors use here as well.
26976.8 -> Like we did it in list.
26979.8 -> So let's talk about QQ is
nothing but first in first
26983.2 -> out whatever goes
26984.34 -> in first would be first to come
out a priority queue allows you
26988.5 -> to initialize the queue.
26990.2 -> These are implementations of Q.
26992.4 -> So you have
a priority queue you have
26995 -> as we said linked list is
list as well as Q so you
26998.6 -> could have linked list assigned
to a queue right linked list
27003.9 -> is the list and linked list is
a queue right is a relationship
27008.3 -> which means it's
extending it right.
27011.1 -> So here we can see double
ended queue lets you to a door
27015.8 -> and remove so double-ended
interface DQ DQ interface
27020.743 -> allows you to Add
27022.1 -> and remove elements from Peak
as well as from the bottom.
27025.6 -> That's what DQ is
double ended queue,
27028.475 -> right and array d q is nothing
but the concrete implementation
27032.5 -> of DQ EQ is an interface
27034.5 -> and the concrete
implementation is array d
27037.3 -> q.
27038.1 -> So what are the Q
& DQ methods you have ADD method
27041.9 -> which is nothing but it adds
to the top of the queue
27045.2 -> and it returns a Boolean
27046.4 -> as you could see here
if it is successful
27048.4 -> if it has added
to the top of the queue
27050.933 -> it would give you true.
27052.5 -> And if not,
27053.284 -> then it would give you
false right you have offer
27056.614 -> which inserts the specified
element into the queue again,
27060.733 -> it does the similar stuff.
27062.6 -> It inserts to the cube.
27064.4 -> All right, you have removed
27066.1 -> which removes the head
of the queue we have pull
27069.3 -> which retrieves and removes
the head of the queue again.
27072.6 -> It does the same thing retrieves
27074.338 -> and removes the head
of the queue and returns null
27077 -> if the queue is empty.
27078.4 -> All right, bullying is nothing
but getting the top
27080.9 -> of the queue.
27081.8 -> And you have element
27083.9 -> which retrieves but
does not remove.
27086.2 -> All right.
27086.7 -> So when you do Q dot element
it would give you the top
27090.5 -> of the queue of the head
of the queue,
27092.676 -> but it would just give you
but it would still be there.
27095.577 -> So if you want to check value
that is on the top of the queue
27099 -> if you want to check it
27100.352 -> and do something with it
based on the value
27102.6 -> that is there on the top
of the list or top of the queue.
27105.7 -> If you want to perform
some actions we can do it
27108.4 -> using element Peak again does
the same thing it retrieves
27111.7 -> but it does not remove
the head of the queue
27114.1 -> if you want to actually retrieve
and remove the head
27116.9 -> of the queue you would
either use remove or pole.
27120.058 -> Basically you would use pole
27121.9 -> not remove right remove is
not a good operation to do
27125.4 -> when you want to retrieve
and do some actions on it.
27128.4 -> The best practice would be
27130.4 -> to use piec to retrieve and use
Pole to actually retrieve
27135.8 -> and remove Alright,
27139.4 -> so let's take an example of Q.
27144.676 -> So right here
in the package I create.
27149.9 -> Secretary main method, right?
27153.4 -> So I create private.
27157.4 -> Q v8q for demo All right,
27161.91 -> so it's asking me
which Q I will go with this one,
27166.2 -> which is Java dot util dot Q.
27169.2 -> All right.
27169.5 -> Now I am creating
27170.5 -> a new priority queue which is
a concrete implementation
27174.4 -> which would be say
for example of integer, right?
27179.3 -> So I create a queue of integers.
27181.946 -> So we are putting integers
within all right,
27185.6 -> and what we are doing is new.
27187.624 -> I am instance eating it.
27190.3 -> Alright, so this is a q
27192.2 -> which is going to
hold just integers.
27194.4 -> That's what Jen Rick's come
into picture, right?
27198.4 -> Queue of integers
dot add suppose.
27201.1 -> I put a hundred and then
I put ad could is used to
27206.4 -> as I said to insert
right and I put 50.
27213.2 -> So I've created a queue
and I written this Q.
27217.6 -> So I've created a q so far.
27219.611 -> Let me print this queue.
27222.569 -> Alright, so we have
27224.2 -> which is going to return void
and print queue for demo
27231.2 -> and which is going to take you.
27233.6 -> All right Q of Cl you
don't even put it here.
27240.9 -> I so now, let's see
27243.861 -> how we can retrieve elements
from it one way is
27247.4 -> to I trade through it
and let's see how pole
27250.882 -> and other things work right?
27254.492 -> So let me get the head
of the list.
27259.1 -> So this is just retrieving
it right retrieving
27261.999 -> head of the list.
27263.019 -> We are not removing it it is
still there in the queue.
27266.2 -> We are just trying
to check what it is.
27270.4 -> So when I say when it's
retrieving it speak right now
27274.4 -> if I want to remove it
27276.1 -> if I want to kind
of retrieve and remove it.
27281.5 -> So basically what I'm
trying to say here is
27283.996 -> when you have q dot Peak
it's going to return
27286.476 -> the top of the list
which is nothing but 50.
27288.9 -> All right.
27289.6 -> So the first one the peak
is just retrieving it.
27292.3 -> Whereas when I pull it
it's going to retrieve
27295.712 -> and remove as well.
27297.8 -> So I have q dot pole
is going to now
27303.8 -> when I do s out retrieve
27307.4 -> and remove Say this is
the first attempt.
27313.1 -> All right, and we again do it
which is the second attempt.
27317.3 -> This is just to show you
27318.813 -> that when you pull it it's
actually removing it as well.
27322.281 -> Whereas Peak is not removing it.
27324.3 -> All right.
27325.5 -> So Peak is just retrieving it
and this one is removing it.
27329.7 -> So the first pole
is going to give you 50
27332.9 -> whereas the second pole
is not going to give you 50.
27335.5 -> It's going to give you 200
27336.8 -> because it has removed
50 from the queue.
27338.8 -> All right, so this is
what I wanted to show.
27341.2 -> So let me Q demo Alright,
so here I'm going to do demo
27350.2 -> Dot.
27353.3 -> So when it comes to generic we
can make this generic Q program
27357.6 -> by doing something of this
27359.485 -> and instead of hard-coding it
you could put a Ste here.
27364.8 -> Right now, let's keep it as is.
27369.307 -> Alright, so the first case Q is
being created the second case.
27374 -> We are going to see
how we can pole works.
27378.9 -> Retrieving is just ringing
27380.7 -> and it is still
keeping that element
27382.993 -> at the top of the queue
27384.5 -> whereas polling is actually
removing it as well.
27388.8 -> All right, so you could see
here Peak is giving you
27391.541 -> the last one here.
27392.6 -> It's a double-ended one.
27393.841 -> So it's giving you
the last one here
27395.9 -> and pull is giving you this one.
27399.3 -> It's based on Friday.
27400.8 -> I think.
27402.4 -> All right, so you can see pole
27404.362 -> is giving you 50 as well
and when you pull it again,
27408.2 -> it's giving you a hundred.
27410.9 -> All right, let's move
on to the double ended queue.
27414.6 -> All right.
27415.3 -> So here we have something
like you could remove first.
27419.1 -> All right, you know,
27420.2 -> so it's a double ended queue
you could in fact
27422.8 -> in both the directions
you you could actually
27425.521 -> remove first and add to the last
27427.3 -> and stuff like that.
27428.3 -> So you could see here
27430 -> that there's a double
ended queue created
27432.6 -> with four elements initially
2142 63 and 84 and you could see
27438.769 -> that remove first is removing
27441 -> 4221 rather from here
since 21 is the first one
27445 -> so it's removing 21
and remove lost or add
27448.746 -> last it's adding to the last
27450.9 -> which is nothing but it's adding
hundred and five to the last
27455 -> So what is set is nothing but
27456.854 -> as we said it's a representation
27458.9 -> of mathematical set
which is unique
27461.726 -> which holds unique values right?
27464.2 -> You cannot have duplicate values
27466.2 -> within set set has
its implementation
27468.641 -> in various classes such as
hashtag preset and linked
27472.1 -> as set so it's
a mathematical set abstraction.
27476.1 -> We have variants of set in Java
27478.265 -> which is has said
linked hash set
27480.5 -> and we said hash set is
nothing but it hashes it
27484.1 -> or basically there's
this indexing done
27487 -> and it's good for retrieval
27488.636 -> as you could imagine
since it's indexed.
27491 -> It's good for retrieval.
27492.6 -> Okay.
27493 -> So the analogy
27494.2 -> behind this could be our it
is analogous to index page
27498 -> that you have in books,
27499.559 -> right you have
index page you just go
27501.949 -> to the index page and see
at what page is the content
27505.4 -> that you are looking
out for this one is
27507.7 -> pretty much similar to that.
27509.1 -> So when you do hashing
you would be able
27511.6 -> to retrieve it much faster
then sequential retrieval.
27515.6 -> All right, so that's
27516.835 -> what has said does and it
has unique values of course,
27520.098 -> which is a property of a set.
27521.848 -> You can't have
multiple values within
27524.099 -> or duplicate values within it
doesn't sort automatically.
27527.6 -> This is a typo here has set is
27530.6 -> acid doesn't maintain
maintain any order
27533.6 -> at all its internal to The order
27536.4 -> in which the retrieval would
be done is pretty much internal
27539.4 -> to the runtime or
what I mean to say is
27541.635 -> if you have a has set
with the same content
27544.128 -> and if you run it
multiple times you would see
27546.8 -> that the retrieval is different
in different instances.
27550.5 -> So it doesn't maintain
any order your application
27554 -> might demand something
or demand a data structure
27557.2 -> that is set as well
as it maintains just
27559.9 -> the insertion order right?
27562.2 -> That's a scenario
27563.2 -> in which you would go
with linked hash set.
27566 -> So link -
27566.8 -> there is nothing
but set which has
27569.275 -> its insertion order maintained.
27572 -> All right.
27572.7 -> So the third one is tree set,
27575.03 -> which is nothing but it
27577 -> so these are the methods
that gets inherited
27579.58 -> into hash set and but similar
to other collections
27582.594 -> that we have,
27583.423 -> but just to talk about this one
27585.4 -> so you have ad which is just
adding object into hazard
27590.1 -> or linked has set
you have contains
27592.9 -> which is basically checking
27594.591 -> whether a particular.
27595.811 -> Object is present in a set.
27597.4 -> You can clear
the contents of the set.
27599.365 -> You can check
27600.061 -> whether a set is empty
using he's empty method.
27602.541 -> You can remove a particular
object from a set using
27605.247 -> remove method and pass.
27606.6 -> The object that you
want to remove clone
27608.927 -> is nothing but a method
27610.3 -> that is inherited
from object class,
27612.8 -> which is super class
27614.1 -> and it is basically meant
for cloning any data structure
27617.727 -> or any class
or any instance of a class.
27620.511 -> All right.
27621.2 -> So when I say cloning it's
not but making a copy of it
27625.1 -> and it's a shallow copy.
27626.7 -> There is a steep coffee
27628 -> and there's a shallow copy
shallow copy is nothing
27630.6 -> but the properties
within the set.
27632.8 -> So the references remain
the same basically you
27635.8 -> would have a value say
for example string right?
27639.028 -> If you have a value say
at Eureka you would basically
27642.7 -> have both the set pointing to
the same instance of a dareka.
27647.3 -> All right.
27647.868 -> So it's a shallow copy
and deep copies were
27650.3 -> in you would have
different instances or together.
27653.4 -> So when A Change Is Made
in new set A particular element
27657.5 -> it won't be reflected
in the other set.
27659.4 -> So that's deep copy,
27660.717 -> but by default the shallow
copy that's done.
27663.5 -> If you want to deep
27664.683 -> copied then you will have
to use some other utility
27667.8 -> or you some other class.
27669.362 -> All right, there's an iterator
similar to other collection
27673.046 -> you can have I traitor
to iterate through the set
27676.042 -> and if you want to check
27677.54 -> the size of the set you
could use the size method.
27680.7 -> All right.
27681.782 -> So let's see an example
of hash set and linked has set.
27686.1 -> Alright, so here I have created
two methods create hash set
27691.2 -> which creates the instance
of has set and add
27694.405 -> some integer values to it,
27696.3 -> which is 130 340 and 440
27698.2 -> and you see there is
one more method created
27701.5 -> which is create linked hash set
27703.526 -> which is again inserting
three elements into it,
27706.6 -> which is hundred three hundred
and five one.
27709 -> So I return this.
27711 -> All right now I write a method
to 848 through it.
27715.7 -> Which is displaying nothing
27717.776 -> and Print set and
which would hit s.
27724.7 -> All right.
27725.8 -> What you do is you have like set
27728.6 -> to print dot you
could have I traitor right
27732.1 -> which would give you I traitor
27733.943 -> which would give you an instance
of I traitor for set.
27739.3 -> Alright, so we have I
traitor created for set now.
27742.279 -> Let's iterate through it.
27746.5 -> so remember how we
I treated list
27749.7 -> so you would say set
I traitor dot has next
27753.784 -> if it has next then
print the value
27756.4 -> of So basically we have this
27762 -> then you have set
I traitor dot next
27765.9 -> which would give you
the actual value.
27769.3 -> Alright, so we have a method
27771.22 -> which would I trade
through the set
27773.553 -> and display its content?
27775.9 -> All right.
27776.6 -> Now what I do is I create
instance of set demo.
27785.1 -> I create has set
and whatever value I get.
27788.9 -> I put it as as set.
27792.6 -> That's it for demo.
27795.8 -> All right, keep it I set.
27797.8 -> All right.
27799.1 -> Now I have against it.
27801.692 -> I say linked has set for demo.
27804 -> So basically we just
creating the set.
27807.9 -> All right, then we create
the linked hash set now said
27812.197 -> demo we are going to print it.
27814.588 -> The first one to be printed
is is Hash set for demo.
27818.8 -> And this is what is
reusable ET right?
27821.565 -> See I'm not fighting the method
to print it multiple times.
27825.9 -> It's just once and
which could be used
27828.4 -> for printing has set as
well as linked has sit.
27832.1 -> So this is what reusability
is all about.
27834.5 -> If you don't expose
it as a method and
27836.7 -> if you write it
within your main method,
27838.667 -> you won't be able to reuse it
27840.213 -> and you would have
to write the same piece
27842.4 -> of code multiple times
27843.751 -> which adds to the redundancy and
which is not a good practice.
27848.2 -> And this also makes it much
more readable by looking at it.
27852.1 -> You can understand that.
27853.312 -> Okay, it's creating a hazard.
27854.856 -> The second method
is creating a link has said
27857.2 -> and the third one
is printing asset.
27859.1 -> So it makes much
more readable, right?
27861.457 -> So that's an important
factor as well
27863.751 -> when it comes to programming.
27866.2 -> Alright, so here we can see
27868.2 -> that when I printed the hash set
it gave me 133 4440.
27872.4 -> Now the thing is it's
just three elements.
27874.677 -> So it has maintained
the insertion order.
27876.9 -> But basically if I have
more elements you can just
27880.1 -> copy this multiple.
27882.8 -> Okay, I remove this.
27887.9 -> Okay.
27888.517 -> Now you can see
27889.373 -> that you won't get it
in insertion order
27891.6 -> since it was it was
just three elements
27894.294 -> its by fluke
27895.217 -> that you got it in the same
order as which you inserted.
27899.942 -> So if you see it now.
27902.7 -> So now you can see that,
27904.351 -> you know, the first element
that got retrieved is 4401
27908 -> which was basically you put
it at the last ride.
27911.275 -> So it's pretty much random.
27913.053 -> As I said linked has set.
27914.7 -> The retrieval would be
pretty much random.
27917 -> You could see 4401 then 130
which was the first element
27921.6 -> inserted than 340 then
440 then you saw 40,
27925.1 -> which is again out of order.
27927.261 -> So basically this is
27928.8 -> what linked has said does
and suppose I put
27932.2 -> the same values in the link
has set you would see
27935.7 -> that insertion order
is maintained.
27937.8 -> All right, so from here
27940.5 -> if you see from 130
in from here,
27943.7 -> it's printing linked has it
27945.556 -> and you could see the insertion
order being maintained
27949.2 -> as is 4410 and
when you see Hazard,
27953.5 -> which is very much
like this one,
27955.1 -> you can see that it's random.
27957.089 -> All right, so
27958.027 -> that's what link has set
an asset differs own
27961.2 -> preset is nothing,
27962.524 -> but it Sorted set
27963.741 -> and you have a retain
all method retain all method is
27967.4 -> nothing but intersection
between two sets.
27970.238 -> So basically you
could pass one more set
27972.814 -> to the retain all method
27974.4 -> and you would get
an intersection of two sets.
27977.2 -> So what I mean to say is
if you set has value one,
27980.8 -> two, one, two,
27981.9 -> three four and you
pass one more set to it
27985.1 -> or you invoke retain all method
and pass one more set to it
27989.561 -> which has values 1 and 2.
27991.9 -> All right.
27992.7 -> So your Source set on
which retain all method
27995.895 -> is being called that has got
four elements 1 2 3 & 4
27999.6 -> whereas the set
28000.45 -> that is passed to retain all
contains only two elements.
28003.566 -> That is one and two.
28004.7 -> All right.
28005.2 -> Now when you invoke it
your Source will have only
28008.4 -> one and two your 3 & 4
would be removed off
28011.222 -> from the source set
28012.5 -> because the retinol method is
nothing but it's an intersection
28016.6 -> between two sets.
28018 -> Okay?
28019.5 -> So size and hashcode,
28022.373 -> so all these methods remain
the same as other ones
28026.142 -> that you have
in different collections, right?
28029.7 -> So you have like size
which would give you size.
28032.671 -> Hash code is nothing
but a unique integer
28035.2 -> that's written for
any object in Java.
28037.827 -> It's not just free set.
28039.386 -> Any object in Java
when you invoke hashcode,
28042.5 -> it would give unique integer.
28044.3 -> All right,
28045 -> because this particular method
is inherited from object class
28049.1 -> of java contains is nothing
28051.1 -> but pretty much similar you
pass element and check
28053.723 -> whether that element
28054.9 -> is contained in the
source set contains.
28057.6 -> All is something like retain
all it would return true only
28061.7 -> if all the elements
in the collection
28064 -> that's passed here
28065.2 -> as an argument is present
in the source set.
28068.6 -> All right, it has to have
everything all the elements.
28071.832 -> So the previous case wherein
I said the source has one two,
28075.481 -> three and four and
if you do collect contains all
28078.5 -> on a set Are you pass
a set to contains all
28081.317 -> with values 1 and 2
28082.591 -> it would return true.
28084.138 -> Whereas if you pass a collection
28086.6 -> with values 5 & 6
it would say false
28089.8 -> because you don't have values
5 & 6 in your Source collection.
28094 -> All right, I traitor is nothing
but it Returns the iterator
28097 -> that we checked on you
28098.6 -> can convert it
28099.6 -> to to array any collection
could be converted to to array
28102.8 -> which would give
you object array.
28105.282 -> You could check
equals basically checks
28108.261 -> if the collection is I
think it has to be empty
28111.8 -> here it checks whether
your collection is empty.
28115.7 -> So there's a typo here.
28118.8 -> Just to give you an example.
28120.8 -> I will create one more.
28124 -> So I copied the same method
and I said create rehash set.
28129.8 -> All right.
28130.6 -> So what I do here is I
will make these changes.
28133.743 -> I will keep it
28134.7 -> as this could be kept as set
and this is like free.
28141.3 -> All right, so tree set
and and we are set.
28148.1 -> Now I print this one.
28151 -> Okay, basically set
the dough dot create rehash set.
28157.5 -> All right, so I'm printing
this so prior to that.
28161.3 -> Maybe I will put a statement
here printing stre set.
28168.83 -> All right, so I created a tree
set with this random values
28172.3 -> 133 4440 and stuff like that.
28174.9 -> Now let's check
whether it has sorted it or not.
28178 -> Right?
28178.7 -> So I created a tree set
and I'm just printing it here.
28182.7 -> So what you can see here there's
we have created reset now
28188.8 -> if you see it right
28190.258 -> after printing tree
set all the values
28193.1 -> that you see here
then 3044 41 3440.
28198.2 -> It's all sorted efficiency.
28200.104 -> Right and it's Unique as well.
28202.2 -> So if you insert it
multiple times like
28204.835 -> if you insert
28205.742 -> n multiple times still in it
would take Just one value of 10.
28209.929 -> All right, so you
cannot have multiple values
28213.4 -> if you put 10 unlike array list
or linked list,
28216.9 -> which will have multiple values.
28218.926 -> This would take just one 10.
28220.7 -> All right, it would
ignore the other one.
28223.6 -> Enunciate is a special type
of set which creates genome
28227.3 -> is nothing but a constant
it's a replacement
28230.01 -> for constant in Java.
28231.42 -> So basically the replacement
28233.3 -> for public static
final and basically
28236 -> for constant earlier.
28237.559 -> It was like we used
to use public static final
28240.9 -> but now it's advisable
to use enums four constants.
28245.2 -> All right, we'll see an example
28246.7 -> which would give you much
more clear idea about it.
28249.2 -> So first one is all of all
of method is nothing
28252.302 -> but creates an enum set
containing all of the elements
28255.876 -> in the specified element type.
28257.9 -> So it would create enum set
with all of the elements
28261.923 -> that you have copy
28263.287 -> of is nothing but creates
an enum set initialized
28266.802 -> from the specified collection.
28269 -> All right, so you
could pass a collection
28271.074 -> and it would create
an enum set out of it.
28273.276 -> None of is creates a MD enum set
with the specified element type
28278.4 -> or this creates a in mm
28280.5 -> set initially containing
the specified element.
28283.9 -> Can you could
initialize it as well?
28286.2 -> So basically here we
28287.9 -> are giving a specific class
with which it would be created
28291.8 -> or the enum set would be
created range creates a enum
28295.8 -> set initially containing
the specified elements,
28300.2 -> right and clone is nothing.
28302.8 -> But again, it's
pretty much similar.
28305.1 -> As I said clone is a is a method
28307.524 -> that is inherited
from object class
28309.982 -> and is meant to clone
28311.5 -> or have a shallow copy
of the data structure
28314.2 -> against which it is invoked
or object against which it
28317.766 -> which the Clone
method is invoked.
28319.8 -> All right.
28321.3 -> So here we can see
there's the enum
28323.5 -> which is months.
28325.1 -> Alright, so here you
could see a in a months
28327.801 -> which has like
three months declared
28330 -> within Jan Feb and March.
28332 -> All right.
28332.5 -> So now what you do is,
you know him set off
28335.695 -> and you just wait set out
of two of these elements,
28339.5 -> which is Fab and March.
28341.3 -> All right, so this is
what Them office
28344.2 -> so you could have
28345.348 -> some enum values put in and it
would create set out of it.
28349.2 -> Now when you write
rate through it,
28351.3 -> you would see
that you have Fab
28353.6 -> and March into your genome set.
28357 -> All right.
28357.496 -> So this is something
that is required
28359.315 -> when you have enums
with multiple constants
28361.446 -> and if you want to have
28362.798 -> or you want to create set
out of it and do something
28365.4 -> with it, right?
28366.5 -> So it would be
pretty much common
28368.9 -> or you imagine of enums as
exhaustive list of constants,
28374.3 -> right which is used
throughout your application.
28376.8 -> Now there might be instances
28378.527 -> where in you want to have
you want to put them into set
28381.938 -> and do something with it.
28383.523 -> Right?
28384.1 -> So basically this is mint
28386 -> because the values
within your enum cannot be put
28389.41 -> into a data structure as of now
or prepare to enum set.
28393.363 -> We were not able to put
the values within the enums
28396.926 -> into a data structure, right?
28398.992 -> It was considered as
a separate entity.
28401.8 -> So now this is
28403.4 -> That you could put it
into a data structure as object
28406.9 -> and you could play
around with it.
28408.88 -> So that's the reason
we have enum set.
28411.6 -> What is map map is nothing
but it's a key/value pair
28415.215 -> and it is unique Keys
you it holds unique keys.
28418.389 -> So suppose if you try to insert
same key with different value,
28422.7 -> you would have
your value updated
28424.653 -> or overwritten with the new one.
28426.747 -> All right, so
28427.531 -> but it won't duplicate it.
28429.146 -> So what I mean to say is
it maintains a key value pair,
28432.7 -> but the key is going
to be unique across.
28435.7 -> All right.
28436.2 -> So This Could Be Imagined
as a table, right?
28438.729 -> You have a table
in data structure,
28440.7 -> which has got one primary
key say employee ID
28443.751 -> and there's a name
28445 -> which is like name
of the employee right?
28448 -> Imagine.
28448.4 -> This ID is a primary key, right?
28451.3 -> So you cannot
have multiple values.
28453.3 -> So if you try
to put some multiple
28455.379 -> if you try to put
one more value to it,
28457.772 -> it won't allow you to put in.
28459.6 -> The only thing that you
could do is update the value
28462.4 -> of existing ideas.
28463.7 -> He's our add a new ID.
28465.8 -> So this is pretty
much similar to that.
28468 -> Right map is specifically
for maintaining key value pair
28471.856 -> and we're in Keys
would be unique
28473.995 -> and if you try to map
28475.4 -> and existing key
with a new value,
28477.4 -> you would see that the value
is been overwritten,
28479.9 -> but you won't have
to kick it keys.
28481.9 -> Right again.
28483.1 -> There are different variants
28484.6 -> that we would look
at map has hash map
28487.2 -> which is similar to Hash set
28489.267 -> which is based
on indexing or hashing.
28492.1 -> All right, you
have linked hash map,
28493.976 -> which is pretty
much similar again.
28495.8 -> Hashmap doesn't maintain
the sequence of insertions
28499.017 -> linked hashmap maintains
the sequence of insertions.
28502.3 -> There is a sorted map
which is again free map
28505.8 -> and which is sorted
on based on Keys.
28509.4 -> All right.
28509.988 -> So the structure
28510.971 -> that you see here is
pretty much similar to set
28513.8 -> right we had hash set
28515.3 -> we had linked hash set
and we had preset
28518.105 -> so this one is pretty much
on the same lines
28521.2 -> as set So how do you put data
into your hash map?
28525.5 -> It's with put method,
28526.977 -> right you have put method and
you you put some key and value.
28531.3 -> All right, we have put all
we can have an existing map.
28534.9 -> And if you want to put
all the key value pairs
28537.4 -> that they're into a map
into a new map,
28539.7 -> you could use put all
or you could remove some key.
28543.5 -> You could get some key.
28545.2 -> All right, you could check
28547 -> whether a particular key
is contained within hashmap.
28550.184 -> You could get
your key all the keys
28552.8 -> in the hashmap as a set,
28555 -> which is key set give
you extract all the keys
28558.2 -> as set and as
their unique already,
28560.688 -> then you would get
a new set returned out
28563.531 -> from he said entry said
28565.184 -> Returns the set view containing
all key value keys and values.
28569.692 -> So basically you
would get all the keys
28572.5 -> and values as a set
28574.1 -> when it comes to entry set
28575.582 -> from the entry said
you could get key
28577.7 -> and value distinctly.
28579.5 -> All right, so get key
is nothing but obtained
28583.1 -> a key get value would give
you a value against the key.
28587.1 -> Now.
28587.3 -> What are the typical exceptions
28588.8 -> that you get when you deal
with map some exceptions Throne
28592.3 -> while using map interface is
no such element exception.
28595.7 -> So when you are trying
to invoke some item from the map
28598.4 -> if you're trying to invoke a key
that doesn't exist.
28601.4 -> This is what you would get.
28602.9 -> Okay, this is more about
when there are no items
28605.8 -> if there is no item
that exists in the map at all
28609 -> if it's an empty one,
28610.2 -> and if you are trying
to retrieve something
28612.458 -> that's when you would get
no such element exception.
28615.4 -> All right Class cast exception
is pretty much.
28618.204 -> It's a generic exception
28619.7 -> that you get when you try
to cast it against an object
28623.577 -> or suppose value is a string.
28625.7 -> All right, and if you try
to cast it to integer you
28628.417 -> would get a Class cast exception
28630.3 -> since string cannot be
mapped into integer.
28633.8 -> All right.
28634.8 -> Now pointer exception
is the runtime exception
28637.848 -> which we saw that
28639 -> if You haven't initialized
your hash map.
28641.9 -> And if you try to put
something into it,
28644.2 -> you would get
null pointer exception.
28646 -> So you have to make sure
28647.2 -> that you instantiate
the map first
28649.7 -> and then start using it
unsupported operation exception.
28653.985 -> This occurs when an attempt
28655.944 -> is made to change a map which
is unmodified unmodifiable.
28659.895 -> So you can get unmodifiable
version of a map.
28663 -> And if you try to change
something within it this is
28665.735 -> what you are going
to get unsupported operation.
28669.703 -> Hashmap linked hashmap
and free map.
28672.9 -> So this is pretty much similar
to the examples
28675.547 -> that we saw
28676.3 -> for the set write Java
hashmap class implements
28680.092 -> the map interface
by using hash tables.
28683.161 -> It inherits abstract map
and implements map interface.
28687.4 -> It contains only unique
elements hash map contains
28691.326 -> values based on the key.
28693.569 -> It may have
multiple null values,
28696.253 -> but only one real key.
28698.3 -> So this is important to note.
28699.892 -> You can have
multiple null values.
28701.8 -> But only in one alky
you can't have multiple
28704.5 -> in alkies sonal is also
treated as a key as a valid key
28708.9 -> when it comes to hashmap, right?
28711.021 -> Whereas in hash table
28712.433 -> this one more variant
of key-value pair,
28715.055 -> which is Hash table,
28716.4 -> which would throw you an error
if you have G as null
28719.715 -> but hashmap take ski as null so
that's an advantage of it.
28724.1 -> So hash map doesn't maintain
the order of the element
28727.3 -> linked hashmap maintains
the order of the elements.
28729.8 -> In which they were entered
28731.292 -> and treemap sorts
based on the key.
28734.8 -> So these are pretty
much the same thing
28737.2 -> that we discussed
for map earlier.
28739.4 -> If you see entry set key set
and all those things
28742.6 -> we have already discussed about
and it's the same this something
28747.312 -> that we have
in specific to tree map.
28750 -> You could get first key.
28751.736 -> You could get lost key.
28753.4 -> All right,
28754.2 -> since it is sorted
you could get it now.
28757.633 -> There's a hashmap example.
28768.4 -> I create a main method first.
28770.6 -> Then I create private map
and then create.
28777.4 -> hashmap And I create
a new map here
28782.2 -> say app of integer string.
28788 -> Typically you would have integer
as your ID right employ map.
28795.2 -> All right, and which
would be new suppose.
28798.101 -> I create a new hash map.
28801.6 -> Read so I'm creating
a new map here,
28803.933 -> which is like the key
28805.333 -> would be integer
your value would be string.
28810 -> not put Buddhism method
28812.5 -> that we use and say
employ map dot put Alright,
28818.1 -> so this is how you put
into it put into map.
28821 -> All right, so I'd written
this map from here.
28823.9 -> So we so we'll take
an example of hash map.
28827.3 -> Where in we would
be putting some ID
28829.706 -> and we would be putting
some value as a string
28833.1 -> and we would check
28834.4 -> how it gets I treated
28835.903 -> or how we can hydrate through
or get something out of the set
28840.2 -> out of the map.
28841.5 -> Okay.
28842.3 -> So here you can see
that I created a hashmap.
28845.5 -> I created this method
28846.756 -> which is create hashmap
and I put some value
28849.319 -> within which is nothing but
and you could see here.
28852.4 -> It's a map of
integer and string.
28854.5 -> So I put a value of one
28856.6 -> and I put value as
X I put 2 and value
28860.346 -> as Y and I put a hundred
and value as a right.
28864 -> So I created a map
of employee ID and employ name
28868.434 -> so to say right?
28870 -> Okay, so I've created this
28872.6 -> and so what we
are going to do here
28874.6 -> is so you could even
print out a map.
28877.673 -> See if you want
28878.826 -> if I print it out like this like
map to print you would see all
28884.7 -> the values contained
within the map.
28887.392 -> All right, so this is all right.
28889.846 -> I print the hash map right here.
28892.303 -> So basically I created
demo dot create hashmap.
28897.5 -> Okay, demo dot print map and
let's print this map here.
28903.9 -> All right, so we have inserted
three entries into this map 12
28909.1 -> and hundred with ID 1 to 100
and which has got value of XY
28914.8 -> and a respectively
28918.1 -> And what we are doing is we are
just printing the map contains
28921.7 -> of the map right here.
28923.465 -> So you could see here is 1/2 and
hundred been printed out here.
28928.4 -> Alright.
28929.3 -> So again, this is a hash map
28931.3 -> and you could have
it's based on hashing.
28934.611 -> So it doesn't
maintain any order.
28936.7 -> So if you have multiple values
within you would see
28940.352 -> that the order is
not maintained similar
28943.2 -> to what we had in hashmap.
28945.4 -> So if I put something
like this Alright
28948.7 -> now when I run it you would see
28950.523 -> that insertion order
is not being maintained
28952.929 -> and when you retrieve it,
28954.4 -> you will get it in any order.
28957.1 -> All right here we can see
that the order
28960.6 -> is not been maintained
112 is displayed first,
28963.42 -> which is second last actually.
28965.3 -> All right, so it gives you
all the entries within the map
28968.594 -> but it won't maintain
the insertion order.
28970.7 -> So that's if you want
28972 -> to maintain the insertion order
you have used linked hashmap.
28975 -> All right,
28976.1 -> if I change this to link
to map linked hashmap just
28980.874 -> one single change would sigh
copy the same stuff here.
28985.1 -> All right, and I
put a link hashmap.
28988.6 -> All right and suppose I create
one more which is 43 map.
28997.3 -> All right, so we
have created three Maps
28999.7 -> here one is your tree map.
29001.8 -> So the other one is linked
hashmap link - map now.
29007.6 -> Let's print one by one, right?
29010 -> The first one is hashmap that's
already been printed here.
29013.9 -> Now, I create linked hashmap.
29017.2 -> Right?
29018 -> And the third one that I print
is demo dot create remap.
29024.7 -> All right, so we have all
the three maps created
29028.382 -> and we are printing it here.
29030.8 -> Alright, so here you could see
that when it comes to hashmap.
29035.6 -> The key value pair
is not maintained.
29037.717 -> Right?
29038.517 -> Whereas when it comes
to link the hashmap.
29041 -> This is a link hashmap
and you could see
29043.5 -> that the order is exactly
the same as the order
29046.613 -> in which we put in.
29047.9 -> All right, and when it comes
29050.6 -> to tree map with the third one
and here you can see
29054.7 -> that it's sorted one.
29056.4 -> So sorted by your key.
29058.623 -> Not the value.
29059.7 -> Alright, so see the key
to the left hand side
29061.9 -> when it says 1 equal to X1 is
the key and X is the value
29066.261 -> if you see it will see that
29068.338 -> 12 Levin 2,100 hundred
and eleven hundred
29072.4 -> and twelve 1010 and 1100
29075.6 -> so you could see
that it's been sorted / the key.
29080.7 -> All right.
29081.2 -> So this genome map
29083.169 -> in a map with specialized map
implementation for enum Keys.
29087.9 -> All right, which we saw here.
29090.2 -> We can see that there is a enum
which is nothing but constants
29093.788 -> and you could see
three constants been put
29096.026 -> into the months,
29096.9 -> which is Jan Feb and March
29098.9 -> and you could see here
is a in a map created
29102.232 -> for all the months
or for all the months
29105.6 -> that you have within your genome
29107.9 -> that is months right
you have this in a map
29111.8 -> and you could actually put in
values something like this.
29115.6 -> So basically in a map is nothing
but you could use the enums
29119.982 -> or the value within
the enums as your keys.
29123.1 -> All right, when you use
in a maps and you
29125.8 -> could just write rate
through it to see
29128.211 -> that you know,
29129.1 -> you have this Keys put in
and values put in properly.
29133.1 -> All right.
29133.6 -> So, so just to give you
an example we can have
29141.461 -> we can create an enum here.
29145.2 -> I'll choose to create
them same one
29148.192 -> and I create enum here, right?
29150.5 -> So I create in a month and
which has got say for example,
29154.6 -> Jan Feb March.
29156.8 -> All right, so we
have created this now
29159.646 -> what I do is I create a new
in a map with months
29163.6 -> and with string as its value,
29166.819 -> so I create a main.
29170.9 -> Gina map fifth month
29173.5 -> and maybe we could put
into your head.
29176.723 -> I create this in a map here.
29179.6 -> All right in a map of our you
have month and integer.
29189.5 -> Alright, so here we
will have to give a month dot
29195.946 -> or even months.
29197.1 -> Okay?
29198.8 -> Ticks class 1 class.
29202.4 -> All right.
29203.5 -> So in the Constructor we
could see that it takes
29206.4 -> class as a parameter.
29208 -> So we put one thought class
as a parameter now I put ma'am
29212.384 -> don't put I put like the the key
29219.7 -> is your it
is depicting something
29224.2 -> like seals ton per month.
29226.8 -> All right it basically
it refrains you
29229.8 -> from putting anything but
the enum value as your key.
29234.3 -> All right, so that's
29235.3 -> what we are trying to do here
and you could just print.
29241.1 -> In a map calendar
29242.5 -> and you should be able
to see the values.
29244.8 -> All right, so it's basically
restricting the key as one
29248.384 -> of the values or one
of the constants declared
29251.371 -> within your enum.
29254.2 -> See how you can see here.
29255.782 -> Jan is equal to hundred fehb
is equal to 200 you could.
29260.5 -> Now I will quickly talk
about comparable and comparator
29263.5 -> comparable and comparator are
the two interfaces or it's used
29267.9 -> when you want to have sorted set
29269.9 -> or if you want to sort
a collection say for example,
29272.9 -> you have lists of integer
29274.305 -> and you want to sort it a list
of integer is something
29277.423 -> that is by default could be done
29279.3 -> because integer itself
implements comparator,
29282.241 -> but if you have
a self-defined class
29284.5 -> or if you have your own
class say for example,
29287.4 -> if you have your own
defined class something
29290.592 -> like this vehicle info,
29292.32 -> which has like a number
of Wheels mileage and name
29296 -> of the vehicle put in now
29298 -> if you want to sort
this particular class
29300 -> if you give it to a sorter,
29301.569 -> it won't understand
29302.652 -> because this is
a self-defined class straight.
29305.3 -> It won't understand
29306.417 -> what you want to sort
in this right.
29308.4 -> Basically when you have
something of this sort
29310.6 -> when you have your own defined
class and you want to sort it,
29313.9 -> that's when you use
some variable and comparator.
29316.7 -> All right, so I'll just walk you
through it so comparable.
29320.5 -> Phase is used to sort
29321.9 -> the objects of user-defined
class in an order.
29325.1 -> So to give you an example
29326.9 -> suppose you have
an employee class
29329 -> which has got ID and
say salary, right?
29331.9 -> If you want to sort
it by default.
29334.2 -> Java wouldn't know
29335.1 -> what you want to sort within
that particular class, right?
29338.1 -> You want to sort it
by the identifier
29340.2 -> or the ID field
within the employ
29342.5 -> or if that's the use case,
29344.2 -> then it could be
29345 -> like you want to understand
the order in which employees
29348.407 -> joined the company
and the other case.
29351.049 -> Could you want to sort it
by salary to understand
29354.018 -> which employees taking
the most salary
29356.352 -> or to understand the sequence
29358.254 -> in which salaries been paid
to the employees, right?
29361.53 -> So to make Java understand
29363.2 -> which use case you
are trying to solve
29365.4 -> based on which identifier
29367.282 -> or based on which property
29369.2 -> or instance variable
within your class.
29371.9 -> You want to sort
to just indicate Java
29374.5 -> that this is what we want
to do express it
29377.1 -> in a form of implementing
comparable interface.
29380.3 -> It is in Java dot length package
and it contains only one method
29384.337 -> that is compared to it provides
single sorting sequence only
29388.1 -> that is you can sort
the elements based
29390.6 -> on one data only you can't have
multiple data consort based
29394.621 -> on multiple data.
29395.8 -> All right.
29397.9 -> So I'll just walk
you through this
29399.9 -> which would give you an example.
29401.9 -> So so basically
you have a student
29404.4 -> which implements comparable
now here you could relate
29407.766 -> to the example
29408.59 -> that I took wherein
you have roll number
29410.884 -> and name now you
want to sort it.
29412.7 -> Now what we are trying to sort
here is by rule number.
29415.7 -> So that's how you
express using comparable.
29418.2 -> Right?
29418.5 -> You have comparable
student, right?
29421.5 -> And you could see here.
29423.2 -> There's a compareto method
29424.847 -> that this comparable student has
got all the comparable interface
29428.9 -> has got now compared to will
take student as a parameter.
29433.1 -> All right.
29433.823 -> Now you could see
29434.99 -> that we are comparing
rule number right
29437.7 -> you're comparing the rule number
of the parameter student
29441.2 -> that's been passed
to the compared to
29443.4 -> if it is equal then it's 0
29445.6 -> right you don't have
to do anything
29448.2 -> if it is greater,
29449.3 -> then you written as 1 and
29451.016 -> if it is less then you return
as minus 1 so basically based
29455 -> on this compared to Java
will do sorting All right,
29458.6 -> it will sort it based
on whatever you provide here.
29461.7 -> So what you are trying
to tell Java is
29463.912 -> if it is equal we are returning
0 so this is a contract.
29467.384 -> Okay.
29467.7 -> This is what we need
to actually this is
29470.365 -> how it's been coded
or this is a contract
29473.1 -> that you need to follow
whenever you compare to.
29475.7 -> So if it is a real number
then you say it's
29479.079 -> rule number 0 or return 0 if
if both the real numbers match
29483.6 -> if the one in your
instance is greater
29486 -> than the one being passed here.
29487.9 -> Then it would written
one or else - one.
29490.8 -> All right.
29491.702 -> So how do we use this?
29493.5 -> So basically you can see
here you created student.
29497.63 -> All right, so they were
29499.4 -> like three students
created 101103 and 102.
29503.234 -> You could see three IDs
being created here.
29506.465 -> All right.
29507.3 -> Now what you're doing here
is collections dot sort
29511.5 -> and you're passing
your array list of student
29515.2 -> and you use collections dots
29517.6 -> Not right when you do
collections dot sort
29520.2 -> what it would do is
it would arrange it
29522.8 -> or it would sort the array
the order of rule number so 1 0
29527.78 -> 1 would be first
102 would be second
29530.479 -> and 103 would be the last.
29534.1 -> All right, so there's comparable
and this comparator.
29537.8 -> All right.
29538.3 -> There are two interfaces
comparator is nothing
29541.088 -> but it is used to order
the object of use again.
29544 -> It is used to order the object
of user-defined class.
29547.684 -> But what is different
29549.3 -> in comparable is
comparable takes compared
29552.5 -> to which takes just
one parameter as input
29555.7 -> and the other parameter is
nothing but the instance
29558.808 -> within the class itself.
29560.3 -> All right,
29560.8 -> although this instance
rather the instance
29563.59 -> on which this particular method
29565.7 -> or instance on which
compareto method was called.
29569.6 -> All right.
29570.229 -> So basically comparable
will have only one method
29573.923 -> compared to all right,
29575.505 -> whereas comparator
29576.8 -> when you use comparator
interface it will it
29579.654 -> will take two methods
29580.99 -> or it will take two parameters
in the compare method.
29584.3 -> All right, and it will compare
both the parameters
29587.3 -> that are passed.
29588.5 -> So basically it's
29589.618 -> for customized sorting
in the first example,
29592.906 -> that is comparable.
29594.2 -> We are putting
the logic of comparing
29596.748 -> within the class itself,
29598.478 -> but you have a separate class
29600.568 -> which implements this
particular comparison logic.
29604.8 -> So basically you could see here
right you have a class student
29608.824 -> and student is just holding
the values of roll number name.
29612.561 -> All right, you don't see
29614.107 -> how you don't see
the comparison logic with them.
29617.276 -> Now you have another class
which is named comparator
29621.2 -> which implements comparator.
29623.7 -> Alright this name comparator
which implements comparator now
29627.81 -> if you see the compare method,
29629.9 -> it takes two parameters,
29632.5 -> the earlier one the compareto
method incomparable was taking
29635.788 -> just one parameter here.
29637.216 -> It is chicken
two parameters, right?
29639.3 -> And what you could do is
you could simply compare
29642.992 -> based on name right
29644.6 -> since name is a string you
could do S1 dot name dot
29647.871 -> compared to S 2 dot name.
29649.5 -> This would compare
based on name.
29651.4 -> There's another one you could
have one more class created
29654.588 -> which is nothing
29655.5 -> but rule number comparator which
implements again comparator.
29660.3 -> Now here you would
use the same logic
29662.668 -> that you defined earlier
for rule number.
29665.3 -> All right.
29665.919 -> If S1 dot roll number
is equal to equal to S
29668.637 -> 2 dot roll number return 0 else
29670.687 -> if S1 dot roll number
is greater than x
29673.2 -> 2 dot roll number
written one or else
29675.627 -> if it is less
29676.554 -> if S1 dot roll number
is less than S2.
29679.081 -> Total number written minus 1 So
29681.2 -> based on this logic
you would see
29683.209 -> that the compare or you
would see the Sorting Happening
29686.6 -> Now, how do we use this?
29687.911 -> So we have defined a class.
29689.5 -> We have defined a model class.
29691.4 -> So model class is
nothing but a class
29693.691 -> that has got just
the state right student.
29696.3 -> If you see student
doesn't have any Behavior
29698.711 -> as such it doesn't have
any method with them.
29701.3 -> It is just a state.
29702.9 -> So this is a model class.
29704.483 -> Alright, so student
is a model class
29706.7 -> which has record roll number
and name and we have
29709.5 -> two separate comparators
defined here named comparator,
29712.2 -> which is comparing
the name and we have
29714.009 -> a rule number comparator,
29715.2 -> which is comparing
based on rule number.
29718.1 -> Alright now, how do we use it?
29720.8 -> This is not sorting at yet.
29722.436 -> Right?
29722.8 -> How do we use it?
29724.8 -> So how do you use it is
29726.915 -> nothing but you have
collections dot sort.
29730.3 -> All right.
29730.943 -> This is pretty much similar
29732.767 -> to proceed other part
of the program.
29735.2 -> This is just about putting
the data into your class.
29738.7 -> All right, so you have 1 0 1
29740.853 -> put in as Vijay 106 put in
as a J1 05 put in as Jay.
29745.4 -> Alright, and now we
are trying to sort this
29749.1 -> based on rule number
as well as name.
29752.2 -> So both this can't happen
in one go by the way.
29755.157 -> All right.
29755.8 -> This is like first you can have
something done on rule number
29760.195 -> and so it's not in one go.
29762.1 -> All right, you could do it
in step five manner.
29764.9 -> So as you could see here,
29766.55 -> how are we using this comparator
29768.596 -> is nothing but you have
collections dot sort
29771.3 -> and then comes the collection
29773 -> that you want to sort.
29774.2 -> In this case.
29775.3 -> It is a L2.
29776.6 -> All right, and then you
provide the comparator.
29779.919 -> So here you are providing
new name comparator.
29783.1 -> Alright, so after
This particular statement
29786.2 -> is called you would see
29787.673 -> that the collection
is been sorted based on name.
29790.869 -> All right, and
the first one here
29793.171 -> as you could see
collections dot saute L2
29795.8 -> and here you are passing
roll number comparator
29798.8 -> in the first statement
29800.302 -> or here the first collections
dot sort statement would sort
29804.384 -> based on Roll number.
29805.831 -> Whereas the lower one
would sort based on name.
29809 -> All right.
29809.8 -> So this is basically offloading
29811.9 -> or just decoupling
your comparison logic
29815.1 -> out of your class.
29816 -> That's when you would
go with comparator.
29818 -> Whereas you would go
with comparable when you
29820.2 -> want to put the logic
within the class itself.
29822.805 -> All right, so it depends on
what use case you want to do.
29826.3 -> But as far as the
performance is concerned,
29828.8 -> it's pretty much the same.
29830.449 -> All right, even
29831.4 -> if use comparable or comparator,
it's pretty much the same.
29834.8 -> It just depends on
how you want to write
29837.4 -> it the programmers wish
so few people refer
29840.6 -> to have modular programming
rather than coupling everything
29844 -> into one class.
29844.9 -> They would go with comparator
29846.833 -> and few people like to add
things to the class itself,
29850.366 -> which they would
go with comparable.
29854.1 -> So what is comparator
29855.3 -> and comparable comparator
provide single sorting sequence?
29858.4 -> That is we can sort
the collection on the basis
29860.7 -> of single statement
such as ID or name
29863.7 -> as we saw that you would have
just one compareto method
29867 -> and based on that.
29868.1 -> You would have
the sequencing done
29869.9 -> or the Sorting done.
29871.1 -> Whereas comparator you
could have multiple learning
29874.17 -> since you could
have multiple classes
29876.287 -> implementing this comparator
29877.9 -> and you could write
your own logic
29879.7 -> like in the previous example,
29881.29 -> we saw that we had a comparator
based on rule number
29884.087 -> and we had a comparator
based on name as well
29886.8 -> comparable effects original
29888.592 -> class comparator does not affect
the original class.
29891.878 -> So we saw the student class
right the student class
29895.1 -> within the student class itself.
29896.982 -> You define the compareto method
when you use comparable,
29899.972 -> whereas when you use comparator
you wrote different classes.
29903.442 -> So that's about decoupling
29905 -> that I mention comparable
provides compare to method
29908.735 -> to sort the elements
29910.2 -> and comparator provides
compare method to sort.
29914.6 -> All right comparable is found
in Java dot Lang package
29919.069 -> and comparator is found
in Java dot util package.
29923.1 -> We can sort the list
of comparable type
29926.2 -> by collections dot sort lists
29928.8 -> and we can sort list
of elements of comparator type
29932.1 -> by collections dot sort lists
comma comparator method.
29936.384 -> All right,
29937.203 -> when I say list,
it's a list of some type, right?
29941.1 -> So in the previous case,
it was list of student
29944.24 -> and since student class itself
at the logic for comparison.
29948.217 -> We don't have to mention
it explicitly taken
29951.092 -> care of by itself.
29952.306 -> Whereas in this case,
29953.668 -> where an you use comparator
and you had different classes
29957.383 -> where in you put the comparison
logic in that case,
29960.7 -> you have to explicitly
give the comparator right?
29963.9 -> Like we give something
for rule number.
29966.483 -> We instantiated rule
number comparator
29969 -> and gave it for sorting
29970.661 -> by a rule number and we
instantiated name compare.
29974.2 -> There for sorting by name.
29977.088 -> Alright, so that's how we sort
user defined classes.
29981.4 -> So basically why do we have
comparable and comparator just
29985.6 -> to reiterate but jvm
or Java wouldn't know
29989.566 -> how to sort
a user-defined class, right?
29992.6 -> It could be based
on rule number.
29994.482 -> It could be based on names.
29996 -> It won't know by itself
what you're trying to do.
29999 -> So that's how you using.
30000.7 -> This interfaces you express
your logic of comparison.
30006.5 -> So what is XML so Henry handles
the database of a college
30011.4 -> but the data is stored
in a form of XML file.
30014.7 -> He wants to extract
information from this now.
30018.2 -> He is learning XML
so that he can handle it easily.
30022.6 -> So what is XML all about?
30024.646 -> It's extensible markup language.
30027.265 -> It is designed to store
30029.1 -> and transport data XML
has hierarchical human
30033.3 -> readable format XML
is platform independent
30036.6 -> and language independent.
30038.5 -> Why did XML come into picture
at the first place?
30041.7 -> So it's basically you have
different systems Mauro
30044.9 -> you might develop some system
or you might have some service
30048.4 -> that is exposed
to the outside world.
30050.9 -> So what happens is they has to
be some contract you as a client
30055.192 -> or you as a service provider.
30057.2 -> First of all would expose
a contract saying
30059.9 -> that if you give input to
my service in so-and-so format,
30063.5 -> I will give you output
in Swann Format,
30066.075 -> so basically when you want
to send data from a client
30069.6 -> the service you would send it
in a specific format
30073.01 -> that the client understands
or the server understands.
30076.8 -> So the server exposes
30078.6 -> or the server expresses
the input format
30081.6 -> in a XML form and this
is platform independent.
30085.3 -> This is like you might have
a service tomorrow
30088.1 -> in created in.net
which can use the same XML
30091 -> as used by Java program as well.
30093.117 -> So it's a platform
independent thing.
30095.5 -> Basically, it's used
for carrying data
30097.7 -> as I said store
and transport of data,
30099.961 -> which we'll see
in the coming slides
30102.1 -> but you could imagine
this as nothing but a file
30105.6 -> which is used to send
data from your client
30108.07 -> to the server for communication.
30109.9 -> It's pretty much human readable.
30111.5 -> It's not like yesterday we saw
30113.087 -> but serializing and serializing
the state of the object
30116.348 -> which was not human readable.
30118.1 -> So this one is pretty much
human readable you could imagine
30122.179 -> like you would have
an employee ID
30124.5 -> or You want to start something
in the employee directory
30127.529 -> and there's a service
30128.691 -> which is exposed for
that you could imagine
30130.917 -> that you could send the ID to it
30132.892 -> or you could send
an employee name to it
30135.3 -> and format in which it is sent
30137.192 -> would be pretty
much human readable.
30139.4 -> You could see that okay,
there's an ID
30141.4 -> there is a name
30142.216 -> which is sent to the server
and the server is doing so
30145.1 -> and so things
so it's hierarchical
30147.952 -> and it's pretty much
human readable again,
30151 -> as I mentioned
platform independent
30153 -> and language-independent.
30154.64 -> It's agnostic of all
these Technologies.
30157.2 -> So there are a lot
of existing Services
30159.978 -> which use xml's as a part
of input data and output data.
30164 -> So as we go
through the examples,
30166.5 -> you should be clear to you guys
about what XML is all
30170.5 -> about why we need XML XML
is an industry standard
30175.053 -> for delivering content
on the internet.
30178.076 -> So it's a standard.
30179.6 -> So most of the services most
of data entry communication
30183.4 -> that's happening within
in Annette is done
30186.133 -> in the form of XML.
30187.434 -> They communicate with each other
in the form of XML XML
30191.2 -> is designed to store
30192.7 -> and transport data XML
is the extensible
30195.9 -> because it provides
a facility to Define new tags.
30200.2 -> It's not that
once you define it.
30202.3 -> It's all done.
30203.4 -> So it's extensible.
30205 -> It's extensibility feature
wherein I can say today,
30208.437 -> my server is accepting employee
ID and employee named tomorrow.
30212.745 -> My server want to accept
employee salary as well.
30216.178 -> So you could add
that to it add tags to it,
30219.094 -> which makes it extensible.
30220.853 -> So it's not one time Define.
30222.817 -> You could change it.
30224.228 -> You could evolve the xml's XML
is used to describe the content
30228.516 -> and structure of data
in a document.
30230.921 -> So it has got its own schema
and you can say
30233.811 -> that my XML is going
to contain just email ID
30236.7 -> and employee named nothing else
and you could validate VL XML
30240.9 -> or the actual XML
30241.906 -> that you have against the schema
30243.8 -> and if you Some extra
parameters put in it.
30246.495 -> Would throw you an error.
30248.1 -> So that's about white need XML.
30250.8 -> Let's talk about what are
the features of XML?
30254.5 -> Why is it so widely used
writing XML is pretty much easy.
30259.4 -> As I said,
30260.058 -> it's human readable
and you could actually write it
30263.2 -> and there's a lot
of API or lot of sdks
30266 -> that are exposed for reading
30267.965 -> and writing with xml's and very
optimized version of it.
30271.868 -> So you could see parses, right?
30273.952 -> We had multiple parses.
30275.5 -> It's for Performance
Based on the needs
30278.095 -> of your particular application
30279.902 -> or the nature
of your application.
30281.891 -> You would select one
of the parsers.
30284.1 -> So writing xml's is very easy.
30287.1 -> The other one is XML data can
be extended with DTD and xsd.
30292 -> It's a schema description.
30293.8 -> As I said, you could extend it.
30295.737 -> It's not that it's
one time Define.
30297.85 -> You could extend it XML
30299.305 -> can work on any platform
this platform agnostic.
30302.378 -> You could run it
on any platform either Dot.
30305.037 -> Or it could be different
languages or different platform.
30308.5 -> It could be different
operating systems as well.
30311.296 -> I could run it
on line X tomorrow
30313.2 -> or I could run it on dotnet
any tool can open XML file
30317.907 -> and can parse it
in programming language.
30320.96 -> So simple editor or even
notepad you could open it
30324.7 -> in notepad plus plus
and just you through it
30327.6 -> and there are different tools
available in the market as well,
30331.2 -> which would give you
kind of format your xml's
30334.18 -> so that it's much more readable.
30336.3 -> So there are a lot
of tools available already
30339.2 -> XML separates data from HTML.
30342.7 -> It separates the actual data
30344.4 -> from HTML code XML
simplifies data sharing.
30348.5 -> So basically as I said it
30350.6 -> pretty much intercommunication
standard between systems,
30354 -> you just have to put it into XML
30356 -> and you share it across systems
XML simplifies data transport.
30360.978 -> What is the difference
between XML and HTML
30364.5 -> so XML is used for storing data
and data communication.
30369.242 -> So as I said inter
system communication standard
30373 -> and HTML is used for display.
30376.1 -> So whatever you see
on the web is something
30378.9 -> that is you have a HTML page
you have coded it in HTML format
30383.6 -> and it's used for displaying it
XML uses user-defined tax HTML
30390.115 -> has its own predefined tags.
30392.4 -> So when you define your XML,
it's a user-defined XML.
30396.2 -> As I said today.
30397.156 -> I might have a service
30398.47 -> which is taking employee ID
and employee name
30401.1 -> which is like user defined
which is not predefined.
30403.8 -> Whereas when you use
HTML HTML is nothing
30407.1 -> but it has to get parsed
30408.95 -> into or it has to get
past into a page
30411.8 -> which has been
visualized by clients.
30414.4 -> So that's why you have
a predefined tags.
30417.212 -> You cannot have anything you
30419.181 -> cannot put something of your own
or if you put your own tags,
30423.4 -> it would show up an error.
30425 -> So it's validated reason
being you have to compile it
30428.502 -> or you have to run through
to show it as a view
30431.6 -> or show it as a HTML page
with the plants.
30434.7 -> There's an interpreter
30435.8 -> which has to understand
what you're trying to do.
30438.1 -> So it's predefined
30439.4 -> tags XML is case sensitive and
HTML is case insensitive in XML.
30445.684 -> It is mandatory
to close all the tags.
30448.6 -> So you cannot keep
any tags open.
30451.2 -> So we'll talk about the tags.
30453.3 -> Once you see the format
of the xml's but basically
30456.3 -> if you have a every property
or every data
30459.3 -> that you want to send
out will be enclosed
30461.8 -> in a tag you'll have
to ensure the tag is closed.
30465 -> So for example employee ID
right employee ID will have
30468.8 -> opening tag and it will have
an employee ID as a value
30472.5 -> and you will have to close
the tag you have to ensure
30475.6 -> that employee ID tag is closed
right after the value in HTML.
30479.369 -> It's not mandatory
30480.5 -> to close the tax all
the time XML is dynamic
30483.62 -> because it is used
to Transport data HTML is static
30487.249 -> because it is to display it it.
30489.5 -> So basically when I say,
it's Dynamic it's extensible.
30493.4 -> So tomorrow you could change it.
30495.6 -> You could change the format
30497.3 -> or you could change
add few more elements
30500.4 -> or few more tags
or add some attributes.
30503.8 -> So it's pretty Dynamic
would change it
30506.3 -> whereas HTML is aligned
to a proper predefined tags
30510.6 -> and you can't change return.
30512.647 -> You cannot add
some tags additional tags
30515.5 -> of your own XML preserves
30517.489 -> white space and HTML
does not preserve white space.
30521.7 -> So what are the rules let's talk
30524 -> about XML rule XML considers
white space as the actual data.
30528.9 -> So whatever you are sending
data through XML.
30532.2 -> So imagine you are sending data
between two systems, right?
30536.419 -> So space is also a character
when it comes to XML.
30539.9 -> So suppose you want
to send some data
30542 -> that is client is typing.
30543.866 -> So of course you need To have
Space Center as well.
30547.558 -> You cannot have spacing node.
30549.7 -> It's actual data between
two systems communication
30552.8 -> between two systems and
since space is valid data.
30556.547 -> It's been considered
as data by XML ordering
30559.806 -> and nesting of XML document
should be proper.
30563.1 -> As I said,
30563.73 -> you have to ensure
that once you open
30566 -> a tag you have to close
it there could be nesting
30569.2 -> so there could be a tag
30571.1 -> with says employ
and within employed tag,
30574.216 -> you might have employee ID tag,
30576.4 -> and you might have
employee name tag.
30578.536 -> And once you have
this employee ID
30580.477 -> and employee name tag,
30581.828 -> you have to ensure
that you close the employee tag.
30584.9 -> So that's nesting.
30586.146 -> So your nesting ID
and name within employee tag.
30589.4 -> So your this might be really
confusing at this point.
30592.051 -> If you have no idea
30593.023 -> about what the structure
of XML is all about,
30595.611 -> but don't worry
in the coming slides.
30597.8 -> We have examples
30598.9 -> and it's pretty straightforward
XML tags are case sensitive
30603.186 -> every opening tag must.
30604.806 -> Have a close tag else XML
be not correctly function.
30608.4 -> What does an XML file consists
of it has one root element
30612.707 -> that is one tag,
30613.988 -> which encloses
the remaining tags.
30616.7 -> So it has one root element
30618.7 -> within which the entire
content would be
30621.8 -> and each elements consist
of start tag content tag
30625.6 -> and an end tag.
30627.2 -> So there is one
of the components
30629.5 -> of XML is nothing but element
30631.7 -> within an element
you would again have
30634.4 -> some content expressed
in form of element again,
30637.832 -> which will have start
tag content tag again
30640.84 -> and end tag.
30641.7 -> This is about nesting it
will see in the example
30645.013 -> which is pretty much
like readable format XML tracks
30648.5 -> are case-sensitive opening
30650.6 -> and closing tags should be
30652.7 -> exactly the same without
any difference in the case.
30656.3 -> So you have to ensure
30657.7 -> that it's been enclosed
with the same case
30660.433 -> as it was started off.
30661.9 -> This is an XML.
30663.392 -> So the first That you see is
nothing but XML declaration.
30667.7 -> The first line that you
see here rather is nothing
30671.1 -> but XML Declaration of prologue.
30673.5 -> So this is nothing but kind
of saying what the XML is
30677.366 -> or the format in which
it is encoded here.
30680.4 -> You could have your dtds
30682.067 -> which we'll see
in the coming slides
30684.5 -> but so kind of summarizing your
XML what the XML is all about.
30688.8 -> That's your Declaration of
prologue and that's mandatory.
30692.3 -> If you don't put it it
would throw you an error then
30695.3 -> comes the student tag,
30696.665 -> which is user defined you
30698.293 -> could imagine this as
a user-defined XML,
30700.838 -> right and you could imagine
this as data being
30703.7 -> or you could have
a service a for example,
30706.1 -> which is doing something
with this data may be inserting
30709.1 -> to a database right?
30710.446 -> So you could imagine this
being sent from client
30713.535 -> or you have a webpage
say for example,
30716.067 -> wherein you enter
first name last name
30718.8 -> and email address
of a student and say for example
30722.178 -> that comes to a server
and it's loaded.
30724.8 -> To your database.
30726.1 -> So the root element
30727.479 -> of the document is nothing
but student here,
30730.6 -> you can see a student tag.
30732.4 -> And as you can see here,
30734.037 -> it's an element
30735.061 -> which starts with angular
bracket then the name
30738 -> of the element and it ends
with the angular bracket.
30741 -> So this is student
and then the next line is
30744.3 -> about you define
three tags within it.
30747.1 -> This is nothing
but the content of student
30749.256 -> and here you can see
it's following same strategy
30752.104 -> or it is following
the same structure.
30754.317 -> You have was named Henry
30756.2 -> and disclosed the
first name element.
30759.1 -> You can see the second element
as last name and with starts
30762.784 -> with angular bracket last name
and and the angular brackets.
30766.545 -> Then there is actual value lie,
30768.578 -> and you could see
that it ends with the tag
30771.332 -> or with the element last name.
30773.3 -> So one thing to remember here
is about start and ending
30777.5 -> of a tag ending of element.
30779.8 -> You can see the right
after the value.
30782.1 -> The element is closed and you
can see This thing here as well.
30786.2 -> So student is a element
30788.5 -> and you can see
first name last name
30790.999 -> and email being nested
into student element nested
30794.5 -> or they are the child elements
of the root element.
30797.5 -> So you have child
elements defined here
30800.7 -> and you have the last line
30802 -> which defines the end
of the root element here.
30804.991 -> We have XML which has doors
or which is used to transport.
30808.78 -> First name last name
30810.109 -> and email address
of a student across systems.
30813.2 -> Let me show you
the tree structure of this XML
30816.391 -> so it could be imagined as
student being the root element
30820.45 -> and you can see
that first name last name
30823.4 -> and email is nothing
30825 -> but your child or is
the child for student
30828.7 -> since it's a root element
and you could see the values
30832.1 -> the actual content of it
within your first name tag,
30835.463 -> you saw the value
Henry within the last name
30838.3 -> you saw the value lie
30839.874 -> and within the email address
you saw Henry 123 at gmail.com.
30844.7 -> So the leaf node is nothing
but the content of elements
30848.5 -> or the actual
contents of the XML
30850.516 -> that you're trying
to send across systems.
30853.1 -> This is pretty straightforward.
30855 -> Like you could realize XML
in a form of free format
30858.1 -> where in your root node is
nothing but element of your XML
30862.5 -> and the leaf nodes
30864 -> or the leaves are nothing
30865.904 -> but the actual value
stored in the XML.
30868.9 -> So let me talk about three rules
in this given example student is
30874.7 -> a root element.
30875.946 -> Then first name
30877.1 -> last name and email are
descendants of student.
30880.7 -> This is pretty
much straightforward
30882.4 -> when it comes to tree
30883.848 -> so you have a root node
and you have descendants
30887.091 -> and we can see
from the structure
30889.5 -> and sisters in this example
student is ancestor
30893.5 -> of all other elements,
30895.6 -> so root node,
30896.709 -> so it's ancestor
30898 -> of all other elements
within this tree order
30901.307 -> XML attributes you
can have attributes.
30904.5 -> Which are common across
30906.4 -> or you could have
some attributes defined
30909 -> within an element.
30910.295 -> So here we can see that message.
30912.6 -> That's nothing but an XML
with the root node messages
30916.3 -> and you could see
individual messages within so
30920.1 -> there are two messages here
within messages Tab.
30923.6 -> And the first one is to any
and it's from John
30927.9 -> and you have a body there
the actual body of the message
30931.4 -> what you want to send
and you can see here this ID
30935.189 -> or this something
30936.4 -> that has been provided
as an attribute,
30938.821 -> which is nothing but you
could see Mi di is equal to 1
30942.2 -> that's attribute has to be
enclosed within single quotes
30946.248 -> or double quotes.
30947.5 -> So whatever you see
within the element
30950.379 -> and closed within codes
30952.173 -> that is nothing
but attribute so modifier,
30955.327 -> you can say some kind
of a modifier to your element.
30959.5 -> So attributes add more
information about the element
30963.2 -> it is adding some more Formation
30965.4 -> to the element XML attributes
must always be coated either.
30969.6 -> It should be within single quote
30971.74 -> or you could have it
within double quotes here.
30974.819 -> We have it within double quotes
for our XML comments.
30978.6 -> So to make it more readable
30980.605 -> or to increase
the maintainability of an XML
30983.7 -> so that someone
else can understand
30985.839 -> what you are trying to do you
could have comments put in
30989.3 -> so this is pretty much similar
to comments in other languages.
30993.2 -> The reason why we rationale
behind why we put the comments
30997 -> it's more about make
it much more verbose
30999.637 -> and understand what bag is all
about how we comment
31003.038 -> is nothing but you
have opening angle bracket.
31006.1 -> Then you have exclamation mark
then two hyphens and after the -
31010.58 -> you have the comment and
31012.3 -> once you have the comment
you close it with double -
31015.8 -> and then closing angle bracket.
31017.9 -> So one thing to note
here is exclamation mark,
31020.769 -> is there only when you
start the comment
31023.2 -> and at the end you don't have
Exclamation mark double -
31026.619 -> and then closing angle bracket
similar comments are just
31030.1 -> like HTML comments comments
are used to make
31033.086 -> the code more understandable.
31035.148 -> What are the rules?
31036.449 -> Do not Nest a comment
inside the other comment?
31039.606 -> Okay, you can't Nest it.
31041.353 -> And I don't see any need
31043.095 -> to nested was your
just expressing it
31045.7 -> or we are just adding comments
to make it more readable.
31049.5 -> So if you nested it would give
you an error do not use comments
31053.423 -> before and XML declaration
XML declaration should be
31056.696 -> the first line.
31057.6 -> You shouldn't be using comment
before that comments can be used
31061.3 -> anywhere in XML file
except attribute value.
31064.4 -> So you can't put comment
within an element
31067.038 -> or you can't put it right
31068.686 -> after the element
is defined or say,
31070.898 -> for example, you have
this message tag,
31073.3 -> right which starts with
angular bracket and then message
31076.352 -> and right after the message.
31078 -> You can't have comment your
element tag has to be closed
31081.8 -> after this closing angular
bracket you could Any comment
31085.283 -> but it cannot be
31086.247 -> within this space wherein
you define the attribute
31089.2 -> so basically comment
can be put anywhere
31091.5 -> but it cannot be
as attribute value.
31094.045 -> So let's see a well-formed XML
31096.3 -> and what do we
call well-formed XML
31098.9 -> as there must be exactly
1 root element and XML
31103.53 -> should have exactly
one root element.
31106.3 -> You cannot have multiple every
start tag has a match intact.
31111 -> So we saw in
the previous example,
31113.03 -> like if you start student you
have to ensure have an intact
31116.6 -> for student as well.
31118 -> So that's what it is about
every start tag must have
31121.783 -> an end tag attribute must be
coated either with single quotes
31126.025 -> or you could have
double quotes comments
31128.698 -> and processing instructions
may not appear inside a tag
31132.536 -> cannot be inside a tag
31134.1 -> and you have opening
angular brackets or
31137.4 -> and must not occur
inside a data element.
31140.7 -> Your data cannot have this
as value or your data element
31144.195 -> cannot Contain this as a part
of the name of element.
31147.5 -> So let's move
towards XML validation.
31150.8 -> So well-formed XML
can be validated
31153.7 -> against DTD or xsd.
31156.5 -> So communication between
multiple systems you have
31160 -> to ensure plant is sending
data or is kind of you know,
31164.159 -> preparing an XML
31165.391 -> which is aligned
to what server expects right?
31168.819 -> So that's where you
have decreed in the and xsd.
31172.4 -> Let's see.
31173.2 -> What is D TD.
31174.8 -> E TD is a EB NF grammar
defining XML structure.
31179.4 -> It's a normalized
form at grammar,
31181.7 -> which defined XML structure
a DTD defines a legal element
31187.5 -> of an XML document.
31189.022 -> So it says what XML can contain
what an element could be
31193.5 -> or what the attributes could be
and it's a legal element.
31198.1 -> Okay.
31198.452 -> So basically when you define
31200.449 -> a DTD you can expose
the service today,
31203.132 -> which could be used
by Tomorrow right?
31205.745 -> Google can be using it
for some purpose.
31208.5 -> So this is a legal document
saying that my service expect
31213.4 -> or accepts the times
1 so format,
31216 -> so you have to send it
in so-and-so format
31218.46 -> for us to process it through.
31220.3 -> All right.
31221 -> So it's a legal document
between multiple organizations
31225 -> XS T is nothing but used
to address the shortcomings
31229.4 -> of DTD uses name space
to allow for reuse
31233.7 -> of existing definitions.
31235.46 -> So you could Define an xsd
and you could just use it
31239.2 -> or through name spacing you
can have it within other pieces
31243.631 -> of xml's as well.
31244.939 -> So, let's see.
31246.016 -> What is GT D PT d stands
for document type definition.
31251.43 -> DTD is used to define structure
of an XML document
31255.2 -> or DTD defines the legal
elements of an XML document
31259.8 -> as we spoke.
31260.8 -> It defines legal elements,
31262.9 -> or which cannot be Accepted so
31265.3 -> basically you define what your
XML is all about through DTD
31269.1 -> so you could see
a student DTD here.
31271.9 -> So you have XML
31273.1 -> which is nothing but
which has student
31275.551 -> which has first name
last name email and marks.
31278.6 -> All right.
31279.4 -> This is what you have
within your XML.
31281.7 -> Now you define a DTD
31283.3 -> which could be put
into your doctype.
31286.019 -> So the first tag
31287.229 -> that you see is
nothing but declaration
31290.084 -> and it's linking your kind
of tying it against a DTD
31293.894 -> with that's defined
external DTD file.
31296.74 -> All right, you define this
31298.74 -> and you have a DTD file
below which is student dot DT D.
31303.1 -> And here you can see
that it says
31305.561 -> that within student
element you can have
31308.561 -> for other elements or as
a nesting of for other elements,
31313.1 -> which is first name
last name email and marks.
31317.9 -> All right, if you
31319.83 -> since this DTD is linked with
your document or with your ex.
31324.5 -> Mel document now
31325.8 -> if we try to add something
if you have one more element
31329.874 -> here which could be
like a dress right?
31332.6 -> If you have one
more element here,
31334.541 -> which is address.
31335.628 -> It would throw you an error
because your ETD says
31338.8 -> that student can have only
first name last name email
31342 -> and marks address is not a valid
element within student.
31346.3 -> All right.
31347 -> First name now, let's define.
31348.981 -> What can we have in first name?
31350.805 -> Alright.
31351.605 -> So first name is nothing
but character data again.
31354.7 -> Last name is a character
data email is again a string
31358.3 -> and Marx is again taken as
character sort of so this is
31362.8 -> how we Define DTD.
31364.8 -> Alright, so we are trying
to establish the structure
31368.59 -> or we are trying to say
31370.25 -> that student can have
a nice one so fields
31373.408 -> and if there's something
else then it's invalid.
31376.8 -> So here we can see
ETD contains root element
31381.5 -> and declare the child
elements we can see
31384.4 -> That it says student can have
only first name last name
31388.048 -> and email and marks.
31389.6 -> It defines last
name child element
31392.597 -> and data from this element
is possible right
31396.338 -> when it is PC data.
31397.8 -> It's possible again
you have first name,
31401 -> which is possible
you have last name,
31403.117 -> which is possible
you have email address
31405.341 -> which is possible
and you have marks
31407.4 -> which is possible.
31408.6 -> All right.
31409.1 -> So what is XML schema XML schema
is used to express constraints
31414.2 -> about XML document.
31416.4 -> All right, it's pretty much
it does the same purpose as DTD
31420.4 -> but it's much more
advanced than DTV.
31423.2 -> It has much more features
XML provides more control
31428 -> on XML structure
31430 -> a well-formed XML document
can be validated against xsd.
31435.7 -> So you have an xsd
again similar to DT
31438.7 -> which defines the structure
31440.6 -> and a well-formed XML
should be validated
31443.6 -> or should be Against
a particular axis T.
31447 -> So here we see an xsd,
31449.3 -> which is much more verbose
31451.3 -> or which is much more clearer
31453.53 -> to understand compared
to DT DT D was something
31457.384 -> like was not expressing
to that extent
31460.3 -> but X is T is pretty clear
31462.484 -> in terms of what
the content could be.
31465.6 -> Again.
31466.4 -> It defines the root node
and declare the child elements.
31470.7 -> So here you can see
31472.073 -> that exists is defined
in a form of XML itself.
31475.4 -> All right, it follows
the same pattern as the XML.
31478.9 -> So it says element
which is a keyword.
31481.6 -> All right element is
a keyword for your xsd
31485.1 -> and you have student
as a attribute.
31488.3 -> So this you could realize xsd
as I said as an XML itself,
31493.2 -> it's a valid XML cracker,
31495.113 -> which says that you have
an element with name student now
31499.377 -> what can students
hold is again a sequence
31502.5 -> when you say sequence it has
to The same sequence break
31506.156 -> the sequence it's again
going to be invalid
31509 -> then it says first element
31510.8 -> first child element within
student should be first name.
31514.6 -> The next one to follow
should be last name.
31517.3 -> The next one should be email
31519.353 -> and the last one
should be marks.
31521.7 -> All right, and it
defines what type is
31524.5 -> particular elements hold.
31526.7 -> So first name is a string.
31528.7 -> Last name is a string.
31530.392 -> You may raise a string
and Marx is a string as well.
31534.4 -> So this is how it is you define
a structure to the XML
31538.3 -> and you have to ensure
for your XML to be valid.
31542.6 -> It has to be valid
31543.932 -> against this exists e it's a
similar scheme are descriptive.
31548.6 -> So what's the difference
between DTD and Xs T DT
31552.5 -> v stands for document type
definition XS d stands
31557.4 -> for XML schema definition.
31559.9 -> DTD is not extensible
access T is X Zebra dpv
31566 -> provides less control
31567.7 -> on XML structure xsd provides
more control on XML structure.
31573.2 -> ETD does not support data types
xsd supports data type.
31578.8 -> We sort the data types
like string and stuff which is
31581.883 -> like it supported just in exist.
31583.885 -> You don't have DTD supporting
31585.7 -> and DTD does not define
the order of child elements
31590.5 -> as we could see it just says
31592.089 -> that you could have
four elements within but it
31594.7 -> doesn't have any specific
order as such whereas
31597.78 -> when it comes to xsd.
31599.187 -> You could Define
a sequence right as we saw
31602 -> in the previous example,
31603.2 -> we said that the first one
should be the first name,
31605.8 -> then the last name then
email ID and then marks
31608.9 -> so you could Define the sequence
31610.5 -> in which your sub elements
should occur XML CSS file CSS
31615.8 -> is used to add more tiles
to the XML document.
31620.2 -> So if you want to color
coded or do something that's
31624.1 -> when You CSS pretty much
similar to HTML document.
31627.775 -> So here we can see
that you could Define student
31631.3 -> which has got
a background color of pink.
31634.3 -> Then you have first name,
31636 -> which has different
font sizes here.
31638.333 -> First name last name
and email ID and marks
31641.133 -> which has got
different font sizes.
31643.8 -> So we want to have font size
of 25 for this child elements.
31649.2 -> You want to display it
as a block and color
31652.5 -> as white and the margin
left as 50 pixels.
31656.8 -> All right,
31657.9 -> when you have such thing defined
if you want to link it up
31661.6 -> if you want to link CSS to XML,
31665 -> you need to have
a XML stylesheet tag defined
31669.1 -> and you would type
as text or css
31673.8 -> and you put H ref as
31675.6 -> your CSS name to make
the changes in the styles
31679.113 -> of the XML file CSS file
is linked to XML file
31682.545 -> through this statement.
31684.3 -> So this is how you link
your CSS file to your XML file.
31688.8 -> Now.
31689.4 -> What is XS L XS L stands
31692.2 -> for extensible stylesheet
language XSL navigates
31697 -> all the nodes
31698.146 -> and elements and display
XML data in a particular format.
31702.5 -> All right, it's basically
31704.07 -> for parsing sort of it navigates
through all the nodes
31707.4 -> and elements queries
can be specified in XSL.
31710.9 -> If you want to query
some particular data
31713.4 -> or like we had message
this thing in a couple
31716.457 -> of slides back.
31717.5 -> We saw multiple messages
within message, right?
31720.7 -> So if you want to read some
messages extract the messages
31724.5 -> that are sent by the users
31726.4 -> you could wear it out using
excessive it displays data
31730.325 -> on the browser as
31731.585 -> per the format given
in the Excel file.
31734.742 -> So, let's see what is
accessible file all about.
31738.6 -> Okay.
31738.924 -> So here what you're
doing is nothing
31741.2 -> but you're extracting data.
31743.1 -> All right, you are.
31744.383 -> Acting first name.
31745.6 -> So the first name here
would be taken from your student
31749.224 -> and would be displayed here.
31751 -> And again the second one
31752.799 -> you have last name you select
the last name particularly.
31757 -> This is acting
upon student dot XML.
31759.851 -> All right, how do you
31761.467 -> link up accessible to XML is
pretty much similar to CSS.
31766.1 -> You have style sheet
and you have type as text /
31770.1 -> XSL and not CSS,
31772.4 -> right and you have H ref
as student accessor.
31777.7 -> So that's 4X s l--
and again, let's see.
31781.5 -> What's the difference
between CSS
31783.5 -> and Xs L fi CSS files
are easy to understand
31787.8 -> Excel files are difficult to
understand CSS is less powerful
31792.338 -> than accessible CSS is
specifically for display right
31796.9 -> changing the font size changing
the colors background colors
31800.6 -> and foreground color
and everything XSL is more.
31804.258 -> Full then CSS
31805.3 -> since you can extract
data or do something with it.
31808.633 -> Basically, it's a processor.
31810.5 -> You actually can process
the XML using Excel CSS
31815.1 -> does not use XML notations
Excel uses XML notations,
31820.146 -> which helps in writing code.
31822.4 -> CSS can be read by
modern web browsers XSL
31826.451 -> is not supported by
many web browsers.
31829.8 -> Now, let's talk
about XML parsers.
31832.9 -> Okay.
31833.6 -> So XML parser is nothing
but you parse through you
31837.2 -> have an XML and you want
to read data from it
31840.147 -> or XML parsers could be used
for writing the XML as well.
31843.9 -> Okay, creating an XML
could create an XML
31847.215 -> using XML parsers as well
31849.207 -> or you could read
through the existing xml's.
31852.7 -> So an XML parser is
a software Library
31855.546 -> which provides client
applications to work
31858.7 -> with XML document
and XML parser is used to check
31863.3 -> whether the Comment is
in well format or not.
31867.8 -> It is basically used
31868.8 -> for compiling our parsing
your XML as well.
31872 -> It is used to validate
an XML document
31875.174 -> and parsing XML refers to going
31877.558 -> through XML document
to access data
31880.174 -> or to modify data in one
or the other way.
31883.4 -> All right, you could actually
read through the xml's
31887.292 -> or you could extract data
31889.202 -> or you could modify
data using XML parsers.
31892.8 -> What a bar says here.
31894.266 -> You could see XML document
right being sent
31897.2 -> to the parser parser is
nothing but API
31900.1 -> so you send the XML
31901.8 -> The Source XML or the XML
that you are trying to pass
31904.99 -> is going to be sent
to the XML parser
31907.2 -> and this API is going
31908.813 -> to be used by client application
right to parse the XML files.
31913.7 -> So XML parsing could
be broadly classified
31916.853 -> into two different types
one is object-based
31920.2 -> and one is event-based right
object-based is nothing
31924.365 -> but document object model
or it is also known
31927.7 -> as Dom even base.
31929.3 -> We have two different parses
31931.126 -> when it comes to even
based one is sacks
31933.669 -> and the other one is tax.
31935.6 -> All right, so let's talk about
object based model Dom parser.
31942.3 -> It stands for
document object model.
31946.176 -> It is an object-oriented
31948.6 -> representation of
an XML parser tree.
31952.5 -> So remember we assign XML
31955 -> and we passed it
into a tree like structure
31957.857 -> where in your root node
of the tree was the root element
31961.6 -> from your XML
31962.51 -> and we had all the elements
31964.4 -> and at the end the leaves
were nothing but the values
31967.949 -> or the data
31968.7 -> that the XML stores
actual values right
31971.734 -> or XML stores or care.
31973.8 -> Rather, so that's
what trees all about.
31977.4 -> It defines the standard way
to access and manipulate
31980.4 -> documents Dom is a common way
for traversing the tree.
31984.5 -> So as we look
through the examples,
31986.962 -> you should get Fair idea
31988.7 -> about it creating an XML
document using Dom parser.
31992.7 -> So what is required
to use Dom parsers?
31995.414 -> How do we do that?
31996.8 -> First is you have
to import all the parsers.
31999.628 -> You have to import
all the classes
32001.8 -> that you have
within partial Java x
32004.508 -> dot XML dot parsers.
32007.1 -> These are all input statements
that you have.
32009.4 -> You have to import
different packages
32011.403 -> which when you use
IntelliJ or Eclipse,
32014.9 -> it would prompt you to import
32016.9 -> it it would suggest
you to import it.
32019.092 -> So you did not actually
write this input statements,
32022.203 -> but it's very important
32023.561 -> to understand what we
are trying to do here.
32026.2 -> So these are different packages
that we are trying to import
32029.715 -> and as you could see
all your XML related classes.
32033.8 -> Are put into Java x
32035.4 -> dot XML dot transform
or basically G of x
32039.2 -> dot XML package.
32041.6 -> So once you import it,
32042.989 -> you can start using the classes
within the first thing
32046.4 -> that you do is
when you generate an XML,
32049 -> you have document
Builder Factory,
32051.3 -> so you have document build
a factory dot new instance.
32055.022 -> You create a new instance of it
32057.2 -> and you get document build
a factory that's instance of it.
32061.9 -> So now with the document
Builder Factory instance
32065.6 -> that you got you would create
a new document Builder Okay.
32070.035 -> So this is
a factory design pattern.
32072.8 -> We have a design pattern in Java
32074.906 -> and document Builder factor
is nothing but it's following
32078.466 -> a factory design pattern, right?
32080.5 -> You don't have to
think much about it.
32082.676 -> But basically what we
are trying to do is instead
32085.5 -> of creating the instance
of something on our own which is
32089.3 -> like we usually do with new
and the class name, right?
32093.4 -> Sort of doing it on our own
Factory design pattern is
32096.697 -> nothing but the creation logic
is written within a class
32100.146 -> which is not exposed to you.
32101.945 -> So you need not create
it there's some class
32104.696 -> which creates instance for you.
32106.782 -> All right, and that is nothing
32108.8 -> but a factory class then you
create a document Builder.
32112.9 -> So it's nothing but F dot
new document Builder.
32116.8 -> Okay, you handle exceptions
and everything here.
32120.25 -> So now let's start with creating
the actual document.
32124.5 -> You have the root
element as students.
32128.2 -> All right,
32129.4 -> and within student you have
student within students
32133.9 -> you create student
32135.107 -> and within student you have
like first name last name email
32139 -> and marks and you could see
first name put as Henry.
32143.7 -> So how do you create
element is nothing
32146.4 -> but using dog create element,
32148.541 -> how do you create
X node or text node
32151.2 -> or the actual value
that you have?
32153.562 -> Then your element you would do
it with create text node,
32157.8 -> and you could Nest
it using appendchild.
32162 -> So basically you have
first name appended to T1,
32166.3 -> which is nothing
but this one right T1
32169.2 -> is appended to the first name
first name element
32172.9 -> that you have T2,
32174.2 -> which is the text node,
which is holding.
32176.7 -> The last name is appended
32178.6 -> to the last name element p 3
is appended to email element
32184.1 -> and the for which is your marks
32186.3 -> which is appended
to Mark's element.
32188.866 -> So basically this is
how you make nesting
32191.8 -> of your nesting
within the xml's.
32195 -> Alright.
32195.8 -> So once you create this document
you append all the child's
32199.6 -> and everything you create
a well-formed document here.
32203.4 -> Are you create an XML
here and all the XML
32206.9 -> that you would get
is within this dog,
32209.6 -> since we are creating element
you could see here we are.
32213.3 -> Getting elements within doc
creating elements and text node
32217.128 -> and everything within dog.
32218.8 -> So at the end once you
have all this done,
32221.953 -> you would have a well-defined
XML stored as a form
32225.799 -> of document class.
32227.2 -> So we want to print
this particular document
32230.3 -> in a text format,
32231.433 -> right which could
be readable by us
32233.7 -> or do you want an XML out of it?
32236.23 -> So that's when
we use Transformer.
32239 -> So there is a transform
Factory dot again since it's
32242.5 -> a factory design pattern.
32244.249 -> It's exposing a method
32245.789 -> which is nothing
but new instance.
32248.125 -> So you create a new instance
of Transformer factory
32251.971 -> and you create
a new Transformer.
32254.9 -> So at then what you get is
nothing but a Transformer
32258.2 -> and what are we trying
to transform is nothing
32261.3 -> but we are trying
to transform the object
32264.4 -> or the document object
that we created.
32267.7 -> We are trying to transform it
into a human-readable text file
32272.1 -> or the XML file all So
32274.1 -> that's a transformation
that we are trying to do here.
32277.1 -> So here you could see
32278.637 -> that you transform
it TDOT transform
32281.2 -> and you pass the document object
32283.31 -> that you created and put
the element into element
32286.621 -> and text notes
32287.587 -> and everything into which
is holding a valid XML.
32290.9 -> You are trying to transform
it into a XML file.
32294.376 -> So how you do
that is T dot transform.
32297.5 -> Then you have the new Dom source
32300.4 -> and you specify
the instance of document
32304.5 -> which holds your XML then
you have stream result
32309 -> and new stream result class
32311.043 -> which takes file output stream
as its parameter.
32314.6 -> So you have to pass
the parameter where you
32317 -> want to write this XML to and
when you run this at the end,
32320.849 -> we are just printing
that XML file is been generated.
32324.4 -> The first thing that we do
is we are creating a document
32327.7 -> and using the document.
32329.215 -> We are creating elements
the wave that we want.
32332.474 -> So in this case,
32333.474 -> We have a students
as the root node
32335.6 -> and within student
you have student
32337.707 -> and within student
you have first name
32340 -> last name email ID
and marks, right?
32342.449 -> We created this
structure till here.
32344.9 -> And as you could imagine
this is just dealt
32348.13 -> in the form of object.
32349.823 -> Right which is stored in dog.
32352.4 -> So now since you want
to write it into a file,
32355.8 -> which is into a human-readable
form or which could be
32359.3 -> passed across Network.
32360.9 -> You have to transform
this into XML file,
32363.9 -> which could be read.
32365.3 -> So that's what we do
here through Transformer.
32368.675 -> We are transforming
your document or the XML
32372 -> which is in the form
of document into a file.
32375.161 -> So, let's see this program.
32380.4 -> In the meanwhile,
we can do one thing.
32383.1 -> I will create one
more directory here.
32389.9 -> At Eureka XML.
32393.3 -> Okay, and we don't have
any files with them.
32398.9 -> Yeah, let's hold
on for a minute.
32401.3 -> Yeah, I just come up.
32402.7 -> All right, so it's the same
program that we spoke about.
32406.5 -> So I have loaded into my ID.
32410 -> So we do the same steps here.
32412.007 -> We create all the elements all
the required elements and stuff.
32416.4 -> So we are writing it
into a file right
32418.576 -> so you could have
your own file here,
32420.588 -> whatever file you
want to write into.
32424.3 -> okay, so I right
into the directory
32427 -> that we created
which is nothing
32429.2 -> but Ed Eureka XML we
are writing the XML file there.
32436.5 -> All right, let me
execute this program.
32447 -> It's building it and
32448.8 -> if it's generated you should get
XML file generated at the end.
32456.7 -> So this is about using Dom.
32459.2 -> All right.
32459.946 -> So when you say Dom it's nothing
but document object model
32464.434 -> its building it.
32465.826 -> So hold on for a minute.
32468.5 -> In that see I think it
should come up soon.
32475.9 -> Right.
32476.313 -> I think it's coming up.
32770.2 -> Alright, so we have
this program here,
32772.8 -> which is kind
of creating XML document.
32775.8 -> This is same as
what we spoke in the slide.
32778.864 -> Right what I walked you through.
32781.3 -> So basically you have
students you're creating
32784.181 -> students elements
within students element
32787.1 -> you are going to have student
32789.1 -> and then first name
last name email and marks.
32792.5 -> Alright, we are going
to create a text node
32795.286 -> within this elements.
32796.661 -> So this is nothing
but your first name,
32799.149 -> which would go into
the first name element.
32801.9 -> This is the last name
32802.802 -> which would go into
the last name element
32804.802 -> that we created earlier.
32806.3 -> Then we have email
32807.7 -> and marks going
into a prospective element.
32810.8 -> Alright.
32811.6 -> So basically we are nesting
it here at the end.
32813.94 -> We have the Transformer
32815.293 -> which is kind of taking
the document and converting it
32818.2 -> into XML file that we want.
32820.4 -> So let me go and delete this
off and run the program.
32826.4 -> In this folder,
we don't have any file right
32829.565 -> I run this program from here.
32838.8 -> So you could see
that it says XML file generated.
32843.1 -> All right.
32843.6 -> So let's go to the folder
and see up there is a file
32846.6 -> that's generated that is
student studying similar.
32849.7 -> Now I can open this
32851.161 -> with any tool say
I open it with notepad
32854.4 -> and I see something
like this right now.
32857.1 -> I want to format this
I want to format this
32859.845 -> into because this is
like one single string,
32862.559 -> which is Big right?
32863.843 -> So if I want to format it,
32865.6 -> we have tools
that are online,
32867.8 -> even you could format
it online, right?
32870.5 -> So I put this and I say
I want like three spaces
32874.9 -> or indent level which is good
32877.314 -> and I formatted okay
32878.9 -> when I click the format.
32882.31 -> You can see
32883.11 -> that it formatted
the entire XML for me.
32885.6 -> So the basic thing
32887.2 -> that it's doing is just
about formatting this XML.
32890.5 -> All right, this is much more
readable right after formatting.
32894.049 -> You can see
32894.8 -> that it's readable can see
first name as Henry Lee
32897.8 -> and Henry 123 at gmail.com
and you have 70 put in here,
32902 -> which is what we expect out.
32903.647 -> Okay.
32904.447 -> So we saw this output after
running the program Now quickly.
32908.883 -> Let me run through
what's Dom parser
32911.496 -> and how do we use Dom parser
for parsing and existing XML?
32915.6 -> All right.
32916.3 -> So these are the classes
that you need to import
32918.8 -> which would be suggested
by your IDE as well
32921.932 -> either IntelliJ or Eclipse.
32923.9 -> So you have document Builder
Factory you use the same thing
32927.9 -> get the new instance
from the factory
32930.065 -> where in you get an instance
32931.8 -> of document Builder Factory with
this you create document Builder
32935.8 -> and once you have the document
Builder you parse it
32939.382 -> Boca parse method
32940.6 -> The document Builder and pass
the XML file name, right?
32944.2 -> So whatever XML you want to pass
you would send it across now.
32948.144 -> Once you have this past
if you want to get the node name
32951.8 -> if you want to display something
like what's the root element
32954.9 -> within your XML you
could do something
32957.1 -> like this talk dot get document
element and get no name.
32961.318 -> So this would basically
display the first element
32964.876 -> that you have within your XML,
32967.1 -> which is nothing
but the root element right you
32970.083 -> could read this on the name.
32971.9 -> You have the tag names
or element name.
32974.8 -> So you have methods
32976.185 -> like get Elements by tag name
32978.3 -> and you could give
the name of the element
32981.118 -> and it would retrieve
it as a node list.
32983.8 -> Now, you will have to I trait
32985.59 -> through this node list
to display the contents of it.
32988.9 -> All right.
32989.4 -> So here what you do is
you I trade through it.
32992.047 -> So when you get a node list,
32993.7 -> basically you would
get list of notes.
32995.9 -> All right.
32996.533 -> So now what we are doing is we
are printing it out one by one.
33000.6 -> Printing the nodes
are the contents
33003.2 -> that we have within one by one.
33005.784 -> So in this case,
33007.015 -> you can see that when you
do student dot get Elements
33011.046 -> by tag names and you
can see student here.
33014.2 -> So this would give
the number of student
33016.305 -> that you have within a document
the previous example
33019.247 -> that we took the number
33020.6 -> of element is just one right we
just had entry for one student.
33024.502 -> So it would I try it.
33025.823 -> Just once in this case it would
I try it just once all right.
33029.6 -> And what we are doing here
is we are kind of taking
33033.3 -> again element by tag name
33035.4 -> and these are nothing
but your actual values
33038.707 -> or the first name
last name email
33041.602 -> and marks this Loop
is going to run just once
33045.1 -> since we have only one student
33047.112 -> and this is how you display
the content of an XML.
33050.7 -> So basically what we
are doing is we are parsing it
33053.3 -> when we say parse we
are trying to get data
33056.5 -> or we have trying to load data
into Dom or document.
33060.9 -> And we are printing it out.
33062.925 -> Why do we have parsers is
nothing but to retrieve data
33066.9 -> if you want to query
out particular data,
33068.9 -> you could do it.
33070 -> You could write some logic
to read out a particular data
33073.9 -> from an XML.
33074.869 -> Say for example,
33076.1 -> you might have a long XML
and you want to read data
33080 -> pertaining to student Henry.
33082.6 -> So what you could do
here is you could write
33085.353 -> some logic here saying
33086.858 -> that if student is equal
33088.5 -> to Henry then written
mock secured by Henry.
33091.7 -> So that's why we have
XML parsers in picture
33094.745 -> to have it loaded into memory
and play around with it.
33098.5 -> Alright, so let's see
33100.2 -> the example of XML reading
using Dom I give the path here
33105.4 -> as see Give the same file.
33110.3 -> All right at Eureka XML.
33113.5 -> Student dot XML
33114.653 -> that we created
or let me do one thing.
33126.6 -> So I create one
more student here.
33128.8 -> Say for example.
33161.6 -> Just for Simplicity purposes.
33164.8 -> I'm just putting test last name
as the last name test email
33170.9 -> and I put test Mouse.
33175.8 -> All right.
33176.388 -> So these are the values
33177.649 -> that I have put
for one more student
33179.708 -> that I've created
33180.7 -> or maybe I will put this one
as Just to be consistent.
33187.638 -> So we have two students now
within so first one is Henry D.
33192.1 -> And the other one is
33193.4 -> like we have created
a test to let me show you
33196.357 -> when we run this program.
33198 -> What we are trying to do is
we are going to read this XML
33201.3 -> that we have created
and it's going to parse
33204.067 -> it parsing is nothing
33205.37 -> but it's going to display
the contents of it.
33209 -> So it's going to Loop
33210.235 -> through its going to understand
there are two students
33213.1 -> within and it's going to display
first name last name email
33217.8 -> and mock secured
by each student.
33222.2 -> All right.
33222.9 -> It says the
processing instruction.
33231.3 -> Okay, we can see the output
being displayed here.
33235 -> All right, so we can see
33236.737 -> two students here the current
element and really calm
33240.5 -> and re 1 2 3 gmail.com and 70
and there is one more student
33244.192 -> that we added directly
into the XML and we
33246.815 -> can see it displayed as well
saying that test first name,
33250.4 -> press last name test email
and test marks.
33253.6 -> So that's how we bars it.
33256.2 -> Okay using Dom parser and
what Dom parser does is nothing
33260.2 -> but it creates a tree
33261.7 -> if you remember I said
it creates a tree like model
33264.8 -> that was there
in one of the slides
33266.6 -> that we discussed earlier.
33268 -> It creates a tree-like structure
33270.2 -> with a root element
as your root node,
33273.1 -> and your leaves are
nothing but this values
33276.1 -> Henry Lee and all this stuff
whatever is been displayed here
33280.262 -> or nothing but leaves so
of your tree advantages
33283.602 -> and disadvantages of using
Dom it is preferred
33286.8 -> when we have to randomly
access separate parts
33290.045 -> of the document.
33291.206 -> So if you don't want to do
it sequentially its preferred
33295.291 -> that you use Dom it supports
both read and write operation.
33299.6 -> So we created XML using Dom
33301.669 -> and we read XML
using Dom as well.
33304.2 -> So the first example that
we took about creating
33307.3 -> student dot XML was using Dom
as well since it was document.
33311.9 -> Remember we created
object of document
33314.4 -> and then we inserted
all the elements
33316.517 -> within that is nothing
33317.903 -> but Dom it supports both read
and write operation
33320.951 -> as we saw and what are
the disadvantages of using it.
33324.274 -> It is slower than other parsers
since it has to create free.
33328.244 -> So it's a one time activity
that it does.
33330.8 -> So remember in
the second example
33333.1 -> that we took we saw parse here,
33335.5 -> right the sparse here
33337.2 -> document Builder dot parse this
is going to take lot of time
33341.5 -> because it's going
to create a tree
33343.6 -> if you XML is big enough
based on the size of the XML
33347.235 -> it would take time
33348.493 -> because it's going
to create tree.
33351 -> Parsa's something
33352.214 -> that is going to take time and
it's not very memory efficient
33356.475 -> since you could imagine
if you have a big XML
33359.6 -> so xml's in general are
33361 -> like it could have like
a hundred million records
33363.954 -> within they are humongous.
33365.5 -> They are not small examples
that we are dealing right now.
33368.609 -> It's coming from
different systems, right?
33370.852 -> So you could imagine
their system pushing data
33373.5 -> in the form of XML
33374.601 -> and sending it to some other
system to process it.
33377.6 -> So it could be humongous
could grow up to like
33380.859 -> a hundred million records
or something of that sort.
33384.1 -> So imagine that you want to load
all this into memory, right?
33388.407 -> I'm create a tree.
33389.7 -> So this parse method is going
to take a long time to create
33393.297 -> a tree and the other thing
is it's not memory efficient
33396.7 -> because it's going to load
this entire document
33399.7 -> into your memory,
33400.9 -> right which is going to take
33402.804 -> like lot of achebe's
of memory right to load it.
33406 -> So it's not pretty
memory efficient when it comes
33409.1 -> to parsing using Tom.
33411.5 -> So that's the reason
we have other variants
33414.1 -> of parsing which is
not document object model,
33417 -> which is basically event-based.
33419.446 -> So we have like two parses
even base parser one is like
33423.6 -> for push parsing it is sacks
33426.3 -> and whereas for will
parsing it is Stacks.
33429.6 -> All right, so we'll just go
33431.4 -> through what is sax parser and
sax parser sax parser is nothing
33436.6 -> but it stands for simple API for
XML sax parser reads XML file.
33442.9 -> Sequentially.
33444.1 -> It's an event-based right?
33446 -> So when I say even
based what happens is
33448.6 -> when a parsing event occurs,
33450.8 -> the parser invoke
the corresponding method
33453.392 -> of a corresponding Handler.
33455.1 -> So basically you define
a Handler you say
33458.169 -> that if I get so and so tag or
33460.471 -> if I get start of element tag go
to this particular Handler.
33464.942 -> All right,
33465.742 -> and this handlers are nothing
but user-defined handlers
33469.5 -> so you could say that Not get
a start of element tag.
33473.7 -> Go to this Handler
and do something, right?
33476.476 -> It could be as simple as
33478 -> printing it or it could be
as simple as filtering it.
33481.3 -> So it's up to you to write
the logic for the Handler
33484.451 -> but what the framework
does is nothing,
33486.8 -> but when you see a opening tag,
33488.866 -> it would give a call
to your method.
33491.2 -> Alright you Handler
method sax parser is used
33494.8 -> when we have
a large XML document.
33498.2 -> As I said in the previous
example of you know
33500.982 -> hundred thousand records
33502.5 -> that you have within
XML file document object model
33506.1 -> is not that efficient
33507.337 -> because it's going to load
everything into the memory
33510.396 -> which is going to take a lot
of time as well as memory,
33513.4 -> which is going to consume
a lot of memory.
33515.5 -> So it's not good in terms
of time and space complexity.
33518.6 -> Whereas Sachs does a good job
when it comes to large xml's
33522.4 -> when it comes
to parsing large xml's
33524.594 -> because it's not storing
33526.1 -> or it's not parsing everything
into a object in one go.
33530.1 -> It's an event.
33531.028 -> Just so basically you would see
33533.069 -> that it sequentially goes
through the XML and as
33536.179 -> and when it sees
something right start
33538.549 -> of element start of an attribute
or anything of that sort.
33542.2 -> It would give a call to Handler
and Handler would process it.
33546.1 -> So basically it's
not storing anything.
33548.1 -> It's not retaining
any information into memory.
33551.3 -> It is just calling
the event handler
33553.4 -> and just leaving it right there.
33555.3 -> So since it's
not consuming memory,
33557.755 -> it's good when it comes
to large xml's but it's not good
33561.847 -> for random search
right random parsing
33564.6 -> because it goes sequentially so
for sax parser again,
33568.8 -> you could see the files present
33570.9 -> in Java x dot XML dot parses
dot sax parser earlier,
33575.3 -> it was document and here
it's sax parser again.
33579.392 -> You could have
this Imports done by your ID.
33582.7 -> This is what you
event handler is all about.
33585.1 -> Right?
33585.6 -> So you are defining
a an event handler here,
33588.129 -> which is nothing
but a default Handler
33590.6 -> so Your XML reader
using Sachs is nothing
33594.8 -> but a default Handler
is a relationship is
33598.553 -> a default Handler you extended
your extending default Handler,
33603.556 -> which is maybe an internal
interface to your sax parser.
33608 -> Once you extend it.
33609.4 -> It's not an interface or it
33611.14 -> since it's extending
it has to be class.
33613.653 -> All right, it's a class.
33615.4 -> So the default parser
or the default Handler
33618.8 -> would have this methods
within which is nothing
33621.4 -> but start element you have
33623.6 -> characters you have end
element and end document.
33627.1 -> So these are the methods
within right when you give
33630.4 -> a big XML in this example
or when I say this one,
33635 -> so when it comes to student,
33637.2 -> which is your root node,
33638.905 -> it would go to start document
when it reads this XML.
33642.9 -> It understands that it's
a start of document.
33645.852 -> So it says document begins here.
33648 -> It would go sequentially
this parser what it would do.
33651.117 -> Is it would read
this entire file
33653.2 -> and it would go sequentially
33655.2 -> when I say sequentially
then it would understand
33658.6 -> that there is an element again
33660.878 -> and it would give a call
to start element and here
33664.6 -> what you could do is
you could print it.
33667.077 -> So what we are doing
here is nothing
33669.234 -> but we are printing the XML
document using sax parser.
33672.512 -> All right, which is event-based
whenever a particular event
33676.3 -> occurs in your XML.
33678 -> It would give a call
to the particular Handler.
33680.768 -> So whenever there is a start of
document in this case a student
33684.5 -> is a start of element again,
33686.381 -> which would go
into start element.
33688.6 -> All right,
33689.2 -> when does it come
into characters is nothing
33692.2 -> but when it encounters Henry
when it encounters Henry,
33696.7 -> it would go into characters.
33699 -> All right, you see
a character's method here.
33701.302 -> It would go into characters
and you can see
33703.5 -> that it's a character array.
33705.4 -> Alright, so here it
33707.4 -> would print the entire array
which is nothing but the value.
33711.2 -> Lou Henry and all
this Leaf nodes.
33713.6 -> All right, Henry Lee
and whatever values
33716.662 -> that you have would be printed
by this characters method
33720.8 -> whereas the tag names would be
printed by your start element
33725.5 -> and end element.
33727 -> This would be your end element.
33728.8 -> All right.
33729.35 -> So this is pretty much
like it's an event-driven one,
33732.3 -> whenever it encounters
something framework gives a call
33735.6 -> to a particular method
33737.2 -> and this method is user defined
33739.247 -> you could do whatever
you want to so this is
33742.037 -> how you create a instance of it.
33744.136 -> So you have sax parser
Factory dot new instance
33747.012 -> dot new sax parser.
33748.2 -> You create the instance
of sax parser.
33750.3 -> Now you parse it P dot parse
33752.271 -> and you provide the Handler
as well then let
33755.3 -> that you have provided
33756.671 -> which is nothing
but XML reader using sacks.
33759.222 -> That's your Handler.
33760.4 -> So you have to create
the instance of it
33762.5 -> and pass it over.
33763.755 -> Let's see this program now also
33766.14 -> you could see it is reading
students dot XML, right?
33770.95 -> So I'll have to change
this name to see.
33775.9 -> Ed Eureka XML All right.
33780.4 -> So let's run this program
33782.2 -> which is the same program that
I spoke about in the slide,
33785.651 -> which is even based you
could see methods implemented
33788.8 -> here and you could see
it extending default Handler.
33792.9 -> All right.
33793.4 -> So there's a default
Handler this start document
33797 -> basically start document
33798.2 -> and everything is coming
from your default Handler.
33802.3 -> All right, and in
the start element,
33804.9 -> we are just printing
It characters and again
33808.43 -> when it comes to end
we are ending it
33811.3 -> and when it comes to end
33812.8 -> of the document we
are just printing saying
33815.2 -> that document ends here.
33816.8 -> Alright, so we are reading
the same student file
33819.8 -> and this time it's using sacks.
33826.5 -> So you can see here
33827.9 -> when it encountered
start of the document.
33830.639 -> It printed document begins here.
33832.7 -> Then you could see
elements printed sequentially.
33836.139 -> So this is what it is.
33837.603 -> This is like event-driven right
and at the end
33840.8 -> when it reaches the end
33842.1 -> of the document you
can see document
33844.266 -> and C are being printed out.
33846 -> So basically this is
33847.344 -> as I said even driven
and this is sequential,
33850.3 -> right it goes line by line.
33852.2 -> So if you say you have like
a hundred thousand records
33855.6 -> within your XML and
say the last entry
33857.92 -> that you are searching
33859.3 -> for it's going to go
33860.8 -> through the entire XML delete
encounters the last any
33864.9 -> when it comes
to random search or
33867.8 -> if you want to search randomly
33869.958 -> if it's not well suited
but when it comes to Big XML,
33873.7 -> it's much better than Tom
since it's not loading anything.
33878.1 -> So it's not keeping
anything into the memory.
33880.3 -> It's just parsing it
it just printing it out
33882.8 -> and it leaves it right there.
33884.7 -> So what are the advantages
of Sacks, it is simple.
33888.181 -> It is memory efficient.
33889.851 -> Sax parser is faster
than any other parser.
33892.9 -> It handles large document.
33895.3 -> We spoke about all this right
here disadvantages of using
33899.607 -> is land will be unable to
understand the whole information
33903.992 -> because data is
broken into pieces.
33906.7 -> So it's not storing
it in one place.
33909.31 -> It's broken into pieces.
33911.1 -> It's not even storing it into
memory just flushing it off.
33915.1 -> It's just writing it
and leaving it.
33917.2 -> So what's the difference between
Dom and sax parser Dom stands
33921.377 -> for document object model Sixth
33923.5 -> and four simple API
for XML Dom reads.
33926.8 -> The entire document sacks
reads node by node,
33930.164 -> which we saw sequential.
33932 -> It would go Dom is useful
33934.2 -> when reading small to
medium-sized xml's Sachs is used
33938.9 -> when big XML files
need to be parsed.
33942.9 -> Sax is good for big
and this one Dom is used
33946 -> for Two medium sized Dom
is tree-based parser.
33950.2 -> We saw it creates a tree
and sax is event-based far sir.
33954.73 -> We saw how it has
event handler and you saw
33957.923 -> that it calls a particular
method based on the event
33961.8 -> that it encounters Tom is little
slow as compared to Saks and
33966.7 -> because it has to create
the entire tree
33969.3 -> and sax is faster than Dom
33971.9 -> once the tree is created.
33973.6 -> I think Tom would retrieve
it much faster than sacks.
33976.836 -> But the tree creation
itself takes longer time,
33979.8 -> right when you parse it.
33981 -> It has to create
a document model
33983.3 -> which takes a lot
of time Dom can insert
33986.2 -> and delete nodes
33987.454 -> since it has entire
tree it pre-loaded.
33990.4 -> You could actually go
33991.747 -> and delete it you have
the entire tree loaded
33994.532 -> so you can Traverse
to any particular node
33997.246 -> and delete a particular node
33999.1 -> or delete a part
of a tree itself,
34001.5 -> which means that you could do
insertions and deletions
34005.4 -> whereas sack Doesn't store
34007.4 -> anything in memory
just reads there
34010.345 -> and just pushes it off.
34012.1 -> So you cannot insert
34013.638 -> or delete nodes
into your Source XML.
34016.6 -> So basically it's meant
for just doing something
34019.605 -> or retrieving information
from your XML.
34022.1 -> It cannot manipulate
the source XML sax parser is
34025.604 -> cannot manipulate the source
XML now we have one more
34029.4 -> which is Stacks.
34031.5 -> So in terms of sacks,
34033.3 -> if you imagine sex,
it's a push API.
34036.2 -> All right,
34037 -> when I say push API it's nothing
but it reads through scans
34041.087 -> through the XML and
when it encounters an event,
34044.4 -> it pushes the Handler
to handle it.
34047.2 -> So there's a push
34048.5 -> from your API to the handler
do perform some actions
34052.9 -> whereas Stacks it's a cool API,
34055.8 -> lets go through it
to understand more stack stands
34059.32 -> for Java streaming API
34060.9 -> for XML sax parser
pulls the required data
34064.3 -> from the XML this Sax parser
34067.4 -> maintains a cursor
at the current position
34070.409 -> in the document allows
to extract the content available
34074.372 -> at the cursor.
34075.4 -> So basically it
maintains the cursor
34077.413 -> at the current position
in the document
34079.6 -> which allows it to extract
the content available
34082.9 -> at the cursor again,
34084.6 -> you could see Java x
dot XML dot stream
34088.2 -> in the first one the Dom we
had document the second one.
34091.9 -> We had sacks.
34092.843 -> Now the third one
you could see stream.
34095.6 -> So that's the beauty
34096.804 -> of packages you could understand
what files are there with them?
34100.615 -> Okay.
34101 -> So using Stacks
you could see here.
34103 -> We create an event handler
XML element Factory dot create
34107.407 -> XML event handler
and new file reader.
34110.236 -> So you pass a new file reader
34112.358 -> and it's nothing
but the XML file
34114.7 -> that you want to pass.
34116.3 -> Now, you could see
that you get all the elements.
34119.443 -> So basically you have
even Trader and you
34122.118 -> get the elements of front
34123.83 -> or you get all the events
that you have.
34126.6 -> Then and XML.
34127.8 -> All right and UI
thread through it.
34129.8 -> Now you have a switch statement
34131.928 -> which would do
the processing for you
34134.3 -> which would say,
34135.3 -> for example, you have
a start element similar to
34137.9 -> how we saw in the sax parser.
34140.1 -> So you have a start element and
34142.2 -> if it's a start element
and even would be passed
34145.092 -> and you could actually
get the element value.
34147.872 -> So basically what we
are doing here is we
34150.4 -> are getting all the events
and we are iterating through it
34154.167 -> and we have a switch statement
which is handling the event.
34157.9 -> So instead of having
the event Handler written
34160.807 -> in a separate class.
34162.1 -> We are writing the event handler
in the same class.
34165.2 -> This is kind of
again decoupling right?
34167.986 -> So imagine yesterday.
34169.402 -> We spoke about
comparable and comparator.
34172.1 -> So comparable was like
compareto method was written
34175.347 -> within your class right
within your model class,
34178.5 -> which was student yesterday.
34180.1 -> All right.
34181 -> And again, we had
other example of comparator
34184.2 -> which had a compare method
34186 -> which was Into student objects
as an argument.
34189.3 -> So that's the difference.
34190.845 -> Right?
34191.256 -> So we are decoupling it.
34192.9 -> We are writing
the entire comparison logic
34195.719 -> to a different class so we can
we can imagine the same here.
34199.778 -> So that's what the difference
between Stacks and stacks is
34203.7 -> Stacks is writing it
within the same class.
34206.9 -> Whereas sacks you
have a separate class
34209.8 -> for event handling so you could
see here pretty much similar to
34214.5 -> how we did in the sacks
34216.29 -> so you can have like
34217.785 -> if it's a character
then you have even -
34220.716 -> characters you print
the characters when you
34224 -> encounter and document
34225.674 -> you have event as in document
34227.8 -> and so on basically
you get all the events
34230.8 -> and you I trade through it
34232.7 -> and you have switched
treatment handling the event.
34235.5 -> All right, so I
take this example.
34239.2 -> So the first thing
34240.303 -> that I'll have to do
is change the file name.
34244.6 -> Ed Eureka XML and I
just run through it.
34261.409 -> Alright, so here we can see
start element student.
34265.578 -> You have first element as Henry
and so and so forth again,
34270.4 -> first name Henry and stuff
like that again.
34273.2 -> You can see the same second
student being parsed as well
34276.706 -> which was a dummy student
34278.3 -> that we inserted
34279.5 -> and at the end you will see end
of the element student.
34282.9 -> Alright, so this is
34284.261 -> how we parse using
three different parsers
34287.4 -> and we saw about advantages
34289.6 -> and disadvantages and which one
would be apt one per your use.
34294.2 -> All right.
34294.7 -> So you have to understand
the nature of the application
34297 -> or nature of the XML is
34298.6 -> that you are dealing
with and based on
34300.8 -> that you could decide
which parser to go for
34303.6 -> so that's about the parsers.
34305.488 -> Now, let's talk
34306.5 -> about XPath XPath expression is
a query language used to select
34311.1 -> path of XML document
based on the query string.
34315.1 -> You can create a query string
34317.33 -> and you can retrieve Wait using
X bar X power threatens a node
34322.023 -> set representing XML nodes
at the end of the path red.
34326.6 -> So this is basically
like wearing language
34329.314 -> or you have X path expression,
34331.3 -> which you could write
query in this example.
34334.8 -> If I want to get first name of
a student with so-and-so marks
34339.8 -> if I want to get
a first name of student
34342.74 -> with 80% marks, right?
34344.4 -> I could do that using XPath.
34346.488 -> So basically it's
for querying right
34349.1 -> and it returns a node
representing the XML nodes
34352.3 -> at the end of the path.
34353.822 -> It is used to Traverse
elements and attributes
34356.8 -> of an XML document
XPath defines the structure
34361.383 -> and provides XPath expression.
34363.7 -> So the 7 type of nodes
34365.6 -> that can be output
of the execution
34367.781 -> of XPath expression
34369 -> is root element text attribute
comment processing instructions
34375.9 -> and namespace.
34378.7 -> We'll take a look at it
expert defines a pattern
34382.4 -> or path expression
to select nodes
34384.9 -> or node sets in XML document
34387.8 -> what I expect Expressions
you have node name,
34391.1 -> which is used
to select all nodes
34393.13 -> with the given node name you
define a particular node name
34396.847 -> and you could select all
the nodes within an XML document
34400.5 -> that has named as node name.
34403.2 -> So it could be either element.
34405.152 -> It could be
attribute or anything,
34407.3 -> but it could be just
element named rather.
34410.4 -> It specifies that selection
starts from the root node.
34414.01 -> If you have 1/4,
34415.1 -> it says that it starts
from the root node.
34417.8 -> It specifies that the selection
starts from the current node
34421.27 -> that match the selection.
34422.9 -> All right, so /
34424.2 -> scans the entire document / /
is nothing but the current node
34428.9 -> dot it is again select
the current node.
34431.6 -> So whatever node you
are at during parsing,
34434.5 -> it would print it out
dot dot is parent node.
34438.5 -> And at the rate is
it selects attributes.
34441.6 -> So if you want to carry
out certain attributes
34444.6 -> like at the rate ID is equal
34446.5 -> to 10 say the employee IDs
been stored as an attribute
34450.234 -> and if you want to have
34451.8 -> employee ID with value hundred
you could query out saying
34455.6 -> that at the rate ID is equal
34457.5 -> to hundred steps
to use XPath again.
34460.9 -> You have expert
related packages.
34463.008 -> You have to import you have
to create document filter.
34466.5 -> You have to create
an XPath object
34469.1 -> and XPath path expression
create a document
34472.83 -> from a file or a stream.
34475.3 -> So basically when you
are creating document
34477.8 -> is nothing but it's
a dom-based parser.
34480.7 -> Oh, basically it's
not well suited for big xml's
34485 -> for small or medium-sized XML.
34487.5 -> It's good enough
34488.595 -> because it's creating document
out of your XML then fourth
34492.5 -> create an XPath object
and an XPath expression.
34496.9 -> Let's do you have to create
object and you have
34499 -> to pass the expression
34500.4 -> that you want
to retrieve compile
34502.5 -> the XPath expression first,
34503.8 -> you have to ensure
34504.7 -> that the XPath expression
34506.307 -> that you have provided is up
to the mark and it doesn't have
34510.1 -> any error and you're
following the contract
34512.9 -> that XPath expression has
I'd rate over the list of nodes.
34517.4 -> Once you get the result
of the XPath expression
34519.994 -> you have to I'd read
through the list of nodes,
34522.7 -> which is nothing but the result
and examine attributes
34527.1 -> and examine sub-elements, right?
34530.5 -> That's a typical way
in which you would use XPath
34533.7 -> so you could see here.
34535.392 -> It's again Java x
dot XML dot X path.
34538.2 -> There is a separate
package for it
34540.583 -> and it will have all
the classes related
34543.4 -> to it like expat Factory
you have constants
34547 -> and you have like exception
34549.4 -> and you have expert
class itself here.
34552.8 -> We are again parsing
students XML we pass it
34556.379 -> into Document first
34557.9 -> as we mentioned the steps
that we spoke about we
34562.1 -> create the document
34563.8 -> and then you apply the XPath
you have expression here /
34568.6 -> class / student.
34571.08 -> All right, and then you
compile this expression
34574.7 -> what you expression
34576 -> you have here you compile it
and you then evaluate it
34579.9 -> so evaluation is nothing
but you are retreating
34582.576 -> to the result and you
are printing out the result
34585.4 -> that you got
to broadly classify.
34588.057 -> What we are doing here is we
are creating a document object
34591.9 -> out of the XML file
and the next step
34594.6 -> that we do is we
compiled the expression
34597.338 -> and then we are evaluating it
34599.4 -> evaluation is nothing but doing
something with the result.
34602.9 -> There are a couple
of checked exceptions
34604.9 -> that you will have to take care
of so you could see
34608.233 -> that it's been handled here.
34610.3 -> It's not specifically handling.
34612.425 -> It is just printing
out the stack Trace.
34615.307 -> So let me quickly.
34616.7 -> The take this example.
34619.5 -> Alright, so from here
go to resources.
34626.9 -> So let me go
to documents downloads.
34637.5 -> And it's let me run
through the same example and see
34640.5 -> if it runs.
34647.5 -> Alright, so we have I take
34649.9 -> the same example c letter c
at Eureka XML Okay, so,
34669.442 -> let's see if it runs.
34678.2 -> It in fine dot txt size
change this to XML.
34685.8 -> Okay, let's try to run.
34687.3 -> So what I am doing here
is pretty much passing this XML
34692.6 -> and then reading it through.
34705.2 -> So basically just to again
34707.2 -> tell you I love to see why
it's not running at this point,
34710.3 -> but it's more about you
just created document model.
34714.2 -> You have your XPath set
34716.2 -> or you have the XPath
expression you compile it
34719.119 -> and then you evaluate it
which is nothing but
34721.952 -> whatever results you get.
34723.561 -> You can do something on it.
34725.8 -> All right, let me move
on to the next slide.
34730.805 -> Dom4j is open source,
34732.5 -> Java based library to parse
XML document dom4j is flexible
34736.403 -> and memory efficient.
34737.961 -> It integrates.
34739 -> Well with Tom Sachs apis,
34741.6 -> it should be used
when you need the information
34744.9 -> in an XML document
more than once.
34747.5 -> So basically with sacks
34749.6 -> if you want to pass
through more than once
34752.2 -> if you want the information
from the same XML more than
34754.9 -> once it's not that efficient
34756.344 -> because it will have
to parse it again.
34758.304 -> So it doesn't store anything.
34759.8 -> It has to go through it again.
34761.6 -> Whereas this one is something
34763.5 -> that integrates well
with dom and sax apis,
34766.43 -> which allow developers
to use the information
34769.5 -> in an XML document
more than once.
34771.903 -> So what are the steps?
34773.6 -> So basically you have
to download this dom4j dot jar
34777.336 -> from the website
or from the GitHub.
34779.9 -> So there's a GitHub mentioned
above so you'll have to go
34782.729 -> and download the latest
version from there.
34785.2 -> So once you have that Library,
34787.2 -> this is a common thing
that you do in Java.
34790.3 -> You download a jar file.
34791.8 -> You can go and download
any particular jar file
34794.717 -> that you opt for
when I say jar file.
34797.5 -> It's nothing but the third
party Java archive,
34800.5 -> which is nothing but
it's a group of classes
34803.4 -> together doing something.
34805.3 -> You can download any jar
into a specific directory
34809.3 -> and you can add it
into your application.
34812.9 -> There could be a third
party say for example,
34816.1 -> I want to add
two numbers or say,
34818.5 -> for example, you want to do
some big data processing a Java
34822.5 -> by itself doesn't have
34824.012 -> a big data processing
library or framework.
34827 -> So what it would do
is Big Data framework
34830.2 -> will have a jar file exposed.
34832.43 -> Right which is z for example
Apache Apache is a provider
34837.2 -> which is providing solution
for big data, right?
34840.514 -> So you would have the libraries
34842.7 -> or you would have
everything coded into a jar file
34845.9 -> for big data processing now
you need to import that jar file
34849.7 -> into Are you need to link
up your application
34852.55 -> to that particular jar file
34854.3 -> to leverage big data
processing in application.
34858 -> So in that typical scenario,
34859.4 -> what you do is you would have
this jar files downloaded
34862.544 -> into your local directory
34864 -> and have you could add
those external jar files
34867.2 -> or this is
34868.1 -> how you link
to your applications.
34870.3 -> All right.
34870.8 -> So you go to Java you right
click on your application
34874.5 -> go to build path.
34875.9 -> Then you click
on Java build path here.
34878.8 -> And then there's a button
here to the right
34881.3 -> which is ADD external jars.
34883.5 -> You would have a jar file
in this case dom4j
34887.7 -> 2.1 dot o you have
this jar files here.
34891.742 -> Now you link up
to your application
34894.5 -> and you click on that and you
34896.6 -> click on open that would add
the jar file to your application
34900.759 -> and you can apply and close.
34902.7 -> So now you could leverage
that particular jar file
34905.582 -> or the functionality
34906.7 -> that is exposed by the jar file
into your application.
34910.3 -> All right, in this case,
34911.8 -> it was dom4j introduction
to Jack's be Jack's b stands
34916.3 -> for Java architecture
for XML binding.
34919.5 -> It's a specification.
34921 -> Actually Jack's be is used
to write Java objects into XML
34925.673 -> and vice versa.
34927 -> All right, so you
could write it or read it.
34929.7 -> What are the features
of Jack speed supports
34932.2 -> for all w3c schema features read
34935.5 -> all the standard w3c standard
and all the features
34939.21 -> that you have in w3c.
34940.8 -> It has a support for it.
34942.7 -> It reduces a lot of generated
schema derived classes.
34947.4 -> It cut Downs rather
34949 -> on the generated classes scheme
are derived classes
34952.334 -> small runtime libraries
in terms of size.
34955.93 -> It's pretty lightweight
34957.807 -> it provides additional
validation support by jxp,
34961.5 -> 1.3 validation API.
34964.3 -> It steps to convert Java object
34966.7 -> into XML create a pojo
or bind the scheme.
34970 -> And generate the classes.
34971.9 -> So basically Jags B is nothing
but from the schema,
34975 -> you can create your class.
34977.1 -> All right,
34977.748 -> if you schema says
like remember we had
34980.177 -> an excess T wherein we saw
34981.86 -> that it was like an XML
which you could read through
34985.133 -> like you could have the schema
34987 -> if you remember we had
a student schema
34989.279 -> wherein we declared
this is what the format
34991.8 -> of XML would be you could have
34994.11 -> the name you would have
student as a starting tag.
34997.9 -> We defined the sequence as well.
34999.628 -> Like first name should
be first then last name
35002.16 -> then email address
and then marks right?
35004.276 -> We Define the sequence as well.
35006.1 -> So that is nothing but
that's a schema.
35008 -> That is XS T.
35009.4 -> So when use Jack's be
what you do is from the schema,
35013.448 -> you can create Java classes.
35015.8 -> So basically schema is nothing
but schema tells this is
35019.1 -> what an XML can contain
and from schema.
35021.791 -> You can have
Java classes created
35024 -> so there would be a Java class
35025.853 -> by the name student and within
student there would be spring
35029.5 -> so We had the data type
Putin in the exist as well.
35032.8 -> Like first name
35033.7 -> would be string last name
would be string and stuff.
35036.5 -> There's a mapping
between this data type
35038.987 -> and Java data type.
35040.2 -> What it would do is nothing
35041.875 -> but it would create
all these properties
35044.279 -> or all the properties
35045.641 -> that you have all
the elements of elements
35048.3 -> that you have within student.
35050.291 -> There would be
a corresponding property
35052.9 -> created in a Java class.
35054.6 -> So basically this Java class
35056.474 -> could be thought of as
a container for your XML,
35059.519 -> right you could parse them
into this Java class
35062.5 -> and that's where Jack's
be comes into picture.
35065.3 -> It's a binding it binds your XML
into this Java classes.
35070.2 -> All right.
35071 -> So create Jack's be
context object the
35074.7 -> so the next step is to create
Jack's be context object.
35077.4 -> Then create the
Marshal ER objects.
35080.3 -> You have to
Marshal and unmarshal.
35082.657 -> So in this case,
35083.8 -> since we are going to do
from pocho into XML,
35087.1 -> it's going to
be Marshall method.
35089.5 -> All right.
35091 -> Create the content free
by using set methods.
35095.1 -> All right, whatever.
35096.5 -> You want to set your going
to set it into Java object.
35100.113 -> So unlike earlier
in the Dom example
35102.5 -> that we took we were
actually creating the tree.
35105.096 -> If you remember weapon child
and stuff like that,
35107.776 -> which makes it very difficult
to understand right
35110.6 -> which is difficult to maintain
and if you miss something
35114.11 -> it's cumbersome to
actually maintain it.
35116.6 -> Now, you have a student class
wherein you just have to set
35120.162 -> into the student class.
35121.6 -> All right, so create the content
free by using set methods
35126.111 -> and then call the Marshal method
to convert this class
35130.2 -> into an XML.
35132 -> We have a student class
and within student class.
35134.4 -> We would have all
the properties created
35136.8 -> which is derived
from your schema class
35139.3 -> from your schema xsd
35141.3 -> or rather scheming
existing mean the same
35144 -> and what you are doing here is
35145.5 -> you are going to set
it in to set values
35148.214 -> that you want in the XML in.
35150.242 -> The instance variables
in this class student
35153.55 -> and we are going to Marshall
it to convert this into XML.
35158 -> So basically rather
than creating XML on your own
35161.5 -> what you are doing
here is you're using
35163.7 -> the Marshall method to do it.
35165.6 -> So once you Marshall it,
35167.073 -> you should be able
to get the XML.
35169.399 -> So let's understand Jason.
35171.892 -> Jason is nothing
but JavaScript object notation.
35175.9 -> We will look at the format
of it very soon.
35178.7 -> It is easy to read and write
than XML XML is bit cumbersome
35183.3 -> when it comes to reading
35185.1 -> and writing and it takes
occupies lot of memory as well.
35189.5 -> Jason is language-independent
similar to XML.
35193.5 -> It's language independent.
35195.769 -> It is lightweight
compared to XML
35198.6 -> and which is nothing
but lightweight data
35200.9 -> interchange format XML is a data
interchange format as well.
35205.164 -> And Jason is pretty much
35206.9 -> like the same used
for data interchange.
35210 -> The medium of communication
between two different systems
35213.7 -> Jason supports arrays of objects
strings numbers and values.
35219.2 -> So most of the rest API
is restful apis,
35222.2 -> which is nothing but
a web service built upon HTTP.
35226.2 -> Mostly they use Json
for communication between client
35230.5 -> and rest API systems.
35233.2 -> So this is
35234.017 -> because it's pretty lightweight
and it's lighter compared to XML
35239.1 -> and as you could imagine
35240.724 -> since it is across networks
35242.479 -> since communication is
happening across networks.
35245.6 -> You need to have
lightweight system
35247.751 -> or lightweight medium
35249.092 -> or else it would occupy
lot of the bandwidth
35251.839 -> between communication just
35253.3 -> because it is lightweight.
35254.6 -> It's preferable interchange
format difference between Json
35258.9 -> and XML Json stands
35260.814 -> for JavaScript object
notation XML stands
35263.8 -> for extensible markup language.
35266.1 -> Jason is simple to read
35267.683 -> and write XML is
difficult to Then rate
35270.3 -> so we have been looking
at the examples which were
35272.773 -> not pretty straightforward.
35274.2 -> Right?
35274.8 -> We had a lot
of code to be put in
35277.1 -> so it is difficult to read
35279 -> and write Jason is data-oriented
XML is document-oriented.
35285.4 -> Jason is less secure
than XML XML is more secure
35290.3 -> than Jason Jason supports only
text and number data type XML
35296.03 -> supports many data type
35297.8 -> as text number images
charts graphs Etc.
35303.8 -> Alright, so it has restriction
with the number of data types
35307.3 -> that can hold Json object
holds key value pair.
35311.5 -> We took example of student
earlier the form of XML, right?
35314.9 -> We're in new head.
35315.965 -> First name last name and marks.
35317.9 -> This is the same example,
but in Jason,
35320.8 -> so here you could see opening
brace and closing brace
35324.5 -> and you could see
student is a key
35327.2 -> and followed by colon and again,
35329.7 -> There's opening brace
and closing brace for student
35332.7 -> which means it is saying
35334.6 -> that student is object
if you have value
35338 -> as which starts
with opening brace,
35341.2 -> which means that the object
the second one is
35345.3 -> as you get deep into
35346.8 -> this particular object wherein
you see first name, right?
35350.857 -> First name is the key
and you see a literal
35353.9 -> which is Henry as object
as the value rather and
35358.9 -> as you can see here I
Henry is not object.
35361.9 -> That's why you don't have
it within braces,
35364.6 -> which means it's
a literal value.
35366.7 -> Alright again, you have
last name and D'Souza
35369.779 -> which is a literal value
you have marks and 50,
35372.956 -> which is a literal value just
to summarize whenever you have:
35377.105 -> to the left side of the colon
35379.069 -> is nothing but the key
the right side it's a value
35382.3 -> and if you have a value
starting with coats,
35385.1 -> which means that it's
objects a complex object
35388.022 -> or you have multiple things with
35390.3 -> So in this case,
35391.447 -> you could see
that within object.
35393.749 -> You have like three things put
in like first name last name
35398.04 -> and marks basically
student can be mapped
35401 -> to some object in Java
35402.8 -> which will have first name
last name and mouse.
35405.3 -> So each key is represented
as string in Jason and key
35409.284 -> is always string in Jason
35411.207 -> and the value can be
35412.745 -> of any type Json array
represents order list of values.
35417.7 -> It is always ordered.
35419.3 -> Json array can store string
number Boolean or objects.
35425.5 -> It can have string it can hold
number it can hold Boolean
35429.882 -> or any other object as well.
35432.2 -> So here you can see
35433.661 -> the first example is array
representing days of a week
35438.2 -> and you could see Monday
Tuesday Wednesday, Thursday,
35441.2 -> Friday Saturday and Sunday put
in there, right you could see
35445.179 -> another example is students
35447 -> and within students
you could see it.
35450.3 -> Students is nothing
but array of student
35453.8 -> and each student has
first name last name email.
35458.5 -> So basically this is
how you could interpret it.
35461.1 -> So students is nothing
but it's an array.
35464.6 -> So the key is to dance here.
35467 -> Let's see how to run it.
35468.8 -> So the first thing
that you do is Jason simple,
35472.7 -> so you can see here jar file
is already downloaded
35476.469 -> which I would be using so
we have like Jason simple.
35481 -> All right, so it's not there.
35483.1 -> Let me see.
35484.1 -> So whenever you want to deal
with Jason's the first thing
35487.586 -> that you would do is you have
multiple apis though,
35490.7 -> but the slides to come
we are referring
35493.4 -> to Jason simple jar.
35495 -> So the first thing
35496.384 -> that I would do is I
would download Jason simple jar.
35501.219 -> All right, so I go.
35507.5 -> So you could go and download
this Jason simple jar.
35511 -> Okay, usually nowadays.
35512.769 -> We don't do this
35514.2 -> because we have other we
need tools like mavin mavin
35518.248 -> is a build tool
35519.8 -> and you have a file XML file
wherein you provide all the jars
35524.022 -> that you want and it
would download it by itself.
35527.38 -> So it has got a repository
35529.2 -> from which it would
download all the jars.
35531.8 -> You don't have
to explicitly put it
35533.8 -> but I don't want to confuse
at this point with Maven.
35537.4 -> Let's do it this way downloading
it and then linking it.
35541.5 -> All right, so it's connecting.
35543.3 -> Basically, we are
downloading the jar, right
35545.901 -> and you could see it
has downloaded it.
35548.2 -> It's pretty small
like when dkb jar
35550.904 -> because those are
all class files.
35553.6 -> It's Java archive,
35555.3 -> which is nothing
but class file.
35557.5 -> So I take this and I
kind of unzip it.
35564.6 -> Okay, so I get
this directory here
35567 -> and you should be able
to see a jar file.
35569 -> Now.
35569.248 -> This is nothing
but an executable jar file
35571.8 -> you could see it here would see
the type as executable jar file.
35575.6 -> All right.
35576.3 -> So now I put it into
on let's for Simplicity.
35580.166 -> Let me put it here itself.
35583.3 -> All right, so I
create a new folder.
35586.9 -> Which is Ed, Eureka?
35590.4 -> Jason and I put it here.
35593.3 -> So now we'll have to link up
our application with that.
35597.6 -> So what I do.
35601.1 -> So when we had
this dom4j downloaded
35604.4 -> and linked up we'll have
to do the similar stuff
35607.488 -> for this thing as well.
35609.2 -> So since I am using IntelliJ,
35611.8 -> the steps would be
different than Eclipse.
35615.4 -> But basically what you
do is you go into let
35618.776 -> me see the option here.
35620.967 -> There's open module settings.
35623.2 -> So you go to the
open module settings
35625.9 -> and you would see something
of this sort coming up.
35630.019 -> Alright, so now I want
to add something right.
35634.6 -> Add a particular Library.
35637.311 -> So I go to libraries first.
35639.6 -> I click on add Java
and I've Traverse to the path
35644.8 -> that I put the jar file into
35647.1 -> so I put it into
Ed Eureka Jason.
35650.488 -> I select this jar file
and click on OK.
35654.1 -> So this is basically
you're trying to link
35656.488 -> your application to
a particular jar file.
35658.953 -> All right, so you
could leverage it.
35663.8 -> So here you can see
that this is jar file
35666.502 -> that will link
to your application.
35669.1 -> All right, I apply it
35671.6 -> which I already did
and I will click on OK
35675.8 -> OK, so that's
35676.8 -> how you link any executable jar
to your application.
35681.8 -> So you go to the build path
you go to this is
35684.842 -> how you do it in Eclipse.
35686.516 -> Like in IntelliJ. I
did module settings
35689 -> where as in Eclipse.
35690.215 -> You would go to the build path.
35692.1 -> You would go
to the add external jars
35695.1 -> and you would select the path
and then apply and close.
35700.103 -> So this is how you do
it in Eclipse.
35703.2 -> So encoding Jason in Java,
35706.1 -> how do we encode
Jason in Java?
35708.132 -> How do we write a Jason?
35709.834 -> How do we actually
create Jason in Java?
35712.4 -> All right.
35713.8 -> So I had to comment this
earlier now I uncomment this
35718.2 -> so there was some
are earlier now.
35720.5 -> Let me try to resolving it.
35722.5 -> Okay, it's taking So it's asking
me which Java class to resolve.
35732.812 -> So there is a Json object class.
35735.446 -> We'll have to see so
let me select this one.
35739.4 -> So I have a Json file.
35741.6 -> So similarly, I would prefer
just to keep best practices.
35745.7 -> I would say.
35748.6 -> Json object and this is
35751.3 -> like private method
the return type is Json object
35755.3 -> and I say create Jason.
35759.6 -> Andre and I would prefer
to put this here rather
35763.346 -> than in main method
35765 -> that's one of the best
practices by the way,
35767.4 -> it's not something
that you have to do.
35770.2 -> But as I said,
35771.145 -> I prefer to write something like
this give a meaningful name.
35777.6 -> Something like this.
35779.9 -> So I'm just iterating
through this so
35782.4 -> that you get to understand.
35784.4 -> What are the best practices
it's not mandatory.
35789.446 -> So I say student.
35791.9 -> Jason then I say student.
35796.2 -> So this is to make it
more readable tomorrow
35799.08 -> if I come and look at it.
35800.7 -> I would be able
to understand and maybe
35803.1 -> as I said there would be
many other developers
35805.711 -> who would be looking
at the same code
35807.8 -> that you have written in order
35809.696 -> for them to understand and to
increase the maintainability
35813.3 -> and reusability Factor as well.
35815.5 -> It's better to write like this.
35818.4 -> Alright, and then I
could even say private void.
35825.4 -> Bring Jason.
35828.361 -> And I take the Json object.
35831 -> You have a print method
35832.769 -> which is taking
Json object and say
35835.6 -> I call it as Jason because it
could be any generic Jason
35840.7 -> and I print it out saying Jason.
35845.2 -> All right.
35849.5 -> So you have new Json encode
a Creator instance of it
35856.3 -> and I create Jason
now this Json object.
35864.3 -> Which is nothing
but student Jason.
35867.5 -> It's going to be here
and I'm going to call new.
35871.3 -> Json encode dot print Jason
35875.9 -> and I'm going to pass
the student Jason here.
35882.7 -> So we have created a Json here
with first name last name
35886.5 -> and email address
and we have marks as well
35890.3 -> and we are printing this Jason
there so I have run it.
35894.209 -> Let's see what it shows up.
35896.2 -> So Jason is pretty much light
weight as compared to XML
35899.938 -> as you could imagine
right XML has all
35902.5 -> this start tag in tag
and stuff like that.
35905.3 -> So when it comes to
a humongous big chunk of data,
35908.824 -> like millions of data,
35910.475 -> you're processing you
could imagine the size
35913.7 -> of Jason is size
35915.1 -> of XML would be pretty much high
as compared to Jason
35920.2 -> since Jason is just doing it
in the form of key value pair.
35924.2 -> You don't have to end it
you don't have the end tags
35927.076 -> and stuff like that
when it comes to readability.
35930.4 -> I think in terms
of readability XML
35933.1 -> could be better but
when it comes to size,
35936.6 -> this one is better.
35937.794 -> Jason is better.
35938.808 -> So machine to
machine interaction.
35940.9 -> Jason is better
35942.053 -> whereas Deputy I think XML
could be at times more readable
35946.8 -> to humans compared to Jason's.
35949.6 -> Alright, so here you
can see Jason being created.
35953.1 -> So again if I want to format
this there are online tools
35957.9 -> since this have widely
35959.592 -> become standard for data
exchange standards you have lot
35964.8 -> of tools dealing with it.
35966.723 -> All right, if I want to do
online tools itself rather
35970.9 -> if I want to do
Jason for matter,
35973.15 -> I have Jason for matter as well,
35975.434 -> which is online.
35977.7 -> And it's validating as well.
35979.8 -> If you miss something if you
don't have a empty braces,
35983.109 -> or if you don't have
a closing brace, it
35985.508 -> would give you an error, right?
35987.349 -> So if I do this,
35988.366 -> you can see that it formatted it
35990.4 -> and it has given you
to collapse and expand
35993.3 -> so you could parse through
35995.2 -> and understand more
about this Jesus.
35998.3 -> Also, it validates it.
36000.1 -> So if I remove this
36001.4 -> Cody Breeze and
36002.444 -> if I try to do it it would say
it's a invalid Jason.
36006.173 -> So if I scroll down
it shows invalid Jason
36011.5 -> since it was expecting
closing Breeze at the end.
36015.4 -> I put this braces
and it should be back up again.
36019.1 -> Be able to parse it.
36020.819 -> All right, so
that's about Jason.
36023.819 -> So what do we have next
is creating Json file.
36027.4 -> So you could write
it into a file.
36029.6 -> Basically what you
could convert it is
36031.8 -> into a string and you
could write it into a file.
36034.8 -> All right, so if I want
to write here Yeah,
36042.9 -> I want to write to file
36046.1 -> and I said Json object for right
this Json object into a file.
36052.1 -> What I would do is say I do
it using file writer and I
36057.2 -> take the file name as well.
36059.276 -> Say for example or string.
36064.407 -> It should be absolute filename.
36070.3 -> All right, so it's absolute path
of the file name.
36073.6 -> So I do F or maybe I can use it
within the file writer, right?
36080.4 -> So I create a file writer,
which is nothing but Jason.
36085.7 -> File writer since we know
36087.6 -> that it's going
to write just Jason's.
36090.8 -> All right.
36091.3 -> I create the instance of it.
36093.007 -> What does it take?
36095.8 -> So we have created
a file writer for writing.
36098.512 -> It is showing some exception.
36100.3 -> Remember we have to add
exception to throw it.
36104 -> Now.
36104.7 -> What I do is Json file writer. .
36110 -> Right I'm going
to write this thing
36114.153 -> Json object as a string.
36116 -> Okay, so Jason dot
to Json string.
36120.6 -> All right, I got a string and I
would write it into a file.
36124.2 -> Now.
36124.495 -> What I do is Jason
brighter dot flush.
36127.223 -> I would flush whatever
is been buffered.
36130.9 -> And last thing that I
would do is close it.
36135 -> So one thing to remember is
you should always close it.
36138.3 -> If you don't close it.
36139.476 -> It's going to remain open
36141.4 -> and which is going to consume
lot of your memory at the end
36145.2 -> which might become a bottleneck
for your application.
36148.1 -> So remember you whenever
you deal with file,
36150.7 -> you have to close it at the end.
36152.7 -> Now what I do is new I create
a new instance of Json encode
36159.796 -> and I kind of write to a file.
36162.9 -> Okay write this to a file
36166.2 -> and I need to provide
file path as well.
36170.1 -> So I say Ed Eureka.
36173.5 -> Jason died say
36177.507 -> Student Jason I have to handle
the exception here as well.
36182 -> If I want handle I can handle it
36184.1 -> or else I can choose
to throw it off.
36186.8 -> So in this case,
I have thrown it off.
36193.8 -> So you could see the program
executed successfully now.
36197 -> Let me go to a director Jason
and I see student Jason here.
36202.3 -> Okay, go to see I go
to a to record Jason.
36209.2 -> I just open it up and you
should be able to see students
36212.9 -> that Jason has all the fields
36214.693 -> that we have gotten
right first name marks email
36218 -> and this thing so
36219.7 -> yeah, we saw how to write it
into a Json file, right?
36223.042 -> So we have created a Json file
36225 -> and we have similar thing
like how to read it
36228 -> from a Json file you
have like Json parser,
36231 -> which is again,
36232.1 -> you need to pass
your file reader
36234.7 -> and which would pass it
into a particular Json object.
36238.8 -> So from your file,
36239.864 -> you are basically converting it
into a Json object
36242.8 -> and from Json object.
36244.2 -> You can read whatever data
you want to again give you
36248 -> an example you could have
private void read Json
36257.8 -> and you could have
string say absolute.
36266.586 -> Alright, so you have this now
36268.9 -> what I'm trying to do is
I'll create a new Json parser.
36278.9 -> You can see here.
36280.1 -> There's a parse method
which takes filereader.
36283.1 -> All right, so I do dot bars.
36287.7 -> All right, and you could see
there's a second method here,
36290.6 -> which is taking
reader All right.
36292.6 -> So what I do is bars
36297.7 -> new file reader file reader
is nothing but is a reader
36303.3 -> that's why you can use it there
and I give absolute path name.
36309.4 -> All right, so this
should pass your Jason.
36312.4 -> So it's asking me to import it.
36314.421 -> I am putted it.
36316.8 -> So this file not found exception
36318.87 -> that I need to handle which
I will rather throw it off.
36322.24 -> Alright, so as you
could see here,
36324.317 -> I have thrown of filed all
these other exceptional swell
36328.378 -> that I need to handle
36329.7 -> which is nothing
but IO exception which is again,
36332.1 -> I've thrown it off.
36333.4 -> Alright, so we have
Parts this o on parsing
36336.4 -> what do you get is nothing
but object You get Json
36342.4 -> as object right here.
36344.1 -> You have passed it.
36345.4 -> And you have got
Jason as object.
36347.618 -> Now.
36347.884 -> What I'm going to do is I'm
just print going to print
36351.432 -> say one of the attributes
not all since it's going
36354.776 -> to be the same.
36355.8 -> I'm going to print
the first name.
36366.5 -> So it says there's no method.
36368.73 -> Let me see.
36369.9 -> So you have this it cannot
be taken as object directly.
36375.1 -> It has to be taken
as Json object
36377.457 -> so that we could read it.
36379.3 -> All right.
36380.027 -> So this has to be typed
costed to Json object.
36383.3 -> This is basically typecasting.
36385.3 -> All right,
36385.994 -> what is typecasting is
nothing but you know
36388.985 -> what is going
to be written doubt.
36391.4 -> But from the pass
is going to be Json object
36395 -> so we can do it
something of this sort.
36398.3 -> All right,
36399.1 -> once you do this,
you can get based on the key.
36402.6 -> So I give first name key.
36405.3 -> Let me print
the last name as well.
36413.384 -> All right, and let
me print the email as well
36416.784 -> to for convenience.
36425 -> So basically we are going
to read from this so
36428.3 -> its first name last name
36430.3 -> and email as we can see
first name is lowercase.
36434.215 -> So this would give an error.
36439.134 -> So we have passed it as well,
36441.5 -> right we have read
it from Json file.
36444.4 -> Now.
36444.6 -> What I do is I'll have
to give a call to this
36447.4 -> which is nothing but Jason
and quote dot read Jason
36454.6 -> and I passed the same file here.
36459.3 -> All right.
36459.8 -> Now it is asking me
to handle the exceptions.
36463.242 -> So I add it
to the method signature
36466.1 -> as I choose not to handle it.
36468.8 -> All right.
36469.3 -> So what we have done here
is nothing but we are we
36471.9 -> are parsing the Json file.
36473.5 -> All right.
36474.192 -> So we have a read Jason method
36476.269 -> which is taking absolute
file name as its parameter.
36479.9 -> We have a jsonparser class,
36481.864 -> which is one
of the classes from the jar
36484.7 -> that we downloaded
Jason simple jar
36487.291 -> that we downloaded
36488.533 -> and since it's put
into your application
36491.225 -> since we have attached it
with our application.
36494.35 -> We are able to use
those classes, right?
36497 -> If you wouldn't have done
that step of linking the library
36500.064 -> with the application you won't
be able to use this classes.
36503.07 -> Okay, because these are
third party classes.
36506.1 -> This is not as a part
of the standard Java kit or SDK
36510.161 -> that comes with Java.
36511.9 -> We are to download it
and then link it up
36513.9 -> with our application
using module settings
36516.2 -> or if you are in an eclipse,
36517.896 -> then it would be
configured build path.
36520.2 -> Then you parse it and you
provide the reader instance
36524 -> of reader in this case.
36525.612 -> I passed file reader and I
give the absolute file name.
36529.4 -> Once this is done you
should be able to read messages
36533.4 -> or read the content
or read the keys
36537.2 -> that you have within your file.
36539.3 -> You get this an object then I do
Json dot get first name then I
36543.592 -> do Jason don't get last name.
36545.6 -> And the last thing
that I am printing is email.
36548.8 -> All right.
36549.3 -> Let's see if this works.
36552.23 -> So I'm running this.
36558.2 -> You could see the value
being printed here.
36561 -> First name that came out as John
then the last name that is Lee
36565.11 -> and the email that we printed.
36567.1 -> That is John at the
right one two, three.
36570.2 -> All right,
36570.7 -> so that's about XML and Json
which is nothing but it's
36574.7 -> a standard set across industry
for data entry exchange.
36578.6 -> So yeah having said
36579.795 -> that one of the main
differences between XML
36582.5 -> and Json is its lightweight
36584.218 -> and most of the companies
are the industries moving
36587.4 -> towards using Jason's
rather than xml's
36590.417 -> but xml's our Legacy
36591.9 -> and they have lot
of weed they carry a lot
36594.763 -> of weight in the industries lot
of systems at this point.
36598.542 -> I call the financial systems.
36600.522 -> They have Legacy systems
and they deal with xml's
36603.789 -> and less of Jesus.
36605.066 -> But Jason is something
that is upcoming
36607.752 -> and lot of systems
have started migrating
36610.48 -> to or started using Json speak
36612.526 -> since they are lightweight
36614.7 -> that's pretty much
it from my sight
36616.7 -> and thanks a lot for Sting
36618.643 -> and I hope you guys
all become an emerging coders
36622.232 -> and practice a lot on coding.
36624.615 -> All right, so all
the best thank you.
36628.1 -> I hope you have enjoyed
listening to this video.
36631 -> Please be kind enough to like it
36633.05 -> and you can comment any
of your doubts and queries
36636.2 -> and we will reply them
36637.649 -> at the earliest do look out
for more videos in our playlist
36641.417 -> And subscribe to Edureka channel
to learn more.
36644.6 -> Happy learning.
Source: https://www.youtube.com/watch?v=hBh_CC5y8-s