Java contains Interfaces, Classes and Objects. Distinguishing between each can be slightly difficult at first, but I will explain exactly what a Java interface is in the post.

Firstly, I’d like to start with a short definition of the word “Interface”.

A device or program enabling a user to communicate with a computer.

Given this definition, we know that an Interface is a medium between a user and a computer.

Now, you might be asking, what does an interface look like in Java?

Interfaces look like Classes. However, on their own, their purpose is slightly different.

//This is how you make an interface..

interface LeInterface{

    public void doSomething();
    public void doSomethingElse();

}

//Then, a class can implement the interface...
public class MyClassBro implements LeInterface{

    //Firstly, it must declare the same methods as are in the interface...
    public void doSomething(){
        System.out.println("Something..");
    }
    public void doSomethingElse(){
        System.out.println("Something.... Else... MWUAHAHAHHAHA");
    }


    //Then, we can make a little main..
    public static void main(String[] args){

        //Then we can make a new Object of type "LeInterface", BUT make it an object of MyClassBro()!
        LeInterface oooWhatsThis = new MyClassBro();
        //And, we can run these methods...
        oooWhatsThis.doSomething();

    }

}

We would set the file name to the name of the class in this case. However, you may still be wondering WHAT IS HAPPENING.

To put this in the most simple and sweet manner: An Interface forces the class that implements it to contain the methods laid out in the interface.

So, let’s say we want a Coffee to implement a Hot Drink interface. In the Hot drink interface, we can set some methods equating to:

  • Temperature
  • Water
  • Milk
  • Sugar
  • Ingredients[]

That way we can always be sure that the hot drinks are implementing the right methods!

You don’t want coffee to not have any water in do you? No.

I hope this explains interfaces for you in a beautiful manner!

Until next time, Josh.

Leave a Reply
You May Also Like

4 Essential Software Tools & Services for Internet Marketers

Most people struggle to get free time for themselves, so you need good…

The World Wide Web & The Oddly Named Things In It

The web is “an infrastructure of information combined and the network software…

4 Ways To Make Money with Your Old Computer or Laptop

Many of us have been through a few computers on our journey…

Using IFTTT to automate a simple money-making process

If you like the thought of making money online with little work then…