h1

Not Being Evil (Google and Japan)

March 11, 2011

This post isn’t about Java, or food or an interesting quote. It’s about Google honoring its corporate motto of Don’t Be Evil. Not only are they not being evil, but they’ve done a good thing today.

Within hours of the recent earthquake in Japan they’ve set up a Google Crisis Response for the 2011 Japanese Earthquake and Tsunami.The page has alerts and warnings, bulletin boards, transportation information, power outages information, maps (with KML data links so it can be used in other applications) and a Person Finder where people can post information about people they are looking for or people they have information about.

That’s awesome! Kudos to the folks at Google!

Feel free to leave comments below.

Josh

h1

Definition: Programmer

January 3, 2011

“Programmer – def: an organic machine which converts caffeine into source code”
(on a shirt at CafePress)

h1

Smitty’s Sangria

October 15, 2010

I spent some time living in Spain and tried a bunch of sangrias. Once I returned stateside I missed the sangria on hot afternoons. After trying dozens of recipes I took elements of each and ended up with my own recipe that my friends and family seem to really like. Enjoy!

Ingredients

  • Approximately 1/2 gallon of red wine (Carlos Rossi Sangria base or another Spanish red)
  • 1  to 1 1/2 cup apricot brandy
  • 1/2 to 1 cup triple sec
  • 1 cup orange juice
  • 1 cup apricot nectar
  • 1/2 to 1 cup sprite
  • half an apple
  • half an orange
  • cinnamon

Directions

  1. Combine the liquid ingredients in a large pitcher.
  2. Chop the fruit into bite size pieces and add to pitcher.
  3. Sprinkle cinnamon over the top.
  4. Chill.
  5. Drink. Mmmmmm.
h1

Extracting Integers from Strings

October 7, 2008

The following snippet of source code extracts a single digit from a String and converts it to an int. The String.charAt() method takes a zero-based index of the position of the character to be extracted from the String and the Character.digit() method takes the String from which to extract the digit and the radix.

In the example below I pass 0 to the charAt() method since I want the first character extracted and I pass 10 as the radix since I’m working in base 10.


String myString = "3blindmice";
int digit = Character.digit(myString.charAt(0), 10);
System.out.println("Digit: " + digit);

Output: 3

If the position passed to charAt is not a valid position within the String then a java.lang.StringIndexOutOfBoundsException is thrown.

If the radix is not between Character.MIN_RADIX and Character.MAX_RADIX, -1 is returned.

Comments, alternate solutions and related snippets of code are welcome.

Joshua Smith


References:

API for java.lang.Character.digit(char, int)

API for java.lang.String.charAt(int)

h1

Adding a Java Platform to NetBeans Under Mac OS X

October 13, 2007

This article describes how to add a Java Platform to NetBeans under Mac OS X. This enables you to compile and run your applications under different virtual machines and also to associate Javadocs and source code with a Java platform so that they can be used by NetBeans for code generation and in-context tips and documentation.

These steps assume that you are running NetBeans 6

  1. Select Tools -> Java Platform
  2. Click the Add Platform… button. This will open the Add Java Platform window. Here you will seen all of the Java Platforms that are installed your system.
  3. Drill down until you find the Home folder. Select it and click the Next button.
  4. If you have locally stored copies of source or Javadocs you can associate those with the platform using the Browse buttons. Click the Finish button when you’re done.
  5. Click the Close button.
  6. You can now select this platform for a project by right-clicking a project and selecting Properties. The setting is under the Libraries node.
  7. Finished

Screenshots:

Java Platform ManagerAdd Java PlatformAdd Java Platform 2Project Properties Library

    h1

    Application Monitoring with JConsole

    January 31, 2007

    Introduction

    Hidden in the bin directory of the JDK distribution are some little known, but useful tools. In this article we’ll look at the basics of using jconsole to monitor threads, memory usage and object creation.

    Setting Your App Up to Be Monitored

    If you’re running Java 6, you’re all good to go. The option to allow your application to be monitored is on by default. Skip to the section entitled Launching JConsole and collect 100 points for being on the cutting edge.

    If you’re on Java 1.42 or earlier, do not pass go, or collect $200. Time to upgrade. JConsole requires Java 5 or later.

    If you’re on Java 5, then you need to start the application that you want to monitor while passing an extra flag to the JVM to enable monitoring. For our example we’re going to launch the SwingSet demo that comes with the JDK. If you’re on Windows, Linux or Solaris it’s usually located in %JDK_HOME%/demo/jfc/SwingSet2. If you’re on Mac OS X, it’s usually in /Developer/Examples/Java/JFC/SwingSet2.

    Launching the Application to be Monitored

    If you’re launching the application from the command line, simply add -Dcom.sun.management.jmxremote=true right after the java command. Like this:

    java -Dcom.sun.management.jmxremote=true -jar SwingSet2.jar

    If you’re launching the application from within Eclipse, select Run -> Run…, click on the Arguments tab and specify -Dcom.sun.management.jmxremote=true in the VM arguments field.

    If you’re launching the application from within NetBeans, select the Project, right-click and select Properties, select Run node and specify -Dcom.sun.management.jmxremote=true in the VM Options field.

    Launching JConsole

    JConsole comes with the JDK (not the JRE) and can be found in %JDK_HOME%/bin on Windows, Solaris and Linux and in /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands on Mac OS X. To launch it, open a terminal or command window, change to the directory containing it and execute jconsole. This should open a window that looks like this:

    Jconsole Start

    Click the Connect button to begin monitoring your app. As you can see from the screenshots below you can can view summary information, threads usage, memory usage, current and total classes loaded.

    Jconsole Summary

    Jconsole Threads

    Jconsole Memory

    Jconsole Classes

    The information provided by jconsole is invaluable when tracking down thread creep or memory leaks. It works great to monitor an app while putting it through its paces or when leaving it to run over the weekend to ensure there aren’t any uphill graphs. It’s easy, free and doesn’t require any extra work during application development.

    Joshua Smith

    Technorati Tags: , , , ,

    h1

    Using F-Keys in Mac OS X

    January 31, 2007

    F-Keys are used for special operating system wide functionality in Mac OS X. In this article we’ll discover how to take control of the Mac OS X F-Keys and use them in applications that map keyboard shortcuts to F-Keys.
    By default in Mac OS X the F-Keys provide operating system wide functionality. For instance, F3 and F4 handle volume. F9, F10 and F11 are used for Exposé’s window tricks. That’s nice for being able to get at those features from within any application, but it really messes things up if an application uses F-Keys as a part of their standard keyboard shortcuts. NetBeans is a perfect example. Shift-Command-F4 is the keyboard shortcut for closing all documents, but on Mac OS X, F4 turns down the volume – not the desired output.
    The trick on Mac OS X is that little fn key in the corner of your keyboard and a single setting under System Preferences -> Keyboard & Mouse. By default the F-Keys do Mac OS X things. If you want them to do application specific things you can hold down the fn key and then press the desired F-Key. If you’d like to reverse this behavior, check the box next to “Use the F1-F12 keys to control software features.” With that box checked everything is reversed. The F-Keys will do application specific things and to access the Mac OS X features, you will need to hold down the fn key while you press the desired F-Key. Pick your poison. In either case you have all of the functionality, it’s just a matter of which one you have to hold the extra key for.

    Keyboard And Mouse-1

    Joshua Smith

    Resources

    Amazon Book: Mac OS X for Java Geeks
    Amazon Book: Mac OS X Panther Hacks
    Using NetBeans on Mac OS X
    Marc Liyanage Blog: NetBeans Mac Customization
    Marc Liyanage Blog: More NetBeans on Mac OS X

    Technorati Tags: , ,

    Follow

    Get every new post delivered to your Inbox.