Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, May 24, 2010

Memory leaks in JAVA..

Whenever question was asked about Memory management in JAVA (vs) Memory management in C++, the only thing I knew of is that

- in C++, memory leaks can occur and programmer needs to take care of them by writing cleanup code. and there is also a problem of dangling pointers.
- Clearly in JAVA, garbage collector takes care of memory management, in the sense, it cleans up all the objects to which no references are left. Clearly problem of dangling pointers is addressed. But Is it the same case with Memory leaks ?

There is more to memory leaks in JAVA - some good links.

http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/

http://jb2works.com/memoryleak/index.html

http://jb2works.com/memoryleak/topfive.html

Thursday, August 20, 2009

HashMap & Arbitary number of arguments in java...

It's simple stuff - HashMap

let's say there is a hashmap of strings in java and given a key you want to retrieve the corresponding value - i thought one could do it just by passing the string -- No it does not work that way -

since the get method takes only an object as a parameter - so typically the way to do would be to get all the keys from the hashmap and the iterate over the keys to get the corresponding values --

Arbitary Number of Arguments in Java

I saw a method with the following signature today - public List getXYZ(String... categories) - was wondering what String... means - it can be used to pass arbitary number of arguments in java - here is the explanation....

http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html