Object & Object Oriented
Object means Real-life or world entity such as pen, table, etc.
Object-Oriented means- If something is oriented to a particular thin that is connected with a thing then object-oriented programming is a methodology or paradigm to design a program using classes and objects. It aims to implement real-world entities like inheritance hiding, polymorphism in programming.
BCSE - 506
![]() |
Introduction to Object-Oriented Programing | it2Edu |
Procedural VS Object-Oriented
Procedural | Object-Oriented |
---|---|
Divides program into small parts called functions | Divided into object |
Follow top-down approach | Follows bottom-up approach |
No data hiding because less secure and overloading | Data handling and no overloading |
Functions are more important than data | Data is imporntnathen funciotn |
As for – C, FORTRAN, Pascal Basic | As for – Simula (First OOP), java, C#, PHP, Python, C## |
Object-Oriented Programming Concepts
- Encapsulation
- Abstraction
- Polymorphism
- Inheritance
- Class
- Object
Object & Class
Object:
- Any entity that has state and behavior as for chair, pen, keyboard, etc.
- It can be physical or logical
- An object is an instance of the class
- Object contains an address and take up some space memory.
- An object can communicate without knowing details of each other’s data dan code.
As for –
- Dog- is an object
- State – color, names, feed
- Behavior – wrapping the tail, barking
Class:
- A Class is a collection of objects called class
- Class is a logical entity
- Class is a blueprint from which individual objects can e created
- Class does not ensure any space.
- User-defined data type which holds its data member and member functions
Examples:
Class of cars
- Data Members - data variable as for speed limit, mileage
- Member Function – A function that manipulates data variables using defined properties and behavior as for brakes, increase speed.
When a class is defined, no memory is allocated, but when the object is created then memory is allocated.
Example:
Class person
{
Char name[20];
Int id;
Public:
Void getdetail(){}
};
int main()
{
Person p1;
}
Important Features of the OOP Concept
Encapsulation:
- Wrapping up of data member and member function in simple usage.
- Binding together data and functions that manipulate data.
- It leads to data hiding.
Example:
- If officials from the finance section need information about sales to resolve the same issue.
- The data of sales can't be accessed
- As the data of sales wrapped under the name "Sales Sections"
finance section official ----> should content sales officers
Abstraction:
- Displaying only essential information and hiding the details.
- It can be incremented using classes. Class group data member and member function sing available access specifiers.
- It can be implemented using header files.
Example:
- pow() method ----- present in ----- math.h header file
- User calls pow() method without knowing the underlying algorithm.
Polymorphism:
- Poly means many and morphism means forms.
- The ability of a mess up to be displayed in more than one form.
- An operation exhibit different behaviors in different instances
- It allows operators and function overloading
e.g.
- A person with different characteristics man as father, husband, employee
- Man possesses different behavior in different situations.
Type of Polymorphism
Method Overloading | Method Overriding |
---|---|
Which method to call will be decided at compile time by the types of parameter | Which method to call will be decided at the run time based on object |
Inheritance:
- Ability to inherit the properties of one class to another or inherit the properties from base class to on inherited class.
- It makes code reusable
- It makes easier to add new features or method to a class.
- It provides an overriding feature that allows a child class to have a specific implementation of a method defined in a parent class
Example:
Grand Parents ⇨ Parents ⇨ Child
Dynamic Biding
- It is the process of executing the part of code at runtime.
- It is used to access some part of code at a time.
- Virtual functions are used to achieve dynamic binding.
e.g. Method overriding
method locate() ⇨ Display message depending on the type of object it is associated.
Message Passing:
- It is a term used for communication between processes.
- It is performed by using objects.
- It is a technique for invoking the behavior of the object.
- Invoking of program sends a message to a process and relies on the process and supportive Infos truce to select and invoke actual code to run.
![]() |
Message Passing Objects | it2Edu |
08/09/21
Introduction to Java
- Java was developed by James Gosling at sun microsystem in 1991, later acquired by Oracle Corporation.
- It helps to create reusable code and modular programs.
- Java is class-based, object-oriented programming language.
- A general-purpose programming language mode for developers to "write once run anywhere" that is compiled has code, can run on all the platforms that support java. e.g. Windows, Mac OS, Unix.
- Java is used for mobile applications (Android apps), desktop applications, web applications, web servers, games, database connections,s and much more.
Features of Java
Some of the key advantages of java programming are listed down:
- Object-Oriented: Except for the primitive data types, all elements in Java are objects.
- Platform Independent: Unlike many other programming languages including C and C++. When java is com9led, it is not compiled into a platform-specific machine rather into a platform-independent byte doe. This byte doe is distributed overused and interpreted by a virtual machine (JVM) on which platform is being run on.
- Simple Design: Java is designed to be easy to learn. if you understand the basic concept of OOP java. it would be easy to master.
- Secure: It enables to development of virus-free, tamper-free systems. authentication techniques are based on public-key encryption.
- Articetrual Neutral: It generates an architecture-neutral object file format, which makes the compiled come excusable on many processes, with the presence of a java runtime system.
- Portable: It is easy to port whenever we need to port one to another platform.
- Robust: Java makes an effort to eliminate error-prone situations by emphasizing mainly compile-time error checking and runtime checking.Automatic memory management: Java manages the memory allocation and deallocation for creating new objects. The program does not fave direct error to memory.
09/09/21
Java Virtual Machine (JVM)
- Java Virtual Machine is an engine that provides a runtime environment to drive java code or applications.
- It converts java byte doe into machine language
- Java is the part of JRE (Java Runtime Environment)
- Java compiler produces code for virtual machines known as Java Virtual Machine (JVM).
How it works
- Java Code compile into byte code
- Byte code interpreted on a different machine
- Byte code is an intermediary language
- JVM is responsible for allocating memory space
ClassLoader | ⇨ | Byte Code Verifier | ⇨ | Execution Engine |
---|
Working of Java Virtual Machine
JVM Architecture
Classloader
⇕
JVM Memory
Method Area | Heap | JVM Stack | PC Requisterd | Native Method Stack |
---|
⇕
Execution Engine | Native Method Interface | Native Method |
---|
- Classloader⇨⇨: It is a subsystem for loading class files.
- Major functions
- Loading
- Linking
- Initialization
- Method Area: To store class structures like metadata,
- Heap: All the objects, their related instance variable, and array are stored in heap. This memory is common and shared across multiple threads.
- JVM Language Stocks: It Store local variables and their portable results. Each thread has its own JVM stock.
- PC Registers: Store address of JVM instruction which essentially executing. Each thread has its own PC Replies.
- Native Method Stack: Hold instruction of native code depend on the native library.
- Execution Engine: It is software used to test hardware software or complete systems. Test execution engine never carries any information about the tasked product.
- Native Method Interface: It is a programming framework. It allows Java code which is the runtime in Java to call by libraries and native applications.
- Native Method Libraries: Collection of native libraries (C, C++) which are needed by the execution engine.
Java Program Execution Process
Editor (Type program in Notepad)
⇩
Compiler (Convert HLLto LLL)
⇩
Linker (Compile the different programs)
⇩
Loader (From secondary store to RAM)
⇩
Execution (By OS & processor)