I have a web application written in Java (Spring, Hibernate/JPA, Struts2) where users can upload images and store them in the file system. I would like to scale those images so that they are of a consistent size for display on the site. What libraries or built in functions will offer the best results? I will …
Tag: java
What is the Java ?: operator called and what does it do?
I have been working with Java a couple of years, but up until recently I haven’t run across this construct: This is probably a very simple question, but can someone explain it? How do I read it? I am pretty sure I know how it works. if isHere is true, getHereCount() is called, if isHere is false getAway…
Delete directories recursively in Java
Is there a way to delete entire directories recursively in Java? In the normal case it is possible to delete an empty directory. However when it comes to deleting entire directories with contents, it is not that simple anymore. How do you delete entire directories with contents in Java? Answer You should chec…
Why doesn’t java.util.Set have get(int index)?
I’m sure there’s a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can’t find an elegant way of retrieving a single item from it. If I know I want the …
Why am I getting this UnsatisfiedLinkError with native code?
I have a library called HelloWorld.so and a program HelloWorld.java with this content: Now when I try to run HelloWorld.java I get this error: $ /usr/java1.4/bin/java HelloWorld Exception in thread “main” java.lang.UnsatisfiedLinkError: no HelloWorld in java.library.path at java.lang.ClassLoader.l…
How do I put a Java app in the system tray?
I have a little control-panel, just a little application that I made. I would like to minimize/put the control-panel up/down with the systemicons, together with battery life, date, networks etc. Anyone that can give me a clue, link to a tutorial or something to read? Answer As of Java 6, this is supported in …
Does an open-ended interval implementation exist for Java?
I’ve got a classification of certain values in different intervals. Most have the form [20-30], but some are of the form [30-infinite). Is there an interval class you know of which can represent: an interval which is not closed on both sides (e.g. (0-5) or [0-5) ) an interval which closes (or starts) on…
How to clone ArrayList and also clone its contents?
How can I clone an ArrayList and also clone its items in Java? For example I have: And I would expect that objects in clonedList are not the same as in dogs list. Answer You will need to iterate on the items, and clone them one by one, putting the clones in your result array as you go. For that
Java FileReader encoding issue
I tried to use java.io.FileReader to read some text files and convert them into a string, but I found the result is wrongly encoded and not readable at all. Here’s my environment: Windows 2003, OS encoding: CP1252 Java 5.0 My files are UTF-8 encoded or CP1252 encoded, and some of them (UTF-8 encoded fil…
Is there a Null OutputStream in Java?
I need to specify an OutputStream for an API I’m using, but I don’t actually have a need for the output. Does Java have an OutputStream equivalent to > /dev/null? Answer Since Java 11, there is a static utility that does exactly what you need, a static factory method OutputStream.nullOutputStre…