Monday, December 12, 2011

Java.lang.Object

Java.lang.Object Class:
  • For all classes java.lang.Object is a base class.
  • The important methods of java.lang.Object class is:
    • toString();
    • hashCode();
    • equals();
    • getClass();
    • Notify();
    • NotifyAll();
    • Wait();
Note: The methods marked in blue color can override, and the methods marked in red color cannot be override.

Difference between Primitive types and Objects

Primitive Types:
  • Primitives types are loaded in stack.
  • When the primitive is assigned to another primitive type copy is created.
  • Primitive types are not polymorphic, so it cannot be passed as to a method that takes object as a parameter.
Objects:
  • Objects are loaded in heap
  • When object reference is assigned to another object reference,they share the same object
  • Objects are Polymorphic, so they can be passed as a parameter to any method that takes object as parameter.

OOPS Concepts

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
Encapsulation:
  • Encapsulation is the mechanism that binds together code and the data it manipulates and keeps both safe from outside interference and misuse.
Inheritance:
  • Inheritance is the process by which one object acquire the properties of another object.
Polymorphism:
  • Polymorphism provides a way to take more than one form.
  • Two types of Polymorphism.                        
                               1. Compile Time Polymorphism (Overloading)
                               2. Run Time Polymorphism (Overriding)
Abstraction:

  • Abstraction allows user to view only the essential features without knowing the background details.
  • In other sense we can say that, it deals with the outside view of an object (interface).

Object

  • Object is an instance of a class.
  • Using Object we can access non static member variables and member methods.
  • If we use Objects for accessing static members, a same memory is shared for all Objects.
  • So use class name for accessing static members instead of Objects.

Class

  • Class is a user defined data type.
  • Class contains member variables and member methods.
  • Using Class we can create any number of objects.

Benefits of Java

  • Java is Object Oriented language.
  • Java is platform independent.
  • Java code is reusable and change friendly.
  • Java application don't have memory leak.
  • Java applications are easy to install.