Can I use the same java class in phonegap for Android and iOS ?
e.g. This example will be work on iOS too ?
You cannot use Java on iOS at all.
You'd have to create Objective-C code to do the same thing as your Java class, and if they provide the same interface to Phonegap, at least the Javascript code can be shared.
Now java can be used on iOS, please check this link. Hope the samples will answer your question.