0% found this document useful (0 votes)
9 views

Objected Oriented Introduction - Chapter - 1

Uploaded by

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

Objected Oriented Introduction - Chapter - 1

Uploaded by

babaimposter420
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Chapter 1

Object- Oriented Programming and


Evolution of Java
Concept of Object Orientation
• OOP attempts to provide a model for developing programs and
applications based on objects.
• Objects form the basic unit of object-oriented programming.

• An object in OOP language refers to a specific type or an instance of


a class.
• It has both states (i.e., data value) and behaviors (functionality of an
object).
Need for Object-Oriented Programming
• Though procedural-oriented programs are extremely powerful, they
have some of the following limitations:

 It is difficult to add any new functionality or to upgrade a program.


 Functions have unrestricted access to global data.
 Importance is given to the operation on data rather than the data
itself.
Need for Object-Oriented Programming
• An object-oriented approach to the application development
enables us to design programs.

 Quickly and carry out modification easily.


 This approach makes it easier for programmers to change and
update the program.
 OOPs has made developing large programs more manageable.
Advantages of Object-Oriented Programming
• Reusability - functions and modules can be reused by other users
without any modification.
• Modular structure - provides a clear and modular structure for
program development.
• Easy to maintain and upgrade- Object-oriented systems can be
easily upgraded.
• Inheritance - Allows us to eliminate redundant code and use
existing classes.
• Data hiding -The programmer can hide the data and functions in a
class from other classes.
Characteristics of Object-Oriented Programming

• Data Abstraction
• Encapsulation and Information Hiding
• Inheritance
Characteristics of Object-Oriented Programming
Data Abstraction
• It is the process of extracting the most relevant characteristics of
object data.
• These characteristics should be uniformly possessed by all the
objects of the class.
• E.g. Car
Characteristics of Object-Oriented Programming
Data Abstraction
Characteristics of Object-Oriented Programming
Encapsulation and Information Hiding
• It is a mechanism of wrapping the data and methods into a single
unit called class.
• The data of a class may be hidden so that it cannot be accessed by
the outside code.
• Classes have the provision to hide the data or methods from the
user.
• A class member may be declared as public, protected or private.
• A member declared as private cannot be accessed by any code outside the
class.
• Only class members can access a private member.
Characteristics of Object-Oriented Programming
Encapsulation and Information Hiding
• The one declared protected can be accessed by the class members as
well as members of the subclass derived from the class.
• A member declared public can be accessed by any outside code.
Characteristics of Object-Oriented Programming
Encapsulation and Information Hiding
Characteristics of Object-Oriented Programming
Encapsulation and Information Hiding
• A class may be declared public or without defining any access
modifier.

• A public class is accessible to any outside code, whereas the one


declared without any access specifier is accessible to classes of the
same package only.
Access Control to Data Variables and Methods
Public : It is applied to variables, constructors, methods, and classes.
- If any of these data members are declared as public, they are
accessible to all classes in all the packages.

Private : It can be applied to variables, constructors, methods, and


nested classes (excluding top-level classes).
- A private member is available only to the class in which it is defined
and it cannot be accessed by subclasses or any other external class.
Access Control to Data Variables and Methods
Protected : It is applied to variables, constructors, methods, and
nested classes (excluding top-level classes).
- It implies that the member can be accessed by the same class, its
subclasses, and the classes in the same package.

Default : It can be applied to variables, constructors, methods, and


classes. When no access specifier is used, it implies the default access.
Here, the member can be accessed by the classes within the same
package.
Characteristics of Object-Oriented Programming
Inheritance
• A class can inherit another class;
• It can make use of the data and methods defined in the base
(inherited) class without any change.
• In Java, the base class is called super class.
E.g if class D inherits class B, then class B is called the base class or
super class and class D is called the derived class or subclass.
Characteristics of Object-Oriented Programming
Benefits of Inheritance
• It allows the reuse of already proven software contained in the super
class without any modification in the subclasses.

• The subclass can add on the special features of a subgroup of


objects.
Characteristics of Object-Oriented Programming
Polymorphism
• It is the concept by which a method or object takes different forms
in different. environments.
E.g., the operator + adds two whole numbers, two decimal point
numbers, strings.
⁻ Symbol * (star) shows polymorphic behavior.
⁻ It is used to multiply two values, incorporate comments such as /*
and */, import a package into a program like import java.awt.*;.
Reuse, Coupling, and Coheshion in OOP
Cohesion of a module indicates the extent to which the components of a
module are related to each other.
Coupling is the degree of inter-dependence between the pairs of modules.
- It is a measure of the strength of association established by a connection
from one entity to another.
Reusability is the ability to reuse the previously defined objects and classes.
- In Java, we can reuse the previously defined objects including variables
and operators using inheritance.
- It is one of the fundamental concepts of OOP that provides hierarchical
relationship among the classes.
Object-oriented Analysis and Design
• An object-oriented development process differs from the traditional
software development approach.

• Traditional approach is based on functions and procedures.

• An object-oriented system is based on objects that combine data and


functionality.
Object-oriented Analysis and Design
• An object-oriented development process differs from the traditional
software development approach.
• An object-oriented system development involves developing
software by building self-contained modules or objects that can be
easily replaced, modified, and reused.
• For developing programs for large projects, a systematic approach is
required.
Object-oriented Analysis and Design
Booch (1994) proposed the following five metrics that assesses
whether a class is well deigned or not.
High cohesion- Cohesion implies the extent to which the class is
dependent on other classes in the system.
Low coupling- Coupling is a measure of the strength of association
established by a connection from one entity to another.
Sufficiency- It implies that the class or module possesses enough
characteristics of abstraction for meaningful and efficient interactions.
Completeness- It implies that the interface of the class or module
captures all the meaningful characteristics of abstraction.
Primitiveness- It keeps completeness in check.
Java Bytecode and Valid .class File
• First, the Java compiler generates a class file from its source file
(with .java extension).
• This class file has .class extension and contains the bytecodes that
are platform-independent instructions for Java virtual machine.
• JVM interprets the bytecode and then translates these bytecodes
into platform-specific machine-level instructions.
Structure of Java Language
Primitive data types - There are eight primitive data types.
Keywords- There are 50 keywords.
Java standard library- It contains a large number of predefined classes
and interfaces.
Packages - The related predefined classes and interfaces are packed
into packages.
Exploring JDK
• JDK provides the basic tools for developing and testing programs
written in Java programming language.
• JDK developed by Sun (now continued by Oracle) provides a
powerful environment for developing applications, applets, and
components using Java programming language.
Update Path and Class Path Variables
• To run a Java program, system environment variables (such as Path
or Classpath) need to be modified.
• Path variables are set in order to run the executables (javac, java,
javadoc, and so on) from any directory. If the path variables are not
set, we need to specify the path to the executable when running it.
Testing Installations
For testing the installation, type the following at the command line:

C:\>javac and C:\>java


If the screenshots shown in Fig. are obtained, it implies that Java is
properly installed and the path is set.
Testing Installations
Basic Tools in JDK
java- It is a Java interpreter that runs applets and applications by reading
and interpreting the bytecode files.
Javac- It is the Java compiler. It translates the Java source code files (with
.java extension) to bytecode files (with .class extension).
Javadoc- This utility enables in the generation of HTML documentation from
Java source code files.
Javah- It is a Java header file generator that produces header files for use
with native methods.
Javap- This is a Java disassembler that converts bytecode files into program
description.
Jdb- This is a Java debugger that enables us to find errors in our program and
debug Java classes.
Salient Features and Benefits of Java Language
• Platform-independent and portable The code, once compiled, can run on
any machine that has JVM.
• Object-oriented Java is an object-oriented language. The main focus is on
data and the methods that manipulate the data in the particular
application.
• Multithreading Multithread programming is an inbuilt feature of the Java
language.
• Architectural neutral - the code once written, can run in any machine,
irrespective of the different operating systems and different processors
installed.
• Rich standard library support Java standard library comprises a large
number of packages, classes, interfaces, and methods that support the
programming needs of diverse applications.
Salient Features and Benefits of Java Language
Applet programming It is a program that is different from an
application program.
- It is meant to run on the client’s machine.
Dynamic Java is designed in such a way that new classes can be loaded
at run time.
Distributed The language is designed to work in a distributed
environment of the Internet.
Security Features of Java Language
• In Java, all the operations are designed in such a way that they are
carried in a specific order.
• Java is designed to be safe and easy to use.
• Unlike C or C++, there is no provision of pointers in Java.
• Garbage collection feature automatically frees up memory resources
once they are no longer required.
• Java’s security model protects from hostile programs.
Differences and Similarities between Java and C++

• Java is a pure object-oriented language, whereas C++ is both.


• Java has the provision of packing classes into packages. This feature
is not available in C++.
• Multiple thread programming is in-built in Java, whereas in C and
C++, the programmer has to depend on additions like message
passing interface (MPI).
• There is no concept of pointers in Java, whereas both C++ as well as C
support pointers.
• Java supports applets, whereas in C++, there is no such concept.
• Java does not support multiple inheritances of classes.
• In Java, there can be only one superclass to a subclass, whereas in C++,
there can be any numbers of super classes to a subclass.

You might also like