• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
I AM MIGHTY! Especially when I hold this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic