Is there any performance reason to declare method parameters final in Java?

Is there any performance reason to declare method parameters final in Java?

As in:

public void foo(int bar) { ... }


public void foo(final int bar) { ... }

Assuming that bar is only read and never modified in foo().


The final keyword does not appear in the class file for local variables and parameters, thus it cannot impact the runtime performance. It’s only use is to clarify the coders intent that the variable not be changed (which many consider dubious reason for its usage), and dealing with anonymous inner classes.

There is a lot of argument over whether the final modifier on the method itself has any performance gain since the methods will be inlined by the optimizing compiler at runtime anyway, regardless of the modifier. In this case it should also only be used to restrict the overriding of the method.


Javascript form submit: Object doesn’t support this property or method (IE7)

I’m trying to submit a form with javascript. Firefox works fine but IE complains that “Object doesn’t support this property or method” on the submit line of this function:

function submitPGV(formName, action)
    var gvString = "";

    pgVisibilities.each(function(pair) {
        gvString += pair.key + ":" + pair.value + ",";

    $('pgv_input').value = gvString;

    var form = $(formName);
    form.action = action;

Called here:

<a href="javascript:submitPGV('ProductGroupVisibility','config/productgroupvis/save')">

Here’s the form:

<form id="ProductGroupVisibility" action="save" method="post">
    <input type="hidden" name="ows_gv..PGV" id="pgv_input" value=""/>

Any ideas?


Try checking the type of the element IE is selecting:

// For getting element with id you must use # 
alert( typeof( $( '#ProductGroupVisibility' )));

It is possible there is something else on the page with that ID that IE selects before the form.


How to redefine CSS classes with Javascript

Let’s say we have defined a CSS class that is being applied to various elements on a page.

    color: #DD00DD;
    background-color: #330033;

People have complained about the colour, that they don’t like pink/purple. So you want to give them the ability to change the style as they wish, and they can pick their favourite colours. You have a little colour-picker widget that invokes a Javascript function:

function changeColourful(colorRGB, backgroundColorRGB)
    // answer goes here

What goes in the body of that function?

The intent being that when the user picks a new colour on the colour-picker all the elements with class="colourful" will have their style changed.


I don’t know about manipulating the class directly, but you can effectively do the same thing. Here’s an example in jQuery.

$('.colourful').css('background-color', 'purple').css('color','red');

In plain javascript, you would have to do more work.


What is the best open-source java charting library? (other than jfreechart) [closed]

Why are there not more opensource easy to use charting libraries for Java?. The only successful opensource project in this area seems to be jfreechart, and it doesn’t even have any documentation or examples available.


There is charts4j which is a charts and graphs API. It enables developers to programmatically create the charts available in the Google Chart API through a straightforward and intuitive Java API.

Disclaimer: I wrote charts4j. We will be doing another major release in the next few weeks.


Controlling the classpath in a servlet

My servlet application includes a number of library .jars, some of which contain embedded log4j.xml or files. I’d like to ensure that log4j finds my log4j.xml first! I’ve tried searching for some specification of the priorities of the various classpath elements in a servlet (e.g. does WEB-INF/classes always precede WEB-INF/lib?), or some way to configure or tweak the servlet’s classloader so that a given resource directory appears early in the classpath. So far, I’ve drawn a blank. Any suggestions on ensuring that a servlet .war file loads the correct log4j.xml via the classloader?


As far as I understand the resource selection from the classpath is non-deterministic (from the point of view of the app developer). Even if the same file is loaded consistently the behaviour could change:
1. When you upgrade the version of your current container.
2. If you switch containers.

The simplest solution will be to remove embedded log4j config files from library jars. It is almost never a good idea to embed log4j config’s as it leads to the problem you are seeing here…

Are they third party jars or jars you developed?

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..