JAVA Variables and Scope

JAVA Variables and Scope :

  • JAVA Variables and Scope
  • Java Contains three types of variables
    • Instance Variables
    • Static Variables
    • Local Variable
  • Life span of static variables is till the JVM or application shuts down
  • Life time of Instance variables is till the Object lives.
  • The life span of local variable is till it reaches the end of the method.
  • Instance variable and Static variables are initialized be default, where as Local Variables are not initialized.
  • Local variables must be initializing before using it.
  • Static variables must be declared in class general area.
  • It must not be declared in constructor, blocks and methods.
  • Local Variables have only one modifier, which is FINAL.

If You need more visit our site – www.iguddy.com

Advertisements

Final Variables or Constant Variables in Java

The following are the key points about the JAVA Final Variables or Constant Variables,

  • Final Variables can not be reinitiated.
  • Final methods cannot be overridden.
  • final class cannot be a sub class ( Inheritance cannot be achieved.)

 

If You need more visit our site – www.iguddy.com

Advantages of Encapsulation

Advantages of Encapsulation

  1. If the owner changes the characteristics, it will not affect all the client codes.
  2. Client cannot access the data directly. So, unambiguous data is avoided.
  3. Tight encapsulation is a good encapsulation. This means owner provides only getter to the clients.

 

If You need more visit our site – www.iguddy.com

Encapsulation

The following are the key points about Encapsulation.

  1. Wrapping of data and code into a single unit is called Encapsulation.
  2. In Java, the data and the code are encapsulated. The client able to access a field through a getter and setter.
  3. Setters are called mutators; it allows the client to set the data in which owner can write the validation code.
  4. Getters are called assessors; the client is allowed to get the data.

Advantages of Encapsulation

  1. If the owner changes the characteristics, it will not affect all the client codes.
  2. Client cannot access the data directly. So, unambiguous data is avoided.
  3. Tight encapsulation is a good encapsulation. This means owner provides only getter to the clients.

How Encapsulation is achieved ?

We can achieve encapsulation in the following ways by,

  1. Making all the fields as private
  2. Providing getter and setter

If You need more visit our site – www.iguddy.com

Java Interface

The following are the key points about java Interface.

  • In Interface, all the members are implicitly abstract methods.
  • Interface contains only abstract methods.
  • All the variables in the Interface are implicitly static final variables.
  • Interface is only the reference. We cannot create an object for an Interface.
  • Interface achieves multiple Inheritance.
  • Interface achieves loose coupling of code.
  • Interface involves in designing a good code.
  • Interface avoids unnecessary codes to the client.
  • The main purpose of Interface is not to reveal the unwanted information to the client.
  • Interface is only meant for maintainability. Nothing to do with performance.
  • When you implement an interface method, it must be declared as public.

If You need more visit our site – www.iguddy.com