• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

COMPILER OPTIMIZATION

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
REF P.89 EXAMPREP
"Declaring a class final enables compiler to perform optimizatios"
Can some one kindly explain me what is compiler response to final keyword, and what does the phrase compiler optimization means?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Zeeshan,
When you run <code>javac someFile.java</code> the Java compiler turns your code into a series of <code>bytecode</code> which are translated by Java into machine code instructions when the program is run.
When the compiler runs across a variable it has to create bytecode instructions that say lookup up the value at memory address such and such. This may take 2 or 3 lines of bytecode.
When a variable is declared <code>final</code> you are telling the compiler this variable's value will never change. The compiler can then use one instruction use this value whenever it encounters the variable; it does not need create lookup instructions for that variable.
The end result is shorter or optimized bytecode.
Hope that helps.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic