java

How to refer to the outer class in another instance of a non-static inner class?

I'm using the Apache Commons EqualsBuilder to build the equals method for a non-static Java inner class. For example: import org.apache.commons.lang.builder.EqualsBuilder; public class Foo { public class Bar { private Bar() {} public Foo getMyFoo() { return Foo.this } private int myInt ...

Declare-and-throw vs. throw-without-being-declared exceptions

In Java, what is the difference between the twin methods? public void methodA() throws AnException { //do something throw new AnException(); } public void methodA() { //do the same thing throw new AnException(); } I have a intuition that it has something to do with being a well-designed method (because I put methodA i...

When overriding equals in Java, why does it not work to use a parameter other than Object?

I ran into an interesting behavior recently. It seems that if I override .equals() to take a parameter other than Object, it doesn't get called. Can anyone explain to me why this is happening? It seems to violate my understanding of polymorphism in OOP, but maybe I'm missing something. Here's much simpler code that shows what I'm see...

How to parse arrays of objects returned by DWR?

DWR handles lists of primitives quite straight forward. I could not find whether array of objects returned by a DWR method call represent a JSON object. Any clues? Or do I have to return a JSON string representing the array of objects back to the browser? ...

Injecting beans into a class outside the Spring managed context.

I'm an end-user of one of my company's products. It is not very suitable for integration into Spring, however I am able to get a handle on the context and retrieve the required bean by name. However, I would still like to know if it was possible to inject a bean into this class, even though the class is not managed by Spring itself. Cl...

How do I access Windows Event Viewer log data from Java

Is there any way to access the Windows Event Log from a java class. Has anyone written any APIs for this, and would there be any way to access the data from a remote machine? The scenario is: I run a process on a remote machine, from a controlling Java process. This remote process logs stuff to the Event Log, which I want to be able to...

How do you get jconsole charts to show decimals?

If you return a double or float from your MBean jconsole seems to round it down to the nearest integer. ...

Iterate over HashMap.values() in JSF+Facelets

I'm using JSF/Facelets, and I'm trying to iterate over some Document objects (custom object) that I'm keeping in a HashMap. When the page is loaded, I'm getting the error "Property 'name' not found on type java.util.HashMap$Values". Here's what's in my backing bean: private Map<String, Document> documents = new HashMap<String, Documen...

Best way to configure a Java enterprise application

Hello all, I have a set of EJBs and other Java classes which need to be configured differently based on the system environment in which they are deployed: production, test, or lab. The configuration information includes stuff like URLs and database connection information. We'd like to deploy the same exact product (EAR file) in each en...

Java obfuscators

I'm looking for a good Java obfuscator. I've done initial research into the following Java obfuscators: proguard, yguard, retroguard, dasho, allatori, jshrink, smokescreen, jobfuscate, marvin, jbco, jode, javaguard, jarg, joga, cafebabe, donquixote, mwobfu, bbmug, zelix klassmaster, sandmark, jcloak, thicket, blufuscator, and java code ...

What is Namespace URI Constant.NamespaceSpecNS stands for?

I'm porting parts of Java project to C# and came across this constant Constant.NamespaceSpecNS. One of its uses is in the following Java context: _xmlElement.setAttributeNS(Constants.NamespaceSpecNS,"a_qualified_name", "some_value"); where seAttributesNS is declared in org.w3c.dom Interface Element. So, from this call, I know it is ...

Any implementation of Map<K1, K2, V>, i.e. two keys?

I need a map that has two keys, e.g. Map2<String /*ssn*/, String /*empId*/, Employee> _employees; So that I can _employees.put(e.ssn(), e.empId(), e) And later _employees.get1(someSsn); _employees.get2(someImpId); Or even _employees.remove1(someImpId); I am not sure why I want to stop at two, why not more, probably because th...

JXTable - Highlighter after filtering table

Info - for better formatting, I used code-formatting throughout the whole posting. Hi, I have a highlighted JXTable. Rows are highlighted, depending on the value of a specific column (c2). Everytime the value of column c2 changes, the color is switched from white to grey or from grey to white. Example c0 c1 c2 c3 1...

How do I learn Java EE? Where to start?

I'm going to be honest with you guys. I want to learn Java EE (and its related technologies) because it offers a lot of job opportunities here (the Philippines) and abroad. The problem is I don't know where to start and what to read or where to learn from. I'm almost finished reading Head First Java and I'm liking the language so far. An...

How to grant different permissions to various Java classes?

I have a Java application and I would like to make it extensible. To create an extension, developers within our company will write a Java class that implements a certain interface. They may also wish to write associated helper classes. I would like to load these extensions into the application without an outage. I would like to limit...

What are the hidden features of Maven2?

What are the hidden features of Maven2? ...

Java Regular Expressions Replacement

Just could not get this one and googling did not help much either.. First something that I know: Given a string and a regex, how to replace all the occurrences of strings that matches this regular expression by a replacement string ? Use the replaceAll() method in the String class. Now something that I am unable to do. The regex I hav...

Turning off hibernate logging console output

I'm using hibernate 3 and want to stop it from dumping all the startup messages to the console. I tried commenting out the stdout lines in log4j.properties but no luck. I've pasted my log file below. Also I'm using eclipse with the standard project structure and have a copy of log4j.properties in both the root of the project folder and t...

Initialising Java Web App

I have a simple web app, with a few jsp pages, servlets and pojo's. I want to initialise the connection pool before any requests are made. What is the best way to do this? Can it be done when the app is first deployed or do you have to wait till the first request comes in? ...

How to use generics in a world of mixed Java versions?

I like generics a lot and use them whereever I can. Every now and then I need to use one of my classes in another project which has to run on an old JVM (before 5.0), needs to run on JavaME (where generics are not allowed neither) or in Microsoft J# (which has VERY poor Support for generics). At the moment, I remove all generics manuall...