basic concept of oops

Upload: techswarup1224

Post on 07-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Basic Concept of Oops

    1/3

    BASIC CONCEPT OF OOPS:

    1.OBJECTS:

    An object is an abstraction of a real world entity. It may represent a person,a placea

    number and icons or something else that can be modelled.Any data in an object occupy

    some

    space in memory and can communicate with eachother .

    2.CLASSES:

    A class is a collection of objects having common features .It is a user defined

    datatypes which has data members as well functions that manupulate these datas.

    3.ABSTRACTION:It can be defined as the seperation of unnecessary details or explation from system

    requirments so as to reduce the complaxities of understanding requirments.

    4.ENCAPTULATION:

    It is a mechanism that puts the data and function together. It is bthe result of hiding

    implimintation details of an object from its user .The object hides its data to de

    accessed by only those functions which are packed in the class of that object.

    5.INHERITANCE:

    It is the relationship between two classes of object such that one of the classes ,the

    child takes all the relevent features of other class -the parent.Inheritance bring

    about reusablity.

    6.POLYMORPHISM:

    polymorphism means having many forms that in a single entity can takes more than one

    form.Polymorphism is implemented through operator overloading and function

    overloading.

    7.DYNAMIC BINDING:

    Dynamic binding is the proces of resolving the function to be associated with yhe

    respective functions calls during their runtime rather than compile time.

    8.MESSAGE PASSING:

    Every data in an objest in oops that is capable of processing request known as message

    .All object can communicate with each other by sending message to each other.

    Association & Aggregation:-

    An Association is a channel between classes through which messages can be sent. As sending messages translatesto calling methods in Java, Associations are typically (but not necessarily) implemented by references.

    An Aggregation is an Association which denotes an "is part of" relationship. Unfortunately, the definition of thisrelationship is quite lax, so basically everyone is using his own interpretation. The only definitive (?) property is that inan instance graph, aggregations are not allowed to be circular - that is, an object can not be "a part of itself". (or) Whenbuilding new classes from existing classes using aggregation, a composite object built from other constituent objectsthat are its parts.Java supports aggregation of objects by reference,since objects can't contain other objects explicitly.

    A Composition adds a lifetime responsibility to Aggregation. In a garbage collected language like Java it basicallymeans that the whole has the responsibility of preventing the garbage collector to prematurely collect the part - forexample by holding a reference to it. (In a language like C++, where you need to explicitely destroy objects,Composition is a much more important concept.) Only one whole at a time can have a composition relationship to apart, but that relationship doesn't need to last for the whole lifetime of the objects - with other words, lifetimeresponsibility can be handed around.

    Aggregation and Composition Guidelines :

    Sometimes an object is made up of other objects. For example, an airplane is made up of a fuselage, wings, engines,landing gear, flaps, and so on. A delivery shipment contains one or more packages. A team consists of two or moreemployees. These are all examples of the concept of aggregation, which represents is part of relationships. Anengine is part of a plane, a package is part of a shipment, and an employee is part of a team. Aggregation is aspecialization of association, specifying a whole-part relationship between two objects. Composition is a stronger formof aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage thelifecycle of its parts. From a stylistic point of view, because aggregation and composition are both specializations ofassociation the guidelines for associations apply.

  • 8/6/2019 Basic Concept of Oops

    2/3

    JVM:-

    It is the principal component of Java architecture that provides the cross platform functionality and security to Java.

    This is a software process that converts the compiled Java byte code to machine code. Byte code is an intermediary

    language between Java source and the host system.

    Most programming language like C and Pascal translate the source code into machine code for one specific type ofmachine as the machine language vary from system to system. So most complier produce code for a particular system

    but Java compiler produce code for a virtual machine. The translation is done in two steps. First the programs writtenin Java or the source code translated by Java compiler into byte code and after that the JVM converts the byte code into

    machine code for the computer one wants to run. So the programs files written in Java are stored in .java files and the.java files are compiled by the Java compiler into byte code that are stored in .class file. The JVM later convert it intomachine code. In fact the byte code format is same on all platforms as it runs in the same JVM and it is totally

    independent from the operating system and CPU architecture. JVM is a part of Java Run Time Environment that isrequired by every operating system requires a different JRE. JRE consists of a number of classes based on Java APIand JVM, and without JRE, it is impossible to run Java. So its portability really made it possible in developing write

    once and run anywhere software.

    Thread Synchronization

    One of the strengths of the Java programming language is its support for multithreading at the language level. Much ofthis support centers on synchronization: coordinating activities and data access among multiple threads. Themechanism that Java uses to support synchronization is the monitor. This chapter describes monitors and shows howthey are used by the Java virtual machine. It describes how one aspect of monitors, the locking and unlocking of data,is supported in the instruction set.

    Monitors

    Java's monitor supports two kinds of thread synchronization: mutual exclusion and cooperation. Mutual exclusion,which is supported in the Java virtual machine via object locks, enables multiple threads to independently work onshared data without interfering with each other. Cooperation, which is supported in the Java virtual machine via thewait and notify methods of class Object, enables threads to work together towards a common goal.

    A monitor is like a building that contains one special room that can be occupied by only one thread at a time. The roomusually contains some data. From the time a thread enters this room to the time it leaves, it has exclusive access toany data in the room. Entering the monitor building is called "entering the monitor." Entering the special room insidethe building is called "acquiring the monitor." Occupying the room is called "owning the monitor," and leaving the roomis called "releasing the monitor." Leaving the entire building is called "exiting the monitor."

    In addition to being associated with a bit of data, a monitor is associated with one or more bits of code, which in thisbook will be called monitor regions. A monitor region is code that needs to be executed as one indivisible operationwith respect to a particular monitor. In other words, one thread must be able to execute a monitor region frombeginning to end without another thread concurrently executing a monitor region of the same monitor. A monitorenforces this one-thread-at-a-time execution of its monitor regions. The only way a thread can enter a monitor is byarriving at the beginning of one of the monitor regions associated with that monitor. The only way a thread can move

    forward and execute the monitor region is by acquiring the monitor.

    When a thread arrives at the beginning of a monitor region, it is placed into an entry set for the associated monitor.The entry set is like the front hallway of the monitor building. If no other thread is waiting in the entry set and no otherthread currently owns the monitor, the thread acquires the monitor and continues executing the monitor region. Whenthe thread finishes executing the monitor region, it exits (and releases) the monitor.

    If a thread arrives at the beginning of a monitor region that is protected by a monitor already owned by another thread,the newly arrived thread must wait in the entry set. When the current owner exits the monitor, the newly arrived threadmust compete with any other threads also waiting in the entry set. Only one thread will win the competition and acquirethe monitor.

  • 8/6/2019 Basic Concept of Oops

    3/3

    What Is A Meta-Class? (Object-Oriented Technology)

    A Meta-Class is a class' class. If a class is an object, then that object must have a class (in classical OO anyway).

    Compilers provide an easy way to picture Meta-Classes. Classes must be implemented in some way; perhaps with

    dictionaries for methods, instances, and parents and methods to perform all the work of being a class. This can be

    declared in a class named "Meta-Class". The Meta-Class can also provide services to application programs, such as

    returning a set of all methods, instances or parents for review (or even modification). [Booch 91, p 119] provides

    another example in Smalltalk with timers. In Smalltalk, the situation is more complex. To make this easy, referto the following listing, which is based on the number of levels of distinct instantiations:

    1 Level System

    All objects can be viewed as classes and all classes can be viewed as objects (as in Self). There is no need for Meta-

    Classes because objects describe themselves. Also called "single-hierarchy" systems. There is only 1 kind of object.

    2 Level System

    All Objects are instances of a Class but Classes are not accessible to programs (no Meta-Class except for in the

    compiler and perhaps for type-safe linkage, as in C++). There are 2 kinds of distinct objects: objects and classes.

    3 Level System

    All objects are instances of a class and all classes are instances of Meta-Class. The Meta-Class is a class and istherefore an instance of itself (really making this a 3 1/2 Level System). This allows classes to be first class objects

    and therefore classes are available to programs.

    There are 2 kinds of distinct objects (objects and classes), with a distinguished class, the metaclass.

    5 Level System

    What Smalltalk provides. Like a 3 Level System, but there is an extra level of specialized Meta-Classes for classes.

    There is still a Meta-Class as in a 3 Level System, but as a class it also has a specialized Meta-Class, the "Meta-Class

    class" and this results in a 5 Level System:

    object

    class

    class class (Smalltalk's Meta-Classes)

    Meta-Class

    Meta-Class class

    The "class class"es handle messages to classes, such as constructors and "new", and also "class variables" (a term

    from Smalltalk), which are variables shared between all instances of a class (static member data in C++). There are 3

    distinct kinds of objects (objects, classes, and metaclasses).

    The bytecode formatBytecodes are the machine language of the Java virtual machine. When a JVM loads a class file, it gets one stream of

    bytecodes for each method in the class. The bytecodes streams are stored in the method area of the JVM. Thebytecodes for a method are executed when that method is invoked during the course of running the program. They canbe executed by intepretation, just-in-time compiling, or any other technique that was chosen by the designer of aparticular JVM.

    A method's bytecode stream is a sequence of instructions for the Java virtual machine. Each instruction consists of aone-byte opcode followed by zero or more operands. The opcode indicates the action to take. If more information isrequired before the JVM can take the action, that information is encoded into one or more operands that immediatelyfollow the opcode.

    Each type of opcode has a mnemonic. In the typical assembly language style, streams of Java bytecodes can berepresented by their mnemonics followed by any operand values.