Tuesday, 5 February 2013

Java Important Concepts

Class:

class- It is a Template/Blue print.
     - It represents a real time entity.
     - It defines the behaviour of the entity

     - Fields (attribute/properties/member variables) & Methods
    
      In Java- All the code exist with in the class or interface
             - You can have more than on class inside a java file
             - But you can have only one public class in a java file
             - You can define more than one main method inside the
               java program (In different classes)
             - The file name and the class name need not to be same
               until the class is declared as public

Constructor:
  • Constructor has the same name of the class name
  • Constructors are used for initialization
  • Constructors don't have any return type
  • Constructors are called when ever we declare an object of that corresponding class
Method Overloading
  • When more than one function uses the same name with different parameters , we call it as Method Overloading.
  • Ability to access multiple implementation of functions using the same name is called as Polymorphism 
  • Method overloading doesn't verify the return types
MultiThreading:
MultiTasking :
 * 1. Process Based Multitasking
 * 2. Thread Based Multitasking
 *
       1. Process Based Multitasking:
 *    Simultaneously working with more than one application at a time.
 *    The user can work without closing the application in different processors.
 *    Switching over between the processors is called Context Switching.
 *    Switching between the process with different address space consumes more resources, so we call this as heavy weighed process.

       2. Thread Based Multitasking:
 *       Simultaneously performing more than one task with in the same application is called Thread based multitasking.
 *    Thread is a piece of code with in a program which can execute by itself.
 *    Threads are called as light weight process since they use the same address space. Switching over with in the same address space consumes less resources. Threads can be created using two apis - implements Runnable ( interface )  extends Thread ( class )

Abstract class

It is a collection of abstract & concrete methods
 * Methods without definition/body is called as Abstract methods
 * The class which consist of abstract methods are called as abstract class
 * Such methods and classes are prefixed with the keyword "abstract"
 * When a class inherits an abstract class it must provide definition for all the abstract methods of that corresponding class
 * You cannot create an instance of an abstract class
 * But you can create a reference of an abstract class

Vector - It is a dynamic array of Objects. The methods inside the vector is synchronized
ArrayList - It is also dynamic array of Objects. But the methods are not synchronized


Exceptions

 *    Exceptions are Objects in Java.
 *    When ever an abnormal situation  is raised with in a piece of code, the JRE will search for a class  that describes the situation.
 *    When found, the respective class object is created and thrown into the block of statement.
 *    Such thrown objects can be handled by the user using "try&catch" block or instruct the calling method to handle the exception  using "throws" keyword.
 *    If the user wants to manually raise an exception we use the keyword "throw" and the last block of statement to be executed is provided inside the "finally" block.

Final Variable - cannot be modified
 * Final Method = cannot be overriden
 * Final Class- cannot be inherited

Method Overriding

 *  Ability to reuse the member variables and functions in the sub classes is achieved using Inheritance. Java uses "extends" keyword for inheritance. Java doesn't support multiple inheritance.
 *  Method Overriding- When the base class and the subclass methods  have the same signature then the subclass method overrides the base  class method. This is knows as method overriding.
 *  The return type must be same for overriding methods.
 *  In Overriding the weaker access specifier cannot override the stronger access specifier.




Interface


 * It is a collection of only abstract methods & by default everything is abstract inside an interface
 * Interface is an alternative for multiple inheritance.
 * We use the keyword "implements" to use an interface. In Java we can implement more than one interface (but we can extend only one class)
 * When a class implements an interface it must provide definition for all the interface methods
 * You cannot create an instance of an interface
 * But you can create a reference of an interface
 * One interface can extend another interface. 

Class Variable 
 * A member variable is considered as class variable when it is declared as static.
 * Because the static keyword ensures that, there will be only a single copy of the member variable for the entire class.
 * All the objects of the corresponding class  shares the same variable.
 * As a result, static variable retains the last updated value

No comments:

Post a Comment

VMware Cloud Learning Video's

Here is a nice summary list of all VMworld US 2018 Breakout session with the respective video playback & download URLs. Enjoy! Bra...