File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in final method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in final method" Watch "Doubt in final method" New topic
Author

Doubt in final method

vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
I heard that whenever final method is called subsequent code is subsitute to the method call?

Now i want to know whether it is for all cases R it may be decide by compiler
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
clarify your question.
I seriously doubt my mental capabilities to make sense of your choice of words (and that despite knowing 3 languages fluently and 3 more to some extent).


42
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
HI Jeroen Wenting

Atleast can u get me now???

I heard that whenever final method is called,the corresponding code is subsituted to the method call?

Now i want to know whether it is applicable in all final method calls or its upto compiler to decide upon in some situation to substitute and in some not.
Saurabh Khanna
Ranch Hand

Joined: Apr 03, 2005
Posts: 30
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Vidya is asking about inlining, inserting the bytecode for a method where the method is called.

There is no requirement that a compiler ever inline code, but making a method final, private, or static eliminates run-time dispatching (polymorphism) so inlining is easier. Java Hotspot is so aggressive in inlining that it will even deal with possible polymorphism.

My (pre-Java) textbook says that the main considerations are the size of the method and the scope of references. Sun has some nice discussions of inlining on their web site. Just search on "inlining".

Second Comment:

I had no problem understanding Vidya's question. If you don't understand a question, please ask for clarification or just don't answer. It's even possible that it's you who don't understand. There is no reason to insult someone who is doing his best.


Mike Gershman
SCJP 1.4, SCWCD in process
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Hi Mike,

Originally posted by Mike Gershman:
Second Comment:

I had no problem understanding Vidya's question. If you don't understand a question, please ask for clarification or just don't answer. It's even possible that it's you who don't understand. There is no reason to insult someone who is doing his best.


I'm honestly impressed with you being able to understand what Vidya was asking. Hopefully, your explanation is what he was looking/asking for.

I don't think Jeroen was actually being rude or insulting. As we all know, this being the internet, people from all over the world can access this forum. Some folks may not have the luxury to read visually & relies on software to do the translation of posted messages into verbal messages. Hence, it is for the benefit of everyone that we could, perhaps, try to write our queries and replies in simple, clear & easily understood English.

Of course not everyone would be able to write in perfect English, but if we make an effort to, it would make our questions more easily understood by many others & hence increases the chances of us getting replies. At the same time, we get to improve on our English writing capability.

I'm not implying or suggesting that I could write well. In fact, I think my writing skills have rooms for further improvement. :roll:

Actually Vidya's second post was much clearer. Although I don't have the answer to his query, I could at least understand what he was asking.

Ultimately, we're all here to learn & share knowledge from one another.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Ok friends

I will take it easy,whenever i am going wrong. UR best friends to correct me for my benefit.

If anyone tell answer for my question then i will be very happy
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Chengwei:

Your English is very understandable, you must have really worked at it.

You should know that "hence" is not used much these days. Try using "so". "so it increases the chances ..." "So it is for the benefit of everyone ..."

Vidya:

What you asked about is called "inlining". Read my post above, search the Sun web site, google it, and please come back if you have more questions.
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Originally posted by vidya sagar:
I heard that whenever final method is called subsequent code is subsitute to the method call?

Now i want to know whether it is for all cases R it may be decide by compiler


Even now all guys in forum where discussing some thing other than java ....
Let me know ur doubt n specific....
So i will try to clrify ....


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Originally posted by vidya sagar:
I heard that whenever final method is called subsequent code is subsitute to the method call?

Now i want to know whether it is for all cases R it may be decide by compiler

say for Ex...

public class Final1
{
public final void mtd1()
{
System.out.println(" opps in final mtd");
}

public void mtd2()
{
System.out.println("i am from second");
}



public static void main(String l[])
{
Final1 o = new Final1();
o.mtd1();
}
}

o/p is opps in final mtd

did u menat to say that alll data in 2nd will print.... AS per Ur msg..
Let me know if my way of thinking is Wrong
[ April 13, 2005: Message edited by: Gowtham Ganamukala ]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Most non-native English speakers that I know enjoy blatancy when you point out their mistakes. This means that they can learn something.
If they get defensive, then that's their problem.
Blatancy != offensive (despite some western cultures suggesting so by means of inflated egos).

<two-cents currency="AU"/>


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in final method