Tuesday, 22 October 2013

Mandatory JAVA topics before starting OAF

Hii
this blog helps you to know about the Java Topics which are mandatory before starting OAF

<<Object oriented programming concepts (OOPS concept)>>

  • Objects
  • Class
  • Inheritance
  • Interface
  • Package

What is an Object?
DefinitionAn object is a software bundle of variables and related methods.

Description:
As the name object-oriented implies, objects are key to understanding object-oriented technology. You can look around you now and see many examples of real-world objects: your dog, your desk, your television set, your bicycle. The below diagram explains about an object structure.



           Example


What is a Class?

Definition:A class is a blueprint or prototype from which objects are created.

Description:
In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles.


What is a Inheritance?
Definition:Creating a new class from existing class is called Inheritance.
Description:


Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.
Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass ofMountainBikeRoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:
                                                                       







What is a Interface?

Definition:
An interface in Java is similar to a class, but the body of an interface can include only abstract methods and final fields (constants). A class implements an interface by providing code for each method declared by the interface.
Here’s a basic interface that defines a single method, named Playable, that includes a single method named play:
public interface Playable
{
    void play(); 
}


Description:
As you've already learned, objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world; the buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television on and off.
In its most common form, an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:
interface Bicycle {
 
    //  wheel revolutions per minute
    void changeCadence(int newValue);
 
    void changeGear(int newValue);
 
    void speedUp(int increment);
 
    void applyBrakes(int decrement);
}
To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such as ACMEBicycle), and you'd use the implements keyword in the class declaration:
class ACMEBicycle implements Bicycle {
 
    // remainder of this class 
    // implemented as before
}
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.


Note: To actually compile the ACMEBicycle class, you'll need to add the public keyword to the beginning of the implemented interface methods. You'll learn the reasons for this later in the lessons onClasses and Objects and Interfaces and Inheritance.



What is a Package?
Definition:
A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage. This section explains why this is useful, and introduces you to the Application Programming Interface (API) provided by the Java platform.
Description:
A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.
The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", or "API" for short. Its packages represent the tasks most commonly associated with general-purpose programming. For example, a String object contains state and behavior for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify a file on the filesystem; a Socket object allows for the creation and use of network sockets; various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. There are literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your particular application, rather than the infrastructure required to make it work.
The Java Platform API Specification contains the complete listing for all packages, interfaces, classes, fields, and methods supplied by the Java SE platform. Load the page in your browser and bookmark it. As a programmer, it will become your single most important piece of reference documentation.


Abstraction 
Definition: Hiding unnecessary things and showing the essential information.


Example: Suppose take a car: In that we will have breaks and stering and etc... Here when we are changing the gear box to up or bottom then gears will work but we don't know how they are managing internally and we don't no how it is working. As a driver we don't need to know how it is working internally when we are changing every time. That is the reason they will hide the wires and cables internally and they will show up only gear box to us.


Advantages: 1) Code will be clean and for managing it will be very easy




Encapsulation 
Wrapping up of data and methods into a single unit.


Example: In our class we need to make all our varables and methods keeping together.


Advantage: Maintance will be good




Questions and Exercises: Object-Oriented Programming Concepts
Questions
  1. Real-world objects contain ___ and ___.
  2. A software object's state is stored in ___.
  3. A software object's behavior is exposed through ___.
  4. Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data ___.
  5. A blueprint for a software object is called a ___.
  6. Common behavior can be defined in a ___ and inherited into a ___ using the ___ keyword.
  7. A collection of methods with no implementation is called an ___.
  8. A namespace that organizes classes and interfaces by functionality is called a ___.
  9. The term API stands for ___?










Answers to Questions

1.     Real-world objects contain state and behavior.
2.     A software object's state is stored in fields.
3.     A software object's behavior is exposed through methods.
4.     Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data encapsulation.
5.     A blueprint for a software object is called a class.
6.     Common behavior can be defined in a superclass and inherited into a subclass using the extends keyword.
7.     A collection of methods with no implementation is called an interface.
8.     A namespace that organizes classes and interfaces by functionality is called a package.
9.     The term API stands for Application Programming Interface.