| Author |
Performance comparison of Java class and Interfaces
|
Joe P Kumar
Greenhorn
Joined: Oct 06, 2004
Posts: 3
|
|
Hi all, I would like to know if application performance can be improved by replacing a Java class file which contains final static variables with an interface. Also can someone explain how to measure the time taken by JVM to load a class file against an interface. Thanks Joe.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
It seems VERY unlikely that there would be any difference at all. The distinction between a class and an interface is mainly of interest to the compiler, not to the runtime. Bill
|
 |
Joe P Kumar
Greenhorn
Joined: Oct 06, 2004
Posts: 3
|
|
So does that mean that loading a class on a JVM and an loading an interface on a JVM will nearly take the same time. I thought an Interface will be light weight for the eyes for compiler as well as interpreter. Also, can you please explain as to why class / interface are of interest to a compiler and not the Runtime env. Thanks a lott Joe.
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
Please explain, why you expect a difference. You could write your own classloader. This may sound super-complicated, but a lot of people wrote their own classloader, and you only need to find the place, where you modify the classloading - to insert the stopwatch functionality. I guess the time to load a class or interface will be hard to measure, since it will be a very small time. Perhaps you may generate a big class and interface with generated code, like , to get a measurable difference... Tell us the results.
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
So does that mean that loading a class on a JVM and an loading an interface on a JVM will nearly take the same time. I thought an Interface will be light weight for the eyes for compiler as well as interpreter. Also, can you please explain as to why class / interface are of interest to a compiler and not the Runtime env.
No, it does NOT mean that loading a class will take about the same time - sheesh! Look at the size of the compiled interface and compiled class .class files - unless the interface defines many many constants, it will be quite compact. As for your second question - think about what the compiler has to do: 1. when a class declaration implements an interface 2. when a reference is an interface type At runtime, the JVM only needs to know if a reference is the correct type ie is an instance of a class or implementation of an interface. As far as I can see, the checking mechanism is the same for both. Bill
|
 |
 |
|
|
subject: Performance comparison of Java class and Interfaces
|
|
|