Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Interfaces Executor and ExecutorService

  1. #1
    Junior Member
    Join Date
    Jan 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default Interfaces Executor and ExecutorService

    From my understanding, interfaces aren't concrete and hence can't be instantiated.
    You must implement every method of an interface you implemet or declare the class an absract one.
    My nightmare is with the Executor servuce interfcae used for multithrreading. I understand clearly that to excute a task concurrently, it must implemnt interface Runable, ( in the process override the run() method). And and object of type Executorservice must be create and method execute called on the runnable object.

    An Executor service is and Executor being a sub interface of Executor so how and why does the compiler allow an object to be created from an interface? And

    Why don't we over ride the execute() method of interface Executor since this an abstract one with no default implementation, aren't we supposed to provide implemetation details for this abstract method?

  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Thanked 329 Times in 305 Posts

    Default Re: Interfaces Executor and ExecutorService

    There are a lot of big, fancy words to describe this, but none are coming immediate to mind and I don't want to google.
    Basically, an object is not being created from an interface. The compiler simply assumes the runtime object type the method is being called upon (perhaps a Runnable type) has been initialized with some class which inherits from that type. That is a fair assumption, since the compiler will not explicitly let you initialize an interface or abstract class. So, at runtime, the object type can only be in one of the two states: legally initialized by some class which inherits from said type, or the object is null. If the object is null, a NullPointerException will be thrown at runtime, so that state is taken care of.

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Interfaces
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 14
    Last Post: July 13th, 2018, 12:57 AM
  2. Interfaces...
    By eggpulusu in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2013, 10:52 AM
  3. [SOLVED] What good are interfaces?
    By summit45 in forum Object Oriented Programming
    Replies: 2
    Last Post: August 18th, 2013, 09:39 PM
  4. Question Regarding Interfaces
    By davidrobin in forum Object Oriented Programming
    Replies: 1
    Last Post: April 18th, 2013, 04:10 PM
  5. Interfaces
    By leyland in forum Java Theory & Questions
    Replies: 4
    Last Post: April 5th, 2011, 08:51 PM