Yogesh's Blog

Sharing me with blog…
Archive for the ‘Java’ Category

April 14th, 2016

RegEx to find tags

No Comments, Java, Javascript, by Yogesh.

Starting of Tag: JavaScript: /<([A-Z,a-z,0-9])\w+>/g Java: <([A-Z,a-z,0-9])\\w+> Closing of Tag: JavaScript: /<\/([A-Z,a-z,0-9])\w+>/g Java: </([A-Z,a-z,0-9])\\w+>

October 25th, 2010

XMLGregorianCalendar to Date

No Comments, Java, by Yogesh.

Way to get Date object from XMLGregorianCalender object. Suppose XMLGregorianCalender object is xmlGregCal To get date object, write following statement: xmlGregCal.toGregorianCalendar().getTime()

October 25th, 2010

16 characters random code

No Comments, Java, by Yogesh.

In java, there is a vary simple way to generate 16 characters random code. All you need to do is : write this statement: Long.toHexString(Double.doubleToLongBits(Math.random())) This will return you 16 char random code.

Many time in java development, we need to find out the java class availability in jar file. If there is one jar file then looking class in that is easy, but suppose there are lots of libraries (lots of jars) then to search in those libraries, really really tough task. Here is the solution for it, using JarScan… Steps to search: Put JarScan jar file in some location (Example: D:\Utils\)¬† (download JarScan from here) Open command prompt Use following command Syntex: java -jar <location-pointing-to-downloaded-jar-file> -dir <location-to-search-class-in> -class <classname-only-name-or-with-package> Example 1: java -jar D:\Utils\jarscan.jar -dir D:\myLibraries\ -class MyClassToSearch Example 2: java -jar D:\Utils\jarscan.jar -dir D:\myLibraries\ -class com.mycompany.mypackage.MyClassToSearch You will get list of library files who will be scanned and also finally detail of libraries where specified class is found. Details uses and syntex: Command: java -jar jarscan.jar [-help | /?] [-dir directory name] [-zip] [-showProgress] <-files | -class | -package> <search string¬† 1> [search string 2] [search string n] Command Help: Command option Description -help or /? Displays this message. -dir The directory to start searching from default is “.” -zip Also search Zip files -showProgress Show a running count of files read in -files or -class Search for a file or Java class contained in some library. i.e. HttpServlet -package Search for a Java package contained in some library. i.e. javax.servlet.http search string The file or package to search for. i.e. see examples above