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…
Tag: java
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
Tool to extract java stack traces from log files [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 4 years ago. Improve this ques…
JDBC SQLServerException: “This driver is not configured for integrated authentication.”
I am writing a “server-side extension” for SmartFoxServer (SFS). In my login script, I need to make a connection to MS SQL Server, which I am attempting to do using JDBC. I have tested the JDBC code in my debug environment, and it works fine. BUT When I put the server-side extension in the SFS …
ImageMagick: How to compare original PNG to lossy JPEG?
I want to compare original PNG image to lossy JPEG image to see how much I am loosing. I found that I can use ImageMagic to compare images. I prefer using Java (im4java). I am very confused with their documentation (http://www.imagemagick.org/script/compare.php). It doesn’t describe which platform it is…
RSA in bouncycastle for java – How is ciphertext randomization gained?
I´m acutally using bouncycastle library for my applications RSA crypto. My question is: When I encrypt one plaintext two times using the same key, It will lead to two different ciphertexts, so there has to be some kind of randomization in bouncycastles implementation (RSA itself is not randomized, so enc(a, k…
How to find root of memory leaks?
My app is basicly and image editor. There is a welcome page which opens main activity with an intent. If orientation changes when main activity is working the memory consumption simply doubles up and remains that way. If i close the main activity turn back to welcome activity and start main activity again sam…
Playing .mp3 and .wav in Java?
How can I play an .mp3 and a .wav file in my Java application? I am using Swing. I tried looking on the internet, for something like this example: But, this will only play .wav files. The same with: http://www.javaworld.com/javaworld/javatips/jw-javatip24.html I want to be able to play both .mp3 files and .wa…