I have a software that allow to write add-on in javascript files (.js) that allow to use Java function (I don’t know if this is common, I never saw java call in javascript file before) I need to download a binary file from a webserver and write it to the hard drive. I tried the following code: The resul…
Tag: java
Singleton Design Pattern: Pitfalls [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago. Improve this question Not sure of downfalls using strict global state implementation. When is si…
Java double initialization
In what way are these statements different? double dummy = 0; double dummy = 0.0; double dummy = 0.0d; double dummy = 0.0D; Answer Having tried a simple program (using both 0 and 100, to show the difference between “special” constants and general ones) the Sun Java 6 compiler will output the same …
How do I make HttpURLConnection use a proxy?
If I do this… it prints The problem is, I am behind a proxy. Where does the JVM get its proxy information from on Windows? How do I set this up? All my other apps seem perfectly happy with my proxy. Answer Since java 1.5 you can also pass a java.net.Proxy instance to the openConnection(proxy) method: If…
How to use String as Velocity Template?
What is the best way to create Velocity Template from a String? I’m aware of Velocity.evaluate method where I can pass String or StringReader, but I’m curios is there a better way to do it (e.g. any advantage of creating an instance of Template). Answer There is some overhead parsing template. You…
tomcat session replication – not serialized exception
I am currently working on one messy web application. In this application, there is a class that holds all the data sources. And whenever the need to connect to a specific data source, the method in the instance of the class is called with a parameter to select the data source.And class is like follows And on …
Java http call returning response code: 501
I am having an issue with this error: See this code: Answer A 501 response means “not implemented”, and is usually taken to mean that the server didn’t understand the HTTP method that you used (e.g. get, post, etc). I don’t recognise ClientHttpRequest , but you have a line that says an…
Simulate touch command with Java
I want to change modification timestamp of a binary file. What is the best way for doing this? Would opening and closing the file be a good option? (I require a solution where the modification of the timestamp will be changed on every platform and JVM). Answer The File class has a setLastModified method. That…
What are all the possible values for SQLException.getSQLState?
SQLException.getSQLState retrieves the SQLState for the SQLException object. What are all the possible values that can be returned by this method? Can I use the value to identify specific errors that occurred in the database (i.e. can this value tell me if it was a PK violation, or a unique constraint, or col…
How do I get my Maven Integration tests to run
I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java and Integration.java for unit tests and integration tests respectively. When I execute: mvn test all of the JUnit tests *Test.java within the child modules are executed. When I execute mvn test -Dt…