The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Tutorial : What is an Interface (Remote)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java Tutorial : What is an Interface (Remote) Posted: Aug 27, 2015 7:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java Tutorial : What is an Interface (Remote)
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

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
  • Read: Java Tutorial : What is an Interface (Remote)

    Topic: JavaFX adds docking library for easier use, better customization Previous Topic   Next Topic Topic: Using Docker to Build Debian Packages

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use