hey_hey
asked on
interface questin
why some poeple say the many interfaces slow code?
public class my implements one,two, .... ,hunded
{
//code
}
tell me
public class my implements one,two, .... ,hunded
{
//code
}
tell me
>> why some poeple say the many interfaces slow code?
which people ?
why don't you ask them ? :)
which people ?
why don't you ask them ? :)
I thinks that when you include more interface in your Applet class .Java have to include the code of the libraly that your use in the interface. Then your bytecode will be larger .It can take more time to download from the interface . I thinks that is why it is slower. About take the longer time to download problem
Regards
MAC
Regards
MAC
Hi,
In my opinion,when you implement any interface you have to either implement all the methods of the interface or you have to provide the null body for the non required methods,so by this the byte code size increases and in turn may slows down the execution of the process.
In my opinion,when you implement any interface you have to either implement all the methods of the interface or you have to provide the null body for the non required methods,so by this the byte code size increases and in turn may slows down the execution of the process.
i think that ,
ravindra76's
plus mackrub's & shaveri's comments combined r the answer
ravindra76's
plus mackrub's & shaveri's comments combined r the answer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I still don't see why 'using many interfaces slow the code' ... if you use many interfaces, you'll have more code (slower download time, but not slower execution time), but the same is true if you use many classes ... :)
so
1. I don't think that using many interfaces will slow the execution time of your code.
2. the discussion is quite 'unreasonable ' (can't find better word)
so
1. I don't think that using many interfaces will slow the execution time of your code.
2. the discussion is quite 'unreasonable ' (can't find better word)
Hi heyhey,
I think multiple interfaces will slow down execution.
I read in a book that multiple inheritance willl slow down the execution .
Because
THere are so many baseclasses and finding the method from which it is getting if not present in that class is burden to exeution.
Why this rule won't apply to multiple interfaces in java ( Evne though interface is not true multiple inheritance, it can be manipulaed in some cases).
in 'multiple inheritance' you may have more than one implementation of some method.
in Java you have only ONE implementation of some method, so you won't lose time to find this implementation.
in Java you have only ONE implementation of some method, so you won't lose time to find this implementation.
Any how late binding at execution time may cause execution delay opposed to static binding at compilation time.
>> late binding at execution
but what's the connection between interfaces and late binding ? :)
generally speaking you'll have slower execution time if you use more code (more classes / longer methods etc.). if your class implements some interface you'll have only several more checks (only when you explicitly cast some object from that class).
but what's the connection between interfaces and late binding ? :)
generally speaking you'll have slower execution time if you use more code (more classes / longer methods etc.). if your class implements some interface you'll have only several more checks (only when you explicitly cast some object from that class).
heyhey,
I agree with all above that I read in some book or the other that multiple interfaces slow down code ,but at that time I was too naive to know what it meant. I dont know if the JLS /JVM spec has changed that much that they dont slow down code.
ravindra76,
>>>>>Any how late binding at execution time may cause execution delay opposed to static binding at compilation time.
heyhey is right ,there is no relation between interfaces and late binding.FYI all binding in Java is 'late' as all methods are 'virtual' by default.
u get 'static' binding only when u have the method(s) marked as 'final'
I agree with all above that I read in some book or the other that multiple interfaces slow down code ,but at that time I was too naive to know what it meant. I dont know if the JLS /JVM spec has changed that much that they dont slow down code.
ravindra76,
>>>>>Any how late binding at execution time may cause execution delay opposed to static binding at compilation time.
heyhey is right ,there is no relation between interfaces and late binding.FYI all binding in Java is 'late' as all methods are 'virtual' by default.
u get 'static' binding only when u have the method(s) marked as 'final'
>> I read in some book or the other that multiple interfaces slow down code
can you give me URL or osme quotation ? I am not bytecode / JVM expert - I'm just using my common sence (so I may be wrong of course :)
can you give me URL or osme quotation ? I am not bytecode / JVM expert - I'm just using my common sence (so I may be wrong of course :)
heyhey ,
I am a bit snowed under work will definitely post the info but right off the cuff I think I read this in 'Core Java' the original JDK1.0 edition(i am not sure)
Will post the info soemtime next week after hunting around.
Cheers.
I am a bit snowed under work will definitely post the info but right off the cuff I think I read this in 'Core Java' the original JDK1.0 edition(i am not sure)
Will post the info soemtime next week after hunting around.
Cheers.
ASKER
what book was it ,so i too xcan read.
Hi Guys,
Still i think delay in binding.
Hi Amit:-
I disagree with
>>
u get 'static' binding only when u have the method(s) marked as 'final'
1.In my view, static binding is
Assume thwo methods.
public void someMethod( int a){}
public void someMethod (String s) {}
int a = 5;
String s="ravi",
someMethod(a)//Now in compiling ,compiler knows its reference to int variable method
someMethod(s)//Now in compiler knows it is string object method.
It's also called static binding.
2.Assume a class Vechicle
public abstract class Vehicle{
abstract void move();
}
two deived classes
public class Cycle extends Vehicle {
public void move(){}
}
public class Car extends Vehicle {
public void move(){}
}
And some another class
class x {
// got Vehicle object ( IT may be //cycle or car and called move method.
//Till dynamic binding it don't know //which move will be called
}
Ravi,
from the Java language spec
8.4.8.5 Example: Invocation of Hidden Class Methods
A hidden class (static) method can be invoked by using a reference whose type is the class that actually contains the declaration of the method. In this respect, hiding of static methods is different from overriding of instance methods. The example:
class Super {
static String greeting() { return "Goodnight"; }
String name() { return "Richard"; }
}
class Sub extends Super {
static String greeting() { return "Hello"; }
String name() { return "Dick"; }
}
class Test {
public static void main(String[] args) {
Super s = new Sub();
System.out.println(s.greet ing() + ", " + s.name());
}
}
produces the output:
Goodnight, Dick
because the invocation of greeting uses the type of s, namely Super, to figure out, at compile time, which class method to invoke, whereas the invocation of name uses the class of s, namely Sub, to figure out, at run time, which instance method to invoke.
Again ALL methods in Java are virtual and all of them follow Late binding by default unless you change them yourself.
As a aside,here's 1 little titbit.
In Java you can't have methods where the base class has non-virtual (final)
methods which the derived class can override.
I mean to say
class Parent
{
public void virtualOverrideInDerived()
{
System.out.println("In Parent's virtualOverrideInDerived() ");
}
public final void nonVirtualNOTAllowedOverri deInDerive d()
{
System.out.println("In Parent's nonVirtualNOTAllowedOverri deInDerive d()");
}
}
public class Child extends Parent
{
public void virtualOverrideInDerived()
{
System.out.println("In Child's virtualOverrideInDerived() ");
}
//Error this code wont compile at all.
/*
public final void nonVirtualNOTAllowedOverri deInDerive d()
{
System.out.println("In child's nonVirtualNOTAllowedOverri deInDerive d()");
}
*/
public static void main(String a[])
{
new Child().virtualOverrideInD erived();
new Child().nonVirtualNOTAllow edOverride InDerived( );
}
}
from the Java language spec
8.4.8.5 Example: Invocation of Hidden Class Methods
A hidden class (static) method can be invoked by using a reference whose type is the class that actually contains the declaration of the method. In this respect, hiding of static methods is different from overriding of instance methods. The example:
class Super {
static String greeting() { return "Goodnight"; }
String name() { return "Richard"; }
}
class Sub extends Super {
static String greeting() { return "Hello"; }
String name() { return "Dick"; }
}
class Test {
public static void main(String[] args) {
Super s = new Sub();
System.out.println(s.greet
}
}
produces the output:
Goodnight, Dick
because the invocation of greeting uses the type of s, namely Super, to figure out, at compile time, which class method to invoke, whereas the invocation of name uses the class of s, namely Sub, to figure out, at run time, which instance method to invoke.
Again ALL methods in Java are virtual and all of them follow Late binding by default unless you change them yourself.
As a aside,here's 1 little titbit.
In Java you can't have methods where the base class has non-virtual (final)
methods which the derived class can override.
I mean to say
class Parent
{
public void virtualOverrideInDerived()
{
System.out.println("In Parent's virtualOverrideInDerived()
}
public final void nonVirtualNOTAllowedOverri
{
System.out.println("In Parent's nonVirtualNOTAllowedOverri
}
}
public class Child extends Parent
{
public void virtualOverrideInDerived()
{
System.out.println("In Child's virtualOverrideInDerived()
}
//Error this code wont compile at all.
/*
public final void nonVirtualNOTAllowedOverri
{
System.out.println("In child's nonVirtualNOTAllowedOverri
}
*/
public static void main(String a[])
{
new Child().virtualOverrideInD
new Child().nonVirtualNOTAllow
}
}
heyhey_ ,
(with the trailing '_' )
Can you please take the trouble to explain if u have time?
:-)
ravi ,have u understood finally?
(with the trailing '_' )
Can you please take the trouble to explain if u have time?
:-)
ravi ,have u understood finally?
ASKER
well nobody has time to tell the actuial answer i asked for but instead of deleting it i give mborman points here.
to mbormann,if you come across it as heyhey said post it here.
thank you all for telling me!
to mbormann,if you come across it as heyhey said post it here.
thank you all for telling me!
ASKER
well i give it in hope that i get the answe later,when they have time
check out
http://sunsite.compapp.dcu.ie/IJUG/javaone/transcripts/runtime.html
http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00309.html
hope now it's solved !
http://sunsite.compapp.dcu.ie/IJUG/javaone/transcripts/runtime.html
http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00309.html
hope now it's solved !
Hi,
I think
Getting the Object dynamically that implements the interface may take time.
Anyhow interfaces to be used eventhough it may slow.
Best of luck