It’s possible to add pure Java module to existing Android project. But is it possible to create pure Java project with no Android dependencies? Answer Yes, it is possible. You have to manually create all necessary files. Here are steps for Gradle based project: Remove include ‘:app’ form set…
Publish/Unpublish Adobe AEM page from Java
We have background process that automatically creates AEM pages as well as deletes old AEM pages. For pages to appear/disappear on the published site, they need to be activated (Published) / deactivated (Unpublished). However, after searching from Google, I am not able to find AEM Java API that can publish/un…
Spring JPA no transaction is in progress
I am new to Spring and JPA, wasted 5 days and no result with searching internet. I want to save object to SQL SERVER, connection is correct but when I write .flush() I get the exception nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress This is my jpaContext.xml …
How to Count Number of Instances of a Class
Can anyone tell me how to count the number of instances of a class? Here’s my code The class variable is to be used to keep count of the number of instances of the Bicycle class created and the tester class creates a number of instances of the Bicycle class and demonstrates the workings of the Bicycle c…
How to use Lambda expression to make Java method calls less verbose in Kotlin?
Can the below function be less verbose with a Lambda expression? How can I trim it down? It is calling the FilenameFilter.accept() Java method. Answer I’m not certain about the Kotlin syntax, but you can certainly trim it down by returning the boolean expression directly, eliminating the if: I believe t…
Encrypt password fields in mongodb
I have following code, it insert the userName and password into database but the password is stored in plain text format. I mean when I’ll look into the db I can see the inserted password. I want to store password in encrypted format How can I achieve this? Answer According to the conversation in the co…
Tomcat 8 embedded – ERROR {org.apache.catalina.core.ContainerBase} – A child container failed during start
I’m using tomcat embedded and when I try to star the server following error get occurred. I’m using tomcat 8.0.20 and jdk8 Why I’m getting this? And what can I do to fix thi? Answer I was able to fix this issue by disabling the default TomcatURLStreamHandlerFactory before starting the sever …
How to check does interface with generic fit to class
I have some interface with generic type interface DummyInterface<T> and i have class to which i have to set interface Imagine the situation where i store DummyClass with different generics in ArrayList. When i get class from list i don’t know the generic of class, and i want to check if interface …
java Cannot delete file, being used by another process
I have this code and when I execute it it says java.nio.file.FileSystemException The process cannot access the file because it is being used by another process (in sun.nio.fs.WindowsException) In the sameSha1() I have this: I want to delete the file ‘SHA1.txt’. How can I do this? Answer I guess wi…
How do I disable Java assertions for a junit test in the code
How do I disable java assertions (not junit assert) for a junit test in the code Ive written a junit test but when I run it it doesnt fail as expected because assertions are enabled, whereas they are not in production. Is there a way to disable assertions just in the code so that it work as expected when run