26 July 2009
0 Method Overloading and Method Overriding in JAVA - A comparison study
Static Polymorphism And Dynamic Polymorphism in JAVA
Static Polymorphism in JAVA is also known as Function Overloading in JAVA. Dynamic Polymorphism in JAVA is also known as Function Overriding in JAVA. Let us compare Function Overloading and Function Overriding in JAVA. Here it goes,the difference between Function Overloading and Function Overriding in JAVA
Static Polymorphism | Dynamic Polymorphism |
Function Overloading – within same class more than one method having same name but differing in signature | Function Overriding – keeping the signature and return type same, method in the base class is redefined in the derived class |
Resolved during compilation time | Resolved during run time |
Return type is not part of method signature | Which method to be invoked is decided by the object that the reference points to and not by the type of the reference |
25 July 2009
0 BASICS OF JAVA - Introduction to JAVA
BASICS OF JAVA - CHAPTER-3 -Introduction to JAVA
A language developed by Sun Microsystems
• A general-purpose language
• High-level language
• Developed initially for consumer devices
• Now-a-days, popular platform to develop enterprise applications
Know more about history of JAVA and some intersting factors about JAVA.
Features of Java
• Object-oriented
• Robust
• Portable or 'Architecture Neutral'
• Secure
• Support for Multithreading at language level
• Designed to handle Distributed applications
• Simpler language
0 BASICS OF JAVA - Object Oriented Concepts (OOC) contd.
BASICS OF JAVA - CHAPTER-2 -Object Oriented Concepts (OOC) contd.
In this page we are discussing about advantages and disadvantages of Object oriented concept. In order to analyse the various advantages and disadvantages of the object oriented concepts, we will compare the object oriented concept against the Procedural Programming methodology.
Object Oriented Programming vs Procedural Programming
Object Oriented Programming | Procedural Programming |
Emphasis on Data; binding of data structures with methods that operate on data | Emphasis on algorithms, procedures |
Real world is represented by objects mimicking external entities. Allows modeling of real life problem into objects with state and behavior | Real world is represented by logical entities and control flow. Tries to fit real life problem into procedural language |
Data (State) is encapsulated effectively by methods (Behavior) | In a given module, data and procedures are separate |
Program modules are integrated parts of overall program. Objects interact with each other by Message passing | Program modules are linked through parameter passing mechanism |
Uses abstraction at class and object level | Uses abstraction at procedure level |
Object Oriented decomposition focuses on abstracted objects and their interaction | Algorithmic decomposition tends to focus on the sequence of events |
Active and intelligent data structures (object) encapsulates all passive procedures | Passive and dumb data structures used by active methods |
Object Oriented Languages: C++, Small Talk, Java, C#, JavaScript etc | Procedural languages: C, COBOL, PASCAL |
0 BASICS OF JAVA Object Oriented Concepts
BASICS OF JAVA - CHAPTER-1 -Object Oriented Concepts (OOC)
Java is an Object-Oriented Language. So before learning java, let us have a look on the Object-Oriented Concepts.
Object Oriented Concepts (OOC)
Class and Object
A class is prototype that defines the variables and the methods (functions) common to all objects of a certain kind.
Elements of a class are :
1. Member Variable: Variables declared within a class
2. Member Functions: Functions or methods declared within the class. These methods operate upon the member variables of the class. So a class is a definition of a set of data and methods (functions). When memory space for this data is actually allocated, we say that class is instantiated i.e an object is created.
An object is a representative or specimen of a class. In other words, object is an instance of a class. Each instance of a class will have its own data. Actually an object is a bundle of related variables and methods (functions).
Objects possess two characteristics :
1. State : condition of an item.
2. Behavior : Observable effects of an operation or event including its results.
State can be of two types : Active state which reflects the behavior and Passive State refers to state which does not change. The behavior of an object forms the interface to the external world.
Features of OOP (Features of Object oriented Concept)
Abstraction:
The process of extracting the essential information and hiding the irrelevant details
Encapsulation:
The process of binding code and data together in the form of a capsule
Inheritance:
The feature by which one class acquires the properties and functionalities of another class
Polymorphism:
The feature that allows the same interface to be used for a general set of actions
Explanations with examples
Abstraction is the process of exposing the relevant things and ignoring the irrelevant details. The easiest way to understand and appreciate this concept of handling complexity is by studying the example of Globe, a model/prototype of earth that is used by students to understand its geography. Globe provides only that information that is required and if too much of information is mentioned in it i.e. streets, lakes etc, it becomes too complex to comprehend. Hence Globe abstracts unwanted information and makes it easy to comprehend the complex earth.
Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. The data is not accessible to the outside world and only those functions that are wrapped in the class can access it. These functions provide the interface between the object’s data and the program. The insulation of the data from the direct access by the program is called data hiding.
In OOP, code and data are merged into an object so that the user of an object can never peek inside the box. This is defined as encapsulation (i.e. Object is a capsule encapsulating data and behavior). All communication to it is through messages (i.e function calls which we use to communicate to the object). Messages define the interface to the object. Everything an object can do is represented by its message interface. Therefore, we need not know
anything about what is in the object when we use it.
Inheritance is the process by which one class acquires the properties and functionalities of another class. This is important because it supports the concept of hierarchical classification.. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it.
Polymorphism is a feature that allows one interface to be used for a general class of actions. An operation may exhibit different behavior in different instances. The behavior depends on the types of data used in the operation. It plays an important role in allowing objects having different internal structures to share the same external interface. Polymorphism is extensively used in implementing inheritance.