Chapter 1 -Session 1 and 2
Chapter 1 -Session 1 and 2
OVERVIEW
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
What is Programming?
• Programming is the process of writing an algorithm into a sequence of computer
instructions. Or you can simply say it is the process of writing programs.
• The process of transforming the solution of a specific problem into computer
language.
• Programming requires skill, logical thinking and lots of experience.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Who is a Programmer?
• Programmers are the person who writes programs in a specific computer
programming language.
• They are highly skilled, hard working, problem solvers.
• The world’s first programmer was Ada Lovelace. She was widely known for her
work on Charles Babbage’s Analytical Engine
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Classification of Programming Languages
• Different languages have different purposes. Some types are:
• Machine languages, that are interpreted directly in hardware
• Assembly languages, that are thin wrappers over a corresponding machine language
• High-level languages, that are anything machine-independent
• System languages, that are designed for writing low-level tasks, like memory and process
management
• Scripting languages, that are generally extremely high-level and powerful
• Domain-specific languages, that are used in highly special-purpose areas only
• Visual languages, that are non-text based
• Esoteric languages, that are not really intended to be used, but are very interesting, funny, or
educational in some way
• These types are not mutually exclusive: Perl is both high-level and scripting; C is considered both high-level
and system.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Assembler Vs Compiler Vs Interpreter
• Compiler :
Compilers are used to convert high level languages (like C, C++ ) into
machine code .
– Example : gcc , Microsoft Visual Studio
• Assembers :
Assembler are used to convert assembly language code into machine code.
– Examples : List of assembler
• Interpreter :
An interpreter is a computer program which executes a statement directly
(at runtime).
– Examples: python , LISP
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Programming paradigms
• There are many different approaches to computer programming. These are called programming paradigms.
• Different approaches develop solutions to problems using programs using different paradigms.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Imperative Programming
• Imperative programming is the style of programming in which there is a sequence of statements that
change the state of the program.
Example : • The state of the total variable changed from 0 in the beginning of the program,
var total = 0; to 6 before the print function.
var a = 1;
var b = 5; • Imperative programming says how to do something. An example - the process
total = a + b of baking a cake.
print total;
• The program says how to do something in the correct sequence it should be
done, therefore order of execution (the order in which each statement is
executed) is important
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Declarative Programming
• Declarative programming is a programming paradigm … that expresses the
logic of a computation without describing its control flow.
– Examples would be HTML, XML, CSS, SQL, Prolog, Haskell, F#and
Lisp.
• Declarative code focuses on building logic of software without actually
describing its flow. You are saying what without adding how.
– For example with HTML you use <img src="./image.jpg" />
– To tell browser to display an image and you don’t care how it does
• Imperative:that.
C, C++, Java
• Declarative: SQL, HTML
• (Can Be) Mix: JavaScript, C#, Python
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OBJECT ORIENTED PROGRAMMING - OOP
• Object Oriented Programming is a popular methodology of programming any application.
• Java, is an Object Oriented Programming language.
• It allows users create the objects that they want and then create methods to handle those objects.
• Manipulating these objects to get results is the goal of Object Oriented Programming
• Object Oriented programming is a programming paradigm that is associated with the concept of Class and
Objects
• The four principles of object-oriented programming are,
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OBJECT ORIENTED PROGRAMMING - OOP
• OOP is designed in such a way that one should focus on an object while
programming and not the procedure.
• An object can be anything that we see around us.
• Object oriented programming brings programming close to real life, as we are
always dealing with an object, performing operations on it, using it's methods
and variables etc.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
WHY OOPS
1. OOP provides a clear modular structure for programs
2. OOP makes it easy to maintain and modify existing code
3. OOP provides a good framework for code libraries where supplied software components
can be easily adapted and modified by the programmer.
4. Code Reusability
5. It is suitable for real world problems and real world works
6. OOPs lets the coder to change the implementation of an object without affecting any
other code. (Encapsulation)
7. OOPs lets the coder to think about what should be exposed to the outside world and
what should be hidden. (Abstraction)
8. OOPs allows the coder to have many different functions, all with the same name, all
doing the same job, but on different data. (Polymorphism)
9. OOPs lets the coder to write a set of functions, then expand them in different direction
without changing or copying them in any way. (Inheritance)
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - CLASS
• A class is a template or blueprint that is used to create objects.
• The class is a group of similar entities.
• A class consists of Data members and methods.
• The member functions determine the behavior of the class, i.e. provide a definition for supporting various
operations on data held in the form of an object.
• It is only an logical component and not the physical entity.
– For example, if you had a class called “Expensive Cars” it could have objects like Mercedes,
BMW, Toyota, etc. Its properties(data) can be price or speed of these cars. While the methods
may be performed with these cars are driving, reverse, braking etc.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - OBJECTS
• In real-world an entity that has state and its behavior is known as an object.
• In terms of object-oriented programming, software objects also have a state and behavior.
For Example:
• A Car is an object. It has states (name, color,
model) and its behavior (changing gear,
applying brakes).
• A Pen is an object. Its name is Parker; color is
silver etc. known as its state. It is used to
write, so writing is its behavior.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - OBJECTS
• An object can be defined as an instance of a class, and
there can be multiple instances of a class in a program.
• An Object contains both the data and the function,
which operates on the data.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - ENCAPSULATION
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - Encapsulation
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - Encapsulation
• The “state” of the cat is the private variables mood, hungry and energy. It also
has a private method meow(). It can call it whenever it wants, the other classes
can’t tell the cat when to meow.
• What they can do is defined in the public methods sleep(), play() and feed().
• Each of them modifies the internal state somehow and may invoke meow(). Thus,
the binding between the private state and public methods is made.
• This is encapsulation.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - ABSTRACTION
• Abstraction can be thought of as a natural extension of encapsulation
• Abstraction is the concept of hiding the internal details (implementation) and describing things
in simple terms.
• Revealing relevant/necessary information and hiding the unwanted information is abstraction.
• Object-oriented design, programs are often extremely large.
• And separate objects communicate with each other a lot. So maintaining a large codebase like
this for years — with changes along the way — is difficult.
• Abstraction is a concept aiming to ease this problem
EXAMPLE
• In a mobile phone, dialing a number would call some method internally which will concatenate
the numbers and displays it on screen but, we don’t know what is happening internally.
• When you tap on the call option, it is sending signals to other person’s mobile(whom you are
trying to call) but we are unaware of it’s implementation.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - ABSTRACTION
• You interact with your phone by using only a few buttons. But implementation details are hidden.
• Only a short set of actions are known.
• Implementation changes —
for example, a software
update — rarely affect the
abstraction you use.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - POLYMORPHISM
• Polymorphism means “many shapes” in Greek.
• Polymorphism is the concept where an object behaves differently in different situations.
• Performing a job in different ways.(One to many)
• Polymorphism gives a way to use a class exactly like its parent so there’s no confusion with
mixing types. But each child class keeps its own methods as they are.
• For example, in English, the verb run has a different meaning if you use it with a laptop, a foot
race, and business. Here, we understand the meaning of run based on the other words used
along with it.The same also applied to Polymorphism.
EXAMPLE
• We click photographs and record videos using the camera in a mobile phone.
• Various brands have a plethora of camera modes in a mobile like: split camera/panaroma/slow-
mo.
• The basic purpose is to click/record, so the functionality of camera is the same in every mobile,
whereas the modes enable you to use your camera in different ways.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - POLYMORPHISM
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - INHERITANCE
• Inheritance is the object oriented programming concept where an object is
based on another object
• Inheritance is the mechanism of code reuse.
• The object that is getting inherited is called superclass and the object that
inherits the superclass is called subclass.
Example:
• The basic purpose of using a mobile phone is communication.
• There are several brands in mobiles. So, the brands of a mobile are using this
basic functionality(communication) by extending the mobile class functionality
and adding their own new features to their respective brands.
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
OOP - INHERITANCE
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
9. Size of a class is :
a) Sum of size of all the variables declared inside the class
b) Sum of size of all the variables along with inherited variables in the class
c) Size of largest size of variable
d) Classes doesn’t have any size
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
15.If a function can perform more than 1 type of tasks, where the function name
remains same, which feature of OOP is used here?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
18.The feature by which one object can interact with another object is:
a) Data transfer
b) Data Binding
c) Message Passing
d) Message reading
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
MCQ Based on OOPS Concept
19.The feature by which one object can interact with another object is:
a) Data transfer
b) Data Binding
c) Message Passing
d) Message reading
20.Exception handling is feature of OOP. (True/False)
a) True
b) False
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.
Thank You!!!
SMART TRAINING RESOURCES INDIA PVT. LTD. © 2018 SMART Training Resources Pvt. Ltd.