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…
Size of byte array gets double when it retrieve from Postgres database
I am using JSF2.0, jetty server and Postgres database. I want to store mp3 file in database in byte array formet. I upload the byte array of mp3 file. But when I retrive same byte array from database I get byte array of double size and my because of that my mp3 file is not working as well. Output: Upload
How to parse a String variable into any data type in Java?
I want to build a method that can convert a String value to a given Field object data type through Java Reflection. Here is my code: String value = …; Class clazz = …
How to match any combination of letters using regex?
How can I match letters a,b,c once in any combination and varying length like this: The expression should match these cases: but should not match these ones: Answer Use regex pattern You can use this pattern with any set and size, just replace [abc] with desired set… Example: (above output is from myreg…
Why do I need Transaction in Hibernate for read-only operations?
Why do I need Transaction in Hibernate for read-only operations? Does the following transaction put a lock in the DB? Example code to fetch from DB: Can I use session.close() instead of tx.commit()? Answer Transactions for reading might look indeed strange and often people don’t mark methods for transac…
Java Heap and Pass By Value
I am a little confused as to how my Java program is allocating memory. Below is a typical situation in my program. I have an object created on the Heap inside of a class which I pass to other functions inside of other classes. My question(s) are about how the memory is used. When A’s list gets passed to…
How to tell if one of the heap-generations is full?
We are experiencing some problems in our production environment, where we get an InvalidPropertyException from one of the compiled jsps (which one differs from time to time) after a bit of time. I have a suspicion that this is caused by something “disappearing” from the heap. Further, I suspect th…
JFileChooser change default directory in Windows
I want to change the default directory of my JFileChooser to “My Music” on Windows. This directory is C:UsersFreMusic on my account because my username is Fre The default is set on C:UsersFreDocuments (depends on OS i think). How can I change this? Answer You can use the API method setCurrentDirec…
Needing to double click EditText for click listener to respond
I have a section of code where I want to change the text showing in a textView when the user selects an EditText box. The problem I am having is that the textView only changes when I double click the EditText box, one click and there is no change to the textView. Is there another click listener that I should