aspose file tools
The moose likes Java in General and the fly likes Performance comparison of Java class and Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Performance comparison of Java class and Interfaces" Watch "Performance comparison of Java class and Interfaces" New topic
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
    
    1
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
    
    1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Performance comparison of Java class and Interfaces
 
Similar Threads
another Questions.
abstract class or interface
Enum vs Constant File
Is this statment True?
Some basic questions , i dont know the answer for