Writing by shivdev on Monday, 5 of October , 2009 at 4:14 pm
Here’s a method that shows how to get all the static fields in a Java class and return them.
public static List printFields(Class c) throws ClassNotFoundException, IllegalAccessException {
List fields = new ArrayList();
java.lang.reflect.Field[] f = c.getDeclaredFields();
for (java.lang.reflect.Field field : f) {
int modifier = field.getModifiers();
if (java.lang.reflect.Modifier.isStatic(modifier)){
String val = (String) field.get( null );
System.out.print(field.getName() + ": " + val.toString() + ", ");
fields.add(val);
}
}
return fields;
}
Writing by shivdev on Friday, 10 of July , 2009 at 11:37 am
One of the several eclipse errors.
Could not open the editor: Resource is out of sync with the file system
Easy fix (that worked for me) is to select the Project and hit F5 or Right Click and click Refresh.
Simply refreshing the particular resource did not work.
Usually happens when some files are edited outside of eclipse.
Writing by shivdev on Thursday, 21 of May , 2009 at 6:05 pm
Titan Watches have been doing a version of the Wolfgang Amadeus Mozart – Symphony No. 25 in G minor and I really like this one (some claim this is by A R Rahman). This one has been stuck in my head.
Writing by shivdev on Tuesday, 17 of February , 2009 at 6:12 pm
I got an UnsatisfiedLinkError and wanted to find out whether our JDK upgrade had caused it and did some searching and found that javap -verbose lets you find out the version of a compiled class. So get the class (could be in a JAR file) and then follow this example where I find the version of MyCallback.class
C:>c:\jdk1.6.0_07\bin\javap -verbose MyCallback
Compiled from “MyCallback.java”
public class com.shivdev.MyCallback extends java.lang.Object implements com.shivdev.IFilter
SourceFile: “MyCallback.java” minor version: 0
major version: 49
Alternatively, you can use this java class to find out the version:
public class FindVersion {
private static int convert(byte upper, byte lower) {
int ret = upper << 8;
ret |= lower;
return ret;
}
public static void main(String[] args) throws Exception {
final String CLASS = "MyCallback.class";
ClassLoader loader = FindVersion.class.getClassLoader();
java.io.InputStream in = loader.getResourceAsStream(CLASS);
try {
byte[] buffer = new byte[8];
in.read(buffer);
int minor = convert(buffer[4], buffer[5]);
int major = convert(buffer[6], buffer[7]);
System.out.println(major + "." + minor);
} finally {
in.close();
}
}
}
Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.