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…
Tag: java
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…
Error in Java Import statement “The import javax.validation.constraints.NotNull cannot be resolved”
After developing Spring roo project, I found following errors in class: I am using STS 3.1.0.RELEASE How can this be rectified? Answer The jar containing this class must be added to the build path of your project: http://mvnrepository.com/artifact/javax.validation/validation-api/1.0.0.GA
SQLDeveloper runs query but getting a “ORA-00979: Not a Group By expression” from hibernate
I have data that looks something like this: And a query that works fine in Oracle SQL Developer (It returns data averaged over 15 second periods): but when I plug it into my java code, I get an error: The actual query string I use in the Jave looks more like this: and the parameters are set by calling: Anyone
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…
Displaying AM and PM in lower case after date formatting
After formatting a datetime, the time displays AM or PM in upper case, but I want it in lower case like am or pm. This is my code: Answer Unfortunately the standard formatting methods don’t let you do that. Nor does Joda. I think you’re going to have to process your formatted date by a simple post…