Skip to content

Tag: java

Invert the Selection in JTable

On clicking a button, I want the selected rows to be inverted (non-selected rows should be selected and selected rows should be non-selected). Is there a build-in method in JTable to do it? Answer JTable doesn’t seems to have a built-in way of doing this. So I implemented it with the following code. (Ho…

What is the difference between local and instance variables in Java?

Except the scope and the storage differences, are there any other major difference between instance and local variables in Java? Answer One extra thing I can think of: Instance variables are given default values, i.e., null if it’s an object reference, and 0 if it’s an int. Local variables don&#82…

Importing two classes with same name. How to handle?

Say I’ve a code like: Should I be full qualified class names? Can I get rid of the import statements? Is such a scenario common in real world programming? Answer You can omit the import statements and refer to them using the entire path. Eg: But I would say that using two classes with the same name and …

Adding Buttons inside cell of JTable along with data?

Is it possible to add buttons inside the JTable cell along with data? What I am trying to do is to create a table with columns which display data(number) from the database, and two buttons to increase/decrease the number inside the same cell. |ID | Quantity| |06| 2 [+][-] | it would be something like above wi…

What is chain.doFilter doing in Filter.doFilter method?

In a Filter.doFilter method I made this call chain.doFilter. What is doFilter doing inside a doFilter? Isn’t it a recursive call? Answer Servlet Filters are an implementation of the Chain of responsibility design pattern. All filters are chained (in the order of their definition in web.xml). The chain.d…

What is the replacement for Sets.newConcurrentHashSet()?

I am upgrading from Google Collections 0.9 to 1.0. It seems Sets.newConcurrentHashSet() is no longer available. I was using it in the following construct: What would be the best replacement for Sets.newConcurrentHashSet() ? Edit: The reason for this construct is to have a multimap that is safe to read and wri…