I was looking for a way to get current time in various timezones based on an user input. I know I could use Joda Time! but is that the only way? Isn’t there an option in Java for doing this? I tried the following code which gives the same output for all 3 sysouts. What am I missing here to
Tag: java
Convert minutes into a human readable format
quick question. Is there a smarter/sleeker way to convert minutes into a more readable format, showing only the most significant digit? I’m using Android Studio’s Java. ie My code is very cumbersome, sloppy, and somewhat unreadable. Many thanks, J Answer Well it is possible, I figure it out and I …
Failed to load Main-Class manifest attribute while running java -jar
I have successfully built my Spring MVC project with mvn clean package by following this tutorial. Now I am trying to run the service with: But I get this error: Failed to load Main-Class manifest attribute from target/gs-serving-web-content-0.1.0.jar Am I missing something? Answer If you are working with Spr…
log4j configurations with daily rolling, gzip and max backup files
Is there an appender that I can use that will get me daily rolling, compression and max files? I can get daily rolling file with compression using apache-log4j-extras with this configuration: But I can’t specify MaxBackupIndex as in org.apache.log4j.RollingFileAppender (note the slight namespace differe…
Java FTP 550 error
I’m getting this error (550 the filename, directory name, or volume label syntax is incorrect. ) I think the url is correct (obviously not though). Any thoughts? Here is the url: Here is the invocation method: ftp class: Answer If the FTP server is running Windows, the ‘*’ characters are the…
java.lang.OutOfMemoryError: Java heap space in allocating array size
I am doing very small program in java using Eclipse Kepler IDE. I am allocating the size of the array at run time using the following statement. so as per my knowledge the java program runs with some of its own heap space like 32 MB. And for my program i think this space is enough. I just given the
How to get host name with port from a http or https request
I have two applications deployed in a JBoss container (same unix box). If I receive a request from app1, I need to send a corresponding request for app2. An Example: If app1 requests: http://example.com/context?param1=123, then I need to extract http://example.com/, so that I can send the request for the seco…
How can I draw with Graphics2D on the JGraphX graph?
How can I can draw with Graphics2D on the JGraphX graph? I tried something like this: Answer First, graph.refresh(); will erase the dranw line since it will re-render all the graph on the graphics of the component. Secondly, don’t forget to call the draw function in the ADT Thread Other than that, it sh…
Saving byte array using SharedPreferences
So I have a byte [] array which I have created in my android app. I want to use SharedPreferences from android to store it and retrieve it back again when I start my app. How can I do that ? Answer You could try to save it has a String: Storing the array: Retrieving the array:
Hibernate SaveOrUpdate – multiple workthreads
While I have been able to find information on how Hibernate’s transaction work, so the database doesn’t corrupted, it has been harder to understand how Hibernate treats an object which is shared between threads, and each thread tries to save it to the database. This is my theoretical question: 1) …