• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reg:use of interface in realtime environment

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

What is the use of interface in realtime environment?
can explain with real time scenario in application?


Thanks in advance
Birla
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Real Time environment doesn't require or preclude interfaces, but I suspect you are not really asking about real time computing?
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:A Real Time environment doesn't require or preclude interfaces, but I suspect you are not really asking about real time computing?



Hi Paul,

Thanks paul
But ,I am not asking about real time computing

I am asking for java interfaces in real time application.

Thanks & Regards,
Birla
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'll assume when you say "real time application" you mean a real application and not one that has anything to do with time.

Generally its a good idea to code to interfaces. This makes applications easier to modify and extend. Interfaces define what fucntionality a type has and this is seperate from how it is implemented. One of the most common applicaitons of interfaces in Java are JDBC drivers. Sun have defined a set of interfaces for accessing databases. How these are implemented is left up to the database vendors so all you ever need to do is write your code to the interfaces and you know you can swap from database to database and it will just work.
 
Marshal
Posts: 79462
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
West of Baghdad we usually say "real life". We would use "real time" to mean something which has to respond immediately.

I looked up "program to the interface" on Google and found this, which looks useful. One place in Java where interfaces are used a lot, and I suggest you read about, is in the collections framework.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
friends:

sorry for the things which I was not asked clear
Thanks for the help

 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see the given program

think about an implementation without interfaces
now tell me which is simpler ?
one without interfaces or one with an interface


This was just a simple example using generalization.

i can provide more examples of interfaces in different situations.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just another point:

major applications provide their interfaces as APIs !!!

Did you know that Connection,Resultset,Statement,Driver,ResultsetMetaData are all interfaces in java.sql package ???

now imagine a real application without these


 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for everyone,

I have a doubt ,ie

In Interfaces,for invoking thier methods, dyanamic lookup is done at run time based on appropriate instance of class.
But for normal method,the invocation is done at compile time itself,so dyanamic binding may arise performance issues interms of speedness

so my question is where to use interfaces? and where to not use that.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
define

normal method






As I have not used interfaces at all in the program, what would you think the output would be?
Could this invocation be done at compile time ?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In Interfaces,for invoking thier methods, dyanamic lookup is done at run time based on appropriate instance of class.
But for normal method,the invocation is done at compile time itself,so dyanamic binding may arise performance issues interms of speedness


Other than this statement being wrong, picking whether or not to use an interface based on possible performance issues is daft. As with any early optimisation its going to needlessly hinder the development of any application you apply this principal to.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello friends,

see salvin ,you have given some example , In that example also, the method invocation is done by dyanamic late binding,
so anyway both Interface and Abstract class method invocation were done by dyanamic late binding,
i left out the Abstract class invocation in previous post. so what you given is not a normal method.
Normal method in the sense ,the oveloaded methods which uses static binding.


ok paul, i agree what you said,since through Interfaces only,we can inderctly implement the multiple inheritance and this only solves the ambiguity problem,so with out it we cann't able to develop the application,

But my question is

In some cases ,it should be avoided in sections of code which are called frequently in performance-sensitive applications.

since dynamic late binding gets invoking the methods by Java reflection at run time,
and static early binding improves the performance by avoiding the frequent use of Java reflection


Here some example



public class exp {

public static void main(String[] args) throws Exception
{
noRegular();
yesReflection();
}

public static void noReflection() throws Exception
{
long startTime = System.currentTimeMillis();
for (int i=0; i<1000000; i++)
{
New a = new New();
}
System.out.println("No reflection :"+System.currentTimeMillis() - startTime);
}

public static void yesReflection() throws Exception
{
long startTime = System.currentTimeMillis();
for (int i=0; i<1000000; i++)
{
New a = (New) Class.forName("misc.New").newInstance();
}
System.out.println("Yes Reflection: "System.currentTimeMillis() - startTime);
}
}

output

No reflection:15
Yes Reflection:1781

what you say


 
Campbell Ritchie
Marshal
Posts: 79462
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you really using reflection with Class.forName and newInstance?

Maybe that simply demonstrates that it is inefficient to tell your Class Loader to look for a class file a million times, and attempt to load it only to find it is already in memory 999999 times.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


since dynamic late binding gets invoking the methods by Java reflection at run time,
and static early binding improves the performance by avoiding the frequent use of Java reflection


Reflection being slow has always been a bit of a performance myth. OK, back when reflection was introduced things were maybe a tiny little bit slower but these days you only have to look at the vast number of reflection-backed frameworks out there to assume its not really an issue any more.

Like I said before, this smells like an unneccesary early optimisation.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

since dynamic late binding gets invoking the methods by Java reflection at run time,
and static early binding improves the performance by avoiding the frequent use of Java reflection



Also, this is not true at all. Late binding and reflection are completely orthogonal concerns.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

friends,

As I before said,

Hi paul:

In Interfaces ,the method inovacation was done by dynamic binding which use java reflection frequently which interms call the Class.forName() method.
so if call interface methods in sections of code which contains loops has to be executed many times, say 100 times
the speedness of execution gets reduced

so my point is ,we have to avoid this in loops which called frequently in performance-sensitive applications.

Hi Garrett Rowe:

can you explain Late binding and reflection are completely orthogonal concerns with some examples

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll turn the question around. Why do you believe polymorphic method calls in Java are resolved by reflection?
 
Master Rancher
Posts: 4918
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(hint: they aren't)
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Garrett Rowe wrote:I'll turn the question around. Why do you believe polymorphic method calls in Java are resolved by reflection?



obviously,java internally without using reflection for polymorphic method calls ,how can they know particular class methods gets called.
see ,based on the instance of class only,we are invoking the method,so first java will get the className of invoking object and then execute that version of method.

This process is called reflection.

otherwise you explain me how java resolves polymorphic method calls internally.

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Individual Java implementations are free to use any mechanism to resolve polymorphic method calls. One mechanism that may be used is a Virtual method table. For alternative mechanisms check out this paper.

In short, the way dynamic invocation works is left up to the architects of the JVM you are using. But reflection is not used any JVM that I know of to resolve polymorphic method calls.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Garrett Rowe:

i have seen the wikipedia link for virtual method table which you given.

In that wikipedia ,it says , vtable solution mechansim also implement such dynamic dispatch but it's not a one

and also not says specfically for the java.

the below are the wikipedia lines

There are a variety of different ways to implement such dynamic dispatch, but the vtable solution is especially common among C++ and related languages


see this below pdf document also


http://myweb.msoe.edu/~blessing/cs4811/inheritpoly-ch5-6up.pdf

please find this text ,Run-time type Identification and have a look at it.


if you want i will send many links regarding this.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know what reflection is. Nowhere in the link that you provide does it state that Java uses reflection to implement dynamic dispatch. That is not how it's done. Period. So again I have to ask, why do you believe that it does. Surely you've never read that in any credible source.
 
Mike Simmons
Master Rancher
Posts: 4918
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternately, it sounds like Birla is actually interested in talking about early binding vs. late binding. Birla, reflection is different from either of these. You are distracting people from answering your original question, because you are using the term incorrectly. The simplest solution for you would be to stop talking about "reflection" if what you mean is late (dynamic) binding. That was the wrong word. If you stop using it, and move on, you will have a better chance of discussing the question you intended to ask.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Birla,

There is no performance penalty for using interfaces.

Reflection is irrelevant to late binding because most JVMs are written in a language like C++ which has lower-level constructs than Java has. The SUN JVM is written in C++. You might be thinking that late binding is implemented in Java code, which is usually not the case. Java reflection is not used to call an implementation method of an interface variable.

Let's try your timing program again, but this time let's use an interface in one trial and no interface in the other trial. In this test we'll leave out the irrelevant issues of class loader speed and reflection speed.
Output:
Concrete:203
Interface:203


If you still think there is a performance penalty for using interfaces, try another test to demonstrate the performance penalty.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Mike:

i won't say dynamic binding is a reflection, i think you haven't read the post clearly what i was posted previously,

what I asked was ,for dynamic binding is java use reflection mechanism ?.so first understand what i said before.

since i want to know the interface deeply,since polymorphism concept comes along with interface,so i have discussed with java rangers, i don't know why you are saying "i am distracting others " ???

so don't distract me...
 
Mike Simmons
Master Rancher
Posts: 4918
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, good luck with that then.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did i miss a War here ???
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets all please remember to stay civil folks! As a gentle reminder... Our Policy.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic