0% found this document useful (0 votes)
3 views34 pages

Java Chapter-1

The document provides an introduction to Object-Oriented Programming (OOP) concepts and Java, detailing the differences between procedure-oriented and object-oriented programming. It covers key features of OOP such as encapsulation, inheritance, and polymorphism, as well as the structure of classes and objects. Additionally, it discusses the advantages and limitations of OOP, applications of Java, and the components of the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM).

Uploaded by

relzzy63
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views34 pages

Java Chapter-1

The document provides an introduction to Object-Oriented Programming (OOP) concepts and Java, detailing the differences between procedure-oriented and object-oriented programming. It covers key features of OOP such as encapsulation, inheritance, and polymorphism, as well as the structure of classes and objects. Additionally, it discusses the advantages and limitations of OOP, applications of Java, and the components of the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM).

Uploaded by

relzzy63
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING CONCEPTS & JAVA el Contents «Introduction to Procedure Oriented Programming + Object Oriented Programming © Features of Object Oriented Programming ©. The Basics of Object Oriented Programming (Core Concepts of OOP) © Advantages of Object-Oriented Programming (OOP) © Limitations of Object-Oriented Programming (OOP) © Applications of Object-Oriented Programming (OOP) + Comparison of Procedure Oriented and Object Oriented Programming + Introduction to Java + Javo- Feotures + The Difference between Java and C + Jeva Editions + Jova Development Kit (JDK) + Java Runtime Environment (JRE) + Java Viral Machine (JVM) © Architecture and Components of JVM + Java Application Programming Interface (Java API) ‘JDK Vs JRE Vs JVM + Applications of JAVA + Advantages and Disadvantages of JAVA + Review Questions 12 | Java Programming atu In computer programming, there are various types of programming JanguaReses mong them, majo, languages follow either a procedural or object-oriented approach. The term procedure! refers to a Set of procedures, which are subroutines or functions used to break down a program into Smalley Parts. Functions are a set of instructions which performs a particular task. Functions are calleq Tepeatedly in a program to execute tasks performed by them. High-level programming languages such as COBOL, FORTRAN, PASCAL, and C are commonly known, as procedure-oriented programming (POP) languages. These languages follow a structured approach where programs are divided into functions or procedures to perform specific tasks. In a procedure oriented programming, emphasis is given to functions or subroutines. In procedural programming languages, bigger problems are broken down into small solvable Problems. These small problems are converted into procedures or functions, This way the procedural Programming language emphasizes functions rather than data. Thus procedural languages neglecteq data completely and thus they do not ensure data security at all. Example: A program may involve performing arithmetic calculations on two numbers. Here, we can add, subtract, multiply, and divide two numbers, Each of these operations is considered a different function. The main function can call each function separately to perform a specific task. Introduction 10 Object Oriented Programming Concepts & J Oncepts JOVI Handling of data and functions in POP. ec) eI CIE) Function- 4 Function - 2 Function -3 Local data Local data Local data in Procedure-Oriented Programming (POP) can be solved using Object-Oriented (00P). OOP focuses on objects instead of functions and it keeps data secure by hhin objects. It also improves modularity and reusability. This makes programs The problems programming t wit capsulating i ence manage and debug, Object-Oriented Program ‘solve the problems of procedural programming, OOP focuses on data rather than just created t pe A a tions. It keeps data safe by binding it with functions that operate on it. This prevents outside fl functions from modifying data accidentally. Procedural programming organizes programs around functions that act on data. In contrast, object- oriented programming organizes programs around data that controls which functions can access po? defines data types and specifies which operations can be performed on them. This makes secure, modular, and easier to manage. Object-Oriented Programming (OOP) is a programming approach that focuses on organizing code around objects rather than just functions and procedures. An object is a unit that contains data (anrbutes) and functions (methods) that operate on the data, OOP ensures data security modularity, reusability, and better program organization by following key principles such as encapsulation, sbstraction, inheritance, and polymorphism. This approach makes complex software development programs more more structured and efficient. Definitions : Object Oriented Programming. «Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects. ‘These objects contain data (attributes) and functions (methods) that operate on the data. + Object-Oriented Programming is a method of implementation in which programs are organized as a collection of objects that communicate with each other to perform tasks. + Object-Oriented Programming is a software development methodology that enables data hiding, code reusability, and better software maintainability by defining interactions between objects. dt The organization of data and functions in object oriented programming is shown in the below diagram. + In OOP, objects are the core building blocks ofa program. Each object contains _} |) Organization of Data and Functions in data (attributes) and functions(methods) | | Object Oriented Programming that operate on that data. [object A] * The Program is divided into number of Data & Functions} small units called Object. The data and function are built around these objects. + The data of the objects can be accessed only by the functions associated with that aint onfecta object. Data & Functions] Data & Functions| * The functions of one object can access the functions of other object. Object-Oriented Approach A Library Management System needs to handle book borrowing, returning, and tracking, The system consists of three main objects Object Data Methods yl iorary (Object A)}| = aero * issueBook(Book, Member) > Issues a book to a member Library Name, « returnBook(Book, Member) ~ Records a returned book Issued Books Member Name, + requestBook(Book) > Requests a book from the library Member (Object B)| | Member ID, Rae Becle + returnBook(Book) > Returns a book to the library Book Title, ‘Author, © updateAvailability Status) +Updates book's availability’ Book (Object C) ISBN, ‘+ getBookDetails() > Returns book information | Availability Status Flow of Interactio1 1. Member (Object B) requests a book from the Library (Object A) + Function Call: MemberrequestBook("Data Structures") + Library checks ifthe book is available 2. Library (Object A) issues the book and updates Book (Object C)'s status a + Function Call: LibraryissueBook("Data Structures", Member) + Library updates the Book's availability using ’[Link]("Issued”) 3. Member (Object B) returns the book, and Library (Object A) updates Book (Object C)' status + Function Call: [Link]("Data Structures") + Library processes the return using [Link](Book, Member) : + Library updates the book's status to Wailable" using "Book. updateAvailability(’Available") Introduction to Object Oriented Programming Concepts £100 Features of Object Oriented Programming. ‘The important features of Object-Oriented Programming are listed below. Focus is more on data rather than functions or procedures. programs are divided into entities known as objects. pata structures are designed to characterize objects. Functions that operate on the data of an object are tied together within the object. pata is hidden and cannot be accessed directly by external functions. objects communicate with each other through function calls. New data items and functions can be easily added whenever required. ‘The bottom-up approach is followed in program design. Encapsulation ensures data security by restricting direct access. 10. Abstraction hides implementation details and shows only essential features. 41, Inheritance allows one class to acquire properties and behaviors of another. 12, Polymorphism enables methods or functions to perform different tasks based on context. 13, Modularity organizes code into independent and reusable components. 14, Message passing allows objects to interact by invoking each other's methods. 15, Code reusability eliminates redundancy by using existing classes for new functionalities. 16, Dynamic binding allows method calls to be resolved at runtime for flexibility. 47. Extensibility makes it easy to update or modify the program without affecting the entire system. scalability ensures efficient handling of growing data and functionalities. cy is minimized by storing data efficiently within objects. and behavior. SEAN Ane wn 18, 19. Data redundant 20. Code maintainability improves as each object manages its own data ‘these features make Object-Oriented Programming a powerful approach for building real-world applications. It helps in developing reliable and secure software systems. Italso improves efficiency in software development. EEE: Basics of Object Oriented Programming (Core rently by different people. Itis important to have ts used in Object-Oriented Programming. These d and how they interact within a program. They ig data security, code reusability, and ‘Object-Oriented’ is a term that is understood differ a clear understanding of the fundamental concept concepts define how data and functions are organize help in designing structured and efficient programs by improvin; modularity. The key concepts of Object-Oriented Programming are: 1. Object 2. Class 3. Abstraction 4, Encapsulation 5, Inheritance 6. Polymorphism ee eee = Objects are the basic units of Object-Oriented Programming (OOP). They are created from a class and contain both data and functions to perform tasks. In OOP, everything is represented as an object An object is a real-world entity that has a unique identity, properties, and the ability to interact with other objects. It is designed to closely match real-world objects. Like a structure in C, an object also takes up space in memory and has a specific address. An object is made up of members and methods. Members {also called data members, attributes, or properties) store information about the object. Methods define the actions the object can perform, This allows objects to work together and interact in a structured way. 7 Definition : Object 1 ‘An object is a basic unit of object-oriented programming that represents a real-world entity. It is an instance of a class that contains data (attributes) and methods (functions) to perform tasks. An object has a unique identity, specific properties, and the ability to interact with other objects. Objects are used to model real-world things like a car, student, bank account, or employee in a structured way. we ‘Acaris an example ofan object. thas data members that store information about it, such as helght, weight, number of doors, engine capacity, acceleration, and speed. These members hold data related to the car. ‘A caralso has methods (behaviour or functions) that define what it can do. Some of these methods are drive, park, race, start, and stop, These actions only make sense when they are associated with a car. The members and methods together define the car as an object in a program. What are the three Characteristics of an Object? ‘An object has three main characteristics in Object-Oriented Programming: 1. State (Data Members or Data Fields) : It represents the data or properties of an object. The state defines what values an object holds. Example: A pen has a name (Reynolds) and a color (white), which are its state, 2, Behaviour (Functions): It represents the actions or functions that an object can perform. Example: A pen is used to write, so writing is its behavior. 3. Object Identity: Each object is unique and has a distinct identity. Object identity is maintained through a unique ID, which is used internally to differentiate objects Example; A student is an object. If there are 100 student objects, each student object is unique and has a different ID to identify them separately. Each object in a program maintains its own identity, even if it belongs to the same class. This uniqueness ensures that every object can store different data and perform independent operations, Introduction to Object Oriented Programming Concepts & Java Objects The below image ne how Object-Oriented Programming (OOP) represents real-world entities as hjets. Ie shows three dl ae of vehicles: Car, Auto Rickshaw, and Bike as objects. Each object has properties (2180 known as attributes or data members) and methods (also known as functions or behaviors). car Auto Rickshaw Bike properties Properties Properties + Color : Orange * Color : Yellow * Color: Blue » Wheels: 4 + Wheels: 3 + Wheels: 2 «Seating Capacity : 5 ¢ Seating Capacity : 4 * Seating Capacity :2 IL Methods Methods Methods * Steer * Steer * Steer + Accelerate * Accelerate * Accelerate + Brake + Brake * Brake «. Each vehicle is treated as an object, which is an instance ofa class (eg. the "Vehicle" class). «The properties define the characteristics of each object, such as color, number of wheels, and seating capacity. « The methods define the actions the object can perform, such as steering, accelerating, and braking. «ven though the objects (Car, Auto Rickshaw, and Bike) share common methods, they have different values for properties, which makes them unique. Pcs | \An object is called an “instance” of a class or the objects are members of classes .What does this ‘pean? Let's look at an example. We know that all programming languages have built-in data types. For example, the int data type in C represents an integer: We can declare multiple variables of type int ina program, as shown below: int salary; int marks; int number; Each of these variables is a separate instance of the int data type. Similarly, in Object-Oriented Programming (OOP), we can define a class and create multiple objects from it. A class acts as a blueprint or template that specifies what data (attributes) and functions (methods) will be included in objects of that class. However, defining a class alone does not create any objects, just like having the int type does not automatically create variables. Objects must be explicitly created from the class. This concept allows us to create multiple objects with the same structure but with different data values. 3 The entire set of data and functions of an object can be treated as a user-defined data type ys a class, Objects are variables of type class. Once a class is defined, we can create multiple objal belonging to that class. Each object is associated with the data and functions defined in its ae class is essentially a collection of objects of the same type. For example, mango, apple, and orap, are members of the class fruit Similarly, a class in programming defines a type, and its objects ayg instances of that type. sata Members + Member Functions Class = Classes are user-defined data types and work similarly to built-in types in programming languages The syntax for creating an object is the same as defining a variable of a built-in data type. For example. iffruitisa class, then the statement: fruit mango; creates an object mango that belongs to the class fruit. This shows how objects and classes provide a structured way to manage data and functions in Object-Oriented Programming. Definition : Cl: ‘[Link] is a user-defined data type that serves as a blueprint for creating objects. It defines the data members (attributes) and member functions (methods) that describe the behavior of the objects. A class does not} allocate memory until an object is created from it. Example : A Car class may have data members like color, model, and speed, and methods like accelerate(), brake() and steer() hid} 3] Class and Objects tes the concept of class and objects in Object-Oriented Programming (00P). The The below image illustrat ior of objects. In this case, the class represents a lass acts as a blueprint that defines the structure and behavi car design, which includes specifications such as shape, size, an object 3) are the actual instances created from this blueprint d features. The objects (object 1, object 2, and cr Each object represents a real car built using the same design, but they can have different attributes like color, speed, or model. This concept in OOP allows code reusability, modularity, and better data management, ensuring that multiple objects can be created using a common class structure. Inveducion to Object Onlented Programming Concepts & J tncapsulation is fundamental concept in Object-Oriente da functions into a single unit called a class. It ensures ‘rect access by external code. The data can only be ac gesined within the cass. This protects the integrity ofthe de and data are bound t d Programming (OOP) that combines data that the data inside an object is hidden from cessed or modified through public methods data and prevents unintended modifications. . ogeth wen code and date ae bo nding a this manner, an object is created. Encapsulation is also own a8 ta as es that data and the functions that operate on it remain closely linked. Definition : Encapsulation Encapsulation i the process of wrapping data and functions into a single unit to maintain the integrity of an object. : 2, Encapsulation is an OOP concept that binds data and functions together and protects them from outside! interference and misuse. This leads to the concept of data hiding. L= % Encapsulation is achieved through data hiding, where some parts of an object (data or functions) are kept private and cannot be accessed from outside the class, This ensures that only the class itself can modify its private data to prevent accidental or unauthorized changes. Encapsulation and data hiding together ensure that objects maintain security, integrity, and controlled access, which are essential in building reliable software applications. Definition : Data Hiding Data hiding is the concept in Object-Oriented Programming (OOP) that restricts direct access to the data members of a class. The data is kept private and can only be accessed or modified through public methods in the class, This ensures data security, integrity, and controlled access, ‘Abstraction is one of the fundamental concepts of Object-Oriented Programming (OOP). Its main purpose is to hide unnecessary details from the user and provide only the essential features. This helps in reducing complexity and allows users to work with high-level operations without worrying about the internal implementation. This concept is not limited to programming but is widely used in the real world. Real-Life Example of Abstraction Using a coffee machine is a simple example of abstraction. To make coffee, we need to provide water and coffee beans, turn on the machine, and select the type of coffee. We do not need to know how the coffee machine heats the water, how the coffee is brewed, or how the machine regulates pressure and temperature, These internal processes are hidden from us. We only interact with a simple interface that makes the process easy. Similarly, in Object-Oriented Programming, objects provide abstraction by hiding implementation details, The user only needs to know which methods can be called and what inputs are required. The internal working of the method remains hidden.

You might also like