- [Narrator] The content of the structure,
that holds all the program modules,
functions or methods together is the same
in both languages, Python and Java.
This structure is called a class.
Classes then get instantiated and create objects.
The objects then call the methods, using the dot operator.
They both bring the same benefits
of object oriented programming,
such as modularity, re-usability,
and robustness to the programs.
However, as we've discussed before,
Python as a language, prides itself
in making its' programs very easy to create.
Let's look for a moment here at the program
Python dot py.
It contains both the class
and the client, that which calls the class
in the same file.
This is because the file name and the class name
do not have to be the same like in Java.
This, as you can guess, reduces the amount
of syntax a programmer needs to know.
Each Python file is called a module.
And a module can consist of multiple classes of functions.
If a class from a different file needs to be called,
then the file would need to be created into a package.
And Python requires you to import the package,
using the import line in the first line of the program.
This is, in reality, one of the reasons
Python is hugely popular.
It let's you import libraries with utilities
that are useful for creating powerful Python programs.
Once the library has been imported,
the objects created are exactly like how emp
is created in line number 24 and 25.
Object emp one dot method name display employee.
The naming convention for classes in Java
and Python are identical, in that they used
mixed case letter like class name,
the c is lower case and n is upper case.
And all lower case for method name
like method name one word all lower case.
Now let's take a look at the Java program first
and then we'll move to the Python program.
So looking at the Java program, we see two programs,
employee dot Java employee client dot Java.
The client and class files are both
two separate program files.
Note in the class the default constructor
from line seven to line 12.
And the overloaded constructor from line 14 to line 19.
The private variables are created outside
of the constructor.
And can be accessed only through methods
such as object name dot method name.
For a variable to be called by class name,
the variable has to be declared public and static.
As we can see here in line three,
and can be seen in the client program on line 14
employee dot employee count.
Also looking at the same client program here,
the object is created using the new reserve word.
As you can probably guess, since here
we have two parameters it uses the overloaded constructor.
Now looking at the Python program,
that does the same thing as the Java program.
Let's consider the differences in syntax,
moving to sublime meter and the employee dot py program.
First the constructor.
This is the default constructor.
And here is the overloaded constructor.
It's function is the same, except here
it is a new reserved word, self.
Self refers to the object or variable
that is bound to the class that's getting created.
So in this case, either emp one or emp two,
depending on when it is being con.
Class variables are private and are accessible
only to the dot operator.
For example, emp count.
Emp count is called s employee dot emp count.
Because it's a class variable.
Variables that are declared inside the constructor
on the other hand are called accessible
through the object and the dot operator
and a function name.
So something like if you had to call you would
call display count, which would be able
to access name or salary.
Thus, you can see here as you look through
this program, with minimal syntax,
Python let's a programmer create complex programs
using the class, as well as create and import packages.
Running this program, because I have pre-coded values
set Pat and Matt in there, you see the name
and then you see this salary.
In general, there's a perception,
that if you want to code object oriented programming,
Java is the way to go.
I would like to bring some clarity to this thought here.
In Java there is no getting away from
the object oriented features, such as classes.
In Python a programmer can be quite productive
using functional programming.
While many programmers tend to use Python's
functional paradigm, more than it's object
oriented features, ease of creating classes in Python
should encourage programmers to use it
in Python as well.
This brings a richness of object oriented programming
to an easy to learn programming language.