CH1 Introduction To OOP
CH1 Introduction To OOP
Chapter One
Introduction to OOP
Programming Paradigms
• While writing programs, objects of similar property are defined within classes. A class
is a description of a set of objects that share common attributes and common behavior.
• Objects are so, members of a class that has common attributes and common behavior,
and the attributes and behavior of an object are defined by the class definition.
Read about
• The OO paradigm aims to eliminate some of the flaws of the procedural approach
to programming.
• In OO, data is critical – data is not allowed to move freely around a system, but it
is tied closely to the functions that operate on it. Data is also protected from
unintentional modification by other functions.
• Data is protected because the data belonging to an object can only be accessed and
modified by the methods of that object
Cont.
• Different objects can 'talk' to each other through their methods – in this
way, Object A cannot directly modify data belonging to Object B – but
it can call a method of Object B that in turn modifies the data.
Cont.
• Object-Oriented Programming simplifies the software development and
maintenance by providing some core concepts:
Class
Read about
Object
Dynamic Binding and
Abstraction Message Communication
Encapsulation
Inheritance
Polymorphism
Classes and Objects
• Objects are the basic runtime entities in an OO program. An object:
Is an identifiable thing or individual
Is of significance to the system
Has characteristic behaviour (i.e. functionality)
Has states reflected in the attributes (data) held about the object.
• A class is the definition of a set of objects which are all similar in terms of their
attributes, associations and functionality e.g. customer class defines all customer
objects.
Cont.
E1 S1
Cont.
Technical contrast between Objects & Classes
CLASS OBJECT
Class is a data type Object is an instance of Class.
It generates OBJECTS It gives life to CLASS
• Encapsulation means the wrapping up of data and methods into a single unit (a
class). It also means that the data inside a class is hidden from everything outside the
class.
Information Hiding.
The data can only be accessed by invoking the methods of the class. The
internal workings of the methods are of no concern to other classes in the
program.
Implementation can change without effecting any calling code.
Abstraction
• The original motivation for Java was the need for platform independent language
that could be embedded in various consumer electronic products like toasters and
refrigerators.
• One of the first projects developed using Java was a personal hand-held remote
control named Star 7.
Java Technology
What is Java Technology?
The Java technology is:
• A programming language
• A development environment
• An application environment
• A deployment environment
Cont.
A programming language
• As a programming language, Java can create all kinds of applications that you
could create using any conventional programming language.
A Development Environment
• As a development environment, Java technology provides you with a large
suite of tools:
A compiler (javac)
An interpreter (java)
A documentation generator (javadoc)
A class file packaging tool and so on...
Cont.
An Application and Runtime Environment
• Java technology applications are typically general-purpose programs that run
on any machine where the Java runtime environment (JRE) is installed.
Deployment Environment
• The JRE supplied by the Java 2 Software Development Kit (SDK) contains the
complete set of class files for all the Java technology packages, which includes
basic language classes, GUI component classes, and so on.
Java Features
Java Virtual Machine (JVM)
an imaginary machine that is implemented by emulating software on a real
machine
provides the hardware platform specifications to which you compile all Java
technology code
• A virtual machine (VM) is a software application that simulates a computer but hides the
underlying operating system and hardware from the programs that interact with it.
Bytecode
• a special machine language that can be understood by the Java Virtual
Machine (JVM).
• Independent of any computer hardware, so any computer with a Java
interpreter can execute the compiled Java program, no matter what type of
computer the program was compiled on.
Cont.
Garbage collection thread
• responsible for freeing any memory that can be freed.
• This happens automatically during the lifetime of the Java program.
• programmer is freed from the burden of having to deallocate that memory
themselves
Cont.
Code Security
• Code security is attained in Java through the implementation of its Java
Runtime Environment (JRE).
• JRE runs code compiled for a JVM and performs class loading (through the
class loader), code verification (through the bytecode verifier) and finally code
execution.
• class files are loaded into memory on demand, as needed by the program.
• It adds security by separating the namespaces for the classes of the local file
system from those that are imported from network sources.