Thursday 27 August 2015

Java Tutorial : Java Inheritance Has-A Relationship - Playlist

Java Tutorial : Java Inheritance IS-A and Has-A Relationship - Playlist

Java Tutorial : Java Inheritance IS-A Relationship - Playlist

Java Tutorial : Java Interface - Playlist

Java Tutorial : What is an Interface (Remote)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=rLyF_27YtWw&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : What is an Interface (Remote) 
Java Tutorial : What is an Interface (Remote) 
Java Tutorial : What is an Interface (Remote) 
Person.java
public class Person
{

    private String name;
    private int age;

    public Person(String name, int age)
    {
        super();
        this.name = name;
        this.age = age;
    }

    public String getName()
    {
        return name;
    }

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

    public int getAge()
    {
        return age;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

    @Override
    public String toString()
    {
        return "Person [name=" + name + ", age=" + age + "]";
    }
    
    public void switchOnTheTV()
    {
        System.out.println(name+" is calling switchOn method of Remote ");
        Remote remote = new LEDTVRemote();
        remote.switchOn();
    }

    public void switchOffTheTV()
    {
        System.out.println(name+" is calling switchOff method of Remote ");
        Remote remote = new LEDTVRemote();
        remote.switchOff();
    }
    
}
Remote.java
/**
 * An interface is a group of related methods with empty bodies.
 */
public interface Remote
{
    void switchOn();

    void switchOff();
}
LEDTVRemote.java
public class LEDTVRemote implements Remote
{

    @Override
    public void switchOn()
    {
        System.out.println("switchOn method of LEDTVRemote is called"
                + " and Remote is calling switchOnTV method of LED TV ");
        LedTV ledtv = new LedTV("106 Cm",true);
        ledtv.switchOnTV();
    }

    @Override
    public void switchOff()
    {
        System.out.println("switchOff method of LEDTVRemote is called"
                + " and Remote is calling switchOffTV method of LED TV ");
        LedTV ledtv = new LedTV("106 Cm",true);
        ledtv.switchOffTV();
    }

}
LedTV.java
public class LedTV
{

    private String displaySize;
    private boolean isSmartTv;

    public LedTV(String displaySize, boolean isSmartTv)
    {
        super();
        this.displaySize = displaySize;
        this.isSmartTv = isSmartTv;
    }

    public String getDisplaySize()
    {
        return displaySize;
    }

    public void setDisplaySize(String displaySize)
    {
        this.displaySize = displaySize;
    }

    public boolean isSmartTv()
    {
        return isSmartTv;
    }

    public void setSmartTv(boolean isSmartTv)
    {
        this.isSmartTv = isSmartTv;
    }
    
    public void switchOnTV()
    {
        System.out.println("switchOnTV method of LEDTV is called.");
        System.out.println("LED TV is Switched on.");
    }

    public void switchOffTV()
    {
        System.out.println("switchOffTV method of LEDTV is called.");
        System.out.println("LED TV is Switched off.");
    }

}
InterfaceDemo.java
public class InterfaceDemo
{

    public static void main(String[] args)
    {
        Person peter = new Person("Peter",28);
        peter.switchOnTheTV();
        System.out.println("-----------------------------------------------");
        peter.switchOffTheTV();
    }
}
Output
Peter is calling switchOn method of Remote 
switchOn method of LEDTVRemote is called and Remote is calling switchOnTV method of LED TV 
switchOnTV method of LEDTV is called.
LED TV is Switched on.
-----------------------------------------------
Peter is calling switchOff method of Remote 
switchOff method of LEDTVRemote is called and Remote is calling switchOffTV method of LED TV 
switchOffTV method of LEDTV is called.
LED TV is Switched off.
To Download InterfaceDemoLedApp Project Click the below link
https://sites.google.com/site/javaee4321/java/InterfaceDemoLedApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : What is an Interface (Switch)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=x8SqfAWYE9E&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : What is an Interface (Switch)
    Java Tutorial : What is an Interface (Switch)
    Java Tutorial : What is an Interface (Switch)
    Person.java
    public class Person
    {
    
        private String name;
        private int age;
    
        public Person(String name, int age)
        {
            super();
            this.name = name;
            this.age = age;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
        @Override
        public String toString()
        {
            return "Person [name=" + name + ", age=" + age + "]";
        }
        
        public void switchOnTheBulb()
        {
            Switch bulbswitch = new LEDBulbSwitch();
            bulbswitch.switchOn();
        }
    
        public void switchOffTheBulb()
        {
            Switch bulbswitch = new LEDBulbSwitch();
            bulbswitch.switchOff();
        }
        
    }
    
    Switch.java
    /**
     * An interface is a group of related methods with empty bodies.
     */
    public interface Switch
    {
        void switchOn();
    
        void switchOff();
    }
    
    LEDBulbSwitch.java
    public class LEDBulbSwitch implements Switch
    {
    
        @Override
        public void switchOn()
        {
            LedBulb ledbulb = new LedBulb("'A' shape","2.3 inch");
            ledbulb.switchOnTheLedBulb();
        }
    
        @Override
        public void switchOff()
        {
            LedBulb ledbulb = new LedBulb("'A' shape","2.3 inch");
            ledbulb.switchOffTheLedBulb();
        }
    
    }
    
    LedBulb.java
    public class LedBulb
    {
    
        private String shape;
        private String diameter;
    
        public LedBulb(String shape, String diameter)
        {
            super();
            this.shape = shape;
            this.diameter = diameter;
        }
    
        public String getShape()
        {
            return shape;
        }
    
        public void setShape(String shape)
        {
            this.shape = shape;
        }
    
        public String getDiameter()
        {
            return diameter;
        }
    
        public void setDiameter(String diameter)
        {
            this.diameter = diameter;
        }
    
        public void switchOnTheLedBulb()
        {
            System.out.println(shape +" Led Bulb is switched on");
        }
    
        public void switchOffTheLedBulb()
        {
            System.out.println(shape +" Led Bulb is switched off");
        }
    
    }
    
    InterfaceDemo.java
    public class InterfaceDemo
    {
    
        public static void main(String[] args)
        {
            Person peter = new Person("Peter",28);
            peter.switchOnTheBulb();
            peter.switchOffTheBulb();
        }
    }
    
    Output
    'A' shape Led Bulb is switched on
    'A' shape Led Bulb is switched off
    
    To Download InterfaceDemoSwitchApp Project Click the below link
    https://sites.google.com/site/javaee4321/java/InterfaceDemoSwitchApp.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Tuesday 25 August 2015

    Java Tutorial : Inheritance Has A Relationship (Person)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=p_4U_LVMbSk&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Inheritance Has A Relationship (Person)
    Java Tutorial : Inheritance Has A Relationship (Person)
    Java Tutorial : Inheritance Has A Relationship (Person)
    Java Tutorial : Inheritance Has A Relationship (Person)
    Java Tutorial : Inheritance Has A Relationship (Person)
    Person.java
    public class Person
    {
    
        private String name;
        private int age;
    
        public Person(String name, int age)
        {
            super();
            this.name = name;
            this.age = age;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public int getAge()
        {
            return age;
        }
    
        public void setAge(int age)
        {
            this.age = age;
        }
    
        @Override
        public String toString()
        {
            return "Person [name=" + name + ", age=" + age + "]";
        }
    
        
    }
    
    Address.java
    public class Address
    {
        private String street;
        private String city;
        private String state;
        private String zip;
    
        public Address(String street, String city, String state, String zip)
        {
            super();
            this.street = street;
            this.city = city;
            this.state = state;
            this.zip = zip;
        }
    
        public String getStreet()
        {
            return street;
        }
    
        public void setStreet(String street)
        {
            this.street = street;
        }
    
        public String getCity()
        {
            return city;
        }
    
        public void setCity(String city)
        {
            this.city = city;
        }
    
        public String getState()
        {
            return state;
        }
    
        public void setState(String state)
        {
            this.state = state;
        }
    
        public String getZip()
        {
            return zip;
        }
    
        public void setZip(String zip)
        {
            this.zip = zip;
        }
    
        @Override
        public String toString()
        {
            return "Address [street=" + street + ", city=" + city + ", state="
                    + state + ", zip=" + zip + "]";
        }
    
    }
    
    Employee.java
    /**
     * 
     * Employee class extends Person class means Employee IS-A Person.
     * 
     * Employee extends Person and thus inherits all methods and properties from
     * Person (except final and static).
     * 
     * Employee can also define all its specific functionality.
     */
    public class Employee extends Person
    {
        private String departmentName;
        private int employeeId;
    
        /*
         * Employee HAS-A Address
         */
        private Address address;
    
        public Employee(String name, int age, String departmentName,
                int employeeId, Address address)
        {
            super(name, age);
            this.departmentName = departmentName;
            this.employeeId = employeeId;
            this.address = address;
        }
    
        public String getDepartmentName()
        {
            return departmentName;
        }
    
        public void setDepartmentName(String departmentName)
        {
            this.departmentName = departmentName;
        }
    
        public int getEmployeeId()
        {
            return employeeId;
        }
    
        public void setEmployeeId(int employeeId)
        {
            this.employeeId = employeeId;
        }
    
        public Address getAddress()
        {
            return address;
        }
    
        public void setAddress(Address address)
        {
            this.address = address;
        }
    
        @Override
        public String toString()
        {
            return "Employee [departmentName=" + departmentName + ", employeeId="
                    + employeeId + ", address=" + address + ", getName()="
                    + getName() + ", getAge()=" + getAge() + "]";
        }
    
    }
    
    Student.java
    /**
     * 
     * Student class extends Person class means Student IS-A Person.
     * 
     * Student extends Person and thus inherits all methods and properties from
     * Person (except final and static).
     * 
     * Student can also define all its specific functionality.
     */
    public class Student extends Person
    {
    
        private double grade;
        private int rollNo;
    
        /*
         * Student HAS-A Address
         */
        private Address address;
    
        public Student(String name, int age, double grade, int rollNo,
                Address address)
        {
            super(name, age);
            this.grade = grade;
            this.rollNo = rollNo;
            this.address = address;
        }
    
        public double getGrade()
        {
            return grade;
        }
    
        public void setGrade(double grade)
        {
            this.grade = grade;
        }
    
        public int getRollNo()
        {
            return rollNo;
        }
    
        public void setRollNo(int rollNo)
        {
            this.rollNo = rollNo;
        }
    
        public Address getAddress()
        {
            return address;
        }
    
        public void setAddress(Address address)
        {
            this.address = address;
        }
    
        @Override
        public String toString()
        {
            return "Student [grade=" + grade + ", rollNo=" + rollNo + ", address="
                    + address + ", getName()=" + getName() + ", getAge()="
                    + getAge() + "]";
        }
    
    }
    
    RelationshipDemo.java
    public class RelationshipDemo
    {
    
        public static void main(String[] args)
        {
    
            Address peterAddress = new Address("13th Cross", "Bangalore",
                    "Karnataka", "560001");
    
            Employee peter = new Employee("Peter", 33, "Income Tax Department",
                    350, peterAddress);
            
            System.out.println("Employee Peter Details : ");
            System.out.println(peter);
            
            System.out.println("----------------------------------------------");
            
            Address johnAddress = new Address("17th Cross", "Chennai",
                    "TamilNadu", "600100");
    
            Student john = new Student("John", 33, 3.5,
                    2, johnAddress);
            
            System.out.println("Student john Details : ");
            System.out.println(john);
    
    
        }
    }
    Output
    Employee Peter Details : 
    Employee [departmentName=Income Tax Department, employeeId=350, 
    address=Address [street=13th Cross, city=Bangalore, 
    state=Karnataka, zip=560001], getName()=Peter, getAge()=33]
    ----------------------------------------------
    Student john Details : 
    Student [grade=3.5, rollNo=2, address=Address [street=17th Cross,
    city=Chennai, state=TamilNadu, zip=600100], getName()=John, 
    getAge()=33]
    
    To Download InheritanceDemo-HAS-A-PersonApp Project Click the below link
    https://sites.google.com/site/javaee4321/java/InheritanceDemo-HAS-A-PersonApp.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Monday 24 August 2015

    Java Tutorial : Inheritance Has A Relationship (Car)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=lQlu0kel2x8&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Inheritance Has A Relationship (Car)
    Java Tutorial : Inheritance Has A Relationship (Car)
    Car.java
    public class Car
    {
    
        private String color;
        private int maxSpeed;
    
        public Car(String color, int maxSpeed)
        {
            super();
            this.color = color;
            this.maxSpeed = maxSpeed;
        }
    
        public String getColor()
        {
            return color;
        }
    
        public void setColor(String color)
        {
            this.color = color;
        }
    
        public int getMaxSpeed()
        {
            return maxSpeed;
        }
    
        public void setMaxSpeed(int maxSpeed)
        {
            this.maxSpeed = maxSpeed;
        }
    
        public void carInfo()
        {
    
            System.out.println("Car Color= " + color + ", Max Speed= " + maxSpeed);
    
        }
    }
    
    Engine.java
    public class Engine
    {
        public void start()
        {
    
            System.out.println("Engine Started:");
    
        }
    
        public void stop()
        {
    
            System.out.println("Engine Stopped:");
    
        }
    }
    
    MarutiSwift.java
    /**
     * 
     * MarutiSwift is specific type of Car which extends Car class means MarutiSwift
     * IS-A Car.
     * 
     * MarutiSwift extends Car and thus inherits all properties and methods from Car
     * (except final and static).
     * 
     * MarutiSwift can also define all its specific functionality.
     */
    public class MarutiSwift extends Car
    {
        /*
         * MarutiSwift HAS-A Engine
         */
        private Engine engine;
    
        public MarutiSwift(String color, int maxSpeed, Engine engine)
        {
            super(color, maxSpeed);
            this.engine = engine;
        }
    
        public void startMarutiSwift()
        {
            engine.start();
        }
    
    }
    
    RelationshipDemo.java
    /**
     * RelationsDemo class is making object of MarutiSwift class and initialized it.
     * Though MarutiSwift class does not have setColor(), setMaxSpeed() and carInfo()
     * methods still we can use it due to IS-A relationship of MarutiSwift class with Car
     * class.
     */
    
    public class RelationshipDemo
    {
    
        public static void main(String[] args)
        {
    
            Engine engine = new Engine();
            MarutiSwift marutiSwift = new MarutiSwift("Red", 200, engine);
            marutiSwift.carInfo();
            marutiSwift.startMarutiSwift();
        }
    }
    
    
    
    Output
    Car Color= Red, Max Speed= 200
    Engine Started:
    
    To Download InheritanceDemo-HAS-A-CarApp Project Click the below link
    https://sites.google.com/site/javaee4321/java/InheritanceDemo-HAS-A-CarApp.zip?attredirects=0&d=1

    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Wednesday 19 August 2015

    Java Tutorial : Inheritance IS-A Relationship Animal (Implements)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=oXtnBDbGo5k&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Inheritance IS-A Relationship Animal (Implements) 
    Java Tutorial : Inheritance IS-A Relationship Animal (Implements) 
    Java Tutorial : Inheritance IS-A Relationship Animal (Implements) 

    AnimalDemo.java
    /**
     * Animal is the Super Interface of Mammal,Parrot and Dove classes
     */
    interface Animal
    {
    
    }
    
    /**
     * Mammal is the subclass of Animal Interface.
     */
    class Mammal implements Animal
    {
    
    }
    
    /**
     * Dog is the subclass of both Mammal class and Animal Interface.
     */
    class Dog extends Mammal
    {
    
    }
    
    /**
     * Elephant is the subclass of both Mammal class and Animal Interface.
     */
    class Elephant extends Mammal
    {
    
    }
    
    /**
     * Tiger is the subclass of both Mammal class and Animal Interface.
     */
    class Tiger extends Mammal
    {
    
    }
    
    /**
     * Parrot is the subclass of Animal Interface.
     */
    class Parrot implements Animal
    {
    
    }
    
    /**
     * Dove is the subclass of Animal Interface.
     */
    class Dove implements Animal
    {
    
    }
    
    public class AnimalDemo
    {
        public static void main(String args[])
        {
    
            Mammal mammal = new Mammal();
            Dog dog = new Dog();
            Elephant elephant = new Elephant();
            Tiger tiger = new Tiger();
    
            System.out.print("Mammal IS-A Animal : ");
            System.out.println(mammal instanceof Animal);
            System.out.println();
    
            System.out.print("Dog IS-A Mammal : ");
            System.out.println(dog instanceof Mammal);
            System.out.print("Dog IS-A Animal : ");
            System.out.println(dog instanceof Animal);
            System.out.println();
    
            System.out.print("Elephant IS-A Mammal : ");
            System.out.println(elephant instanceof Mammal);
            System.out.print("Elephant IS-A Animal : ");
            System.out.println(elephant instanceof Animal);
            System.out.println();
    
            System.out.print("Tiger IS-A Mammal : ");
            System.out.println(tiger instanceof Mammal);
            System.out.print("Tiger IS-A Animal : ");
            System.out.println(tiger instanceof Animal);
            System.out.println();
    
            Parrot parrot = new Parrot();
            Dove dove = new Dove();
    
            System.out.print("Parrot IS-A Animal : ");
            System.out.println(parrot instanceof Animal);
            System.out.println();
    
            System.out.print("Dove IS-A Animal : ");
            System.out.println(dove instanceof Animal);
    
        }
    }
    
    Output
    Mammal IS-A Animal : true
    Dog IS-A Mammal : true
    Dog IS-A Animal : true
    
    Elephant IS-A Mammal : true
    Elephant IS-A Animal : true
    
    Tiger IS-A Mammal : true
    Tiger IS-A Animal : true
    
    Parrot IS-A Animal : true
    
    Dove IS-A Animal : true
    
    
    To Download DisplayAllHeadersApp Project Click the below link
    https://sites.google.com/site/javaee4321/java/InheritanceDemo-IS-A-Animal-ImplementsApp.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial