Thursday, June 30, 2016

Is- A Relationship

By using extends keyword we can implemented Is- A Relationship. Its also known as Inheritance. The main advantage of Is -A relationship is code reusability.

we can understand  Is - A relationship  from given example.

class P{
public void m1(){
 System.out.println("parent");
}
}

class C extends P{
public void m2()
{
System.out.println("child");
}
}
class Test{
public static void main(String[] args){
P p=new P(); // case 1
p.m1();
//p.m2();// Compile time error: can not find symbol: method m2 at location Class P
C c=new C(); // case 2
c.m1();
c.m2();

P p1=new C(); // case 3
p1.m1();
//p1.m2(); // Compile time error: can not find symbol: method m2 at location Class P

//C c1=new P(); //case 4
// CE : incompatible types found: P required C. mismatch



}
}


Conclusion:

1. Parents reference can be use to hold child objects but by using that reference we can not call child    specific methods but we can call methods present in parent class

2. Parent reference can be use to hold child object but child reference can not be use to hold parent      object.

3. if in a program we have some common methods(code redundancy)  then we should go for inheritance.

4. by using inheritance we can reduce time and cost.

<<       >>
                           

Wednesday, June 29, 2016

Java Magazine

Hi guys,
Read new java magazine click here.


Tightly Encapsulated Class

Tightly encapsulated Class:

 A class is said to be tightly encapsulated. If and only if each and every variable of class declared as private.

And there is  no need to be worry about whether class contains : corresponding getter and setter methods or not; or whether these methods are declare as public or not.
for example :

example1

  public class Account{
                              private double balance;
                              public double getBalance()
                             {
                                  return balance;
                               }

                             }

example2
 public class A{

                         private int x=0;
                      }


class B extends A
                          {
                           int y=20;
                         }


 in the above  example2  B class is not a tightly encapsulated class. because y variable is not declared as private.


Note : If the parent class is not tightly  encapsulated then  child class will  not be tightly encapsulated.


<<       >>

Tuesday, June 28, 2016

Encapsulation

Encapsulation is the most important concept of Object oriented programming.

Encapsulation is the process of biding data and corespondent methods into a single unit and keeps safe from outside classes.



Example :

package example;

public class Person {
    
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    


package example;
public class Main{
public static void main(String args[]){
       Person person=new Person();
        person.setName("indrajeet Singh");        
        System.out.println(person.getName());
    }
}

in above example name property declared as private. So it could not be accessed directly outside the class.
 So that by using Setter and Getter methods name property or data member is accessed outside class.


Note : If any component follows data hiding and abstraction concepts, such type of component said to be Encapsulation component.

Encapsulation = data hiding  + abstraction



Advantage.
1. Encapsulation is also important concept  for security purpose.
2. It provides you control over the data which is declared as private.


It increases length of code So it takes time to execute the code.

<<       >>


Monday, June 27, 2016

Abstraction

Abstraction  concept seems to like hiding data from outside world.

" Hiding internal implementation and just highlight the set of services what we are offering to the  outside world" its  Abstraction.

Abstraction is achieved by using interface and abstract class. interface gives 100% abstraction.

Example : When we go to the ATM. there we can see only GUI screen. bank management highlights the set of services like cash withdrawal, balance inquiry etc but we do not know what are the process is done internally. they highlight services only without sharing internal implementation.



Advantage :

1.It provides security for application.
2.Enhancement is easy.
3.It improves maintainability of the application
4.It improves easiness to use.


package example;

class Employee extends Person {
    
    private String empCode;

    public String getEmpCode() {
        return empCode;
    }
    public void setEmpCode(String empCode) {
        this.empCode = empCode;
    }
    
}

abstract  class Person {
    
     private String name;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    
}

public class Main{
public static void main(String args[]){
        //INSTIATING AN ABSTRACT CLASS GIVES COMPILE TIME ERROR
        //Person p =  new Person() ;
       
        //THIS REFERENCE VARIABLE CAN ACESS ONLY THOSE METHOD WHICH ARE OVERRIDDEN
        Person person = new Employee();
        person.setName("Indrajeet Singh");        
        System.out.println(person.getName());
    }

}


<<       >>

Data hiding

Data hiding is the most important concepts in OOPs oriented programming. Java security is also depend on Data Hiding concepts.


Its just way to protect your data from the outside world. meanwhile outside person can not access our data its mean our internal data should not go out directly this oops feature is called data hiding.

after validation or authentication of outside world can access our internal data.

if we have a class having public data field or methods. So data member can be accessed by outside person. here, there is no security for internal data.

for hiding our data from outside person , we need to declare our data as private or protected.

 such an example :  If we have an account in a bank. but we are not able to access our account information for accessing our information regarding account, So first bank will provide login authentication your user name and password. then you can check your account information.


        public class Account {
                             private double balance;
                             public double getBalance()
                             {
                               // validation
                                return balance.
                              }
                            }


Advantage of Hiding data for security. So its highly recommended to declare data member variable as private.


<<         >>

Friday, June 24, 2016

Exception handling

Dear All,

If want be a good programmer in Java Technology. Then its needed to be an expert in Exception Handling.

So if you want to learn deeply Exception handling concept.
Please Click here.

Wednesday, June 15, 2016

Collection in easy way

Please go throw below link..and watch it.

collection videos