I’m developing a system that often use the system time because the Delayed interface. What is fastet way to get the time from system? Currently I’m using Calendar.getInstance().getTimeInMillis() every time I need to get the time, but I don’t know if there is a faster way. Answer System.curre…
Head First Design Patterns – Combined Pattern
I’m reading the chapter 12 on the Combined Pattern in Head First Design Patterns. On page 541,the sample DJView,it cant’t run correctly in my computer.when i press the ‘start’, the program only sounds once rather than circularly . i’m not sure whether because of the environment o…
Conversion from 12 hours time to 24 hours time in java
In my app, I have a requirement to format 12 hours time to 24 hours time. What is the method I have to use? For example, time like 10:30 AM. How can I convert to 24 hours time in java? Answer Try this: which produces: See: http://download.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html
volatile with release/acquire semantics
Since Java 5, the volatile keyword has release/acquire semantics to make side-effects visible to other threads (including assignments to non-volatile variables!). Take these two variables, for example: Note that i is a regular, non-volatile variable. Imagine thread 1 executing the following statements: At som…
White spaces are required between publicId and systemId
I am trying to make a ajax call to other domain locally from my computer by writing some proxy code in jsp. And this is my jQuery AJAX code that is calling proxy.jsp page. And my JSP file is:- And When I check the response, I am getting this error for the XML file it is parsing: And the XMl
Best way to play a radio stream ( shoutcast ) in Java?
I want to code an audio player in Java. java.JavaFX has a very nice support for mp3 playing but I want in my player also the possibility to listen to radio. The problem is I have searched for some time and I didn’t find something that works like I want: MP3SPI – this is nice but just wont play som…
java.net.UnknownHostException: Invalid hostname for server: local
What are the steps I should take to solve the error: I added the new virtual host name at Android emulator but the result returns to When I type my virtualhost URL on my PC, it works on display. Then again, when I ran on Emulator and check on Logcat, I couldn’t be able to read or check the HTTP
Java Security: Illegal key size or default parameters?
I had asked a question about this earlier, but it didn’t get answered right and led nowhere. So I’ve clarified few details on the problem and I would really like to hear your ideas on how could I fix this or what should I try. I have Java 1.6.0.12 installed on my Linux server and the code below ru…
REST API for Java?
I am preparing an application which is console based and the outcome of the application is a RDF/XML file which contains data of all my connections from LinkedIn. Now the problem is that my entire application is console based and I need to have a REST API so as to incorporate with my application. I am not awa…
Java CharAt() and deleteCharAt() performance
I’ve been wondering about the implementation of charAt function for String/StringBuilder/StringBuffer in java what is the complexity of that ? also what about the deleteCharAt() in StringBuffer/StringBuilder ? Answer For String, StringBuffer, and StringBuilder, charAt() is a constant-time operation. For…