I want to run some Runnable in a background thread. I want to use Handler because it’s convenient for delays. What I mean is Where runnable should be run in background Thread. Is it possible to create such Handler? Is there a “background” Looper somewhere or how can I create it? P.S. I know …
Calculation of Diffie–Hellman public key slow
hi i’m trying to implement a Diffie–Hellman key exchange but the calculation for 100000 already takes several seconds. I won’t know hoch much time it would take for a 256bit number. Is it so slow because of the implementation of BigInteger or am i off the track? Answer the problem is that g.pow(se…
Doesn’t the JVM release all the resources that are not explicitly closed by the programmer on program exit
I’ve always heard that resources in java must be closed after use or these resources will get exhausted. Is it really a matter of concern for small programs that use very few resources(like 1 or 2 file readers/ buffered readers and all)? Doesn’t the JVM keep track of the resources being used by a …
How to send a button instead of a link in an HTML email?
My app sends an email from my java code. I also want to send a link within a button which will say “Activate your account”. Here is what I have: The following line works as a link right now, I just want to put this link in a button and send that button to user’s email. Is there any solution
Connection refused on remote IP, but accepted on local IP
As the title says, I have my server running on a local machine, I tested and debugged it and it worked perfectly (server is written in java as well). But when I tried to test it with my remote IP (instead of 192.168.0.113 I used 146.255.x.x), and the server didn’t receive anything, while the client has …
How to get the weekday of a Date?
I want to get the day of week from the Java Date object when I have an array of Date in String with me. Does anyone know the answer to this? Answer You can get the day-integer like that: If you need the output to be “Tue” rather than 3, instead of going through a calendar, just reformat the string…
Check and extract a number from a String in Java
I’m writing a program where the user enters a String in the following format: I need to check that there is a number in the String and then extract just the number. If i use .contains(“\d+”) or .contains(“[0-9]+”), the program can’t find a number in the String, no matter wh…
Java fileOutputStream
I have been looking around but could not find what I need. I am writing a simple code to save some strings into a .txt file. I am using: When I do this the .txt is succesfully created and save the info I need to save, BUT it save all in 1 single huge line. How I can save it
Shall we mark private methods as “static” as more as possible?
There are some private methods in a class, and they don’t depend on any instance variables. They accept some arguments, and return a value, no side effects. For example: You see there is a capWord method in this class, which is private but not static. It’s safe to mark it as static, but is there g…
JVM error when try to allocate more than 128M Xms, without specifying Xmx
I am seeing an JVM issue when I am running my application and I simply to below java commands: Even Xms is set to 128M does not work: Works only when Xms is set to 64M or less: The interesting thing is if I specify Xmx, then it works well. More interesting thing is: All above commands run well on