The Artima Developer Community
Sponsored Link

Java Answers Forum
Final Classes in Java

4 replies on 1 page. Most recent reply: Jan 19, 2005 5:51 PM by Chris Miller

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
JavaAdd Ict

Posts: 5
Nickname: javaaddict
Registered: May, 2004

Final Classes in Java Posted: Jan 12, 2005 12:31 AM
Reply to this message Reply
Advertisement
One of my colleagues read this in a book of Data Structures, that in Java if a class is made as final(assuming that its not going to be inherited any further), then it increases the run time performance.

Can someone pls explain how does this happen? How is the bytecode of a final class is different from that of a normal class and in what way is its behaviour different at run time?


lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: Final Classes in Java Posted: Jan 18, 2005 8:40 AM
Reply to this message Reply
Well that's not really true
making a class final is none but keeping it constant
it's really got little to do with performence
wich is highly dependent on the methods on the class
so relax;
best regard

Yogesh

Posts: 19
Nickname: kyogesh
Registered: Sep, 2004

Re : Final Classes in Java Posted: Jan 19, 2005 2:27 AM
Reply to this message Reply
hi
this could be one of the reasons.
inheritance involve key issue of polymorphism which is related to latebinding or dynamic binding.

if a class is final it cannot be inherited. its all methods are also final that means methods cannot be overridden. so no need of dynamic binding. only static binding
and dynamic binding has more overheads than static binding. hence if a class or a method is final only static binding is involved (less overheads at runtime). thus improved performance is achieved.

I don't know about '.class' file structure. check this link :http://www.shsu.edu/~csc_tjm/summer2000/cs278/inheritance.html

Rob

Posts: 2
Nickname: sarsipius
Registered: Oct, 2004

Re: Final Classes in Java Posted: Jan 19, 2005 6:21 AM
Reply to this message Reply
With regards to the class file, the only difference is a flag set on the class (and probably each method as well) indicating that it is final.

With regards to performance, a jvm may also be optimized to inline final methods at run time when generating the machine code.

If you want to know more about how the jvm works, I suggest reading the Java Language and JVM specifications (URL's below). They are pretty well laid out and a relatively easy read.

http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html
http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html

Chris Miller

Posts: 23
Nickname: lordsauron
Registered: Jan, 2005

Re: Final Classes in Java Posted: Jan 19, 2005 5:51 PM
Reply to this message Reply
I suppose it could make it faster, since it isn't being concerned with internal vairables... My best educated guess would be a "possibly."

Flat View: This topic has 4 replies on 1 page
Topic: Bluetooth + Java Previous Topic   Next Topic Topic: threads related question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use