Skip to content

Tag: java

Using BufferedReader to read Text File

I’m having problems with using the BufferedReader I want to print the 6 lines of a text file: Now from what I can gather every time I call the readLine() method it automatically advances to the next line. So I can’t use the condition br.readLine() != null since it’ll already advance it one l…

How do I print a double value without scientific notation using Java?

I want to print a double value in Java without exponential form. It shows this E notation: 1.2345678E7. I want it to print it like this: 12345678 What is the best way to prevent this? Answer You could use printf() with %f: This will print dexp: 12345678.000000. If you don’t want the fractional part, use…

Thread Safe singleton class

I wrote a below Singleton class. I am not sure whether this is thread safe singleton class or not? Can anyone help me with this? Any thoughts on my above Singleton class will be of great help. Updated Code:- I am trying to incorporate Bohemian suggestion in my code. Here is the updated code, I got- Can anyone…

How to paginate a JPA Query

I have a submission table with columns like ID, Name, Code among other properties. My requirement is to search for records based on the mentioned properties and return a paginated set. This is the pseudocode for what I am looking for: There seem to be many options like CriteriaBuilder, NamedQuery, etc. Which …

How to check if Handler has an active task?

If I have a Handler handler = new Handler() and run a delayed task for it handler.postDelayed(xxx, xxx), is that possible to check has the postDelayed() was called or not? Answer is that possible to check has the postDelayed() was called or not? One quick fix, in method assign some boolean variable to true an…

Java Bouncy Castle OCSP Url

I am using bouncy castle 1.48 to verify certificate validation with OCSP. It works good. But I’m using Ocsp Url as static variable and I want to read it from certificate. Url is written in certificate as Authority Info Access I got org.bouncycastle.asn1.x509.AuthorityInformationAccess object from certif…