Introduction to Programming - Types of Languages, Memory Management

00:39:02
https://www.youtube.com/watch?v=wn49bJOYAZM

摘要

TLDRThe video explains various types of programming languages including procedural, functional, and object-oriented programming. It emphasizes that programming languages allow for human-readable code that instructs computers, which ultimately operates using binary. Procedural languages involve a series of structured instructions, whereas functional programming relies on pure functions without altering original data. Object-oriented programming integrates code and data into objects using classes. It also contrasts static versus dynamic languages in terms of type checking during compile and runtime. Finally, the video touches on memory management concepts, including stack, heap, and garbage collection.

心得

  • 💻 Programming languages turn human ideas into machine-readable code.
  • 📜 Procedural languages follow structured steps to complete a program.
  • 🔄 Functional programming uses pure functions and doesn’t modify original data.
  • 🧩 Object-oriented programming combines code and data into objects.
  • ⚖️ Static languages check types at compile time, dynamic at runtime.
  • 🗄️ Memory management includes stack memory for variables and heap for objects.
  • 🗑️ Garbage collection removes objects with no reference variables.
  • 🔄 Functions allow code reuse across multiple problems and files.
  • 📚 Understanding language types is crucial for data structures and algorithms.

时间轴

  • 00:00:00 - 00:05:00

    In this introduction, the creator emphasizes the importance of understanding programming languages like Java, Python, and C++ as foundational elements for data structures and algorithms, highlighting that all computing is fundamentally based on binary (zeros and ones).

  • 00:05:00 - 00:10:00

    The video discusses what programming languages are and how they enable developers to give instructions to computers, illustrating the concept of code as human-readable performance that is converted internally into binary by the machine.

  • 00:10:00 - 00:15:00

    The next section introduces procedural programming languages, which are characterized by a sequence of structured steps, or procedures, necessary for completing tasks, noting that popular languages like Java, Python, and C++ follow this model.

  • 00:15:00 - 00:20:00

    Functional programming is explained next, where functions are used to provide reusable code segments. The concept of pure functions is introduced, emphasizing that they do not modify input variables but can produce new output, with first-class functions as a key feature of this paradigm.

  • 00:20:00 - 00:25:00

    Moving on to object-oriented programming, the video defines it as a model that combines data and code into objects, illustrating how custom data types (classes) allow for better organization and maintainability of code.

  • 00:25:00 - 00:30:00

    The discussion transitions into exploring static versus dynamic typing in programming languages, detailing how static languages check types at compile time while dynamic languages do so at runtime, showcasing the pros and cons of both approaches.

  • 00:30:00 - 00:39:02

    Finally, the creator wraps up with a brief explanation of memory management in programming, clarifying the roles of stack and heap memory, reference variables, and the process of garbage collection where unreferenced objects are cleared from memory.

显示更多

思维导图

视频问答

  • What are the types of programming languages discussed?

    The video covers procedural, functional, and object-oriented programming languages.

  • What is a procedural language?

    A procedural language specifies a series of structured steps to complete a program.

  • What is functional programming?

    Functional programming emphasizes writing programs using pure functions without modifying variables.

  • What is object-oriented programming?

    Object-oriented programming combines code and data into objects defined by classes.

  • What is the difference between static and dynamic languages?

    Static languages perform type checking at compile time, while dynamic languages determine types at runtime.

  • What is memory management in programming?

    Memory management involves how variables and objects are stored in stack and heap memory.

  • What is garbage collection?

    Garbage collection automatically frees memory from objects that have no reference variables pointing to them.

  • How do functions work in programming?

    Functions bundle code that can be reused, allowing for efficient programming across multiple files.

  • Why is understanding types of languages important?

    It helps in grasping foundational programming concepts that are applicable in data structures and algorithms.

查看更多视频摘要

即时访问由人工智能支持的免费 YouTube 视频摘要!
字幕
en
自动滚动:
  • 00:00:04
    hey everyone
  • 00:00:05
    welcome back to the channel and in this
  • 00:00:07
    video we are learning about
  • 00:00:08
    types of languages this is important in
  • 00:00:11
    order to understand you know when we
  • 00:00:12
    will be doing like
  • 00:00:13
    data structures algorithms and even
  • 00:00:15
    though we'll be doing it in java you
  • 00:00:17
    have to you know have a basic idea about
  • 00:00:18
    what all these things
  • 00:00:20
    are and what type of languages you are
  • 00:00:21
    working with be that java
  • 00:00:23
    python or c plus plus so without further
  • 00:00:26
    ado let's just
  • 00:00:27
    jump right into it you know computers
  • 00:00:30
    like
  • 00:00:33
    internally like you know at the very
  • 00:00:35
    minute details it's just bunch of zeros
  • 00:00:37
    and ones
  • 00:00:37
    okay binary numbers and we'll look more
  • 00:00:39
    into like how binary numbers are
  • 00:00:41
    actually stored in memory
  • 00:00:42
    and whatever you know how we convert
  • 00:00:44
    normal decimals to binaries and
  • 00:00:46
    all these other things the memory
  • 00:00:48
    management all of these things will be
  • 00:00:49
    covered in the
  • 00:00:50
    future lectures speaking of programming
  • 00:00:53
    languages
  • 00:00:54
    what are programming languages
  • 00:00:55
    programming languages allow us to you
  • 00:00:57
    know we have some idea
  • 00:00:58
    and we write that in form of a code and
  • 00:01:00
    we get the output for that like whatever
  • 00:01:02
    you want to do let's say you want to
  • 00:01:04
    you know create a function or let's say
  • 00:01:06
    not if i if you don't
  • 00:01:07
    if you're not aware of functions let's
  • 00:01:09
    say you want to create a program
  • 00:01:11
    okay that takes input of all the
  • 00:01:14
    students in your class
  • 00:01:15
    okay or let's say you want to create a
  • 00:01:17
    program that gives you the table of two
  • 00:01:20
    or you want to create a program that
  • 00:01:21
    just you know gives you a nice message
  • 00:01:24
    like
  • 00:01:24
    hi how are you and good morning and all
  • 00:01:26
    these things
  • 00:01:27
    so we can do that via like programming
  • 00:01:29
    languages and
  • 00:01:30
    um programming language is basically as
  • 00:01:33
    i mentioned earlier like
  • 00:01:35
    internally at the very minute details
  • 00:01:37
    it's just a bunch of zeros and ones
  • 00:01:39
    so when you are executing these
  • 00:01:41
    instructions like you're instructing
  • 00:01:42
    your computer
  • 00:01:43
    hey computer please uh please you know
  • 00:01:46
    um
  • 00:01:46
    do this thing for me or tell me the time
  • 00:01:49
    or
  • 00:01:50
    hey computer please uh you know this is
  • 00:01:52
    a program that i have for you like uh
  • 00:01:54
    please print the
  • 00:01:56
    you know date for today so these are
  • 00:01:58
    basically just
  • 00:01:59
    instructions that your cpu is giving
  • 00:02:01
    like you know you're giving to your
  • 00:02:02
    computers
  • 00:02:04
    and computers contains all these things
  • 00:02:05
    like there's a cpu
  • 00:02:07
    there's a ram and how these how all
  • 00:02:08
    these things work we'll look into
  • 00:02:10
    uh later on so internally if it's just
  • 00:02:14
    zeros and ones
  • 00:02:15
    and uh instructions that you're giving
  • 00:02:17
    to your computer
  • 00:02:19
    it would be very difficult to write all
  • 00:02:20
    these instructions in just
  • 00:02:22
    zeros and ones okay there is a reason we
  • 00:02:25
    have like
  • 00:02:26
    programming languages that allows us to
  • 00:02:28
    write all of these programs like okay
  • 00:02:30
    computer do this
  • 00:02:31
    take this output this perform this
  • 00:02:33
    calculate this and do all these things
  • 00:02:36
    that is the reason we have programming
  • 00:02:37
    languages that we can write it in a
  • 00:02:39
    human readable format
  • 00:02:41
    in a human readable format internally
  • 00:02:43
    computer is going to translate it in a
  • 00:02:45
    bunch of zeros and ones
  • 00:02:47
    a computer is problem not my problem
  • 00:02:50
    okay
  • 00:02:51
    cool let's look at the type of languages
  • 00:02:53
    that we may have you might have heard
  • 00:02:54
    about so many languages
  • 00:02:56
    java c c plus plus python no and
  • 00:02:59
    so many other languages the first one we
  • 00:03:02
    are going to look into is called
  • 00:03:03
    procedural language
  • 00:03:04
    now procedural language like very
  • 00:03:06
    initial you know years of programming
  • 00:03:08
    as you can see on the screen it
  • 00:03:10
    specifies a series
  • 00:03:11
    of well-structured steps and procedures
  • 00:03:15
    to compose a program
  • 00:03:16
    now we can do this in you know it
  • 00:03:19
    contains like uh
  • 00:03:20
    an order of statements functions
  • 00:03:23
    and commands to complete a task so for
  • 00:03:25
    example it can be like hey
  • 00:03:27
    first you have to input a number then
  • 00:03:29
    you have to input the second number
  • 00:03:31
    then you have to add the sum of that and
  • 00:03:33
    then you have to print that
  • 00:03:35
    you can also you know see you can see
  • 00:03:37
    this flow of structure that is going
  • 00:03:39
    is it at any point of time going to be
  • 00:03:41
    input a number
  • 00:03:42
    take the sum of the two numbers then
  • 00:03:44
    input the second number
  • 00:03:46
    it will not happen like that right you
  • 00:03:47
    definitely need two numbers and then
  • 00:03:49
    only you will do the sum
  • 00:03:51
    so you can see the series of steps that
  • 00:03:53
    are happening this can happen in many
  • 00:03:54
    ways it can be
  • 00:03:55
    loops if you don't know what loops are
  • 00:03:56
    don't worry you can do this like in your
  • 00:03:58
    statements cases
  • 00:04:00
    functions so many other commands
  • 00:04:02
    basically the idea is to complete a task
  • 00:04:04
    like that
  • 00:04:05
    now you might be wondering hey kunal so
  • 00:04:07
    many languages do this
  • 00:04:09
    i am personally let's say not let's say
  • 00:04:11
    you might be like hey i don't let's say
  • 00:04:13
    know that much about know all the
  • 00:04:14
    languages but i'm pretty sure many
  • 00:04:15
    languages do this
  • 00:04:16
    and you are correct you are correct java
  • 00:04:20
    does this
  • 00:04:21
    python does this c plus plus does this
  • 00:04:24
    so can we say like
  • 00:04:25
    java c plus plus and python and all
  • 00:04:27
    these other languages
  • 00:04:28
    they follow the procedural language
  • 00:04:31
    um the the properties of this
  • 00:04:35
    most definitely they do all right now
  • 00:04:38
    let's look at the next language
  • 00:04:39
    next next type of language is the
  • 00:04:41
    functional language functional language
  • 00:04:43
    what is it
  • 00:04:44
    so writing a pro program only in pure
  • 00:04:46
    functions if you don't know what
  • 00:04:48
    functions are
  • 00:04:48
    do not worry we have a separate module
  • 00:04:50
    for that later in the course
  • 00:04:52
    functions are basically in simple
  • 00:04:54
    language
  • 00:04:56
    whenever i say this thing right whenever
  • 00:04:58
    i say in simple language during the
  • 00:04:59
    course
  • 00:05:00
    that basically means understand what
  • 00:05:02
    it's doing
  • 00:05:03
    ignore how it's doing it because it will
  • 00:05:06
    be covered later in the course
  • 00:05:08
    if you want to google yourself you can
  • 00:05:09
    do that for now just ignore how it's
  • 00:05:11
    doing it because that is a separate
  • 00:05:13
    module in the course
  • 00:05:14
    functions is basically you bundle a code
  • 00:05:17
    together in a particular
  • 00:05:19
    you know let's say something and you can
  • 00:05:20
    use that and reuse that many many times
  • 00:05:23
    if someone asks you hey kunal uh you
  • 00:05:26
    have 10 files
  • 00:05:27
    10 programming files or whatever and in
  • 00:05:30
    every file you have to
  • 00:05:32
    you know take two numbers in sum them
  • 00:05:36
    and print the sum does it make sense
  • 00:05:39
    that i write this program again and
  • 00:05:41
    again for 10 files
  • 00:05:42
    i can just write this program in one
  • 00:05:44
    file and use that particular program
  • 00:05:46
    in every other file saves me time
  • 00:05:50
    also will help me in changing the
  • 00:05:51
    particular function the particular
  • 00:05:53
    program
  • 00:05:53
    if there's an error in the program i can
  • 00:05:55
    just change the main one
  • 00:05:56
    automatically all the ones will be
  • 00:05:58
    changed rather than changing every
  • 00:05:59
    single file
  • 00:06:00
    functions allow us in doing that so pure
  • 00:06:02
    functions are basically never modify the
  • 00:06:04
    variables again if you're not aware of
  • 00:06:06
    variables do not worry
  • 00:06:07
    variable is simply if i'm saying a is
  • 00:06:09
    equal to 10
  • 00:06:10
    so a is a variable and the value of that
  • 00:06:12
    is 10.
  • 00:06:14
    name is equal to kunal name is a
  • 00:06:16
    variable value is kunal
  • 00:06:18
    we'll look into it later on in in this
  • 00:06:20
    particular like shortly as shortly only
  • 00:06:22
    in the next next videos so
  • 00:06:25
    it it is never going to modify it but
  • 00:06:28
    only create new ones as an output
  • 00:06:30
    or in other cases like in simple terms
  • 00:06:32
    if i want to share with you what
  • 00:06:33
    functional programming languages are
  • 00:06:35
    then it can be like used in situations
  • 00:06:38
    where we have to perform lots of
  • 00:06:40
    different operations on the same same
  • 00:06:41
    set of data because it's not modifying
  • 00:06:44
    the
  • 00:06:45
    original data it's creating new one as
  • 00:06:47
    an output
  • 00:06:48
    if you're like hey i am doing machine
  • 00:06:50
    learning here's the data set that i have
  • 00:06:52
    for you
  • 00:06:52
    i'm like okay cool this is my data set
  • 00:06:54
    let's play with this data set
  • 00:06:56
    and you know create some nice algorithms
  • 00:06:58
    and machine learning
  • 00:06:59
    models and whatever right so we are
  • 00:07:03
    doing these things with this data set
  • 00:07:05
    and i am like actually
  • 00:07:07
    utilizing that data set you know uh for
  • 00:07:10
    various operations
  • 00:07:11
    and it might be the case that i'm not
  • 00:07:12
    modifying the original file
  • 00:07:14
    it might be the case that i'm taking a
  • 00:07:15
    copy of that data manipulating it
  • 00:07:17
    changing its type or whatever that i'm
  • 00:07:18
    doing
  • 00:07:20
    another example i can give you is they
  • 00:07:21
    also follow first class functions
  • 00:07:24
    now what are first class functions very
  • 00:07:26
    simple do not worry
  • 00:07:27
    this is very simple stuff first class
  • 00:07:29
    function i'll explain to you right now
  • 00:07:31
    functions are basically just you know
  • 00:07:32
    block of code that i can reuse again and
  • 00:07:34
    again
  • 00:07:35
    many many simple things you can do in
  • 00:07:37
    programming languages like a is equal to
  • 00:07:39
    10
  • 00:07:40
    name is equal to kunal a is equal to
  • 00:07:44
    b that's a b let's say a is equal to
  • 00:07:46
    let's say
  • 00:07:47
    let's say number variable number i i'll
  • 00:07:49
    just write it down over here
  • 00:07:51
    let me just write it down so if i'm
  • 00:07:54
    saying
  • 00:07:56
    let's say in simple programming language
  • 00:07:58
    term i'm saying a is equal to 10
  • 00:08:00
    then i say b is equal to 30 and then i
  • 00:08:02
    say c is equal to b
  • 00:08:04
    so can you see that i reassigned c to b
  • 00:08:07
    if i print c now if i try to get the
  • 00:08:09
    value of c
  • 00:08:10
    it's going to be equal to what the value
  • 00:08:12
    of b which is 30
  • 00:08:14
    so the value of c is also value of b 30
  • 00:08:16
    do not worry about this we'll cover this
  • 00:08:17
    later on
  • 00:08:18
    but the important thing to note over
  • 00:08:19
    here is can you see how i'm reassigning
  • 00:08:21
    variables like this
  • 00:08:23
    c to b and things like that this is
  • 00:08:25
    basically
  • 00:08:26
    means that if you are able to do such
  • 00:08:28
    things with functions as well
  • 00:08:31
    reassigning function variable name to
  • 00:08:33
    other function you know doing all these
  • 00:08:35
    other things
  • 00:08:36
    that basically means that is like first
  • 00:08:37
    class functions
  • 00:08:39
    example for this language that follows
  • 00:08:41
    these sorts of
  • 00:08:43
    you know properties can be python
  • 00:08:46
    python follows such properties python
  • 00:08:47
    has first class functions
  • 00:08:49
    may not be purely functional but it does
  • 00:08:51
    follow the functional programming
  • 00:08:53
    theories now you might be asking hey
  • 00:08:54
    kunal you're saying python is procedural
  • 00:08:56
    also
  • 00:08:57
    saying it follows functionals also which
  • 00:08:59
    one is it
  • 00:09:00
    wait a minute let's look at object
  • 00:09:02
    oriented what is object-oriented
  • 00:09:04
    programming
  • 00:09:05
    so again do not worry if you did not
  • 00:09:07
    like get the gist of it just
  • 00:09:08
    a basic understanding is fine do not
  • 00:09:10
    worry if you did not get the details
  • 00:09:12
    because we have a function
  • 00:09:13
    section separate as a module and
  • 00:09:16
    variables what are variables we will
  • 00:09:18
    cover that in the next next videos
  • 00:09:21
    in this video object-oriented
  • 00:09:23
    programming it basically revolves around
  • 00:09:26
    objects now what is object the idea is
  • 00:09:29
    that code
  • 00:09:30
    the code file that the code that we have
  • 00:09:32
    plus the data
  • 00:09:34
    if you combine these two together it
  • 00:09:35
    forms an object
  • 00:09:37
    what do i mean by an object let's say
  • 00:09:39
    you are like hey kunal
  • 00:09:40
    um can you please collect us a data for
  • 00:09:43
    me
  • 00:09:44
    of 10 people that contains the role
  • 00:09:46
    numbers of those people
  • 00:09:47
    okay that's a problem statement what is
  • 00:09:50
    the type of this data going to be forget
  • 00:09:52
    programming what is the type of role
  • 00:09:54
    number going to be in simple terms
  • 00:09:56
    integer integer let's say hey kunal
  • 00:10:00
    create a collection of data that
  • 00:10:02
    contains
  • 00:10:04
    names of all the students what is the
  • 00:10:06
    type of this data going to be
  • 00:10:08
    string alphabets letters you're like hey
  • 00:10:12
    kunal
  • 00:10:13
    create a collection of data that
  • 00:10:15
    contains all the addresses of people
  • 00:10:17
    what is the type of this is going to be
  • 00:10:18
    maybe like a it's going to be like a
  • 00:10:20
    string or a paragraph
  • 00:10:21
    you know what is the type of all the
  • 00:10:23
    collections of all the people
  • 00:10:25
    the marks of all the people the cgpa
  • 00:10:27
    going to be decimal numbers
  • 00:10:29
    some cgpa 9.5 9.2 9.1 8.7 whatever
  • 00:10:34
    now you might be asking another question
  • 00:10:36
    hey create a collection of data of all
  • 00:10:39
    the students
  • 00:10:40
    where each student has let's say three
  • 00:10:43
    properties
  • 00:10:44
    name roll number and marks now you get
  • 00:10:47
    confused
  • 00:10:48
    okay what is the data type of this going
  • 00:10:50
    to be now what is the data of each
  • 00:10:52
    student going to be of which type
  • 00:10:53
    is it going to be string because we are
  • 00:10:55
    containing names is it going to be the
  • 00:10:57
    integer because we are storing the
  • 00:10:58
    integer like the roll number
  • 00:11:00
    is it going to be decimal point because
  • 00:11:02
    we are storing the marks
  • 00:11:04
    we are storing all of these different
  • 00:11:06
    types of data types
  • 00:11:07
    so what is one single data type that can
  • 00:11:09
    be of a student
  • 00:11:11
    it can be a custom data type which we
  • 00:11:13
    can
  • 00:11:14
    specify using classes do not worry about
  • 00:11:17
    what
  • 00:11:17
    if you don't know what classes are
  • 00:11:19
    classes in simple terms is this only
  • 00:11:22
    named group of properties and functions
  • 00:11:25
    someone is saying create a separate data
  • 00:11:29
    type like a type of data for student
  • 00:11:31
    you're like okay this is neither an
  • 00:11:33
    integer
  • 00:11:34
    nor a string or alphabets nor a decimal
  • 00:11:37
    because it is collection of all
  • 00:11:38
    this collection of all is called a class
  • 00:11:42
    okay so and an instance of this class is
  • 00:11:46
    called an object
  • 00:11:47
    so for example i am of class human
  • 00:11:50
    we all are of class human but i am an
  • 00:11:54
    object of class human i'm a running i'm
  • 00:11:56
    an instance of that class
  • 00:11:57
    a class is like a template a property we
  • 00:12:00
    all know humans have a few properties
  • 00:12:02
    two eyes one nose one mouth two ears two
  • 00:12:05
    hands two legs
  • 00:12:06
    this is a property a template using this
  • 00:12:09
    template god has created many objects
  • 00:12:11
    we we are actually objects we are
  • 00:12:13
    actually the
  • 00:12:14
    the memory inside your ram you know when
  • 00:12:17
    you say a is equal to 10
  • 00:12:19
    a is actually the variable 10 is
  • 00:12:21
    actually the object that is the thing
  • 00:12:23
    that is actually in the memory
  • 00:12:25
    we'll talk more about that later do not
  • 00:12:26
    worry but i hope you are able to
  • 00:12:28
    understand the difference between
  • 00:12:29
    classes and object we'll cover that
  • 00:12:31
    later on classes
  • 00:12:32
    objective programming is a separate
  • 00:12:33
    section but in order to make you
  • 00:12:35
    understand what object-oriented
  • 00:12:36
    programming
  • 00:12:36
    you know is in type of languages it's
  • 00:12:40
    basically
  • 00:12:41
    dividing our code into various chunks so
  • 00:12:44
    that it makes it easy for us to develop
  • 00:12:46
    debug reuse and maintain the software
  • 00:12:49
    for example if you want to create a
  • 00:12:50
    function or sorry not a function a
  • 00:12:52
    program a program
  • 00:12:53
    computer program that has information
  • 00:12:56
    about your car
  • 00:12:57
    it can have many information what is the
  • 00:12:59
    color how what what is the type of the
  • 00:13:01
    car
  • 00:13:01
    supercar or what is the you know how
  • 00:13:03
    many engine does it has
  • 00:13:05
    or what is the type of the engine okay
  • 00:13:07
    so many things
  • 00:13:08
    let's say in your program now you want
  • 00:13:10
    to change the type of the engine
  • 00:13:12
    you're saying hey i want to change it
  • 00:13:14
    from diesel to petrol or petrol
  • 00:13:16
    to diesel or from fuel to electrical
  • 00:13:20
    does it really make sense to change the
  • 00:13:22
    entire car when you go to your car
  • 00:13:23
    mechanic
  • 00:13:24
    and you want to get that you know some
  • 00:13:26
    parts changed do they change the entire
  • 00:13:28
    car or just change that particular part
  • 00:13:30
    they change that particular part if we
  • 00:13:32
    divide the entire
  • 00:13:34
    program also in these parts engine has
  • 00:13:36
    an
  • 00:13:37
    a separate code base steering wheel has
  • 00:13:39
    a separate code base
  • 00:13:41
    you know other properties have separate
  • 00:13:43
    code bases if you want to make a change
  • 00:13:44
    in that entire program just change that
  • 00:13:46
    simple
  • 00:13:47
    part of the program that is what i mean
  • 00:13:50
    by like object-oriented simple terms so
  • 00:13:51
    i'm
  • 00:13:52
    trying to explain it as simple as you
  • 00:13:53
    can as i can do not
  • 00:13:55
    worry about how these things are working
  • 00:13:57
    do not worry about it ignore it
  • 00:13:59
    because it will be covered later on in
  • 00:14:00
    detail ignore what is happening
  • 00:14:02
    just understand what these things are
  • 00:14:04
    ignore how it's happening
  • 00:14:06
    okay now java supports object-oriented
  • 00:14:10
    principles
  • 00:14:11
    okay we can create objects and like
  • 00:14:13
    classes and all these nice nice
  • 00:14:14
    structures that i told you about like
  • 00:14:16
    entire student structure or whatever
  • 00:14:18
    python also supports this
  • 00:14:19
    c plus also supports this i might be
  • 00:14:21
    asking hey kunal
  • 00:14:23
    you're saying java supports both
  • 00:14:25
    procedural and object oriented
  • 00:14:26
    python supports all the three c plus
  • 00:14:29
    plus also supports object-oriented and
  • 00:14:30
    procedural
  • 00:14:32
    are these languages all the types of
  • 00:14:34
    languages the correct answer is yes like
  • 00:14:38
    a particular language if it's object
  • 00:14:40
    oriented it does not mean
  • 00:14:42
    that it will not follow procedural you
  • 00:14:44
    know fundamentals
  • 00:14:45
    procedural rules or functional rules
  • 00:14:48
    java for example follows object oriented
  • 00:14:50
    and procedural
  • 00:14:50
    c we have that follows procedural c plus
  • 00:14:53
    plus we have that follows like you know
  • 00:14:55
    procedural we can also do like some
  • 00:14:56
    functional programming that was as well
  • 00:14:58
    it also follows objective programming
  • 00:15:00
    python you know follows procedural
  • 00:15:02
    functional object oriented so this idea
  • 00:15:05
    that one particular language can only be
  • 00:15:06
    of one type that is not correct
  • 00:15:08
    okay that is not correct it's like
  • 00:15:12
    hybrid sort of like structure follow
  • 00:15:14
    many many other theories
  • 00:15:16
    and that's basically about the types of
  • 00:15:17
    languages we are learning java so we'll
  • 00:15:19
    be doing heavily focused on
  • 00:15:21
    object-oriented principles
  • 00:15:22
    this is also very very important for
  • 00:15:24
    your you know interviews and stuff
  • 00:15:25
    object-oriented we will do in very
  • 00:15:26
    detail
  • 00:15:27
    and so many properties inheritance
  • 00:15:28
    polymorphism abstraction
  • 00:15:30
    encapsulation everything will be done in
  • 00:15:32
    detail do not worry about it
  • 00:15:34
    that was a basic understanding of this
  • 00:15:35
    thing let's move forward
  • 00:15:39
    another types that you might encounter
  • 00:15:41
    are known as
  • 00:15:42
    static versus dynamic languages let's
  • 00:15:45
    look into what is static and dynamic
  • 00:15:46
    language
  • 00:15:47
    let me create a yeah okay
  • 00:15:51
    let me just
  • 00:16:00
    write this thing over here so you are
  • 00:16:01
    able to see i think we all can see this
  • 00:16:04
    now
  • 00:16:06
    cool
  • 00:16:16
    okay just looks good
  • 00:16:20
    so speaking of static versus dynamic
  • 00:16:22
    languages this is based on
  • 00:16:23
    that was based on like the mem like the
  • 00:16:25
    the previous three
  • 00:16:26
    points that we had were like structure
  • 00:16:28
    of the you know how we write code and
  • 00:16:30
    how things are structured and everything
  • 00:16:32
    what are static versus dynamic languages
  • 00:16:36
    static languages before moving forward
  • 00:16:37
    to that we gave the student example
  • 00:16:40
    right
  • 00:16:40
    so i can say i have something like name
  • 00:16:42
    is equal to kunal
  • 00:16:44
    something like this okay now here you
  • 00:16:48
    can see when i write name is equal to
  • 00:16:49
    kunal
  • 00:16:50
    the name the type of this variable that
  • 00:16:53
    we have over here is
  • 00:16:54
    string like letters and alphabets right
  • 00:16:58
    if i say something like roll number is
  • 00:17:00
    equal to
  • 00:17:01
    56 this is of type integer
  • 00:17:05
    okay if i write something like marks is
  • 00:17:07
    equal to
  • 00:17:09
    93.6 this is of type decimal or float
  • 00:17:14
    now there are two ways to approach this
  • 00:17:16
    problem like the problem is that how do
  • 00:17:18
    we know which type how does the
  • 00:17:19
    programming language know
  • 00:17:21
    what is the type of these variables okay
  • 00:17:24
    how does the programming language know
  • 00:17:25
    that
  • 00:17:26
    so the basic idea over here is that
  • 00:17:30
    there are two ways to do this one is the
  • 00:17:32
    static and one is the dynamic
  • 00:17:34
    what is static type checking is you know
  • 00:17:37
    performing the type checking it does the
  • 00:17:39
    type checking at compile time
  • 00:17:41
    so what do i mean by compile time
  • 00:17:42
    remember when i mentioned that
  • 00:17:44
    we write the program in programming
  • 00:17:46
    languages and computer will you know
  • 00:17:48
    compile that and or interpret that in
  • 00:17:49
    whatever sense and
  • 00:17:50
    convert it into the machine readable
  • 00:17:52
    format like zeros and ones or whatever
  • 00:17:54
    assembly or whatever so that the
  • 00:17:56
    computer can understand this
  • 00:17:57
    this conversion is known as compilation
  • 00:18:00
    your source code the code that you will
  • 00:18:03
    be writing in java
  • 00:18:04
    or c plus plus or whatever that gets
  • 00:18:06
    convert to machine code that machine can
  • 00:18:08
    read
  • 00:18:09
    and then machine will read that code
  • 00:18:10
    this is known as compilation of your
  • 00:18:11
    program
  • 00:18:13
    so when you're writing a is equal to 10
  • 00:18:14
    for example
  • 00:18:16
    there are two ways to do this when the
  • 00:18:18
    compilation is done
  • 00:18:20
    and when the program is running that
  • 00:18:23
    time
  • 00:18:24
    if the programming language is like okay
  • 00:18:26
    this is integer that is dynamic language
  • 00:18:30
    entire program is run it is being
  • 00:18:31
    converted to machine language
  • 00:18:33
    and now programming language is like
  • 00:18:35
    okay program is running
  • 00:18:36
    the value of a is equal to 10 so a is an
  • 00:18:38
    integer
  • 00:18:40
    program is running the value of a is
  • 00:18:42
    equal to kunal
  • 00:18:43
    so so value of name is equal to kunal
  • 00:18:45
    sorry name is equal to kunal
  • 00:18:47
    so name has a type of let's say string
  • 00:18:49
    or alphabets or letters or whatever
  • 00:18:51
    okay this is known as dynamic language
  • 00:18:53
    where you do not have to worry about
  • 00:18:56
    specifying the type previously so you
  • 00:18:59
    don't have to tell
  • 00:19:00
    the programming language like hey i am
  • 00:19:02
    giving you a variable
  • 00:19:03
    a which is of type integer like int a is
  • 00:19:06
    equal to 10.
  • 00:19:08
    what is happening in this case this is
  • 00:19:10
    statically typed here
  • 00:19:12
    while the program is compiling while
  • 00:19:14
    it's converting your source code the
  • 00:19:15
    code you have written in machine code
  • 00:19:18
    during that conversion time the
  • 00:19:20
    programming language should know what is
  • 00:19:21
    the type of a
  • 00:19:24
    during that time
  • 00:19:28
    so the type checking here it is done at
  • 00:19:30
    compile time
  • 00:19:32
    while the thing is compiling so you can
  • 00:19:34
    see this left hand side thing what is
  • 00:19:35
    happening is compile
  • 00:19:37
    whatever happens here in the right hand
  • 00:19:38
    side of the equal to is runtime
  • 00:19:40
    this is the actual thing that is stored
  • 00:19:42
    in the object and
  • 00:19:44
    this is the actual object that is stored
  • 00:19:45
    in the memory to understand more about
  • 00:19:47
    this in detail watch the next lecture
  • 00:19:48
    i'll cover it in detail
  • 00:19:50
    what are the memories and how the
  • 00:19:51
    reference variables and everything is
  • 00:19:52
    working in the next detail
  • 00:19:54
    for now just imagine that this is a
  • 00:19:56
    variable a it has a type that is equal
  • 00:19:58
    to whatever type it's equal to
  • 00:20:00
    in simple case again do not worry how
  • 00:20:02
    it's working because that is coming in
  • 00:20:04
    the next lecture
  • 00:20:05
    okay so in static type languages if i'm
  • 00:20:09
    saying you have an
  • 00:20:09
    integer a the value is equal to kunal
  • 00:20:13
    is this possible is this kunal thing
  • 00:20:16
    that i have on the right hand side is
  • 00:20:18
    really an integer
  • 00:20:19
    no it's a string it's letters and you
  • 00:20:22
    know characters
  • 00:20:23
    this will give me an error
  • 00:20:27
    error while my program will be compiling
  • 00:20:31
    it will be like hey you mentioned a is
  • 00:20:32
    integer but you're giving string
  • 00:20:34
    error so errors will show at compile
  • 00:20:37
    time
  • 00:20:38
    okay i hope the first point is clear
  • 00:20:41
    type checking at runtime
  • 00:20:42
    and then static type checking at compile
  • 00:20:44
    time what is runtime when the program is
  • 00:20:46
    running after the compilation period
  • 00:20:48
    okay once the program has been converted
  • 00:20:50
    into machine code
  • 00:20:51
    and when that machine code is running
  • 00:20:53
    that's basically when the runtime thing
  • 00:20:55
    is happening
  • 00:20:56
    okay very simple stuff okay when you
  • 00:20:58
    write
  • 00:20:59
    a is equal to 10 okay let's say this is
  • 00:21:01
    dynamic language i'm not specifying a is
  • 00:21:03
    equal to 10
  • 00:21:03
    i'm like when you run this program you
  • 00:21:05
    figure it out yourself that is what i'm
  • 00:21:07
    saying to the language
  • 00:21:08
    so in this case it will be like okay
  • 00:21:10
    when the program is running so when
  • 00:21:11
    first it will compile and then in the
  • 00:21:13
    runtime like if
  • 00:21:14
    i look at the memories and everything 10
  • 00:21:16
    will actually be stored in some memory
  • 00:21:17
    or ram
  • 00:21:18
    a will be pointing to that all these
  • 00:21:20
    things we'll
  • 00:21:21
    look into it in the next lecture but
  • 00:21:23
    here let's say if we do let's look at
  • 00:21:25
    the second point now
  • 00:21:26
    so error will show at compile time or i
  • 00:21:29
    already showed you if i do something
  • 00:21:30
    like
  • 00:21:31
    you know something like string a is
  • 00:21:32
    equal to 10 or not a something like i
  • 00:21:35
    can do
  • 00:21:35
    int a is equal to kunal
  • 00:21:39
    error kunal is not an integer and you
  • 00:21:40
    are specifying it as integer
  • 00:21:42
    error at compile time let's see how we
  • 00:21:45
    can get an error in the dynamic
  • 00:21:46
    languages
  • 00:21:47
    let's say you do a is equal to 10 this
  • 00:21:49
    will work perfectly fine
  • 00:21:50
    this will work perfectly fine you know
  • 00:21:52
    and uh here you may say
  • 00:21:55
    that um another possibility can be
  • 00:21:59
    a is equal to in the next line i can say
  • 00:22:01
    of the code kunal
  • 00:22:02
    first a was integer now a is kunal
  • 00:22:06
    is it going to give an error pause this
  • 00:22:08
    video and think to yourself
  • 00:22:10
    in dynamic languages where type is not
  • 00:22:12
    specified beforehand
  • 00:22:13
    type is only calculated after the you
  • 00:22:15
    know the in the during the run time
  • 00:22:17
    in python for example okay
  • 00:22:20
    if you said yes then that's not correct
  • 00:22:24
    actually it will not give an error okay
  • 00:22:26
    why it will not give an error watch the
  • 00:22:27
    next video
  • 00:22:28
    it's basically an object and references
  • 00:22:31
    thing and it's uh
  • 00:22:33
    actually like first the value was 10 and
  • 00:22:36
    then the value is going to point towards
  • 00:22:38
    kunal string because at the compile time
  • 00:22:42
    it does not really care about the type
  • 00:22:43
    so it can definitely change things like
  • 00:22:44
    that
  • 00:22:45
    okay first a was pointing to 10 then a
  • 00:22:48
    will be pointing to kunal
  • 00:22:49
    then a will be pointing to 13.5 whatever
  • 00:22:52
    now float or decimals you want
  • 00:22:54
    but this will give an error in static
  • 00:22:55
    languages
  • 00:22:58
    here i have specified a is equal to 10
  • 00:23:00
    there is a rule associated to it
  • 00:23:02
    in the next line if i do a is equal to
  • 00:23:04
    kunal
  • 00:23:06
    this will give an error in static
  • 00:23:07
    languages
  • 00:23:10
    okay so when it's compiling it will be
  • 00:23:12
    like hey you said a is equal to 10
  • 00:23:14
    which is an integer but in the next line
  • 00:23:16
    you are assigning it a string
  • 00:23:17
    this is an error you can definitely do
  • 00:23:19
    something like this
  • 00:23:20
    okay so that's like error will show at
  • 00:23:23
    compile time
  • 00:23:23
    error might not show till the program is
  • 00:23:25
    run so in this case it can be something
  • 00:23:27
    like if you do
  • 00:23:29
    you know if you're doing something like
  • 00:23:32
    a plus 10 so you are adding
  • 00:23:35
    a string and a number this will give an
  • 00:23:37
    error
  • 00:23:38
    okay we'll talk more about this later on
  • 00:23:43
    now declaring the data type before you
  • 00:23:45
    use it we already covered this
  • 00:23:47
    in a is equal to 10 like a is type
  • 00:23:49
    integer value is 10
  • 00:23:50
    declaring the data type before we
  • 00:23:52
    actually use it no need to declare the
  • 00:23:54
    data type
  • 00:23:56
    now what are the advantages
  • 00:23:57
    disadvantages more control
  • 00:23:59
    okay you have to write a little bit more
  • 00:24:00
    code but you have more control over the
  • 00:24:02
    you know type data run time errors are
  • 00:24:05
    reduced
  • 00:24:06
    and in dynamic languages no need to
  • 00:24:08
    specify the type or anything so just
  • 00:24:10
    saves time in writing code but it might
  • 00:24:12
    give error at
  • 00:24:14
    runtime that was pretty much about it
  • 00:24:16
    and we'll cover
  • 00:24:17
    more about the memory management and all
  • 00:24:20
    these things in the next video
  • 00:24:21
    now let's answer a few questions that
  • 00:24:24
    you might be having right you might not
  • 00:24:25
    know what are variables you might not
  • 00:24:27
    know
  • 00:24:27
    how the objects are working internally
  • 00:24:29
    what all this memory thing that i'm
  • 00:24:30
    talking about
  • 00:24:32
    so let's answer that let's take the very
  • 00:24:33
    very simple stuff like the very simple
  • 00:24:35
    stuff
  • 00:24:36
    if you write in a programming language
  • 00:24:38
    something like a is equal to
  • 00:24:40
    10 as simple as it gets i'm just writing
  • 00:24:43
    a is equal to 10 over here
  • 00:24:45
    let's dive deep into how this thing is
  • 00:24:47
    working
  • 00:24:48
    so when you're talking about memory
  • 00:24:50
    management right
  • 00:24:52
    there are two types of memories here in
  • 00:24:54
    your computer you know programming
  • 00:24:56
    languages
  • 00:24:57
    one is the stack memory
  • 00:25:01
    one is the heap memory okay
  • 00:25:04
    so this is the stack memory and this is
  • 00:25:08
    the
  • 00:25:09
    heap memory and when you write in your
  • 00:25:11
    programming language when you write
  • 00:25:13
    something like this
  • 00:25:14
    a is equal to 10 when you write
  • 00:25:16
    something like this
  • 00:25:18
    this a is known as what reference
  • 00:25:20
    variable
  • 00:25:25
    and this 10 is known as what object
  • 00:25:29
    a is not the object many people say is
  • 00:25:30
    the object no a is the reference
  • 00:25:32
    variable 10 is the object
  • 00:25:35
    how is this stored in memory then your
  • 00:25:37
    variables and function calls and
  • 00:25:39
    whatever
  • 00:25:39
    like for now let's just say variables
  • 00:25:42
    they are stored in the stack
  • 00:25:43
    and the actual object that is in the
  • 00:25:45
    memory like the actual value of that
  • 00:25:47
    object
  • 00:25:48
    that is stored in heap
  • 00:25:52
    in this memory let's say in its ram or
  • 00:25:54
    whatever and a
  • 00:25:56
    is going to be pointing towards that
  • 00:25:57
    object
  • 00:26:00
    so when you're saying hey give me the
  • 00:26:02
    value of a
  • 00:26:03
    it's going to say it's 10 how it's going
  • 00:26:05
    to see a is here
  • 00:26:07
    what is a pointing towards a is pointing
  • 00:26:09
    to
  • 00:26:10
    10 this a is going to point to the
  • 00:26:12
    address of this particular thing
  • 00:26:14
    you know every object and stuff has an
  • 00:26:16
    address in the memory like some
  • 00:26:18
    some address in some ram or whatever
  • 00:26:20
    very nice computer science is very
  • 00:26:21
    fascinating
  • 00:26:22
    in simple terms this is how it works so
  • 00:26:24
    you have a is equal to 10
  • 00:26:26
    a is a variable in stack memory pointing
  • 00:26:28
    towards the
  • 00:26:29
    object in heap memory the stack and heap
  • 00:26:31
    and everything is just memory management
  • 00:26:33
    how they are done in
  • 00:26:34
    like computer like scientists and stuff
  • 00:26:35
    they have computer scientists they have
  • 00:26:37
    you know made these things like there's
  • 00:26:38
    a stack memory
  • 00:26:39
    heap memory this thing will be much more
  • 00:26:41
    clear when we'll be doing like recursion
  • 00:26:42
    and stuff
  • 00:26:43
    for now this is as simple as it gets
  • 00:26:45
    it's not like a separate hardware piece
  • 00:26:47
    in your pc okay it's just how memory is
  • 00:26:49
    managed it's how memory is managed
  • 00:26:52
    so a is in the stack memory pointing
  • 00:26:55
    towards the heap memory
  • 00:26:56
    heap is let's say another section of
  • 00:26:57
    your memory or ram or whatever hard disk
  • 00:26:59
    and there's a heap memory allocation
  • 00:27:01
    over there in your you know
  • 00:27:03
    it sometimes there's also like some if
  • 00:27:04
    you talk about cpus they also have some
  • 00:27:06
    memories they have registers and stuff
  • 00:27:08
    but we don't have to go
  • 00:27:09
    in too much detail simple terms
  • 00:27:11
    variables in stack memory
  • 00:27:12
    pointing towards the object in heap
  • 00:27:14
    memory that is simple but that is not
  • 00:27:16
    what i am trying to make you understand
  • 00:27:17
    here
  • 00:27:18
    i am trying to make you understand how
  • 00:27:19
    these things are working and how this is
  • 00:27:21
    going to help us
  • 00:27:23
    what is the actual meaning of object
  • 00:27:25
    what is the actual meaning of reference
  • 00:27:26
    variable let's look into that
  • 00:27:28
    this is the best example and it will
  • 00:27:29
    make things very very clear
  • 00:27:33
    so now we are answering the very
  • 00:27:34
    important question he the
  • 00:27:36
    object and memory and reference variable
  • 00:27:38
    all these things
  • 00:27:40
    previously i mentioned that i am an
  • 00:27:42
    object for by far you should know that
  • 00:27:44
    the reference variable is just like the
  • 00:27:45
    variable
  • 00:27:46
    and the actual value of that variable is
  • 00:27:48
    in the object i'll repeat it again
  • 00:27:50
    variable does not a is not the actual
  • 00:27:52
    value of 10
  • 00:27:53
    in a is equal to 10 10 is actually in
  • 00:27:56
    the memory in the heap memory a is just
  • 00:27:57
    pointing towards that
  • 00:27:59
    for example i am kunal my object is my
  • 00:28:02
    body
  • 00:28:03
    this is a physical object in the memory
  • 00:28:05
    of this of this world
  • 00:28:06
    this is this is the object kunal
  • 00:28:10
    object when i'm saying name is equal to
  • 00:28:14
    kunal
  • 00:28:17
    okay so this object kunal this is a
  • 00:28:19
    object on an actual object
  • 00:28:21
    you might i might ask you hey what is
  • 00:28:23
    the type of this object kunal
  • 00:28:25
    human we are all of class human
  • 00:28:29
    so objects have a type and we can define
  • 00:28:32
    those via classes
  • 00:28:33
    we'll look more into that later on so
  • 00:28:35
    this is the object in the memory in the
  • 00:28:37
    heap memory okay this is in the heap
  • 00:28:38
    memory the object
  • 00:28:40
    if you want to call this object if you
  • 00:28:41
    want to call my myself my my
  • 00:28:44
    physical self how do you call me you
  • 00:28:47
    call me via my name
  • 00:28:48
    so you can say kunal this is the
  • 00:28:51
    reference variable
  • 00:28:52
    pointing to this object so if kunal is
  • 00:28:55
    giving a party
  • 00:28:56
    okay so we'll just say kunal pay the
  • 00:28:58
    bill
  • 00:28:59
    kunal will pay the pill and this objects
  • 00:29:01
    bill account will be reduced like
  • 00:29:03
    this objects money will be spent let's
  • 00:29:06
    say my mom
  • 00:29:07
    also calls me something she does not
  • 00:29:09
    call me kunal she calls me
  • 00:29:10
    son son
  • 00:29:14
    is also the same person if you are
  • 00:29:17
    calling me you will call me kunal
  • 00:29:19
    if my call if my mom let's say only my
  • 00:29:20
    mom if let's say my mom calls me kunal
  • 00:29:23
    same person is being called if my mom
  • 00:29:26
    calls me son
  • 00:29:27
    same person is being called if my sister
  • 00:29:29
    calls me brother
  • 00:29:32
    same person is being called so if kunal
  • 00:29:36
    is giving a party
  • 00:29:37
    or son is giving a party or brother is
  • 00:29:39
    giving a party
  • 00:29:40
    let's say in a hypothetical world i
  • 00:29:42
    might have a girlfriend might call me
  • 00:29:43
    baby
  • 00:29:45
    if baby is giving a party money is being
  • 00:29:48
    spent of the original object only just
  • 00:29:50
    one object
  • 00:29:51
    it's not like there are four canals for
  • 00:29:53
    these four people
  • 00:29:55
    what am i trying to make you understand
  • 00:29:57
    with this if you write something like a
  • 00:29:59
    is equal to 10
  • 00:30:01
    b is equal to 37.5 or whatever you buy
  • 00:30:04
    now you know these are objects
  • 00:30:05
    these are reference variables these are
  • 00:30:07
    in heap memory these are the actual
  • 00:30:09
    objects
  • 00:30:09
    and these are in the stack memory that
  • 00:30:11
    are just pointing towards these objects
  • 00:30:13
    what am i trying to make you understand
  • 00:30:14
    with this example then the thing i'm
  • 00:30:16
    trying to make you understand
  • 00:30:18
    is one object
  • 00:30:22
    or more than one this is what i'm trying
  • 00:30:24
    to make you understand
  • 00:30:25
    listen very carefully more than one
  • 00:30:27
    reference variables
  • 00:30:29
    can point to the same object point
  • 00:30:31
    number one
  • 00:30:32
    pointer number two if any one of these
  • 00:30:35
    reference variables change the object
  • 00:30:38
    original object is going to be changed
  • 00:30:40
    and it is going to be changed for all
  • 00:30:45
    if sun gets a haircut then if br
  • 00:30:49
    if if if uh if son gets the haircut
  • 00:30:52
    then baby also gets the haircut right
  • 00:30:54
    okay if if my mom told me to get a
  • 00:30:56
    haircut
  • 00:30:56
    it's not like my sister will not see
  • 00:30:58
    that haircut even though the change was
  • 00:31:01
    made
  • 00:31:01
    via this reference variable original
  • 00:31:04
    object was changed
  • 00:31:06
    and since all of these other variables
  • 00:31:08
    are also pointing towards the original
  • 00:31:10
    object
  • 00:31:10
    the change is going to be visible to all
  • 00:31:13
    these variables
  • 00:31:16
    this is how it sort of like functions in
  • 00:31:18
    like java and python as well
  • 00:31:20
    so in the future we will be looking into
  • 00:31:22
    like some concepts like pass by
  • 00:31:24
    reference pass by
  • 00:31:25
    value you know might have heard in c
  • 00:31:27
    plus java does not have this thing
  • 00:31:30
    it only has pass by objects value sorry
  • 00:31:32
    not objects value
  • 00:31:33
    pass by reference value okay it does not
  • 00:31:36
    have like value or anything
  • 00:31:38
    pass by reference value that it's there
  • 00:31:40
    in java only we'll talk more about that
  • 00:31:42
    later
  • 00:31:42
    okay how these things are internally
  • 00:31:44
    working but what it's doing are you able
  • 00:31:46
    to understand
  • 00:31:47
    if i'm saying there's a list something
  • 00:31:48
    like this let's say let's say simple
  • 00:31:50
    python example
  • 00:31:51
    let's say i say a is equal to a list
  • 00:31:53
    which is like 1
  • 00:31:54
    3 5 9 or whatever and then i say
  • 00:31:57
    b is equal to a what is happening
  • 00:32:00
    internally
  • 00:32:02
    this is happening internally list is
  • 00:32:04
    nothing but a collection of
  • 00:32:05
    uh numbers or you know elements you can
  • 00:32:08
    you might have
  • 00:32:09
    also heard it like in areas or whatever
  • 00:32:11
    okay let's say this is array forget
  • 00:32:12
    about programming language let's say
  • 00:32:13
    this is an array
  • 00:32:14
    in you know java or python so actually
  • 00:32:17
    internally all of you know this is in
  • 00:32:19
    stack memory pointing towards this
  • 00:32:21
    which is 1 3 5 9
  • 00:32:24
    b is pointing to a means whatever a is
  • 00:32:27
    pointing to b will also point to that
  • 00:32:29
    very simple stuff now if you make a
  • 00:32:32
    change via a if you say the 0th element
  • 00:32:34
    of whatever a is pointing to
  • 00:32:36
    should be 99 this will be changed to 99
  • 00:32:40
    very simple stuff
  • 00:32:41
    now when you display output
  • 00:32:45
    b my question to you is
  • 00:32:48
    is b also going to show this updated 99
  • 00:32:51
    or is it going to show the original one
  • 00:32:54
    pause for a minute and think about it
  • 00:32:56
    if you said that it will also update 99
  • 00:32:58
    that is true because the answer is in
  • 00:32:59
    front of your eyes
  • 00:33:01
    b is also pointing to the same object so
  • 00:33:04
    if this
  • 00:33:05
    simple terms are repeated again if the
  • 00:33:08
    object was changed via one reference
  • 00:33:10
    variable
  • 00:33:12
    then this change will also be visible
  • 00:33:15
    to all the other reference variables
  • 00:33:17
    that are pointing to the same object
  • 00:33:20
    okay there are more things we'll
  • 00:33:22
    consider mutability immutability later
  • 00:33:24
    on
  • 00:33:25
    but this is just like a simple example
  • 00:33:26
    that i'm giving you
  • 00:33:28
    okay don't worry we'll we'll cover
  • 00:33:31
    mutability like how we can modify and
  • 00:33:33
    all these things
  • 00:33:34
    objects and sometimes it may show
  • 00:33:35
    sometimes we may not show but this is
  • 00:33:36
    the
  • 00:33:38
    theory i wanted to show you i noticed
  • 00:33:41
    you were not able to see but i
  • 00:33:42
    i just wrote output b only okay that's
  • 00:33:44
    it output b was only thing written you
  • 00:33:46
    did not
  • 00:33:46
    miss out on anything one more thing i
  • 00:33:49
    want to share with you
  • 00:33:50
    it's another important thing which is
  • 00:33:52
    what happens when there is no reference
  • 00:33:54
    variable to the object
  • 00:33:56
    say it's my name is kunal
  • 00:34:01
    reference variable to something this is
  • 00:34:04
    my body
  • 00:34:05
    okay my object now someone calls me baby
  • 00:34:10
    same object let's say a third person
  • 00:34:13
    came
  • 00:34:13
    let's say um
  • 00:34:17
    i don't know um
  • 00:34:21
    this is a hypothetical situation by the
  • 00:34:22
    way trying to make you understand so
  • 00:34:24
    you know i can either be called kunal or
  • 00:34:26
    baby so if you call me
  • 00:34:27
    by canal or she calls me by a baby same
  • 00:34:29
    person is being called
  • 00:34:31
    okay let's say there comes another
  • 00:34:33
    person
  • 00:34:35
    and let's say this person's name is
  • 00:34:38
    another object so this name is adam
  • 00:34:40
    levine or whatever
  • 00:34:43
    adam levine is married let's take some
  • 00:34:46
    other example
  • 00:34:47
    who is a popular celebrity who is not
  • 00:34:49
    married
  • 00:34:50
    um or i can just take some random name
  • 00:34:55
    uh random name okay alex or alex or
  • 00:35:00
    alex zan alexander
  • 00:35:03
    or something okay this new guy comes
  • 00:35:06
    and now let's say baby now points
  • 00:35:09
    towards alexander
  • 00:35:11
    okay let's say kunal is not the baby
  • 00:35:13
    anymore okay so if alexander is called
  • 00:35:15
    the same person will be called now baby
  • 00:35:17
    will be called
  • 00:35:18
    all the changes made by a baby variable
  • 00:35:20
    will be in this object now
  • 00:35:22
    okay let's say kunal now gets upset
  • 00:35:25
    like i'm not the baby anymore okay so
  • 00:35:28
    what happens to kunal is that
  • 00:35:30
    kunal goes into the forest and like
  • 00:35:32
    leaves the material world and everything
  • 00:35:34
    and gives up his name okay so now there
  • 00:35:37
    is no more name kunal even
  • 00:35:39
    there is no name of this person now this
  • 00:35:41
    person is living alone in the forest
  • 00:35:43
    okay so when this is an object what is
  • 00:35:47
    happening
  • 00:35:47
    this is an object with
  • 00:35:51
    no reference variable
  • 00:35:55
    there is no reference variable to this
  • 00:35:57
    object meaning there is no variable that
  • 00:35:59
    is pointing towards this object
  • 00:36:02
    so this will be removed from the memory
  • 00:36:05
    when garbage collection hits so in java
  • 00:36:08
    there is something known as garbage
  • 00:36:10
    collection
  • 00:36:10
    in very simple terms what is garbage
  • 00:36:12
    collection very simple terms
  • 00:36:14
    garbage collection means that objects
  • 00:36:16
    that do not have a reference variable
  • 00:36:18
    pointing towards them like this example
  • 00:36:20
    no one is pointing to this object when
  • 00:36:22
    the garbage collection hits it
  • 00:36:24
    it is it hits automatically okay when it
  • 00:36:26
    feels like it needs to free the memory
  • 00:36:28
    in that case all the all the objects
  • 00:36:30
    that do not have a variable pointing to
  • 00:36:32
    them
  • 00:36:32
    they will be removed from the memory
  • 00:36:34
    deleted that happens automatically
  • 00:36:36
    we'll we'll look more into that later on
  • 00:36:38
    how we can you know perform
  • 00:36:40
    some functions when garbage collection
  • 00:36:41
    is hit in object 20 programming we look
  • 00:36:43
    into later on there's a finalize final
  • 00:36:44
    finalize on whatever
  • 00:36:46
    okay so if you're doing something like a
  • 00:36:48
    is equal to 10
  • 00:36:50
    so this basically means uh a is pointing
  • 00:36:52
    to an object 10
  • 00:36:54
    then you say a is equal to 37 now a will
  • 00:36:57
    be pointing towards 37
  • 00:37:02
    okay what happens to this 10 no one is
  • 00:37:05
    pointing to 10
  • 00:37:06
    garbage collection will come and remove
  • 00:37:08
    it yam raj
  • 00:37:10
    if you can get that reference okay
  • 00:37:14
    one last thing i wanted to share was in
  • 00:37:15
    like uh previous example i mentioned
  • 00:37:17
    something regarding
  • 00:37:19
    the dynamically type languages
  • 00:37:22
    so why is this thing working so if i say
  • 00:37:25
    something in dynamic type language that
  • 00:37:26
    in python for example if i say a is
  • 00:37:29
    equal to 10
  • 00:37:30
    then i say a is equal to kunal this will
  • 00:37:33
    not give an error
  • 00:37:34
    in dynamic languages where the type is
  • 00:37:37
    decided
  • 00:37:38
    compile at runtime hours this is working
  • 00:37:40
    internally
  • 00:37:42
    now you might be knowing a is pointing
  • 00:37:44
    towards 10
  • 00:37:45
    a is equal to kunal now another object
  • 00:37:47
    will be formed kunal
  • 00:37:52
    a will be now pointing to this this will
  • 00:37:55
    be
  • 00:37:56
    removed when garbage collection hits
  • 00:37:57
    that's how python works
  • 00:37:59
    very simple stuff that's the entire idea
  • 00:38:01
    of objects and you know things and we'll
  • 00:38:02
    go more into details of this when we're
  • 00:38:04
    learning about classes objective and
  • 00:38:06
    programming but this is the general idea
  • 00:38:08
    of memory management
  • 00:38:09
    some simple simple data types we look
  • 00:38:10
    into next lecture is like the integer
  • 00:38:12
    and like character and like booleans
  • 00:38:14
    very simple stuff like int a is equal to
  • 00:38:16
    10
  • 00:38:17
    just created an integer a value 10 this
  • 00:38:19
    is the object this is a reference
  • 00:38:20
    variable this is in stack this is in
  • 00:38:22
    heap
  • 00:38:22
    this is pointing to this that's it if
  • 00:38:24
    you did if you say something like
  • 00:38:25
    output the value of a it will actually
  • 00:38:27
    see where it's pointing and get that
  • 00:38:29
    value and print this for us
  • 00:38:31
    if you say a plus b what is equal to c
  • 00:38:33
    is equal to a plus b
  • 00:38:34
    this will get the value from heap this
  • 00:38:35
    will get the value from heap combine it
  • 00:38:37
    and
  • 00:38:38
    add a value in another another variable
  • 00:38:40
    this also
  • 00:38:41
    will be in heap all the objects are in
  • 00:38:43
    heap nothing to think about here
  • 00:38:45
    very simple stuff all right thanks a lot
  • 00:38:48
    for watching and
  • 00:38:49
    we will see you in the next video make
  • 00:38:50
    sure you like share and subscribe and
  • 00:38:52
    check out the links in the description
  • 00:38:54
    as well
  • 00:39:00
    [Music]
标签
  • programming languages
  • procedural
  • functional
  • object-oriented
  • static languages
  • dynamic languages
  • memory management
  • garbage collection
  • functions
  • coding principles