Can I get localized short day-in-week name (Mo/Tu/We/Th/Fr/Sa/Su for English) in Java? Answer The best way is with java.text.DateFormatSymbols
Running shell_exec(‘which java’) in PHP return nothing
If I run from the command line I get the proper input (/usr/java/…/bin/java). However if I run it in a php script: nothing gets printed out for which java but I get the proper results for which ls… Answer Two things were needed: the full path to the JVM (it wasn’t set in the environment) …
How can I normalize the EOL character in Java?
I have a linux server and many clients with many operating systems. The server takes an input file from clients. Linux has end of line char LF, while Mac has end of line char CR, and Windows has end of line char CR+LF The server needs as end of line char LF. Using java, I want to ensure that the
Eclipse release heap back to system
I’m using Eclipse 3.6 with latest Sun Java 6 on Linux (64 bit) with a larger number of large projects. In some special circumstances (SVN updates for example) Eclipse needs up to 1 GB heap. But most of the time it only needs 350 MB. When I enable the heap status panel then I see this most of the time:
When to use a Map instead of a List in Java?
I didn’t get the sense of Maps in Java. When is it recommended to use a Map instead of a List? Answer Java map: An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. Java list: An ordered collection (also known as a sequence). The user of this
Why do we need immutable class?
I am unable to get what are the scenarios where we need an immutable class. Have you ever faced any such requirement? or can you please give us any real example where we should use this pattern. Answer The other answers seem too focused on explaining why immutability is good. It is very good and I use it when…
How does dependency injection work in Spring?
I want to know how spring does dependency injection. I want the low level logic used. Updates: I want to know how the object references are injected to the constructors or setter methods, is it …
Working with Zip and GZip files in Java
It’s been a while since I’ve done Java I/O, and I’m not aware of the latest “right” ways to work with Zip and GZip files. I don’t necessarily need a full working demo – I’m primarily looking for the right interfaces and methods to be using. Yes, I could look up …
C# DateTime.Ticks equivalent in Java
What is the Java equivalent of DateTime.Ticks in C#? What will be the equivalent of above mentioned code in Java? Answer Well, java.util.Date/Calendar only have precision down to the millisecond: That’s the nearest effective equivalent. If you need to convert between a .NET ticks value and a Date/Calend…
Java: reference escape
Read that the following code is an example of “unsafe construction” as it allows this reference to escape. I couldn’t quite get how ‘this’ escapes. I am pretty new to the java world. Can any one help me understand this. Answer The example you have posted in your question comes fr…