Skip to content

Tag: java

Good way to get *any* value from a Java Set?

Given a simple Set<T>, what is a good way (fast, few lines of code) to get any value from the Set? With a List, it’s easy: But, with a Set, there is no .get(…) method because Sets are not ordered. Answer A Set<T> is an Iterable<T>, so iterating to the first element works: Guava h…

Generate x509certificate certpath in JAVA

I successfully make X.509 certificate from certificate request. However, I need to insert CERT Path informatin in the X.509 certificate. I know that I have to use CertPathBuilder method but I don’t know how to use it. could you give me an code example that suitable for the following code? Answer The bel…

Delete all files with an extension using Java

I’m (relatively) new to Java and I’m trying to implement a .jar that runs a list of commands that in Windows XP’s command prompt it would be: My (failed) attempt: I screwed somewhere around that “get(i)”, but I think I’m pretty close to my goal now. I ask for your help and …

implementing a lazy Supplier in java

What is the right paradigm or utility class (can’t seem to find a preexisting class) to implement a lazy supplier in Java? I want to have something that handles the compute-once/cache-later behavior and allows me to specify the computation behavior independently. I know this probably has an error but it…

UsageMemory threashold in JConsole

I am looking into how to use JConsole to detect memory leaks. I see that in Memory Pool in my MBeans I can define UsageThreashold for my Tenured Generation. So if my application exceeds this threashold the heap memory becomes red in the Memory tab. Question: How does this help? I mean how am I supposed to use…

Get Username from Amazon Access Key in Java

Is there a way to get the User Name attached to the Access Key for the credentials you’re using to access AWS via Java? I would like to be able to get the User Name that’s defined in the IAM Users section so that I can setup user-specific buckets/folders and then dynamically point the script to th…

How to Check if A Git Clone Has Been Done Already with JGit

I learning git and using JGit to access Git repos from java code. Git by default does not allow to clone to a non-empty directory. How do we figure out that a git clone has already been done for a particular git repo in the local machine so that we can only do a Git pull subsequently? Currently I’m usin…