I have an abstract Java class MyAbstractClass with a private method. There is a concrete implementation MyConcreteClass. In my groovy test class I have I get an error that there is no such method signature for somePrivateMethod. I know groovy can call private methods but I’m guessing the problem is that…
Tag: java
Increasing JRE Memory Usage in Eclipse
I read in another question that you can increase the JRE memory allowance for an app through Window -> Preferences in Eclipse, but I can’t seem to find anything related to heap memory allocation. Editing -xms/xmx values in eclipse.ini doesn’t help since those are for Eclipse itself. Answer I be…
What is the proper way to use a Logger in a Serializable Java class?
I have the following (doctored) class in a system I’m working on and Findbugs is generating a SE_BAD_FIELD warning and I’m trying to understand why it would say that before I fix it in the way that I thought I would. The reason I’m confused is because the description would seem to indicate t…
HttpURLConnection timeout settings
I want to return false if the URL takes more then 5 seconds to connect – how is this possible using Java? Here is the code I am using to check if the URL is valid Answer HttpURLConnection has a setConnectTimeout method. Just set the timeout to 5000 milliseconds, and then catch java.net.SocketTimeoutExce…
Why must wait() always be in synchronized block
We all know that in order to invoke Object.wait(), this call must be placed in synchronized block, otherwise an IllegalMonitorStateException is thrown. But what’s the reason for making this restriction? I know that wait() releases the monitor, but why do we need to explicitly acquire the monitor by maki…
Using Regular Expressions
I am having problems trying to use the regular expression that I used in JavaScript. On a web page, you may have: Renewal Date: 03 May 2010
I just want to be able to …
What does the Java assert keyword do, and when should it be used?
What are some real life examples to understand the key role of assertions? Answer Assertions (by way of the assert keyword) were added in Java 1.4. They are used to verify the correctness of an invariant in the code. They should never be triggered in production code, and are indicative of a bug or misuse of a…
How to cast a list of inheriting objects to a collection of objects in Java?
I’ve a collection type: And I’ve a list in my object: Where B is extending A But I can’t do the following: I can’t understand why since Collection is implemented by List. Answer Let’s assume for a moment you could do what you describe: The method call collecA.add(new A()) appears…
how to convert minutes to days,hours,minutes
how to convert minutes into days hours and minutes in java ( we have a week here , 7 days ) I tried this but it dont work thanks Answer A shorter way. (Assumes time >= 0)
What is the “owning side” in an ORM mapping?
What exactly does the owning side mean? What is an explanation with some mapping examples (one to many, one to one, many to one)? The following text is an excerpt from the description of @OneToOne in Java EE 6 documentation. You can see the concept owning side in it. Defines a single-valued association to ano…