I would like a code snippet that checks whether a directory has read/write permissions and do something if it does, and does something else if it doesnt. I tried an example shown here: The problem is the exception is always triggered, so it always ends up printing “Bad” regardless of whether the d…
Java heap space error while creating ArrayList of large number of objects?
I have created an ArrayList (Java) of my custom class objects with a size around 3000. But when I run my code it gets the error “Heap space error”. I want to keep thousands of objects in an ArrayList …
Auto code completion on Eclipse
I want Eclipse to automatically suggest to me all possible options, while I’m writing some variable/class name or keyword, like in Flash Develop or Visual Studio. Is it possible? If not, with which Java IDE can I get this? I’m specifically asking about a way to automatically get the same thing I g…
Which is the Best Java IDE for Spring Framework? [closed]
Which is the best base java IDE (eclipse, Netbean) for developing spring based application apart from IntelliJ. I have used NetBean so far , the online documentation and google search points to only …
Tracking “hidden” exceptions
I am inspecting the output of a program of mine where from time to time I see a message like “java.lang.NullPointerException” and nothing else. Because this doesn’t come from my code, I am pretty sure, there is some 3rd party library, where some jerk has done something like: catch ( ex ) { p…
Stuck implementing Wikipedia’s A* (“A star”) algorithm
I’m implementing the A* search algorithm from this pseudo on wikipedia’s article: I’m stuck on the line where I’m asked to retrive the node in openSet with the lowest f value. When has openSet been filled? With what? Should it just have start on the first run? I also don’t undest…
How to calculate HashMap memory usage in Java?
I was asked in an interview to calculate the memory usage for HashMap and how much estimated memory it will consume if you have 2 million items in it. For example: The mapping is like this. How would I estimate the memory usage of this HashMap Object in Java? Answer The short answer To find out how large an o…
How to create a file in a directory in java?
If I want to create a file in C:/a/b/test.txt, can I do something like: Also, I want to use FileOutputStream to create the file. So how would I do it? For some reason the file doesn’t get created in the right directory. Answer The best way to do it is:
Naming threads and thread-pools of ExecutorService
Let’s say I have an application that utilizes the Executor framework as such When I run this application in the debugger, a thread is created with the following (default) name: Thread[pool-1-thread-1]. As you can see, this isn’t terribly useful and as far as I can tell, the Executor framework does…
Java – Forward Slash Escape Character
Can anybody tell me how I use a forward slash escape character in Java. I know backward slash is but I’ve tried / and / / with no luck! Here is my code:- Thanks in advance! Answer You don’t need to escape forward slashes either in Java as a language or in regular expressions. Also note that