Sunday, June 24, 2012
Episode 26. I take Exception to that statement! A quick overview of Exception quirkiness
(~)P (~)P (~)P (~)P (~)P (Beer) (~)P (~)P (~)P (~)P
It's SUMMER! If you like what you hear, DEFINITIVELY, treat me a beer ! :) (It's the Java pub house after all :) https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4
(~)P (~)P (~)P (~)P (~)P (Beer) (~)P (~)P (~)P (~)P
Tweet, Tweet! (https://twitter.com/#!/fguime) Try-with-resources construct http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
Exception Definition http://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html
Checked vs Unchecked Exceptions Debatehttp://www.ibm.com/developerworks/java/library/j-jtp05254/index.html
More Exception Debates from C vs C++, still a useful read. http://www.250bpm.com/blog:4
Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Questions, feedback or comments! comments@javapubhouse.com
Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss)
ITunes link (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Java 7 Recipes book! (http://www.amazon.com/gp/product/1430240563/ref=as_li_ss_il?ie=UTF8&tag=meq-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1430240563)
Hey! if you like what you hear, treat me a beer! (It's the Java pub house after all :) https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4
Wednesday, June 6, 2012
Episode 25. Reflection and vampire classes, and compiling Java from within Java.
It's SUMMER! If you like what you hear, DEFINITIVELY, treat me a beer ! :) (It's the Java pub house after all :) https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4
Nimbus code to get the dang CacheMode (considered a private variable)
public class ButtonPainter extends AbstractRegionPainter {
public ButtonPainter() {
Class<?> c = null;
PaintContext ctx = new PaintContext(new Insets(0,0,0,0), new Dimension(100,100), false, null, Double.POSITIVE_INFINITY, 2.0 );
try {
c = Class.forName("javax.swing.plaf.nimbus.AbstractRegionPainter$PaintContext$CacheMode");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (c != null) {
Object cacheMode = c.getEnumConstants()[2]; // NINE_SQUARE_SCALE
for (Field field : ctx.getClass().getDeclaredFields()) {
if (c.getName().equals(field.getType().getName())) { // if Field is the CacheMode
try {
// the following lines would not be necessary for example if
// AbstractRegionPainter.cacheMode were protected or public.
field.setAccessible(true); // make it accessible so that we can set it
field.set(ctx, cacheMode); // set the cachemode
// this is equivalent as sayin "ctx.cacheMode = CacheMode.NINE_SQUARE_SCALE" if it were public/protected
break;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
@Override
protected PaintContext getPaintContext() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
Code to get instance from a source file
public static Object getInstanceForSource(String className, String sourceForRule) {
String filename = "tmp/" + className + ".java";
File file = new File(filename);
writeFile(filename, sourceForRule);
String classPath = System.getProperty("java.class.path");
String[] args = new String[]{
"-classpath", classPath,
filename
};
StringWriter compilerOutput = new StringWriter();
int status = com.sun.tools.javac.Main.compile(args,new PrintWriter(compilerOutput));
additionalInfo.value = compilerOutput.toString();
switch (status) {
case 0: // OK
// Make the class file temporary as well
File classFile = new File("./tmp/");
try {
// Try to access the class and run its main method
URLClassLoader loader = new URLClassLoader(new URL[] {classFile.toURI().toURL()});
Class clazz = loader.loadClass(className);
return clazz.newInstance();
} catch (Exception ex) {
additionalInfo.value = "Exception in main: " + Utilities.exceptionToString(ex)+"\n"+additionalInfo.value;
}
break;
case 1:
System.out.println ("Status: Error" +"\n"+additionalInfo.value);
break;
case 2:
System.out.println ("Status: CMDERR" +"\n"+additionalInfo.value);
break;
case 3:
System.out.println ("Status: SYSERR" +"\n"+additionalInfo.value);
break;
case 4:
System.out.println ("Status: ABNORMAL" +"\n"+additionalInfo.value);
break;
default:
System.out.println ("Status: UNKNOWN" +"\n"+additionalInfo.value);
break;
}
return null;
}
public static void writeFile(String fileName, String content) {
Writer writer;
File file = new File(fileName);
try {
writer = new BufferedWriter(new FileWriter(file));
writer.write(content);
writer.close();
} catch (IOException e) {
System.out.println ("I/O exception "+e);
}
}
Tweet, Tweet! (https://twitter.com/#!/fguime)
Reflection 'trail' http://docs.oracle.com/javase/tutorial/reflect/index.html
Create dynamic applications with javax.tools http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
URLClassLoaders (loads .class files generated http://docs.oracle.com/javase/6/docs/api/java/net/URLClassLoader.html
Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Questions, feedback or comments! comments@javapubhouse.com
Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss)
ITunes link (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Java 7 Recipes book! (http://www.amazon.com/gp/product/1430240563/ref=as_li_ss_il?ie=UTF8&tag=meq-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1430240563)
Hey! if you like what you hear, treat me a beer! (It's the Java pub house after all :) https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4
Sunday, May 6, 2012
Episode 24. Usability for Engineers. A simple way to achieve usability for the hardcore engineer
Designers will come to you, and say "Hm, I think your program is not as user-friendly". And sometimes, when you ask them to elaborate, they seem to follow a hidden and cryptic ritual. They are right, yet, is hard to see how did they come up with those usability suggestion. Alas, behind every usability magician, there is a magic trick! and on this podcast we reveal in plain sight what makes interfaces usable (and quote a lot from Alan Cooper's book). Once you see the trick, you would never be daunted on spotting usability yourself, and making things much more usable before passing them on. Usability magic for all of us!
If you like what you hear, treat me a beer!https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4
Twitter, twitter, twitter, twitter! (https://twitter.com/#!/fguime)
The immates are running the asylum (Alan Cooper) http://www.amazon.com/The-Inmates-Are-Running-Asylum/dp/0672316498
Don't make me think http://www.amazon.com/Dont-Make-Me-Think-Usability/dp/0321344758/ref=sr_1_1?s=books&ie=UTF8&qid=1336346454&sr=1-1
Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Questions, feedback or comments! comments@javapubhouse.com
Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss)
ITunes link (http://itunes.apple.com/us/podcast/java-pub-house/id467641329)
Java 7 Recipes book! (http://www.amazon.com/gp/product/1430240563/ref=as_li_ss_il?ie=UTF8&tag=meq-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1430240563)
Hey! if you like what you hear, treat me a beer! (It's the Java pub house after all :) https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8V2ZWV93UMW4