Sun, 24 June 2012
As developers, we have to deal with Exceptions every day (or at least every other day). In this episode we dive a bit on exception (and exception handling), plus we talk about certain behaviors that are not so well-understood (try returning from a finally block, or why exception stack traces sometimes misteriously disappears). A good review for those who already know, and a great primer for those diving into Exceptions, this episode is sure to show some surprises! (~)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 constructhttp://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html Exception Definitionhttp://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) 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 |
Wed, 6 June 2012
Episode 25. Reflection and vampire classes, and compiling Java from within Java. We have heard the word "Reflection" thrown around, what does it mean? it is a new Twilight series? is it about Vampires? In all, we shed sunlight into what reflection is (and more importantly why in the world you want to use it). And also cover a technique to compile and load programs within your program. Javascript guys had access to this by doing eval("your program here"), and while Java doesn't have an eval function, there are ways of achieving similar results (and very specific reasons to do this crazy technique. Mostly performance)
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 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) 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 |
Sun, 6 May 2012
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 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) 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 |
Sun, 22 April 2012
Episode 23. Who is interrupting me while I sleep in the waiting room? (A talk on wait/notify and interruptedExceptions)
It always starts when you do your first Thread.sleep(). Why do I have to check for InterruptedException? is it serious? why do I have to catch it? We start with answering these questions and step down the rabbit hole to discover the inner workings of Wait/Notify (and what the IllegalMonitorStateException really means). If you ever have to work with more than one thread (who doesn't nowadays?) take a listen! You'll be notify()ed of your success! Twitter, twitter, twitter, twitter!(https://twitter.com/#!/fguime) Wait/Notify http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#wait() 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) 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 |
Sat, 7 April 2012
Garbage collections are like the engine of a car, we know it works, we know that it powers the car, but not much else, but once it breaks down, we usually don't have a too much of a clue on how to fix it. In this episode we talk about how garbage collections happen, the things it looks for, and more importantly, how it changes your code (there are certain things that you can do to make your code garbage collector friendly). Having this knowledge will help you in the long road on troubleshooting any garbage collection issues (including tuning!), so take a listen to the garbage man! There is a new band in town! Lambda Expression. Listen to me, and my one-man band in facebook (www.facebook.com/lambdaexpression). And LIKE! (doesn't cost anything!) 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 Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329) The holy grail of JVM Tuning http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |
Thu, 22 March 2012
So you're programming along when suddenly support calls and says that the application just "disappeared", or, the server process is not there anymore, both of them leaving you with a hprof.pid file. You have just witnessed the murder of a Java Virtual Machine, and now is your turn to figure out what happen, and what can we do to prevent such senseless crashes. We cover the main reasons for crashes (most likely not your fault), and best of all, ways around it! So put on your detective hat and let's solve the mysteries surrounding JVM Crashes once and for all! 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 Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329) Most JVM Options http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html Java 7 recipes book made it to the Java Magazine!http://www.oraclejavamagazine-digital.com/javamagazine/20120304?pg=3#pg10 Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |
Thu, 8 March 2012
Episode 20. Excuse me, do you know what Date it is, or what Date is? A discussion about Date and Calendar in Java
In this podcast we turn and talk of that embarassing uncle that every API has (java.util.date), you know, the one that you have to live with because is family, but don't really like that much? We dive into what to avoid when using Date (and Calendar), and the most common pitfalls that we have falled for (1000*60*60*24 anyone?). In all, if you have used date extensively you probably already migrated to JodaTime, but if you are a casual user, then take a listen, just to make sure you are not bitten by the Date traps! Vote for us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329) http://joda-time.sourceforge.net/ (Joda Time) Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |
Thu, 1 March 2012
We finish our discussion on the ObjectOutputStream by covering the SerialVersionUID, and then move onto ObjectOutputStream's citadine cousin, XMLEncoder and Decoder (and why would you go and hang out with it). We also make a quick introduction to "The Bean" (Java Beans that is), and discover there isn't too much to it. If you are persisting and/or transmitting, listen to the shocking conclusion (gasp!) of serialization! Rate us in iTunes (http://itunes.apple.com/us/podcast/java-pub-house/id467641329) http://java.sun.com/developer/technicalArticles/Programming/serialization/ (Serialization/Deserialization) Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |
Thu, 16 February 2012
We all have the need to serialize/deserialize objects (either through the "wire" or to file). In this podcast we go and analyze what exactly happens when we create an ObjectOutputStream and write to it, and more importantly what pitfalls are there to avoid (Out ot memory errors, stale object updates, Not Serializable Exceptions, and toenail fungus!). If you ever considered using ObjectOutput/InputStream, or are actively using in your current projects, take a listen! https://github.com/eishay/jvm-serializers/wiki/ (Serialization performance comparison for Java, pick one!) Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |
Thu, 9 February 2012
Every developer at one point in time runs into the question, what is beautiful code? Is it code that is expressed concisely? is it code that does a lot in a few lines of code. Well, while we're not the DeveloperPeople's magazine at least there are fundamental concepts that describe code beauty. And while there isn't a consensus (what is beauty anyways), at least there is a baseline for code that is not ugly (hint. It's maintainable). At least a conversation starter, this podcast covers the very minimum that code has to be to not be ugly! Questions, feedback or comments! comments@javapubhouse.com Subscribe to our podcast! (http://javapubhouse.libsyn.com/rss) |