I am trying to embed java virtual machine in my program but I libjvm.dylib lacks JNI_GetCreatedJavaVMs. The program works fine both on Windows and on Linux platforms. However, when running on Mac OS I’m getting: exception. I use libjvm.dylib located in /System/Library/Frameworks/JavaVM.framework/Version…
Tag: java
How to get the JAR file for sun.misc.BASE64Encoder class?
I have some code in my Activity class that uses sun.misc.BASE64Encoder class. But it is showing java.lang.NoClassDefFoundError : sun.misc.BASE64Encoder. Do I need the jar? Where can I download it from? Answer Don’t use sun.* classes. For Base64 in Android, use its native class or add a library to your p…
Get Android Device Name
How to get Android device name? I am using HTC desire. When I connected it via HTC Sync the software is displaying the Name ‘HTC Smith’ . I would like to fetch this name via code. How is this possible in Android? Answer In order to get Android device name you have to add only a single line of code…
Converting Integer to String with comma for thousands
I want to convert an Integer 35634646 to have the thousand “,” so it should be 35,634,646. What would be the quickest way to doing that? Answer
How to change menu item text dynamically in Android
I’m trying to change the title of a menu item from outside of the onOptionsItemSelected(MenuItem item) method. I already do the following; however I’d like to be able to modify the title of a particular menu item outside of this method. Answer As JxDarkAngel suggested, calling this from anywhere i…
When and how to use hibernate second level cache?
I have trouble understanding when hibernate hits the second level cache and when does it invalidate the cache. This is what I currently understand: Second level cache stores entities between …
How To Check If A Method Exists At Runtime In Java?
How would one go about checking to see if a method exists for a class in Java? Would a try {…} catch {…} statement be good practice? Answer I assume that you want to check the method doSomething(String, Object). You might try this: This will not work, since the method will be resolved at compile-t…
Thread Safe Singletons in Java
The wikipedia article on Singletons mentions a few thread safe ways to implement the structure in Java. For my questions, let’s consider Singletons that have lengthy initialization procedures and are acccessed by many threads at once. Firstly, is this unmentioned method thread-safe, and if so, what does…
Java Regex: matches(pattern, value) returns true but group() fails to match
I have an odd problem with a regular expression in Java. I tested my Regex and my value here and it works. It says there are 3 groups (correct) the match for the first group (not group zero!) is SSS, …
How do I figure out and change which version of Java Maven is using to execute?
When running our Maven build, a member of my team gets a NoSuchMethodError in one of the dependant plug-ins when executing. However, when we run java -version from her command line, it indicates Java 1.6.0_26. The error obviously seems to be screaming that Maven is using Java 5. How do I figure out and change…