Page 1 of 1  1 

Archive for the 'Java' Category

Java: How to Generate Encrypted String without Any Special Character

Many times, when we generate an encrypted string, the resulted output string is filled with all sorts of special characters. While this encrypted string is usually fine and safe for database storage, but it’s a big problem in some instances - such as XML file, or when it’s needed to be transmitted as HTTP GET request.

In this case, we can apply Base64 on the encrypted string, convert it to an US-ASCII character string. Following is an example of code snippet. Please note that, the Encryption class is just a dummy example to simplify this example. You may use the Java Cryptography Architecture (JCA) Cipher class to achieve reversible encryption.

String encryptedString = Encryption.encrypt("StringToBeEncrypted", "key");
String base64Encoded = Base64.encode(encryptedString.getBytes());
System.out.println("Encoded: " + base64Encoded);

byte[] base64Decoded = Base64.decode(base64Encoded);
String descryptedString = Encryption.decrypt(new String(base64Decoded), "key");
System.out.println("Decrypted: " + descryptedString);

In the above example, I’m using com.sun.org.apache.xerces.internal.impl.dv.util.Base64 (found in rt.jar of Java5 and above) to apply Base64 encoding. You may also use org.apache.commons.codec.binary.Base64 found in Apache Commons Codec to achieve the same result.

Java VisualVM is Now Bundled with JDK6 Update 7

Java SE 6 has already been released for quite some time (ya… now already update 7 looo). Even though many monitoring and diagnostics features are enhanced and introduced in Java 6, but it has been lacking an out-of-the-box bundling of a convincing visual Java application monitoring or profiling tool, until the most recent JDK6 Update 7.

In this latest update of JDK 6 (version 6u7), the Java VisualVM - a visual tool integrating several lightweight profiling capabilities for troubleshooting Java applications, is bundled. After installation of JDK 6u7, you can find jvisualvm.exe in the /bin folder. By the way, VisualVM is similar to JConsole to certain extends, but a lot better than JConsole.

You might have heard of JProfiler, or even have some first-hand experiences with it. No doubt it’s an comprehensive Java application profiler, but it comes with a price tag :) Java VisualVM is FREE, free like a free beer!

How to take advantage with Java VisualVM?

Java VisualVM

Firstly, in order to benefit from the full profiling advantage of Java VisualVM, you must run your Java application on JVM 6. No worry, you can also compile your codes with Java 5 compatibility, and run the application on JVM 6, so that it is profilable by VisualVM.

For all applications running on JVM 6, you will be able to create CPU and memory profiler, take thread dumps, browse heap dumps, and more. For applications running on JVM 5, the most that you can monitor with VisualVM, is only the threads. Click here for more details on Java VisualVM features. Continue reading ‘Java VisualVM is Now Bundled with JDK6 Update 7′


Subscribe

Subscribe to my RSS Feeds

Subscribe by Email

Enter your email address:

Delivered by FeedBurner

My Tweets

Powered by Twitter Tools.