Basic Concept of Oops

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 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 translates to 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 this relationship is quite lax, so basically everyone is using his own interpretation. The only definitive (?) property is that in an instance graph, aggregations are not allowed to be circular - that is, an object can not be "a part of itself". (or) When building new classes from existing classes using aggregation, a composite object built from other constituent objects that 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 basically means that the whole has the responsibility of preventing the garbage collector to prematurely collect the part - for example 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 a part, but that relationship doesn't need to last for the whole lifetime of the objects - with other words, lifetime responsibility 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 more employees. These are all examples of the concept of aggregation, which represents is part of relationships. An engine is part of a plane, a package is part of a shipment, and an employee is part of a team. Aggregation is a specialization of association, specifying a whole-part relationship between two objects. Composition is a stronger form of aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage the lifecycle of its parts. From a stylistic point of view, because aggregation and composition are both specializations of association the guidelines for associations apply.

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 of machine 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 written in 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 into machine 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 is required by every operating system requires a different JRE. JRE consists of a number of classes based on Java API and 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 of this support centers on synchronization: coordinating activities and data access among multiple threads. The mechanism that Java uses to support synchronization is the monitor. This chapter describes monitors and shows how they 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 on shared data without interfering with each other. Cooperation, which is supported in the Java virtual machine via the wait 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 room usually contains some data. From the time a thread enters this room to the time it leaves, it has exclusive access to any data in the room. Entering the monitor building is called "entering the monitor." Entering the special room inside the building is called "acquiring the monitor." Occupying the room is called "owning the monitor," and leaving the room is 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 this book will be called monitor regions. A monitor region is code that needs to be executed as one indivisible operation with respect to a particular monitor. In other words, one thread must be able to execute a monitor region from beginning to end without another thread concurrently executing a monitor region of the same monitor. A monitor enforces this one-thread-at-a-time execution of its monitor regions. The only way a thread can enter a monitor is by arriving 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 other thread currently owns the monitor, the thread acquires the monitor and continues executing the monitor region. When the 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 thread must compete with any other threads also waiting in the entry set. Only one thread will win the competition and acquire the monitor.

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, refer to 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 MetaClasses 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 is therefore 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 format Bytecodes 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. The bytecodes for a method are executed when that method is invoked during the course of running the program. They can be executed by intepretation, just-in-time compiling, or any other technique that was chosen by the designer of a particular JVM. A method's bytecode stream is a sequence of instructions for the Java virtual machine. Each instruction consists of a one-byte opcode followed by zero or more operands. The opcode indicates the action to take. If more information is required before the JVM can take the action, that information is encoded into one or more operands that immediately follow the opcode. Each type of opcode has a mnemonic. In the typical assembly language style, streams of Java bytecodes can be represented by their mnemonics followed by any operand values.

You might also like