Thursday 27 August 2015

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
  • No comments:

    Post a Comment