<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mac Developer Tips &#187; Java</title>
	<atom:link href="http://MacDeveloperTips.com/category/java/feed" rel="self" type="application/rss+xml" />
	<link>http://MacDeveloperTips.com</link>
	<description>Tips, tools and code for iPhone and Mac developers.</description>
	<lastBuildDate>Mon, 27 Apr 2009 13:07:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>NetBeans, Java, AppleScript and iTunes &#8211; Part 2</title>
		<link>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-2.html</link>
		<comments>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-2.html#comments</comments>
		<pubDate>Tue, 29 Apr 2008 12:03:45 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-2.html</guid>
		<description><![CDATA[Learn how to interact with iTunes using AppleScript and Java.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://macdevelopertips.com/java/netbeans-java-applescript-and-itunes-part-1.html" target="_blank">part 1 of this series</a> I demonstrated how to create a short Java application in NetBeans that communicated, using AppleScript, to the Mac apple event system. The application was a no thrills look into how to invoke the TextEdit application. Despite the brevity of the application it provided the foundation for this next tip, which will build on the ideas to create something a little more salient, as in, something that you might actually find yourself using.</p>
<p>The gist of the application is to instruct iTunes to play a random song, move to the next song, pause, etc. I&#8217;ll show one use of the application by wrapping the code into a bash script that allows you to invoke the program (and all commands) from within a terminal. Watch the video that follows for all the details&#8230;</p>
<p><a href="javascript:lynkVideoPop(719,'1209472338');" class="lynkvp"><img src="http://macdevelopertips.com/wp-content/uploads/images/NetBeans-Tips-Intro-Click-Here.png" /></a></p>
<p>This application is all of about 80 lines, including the bash script. Sometimes a little creative thinking and a few lines of code are all that&#8217;s needed to write an intriguing (and hopefully useful) application.</p>
<hr color="#00008b" size="1" /><img src="/images/blank.gif" border="0" height="1" />The music in the video is Led Zeppelin and the song: Moby Dick. <a href="http://www.amazon.com/gp/product/B000002J03?ie=UTF8&amp;tag=macdevelopertips-20&amp;link_code=as3&amp;camp=211189&amp;creative=373489&amp;creativeASIN=B000002J03" target="_blank">Led Zeppelin at Amazon</a><br />
<img src="/images/blank.gif" border="0" height="3" /><br />
<img src="http://www.assoc-amazon.com/e/ir?t=macdevelopertips-20&amp;l=as2&amp;o=1&amp;a=B000002J03" style="border: medium none  ! important; margin: 0px ! important" border="0" height="1" width="1" /><br />
<img src="/images/blank.gif" border="0" height="3" /></p>

<!-- start wp-tags-to-technorati 0.9 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/AppleScript' rel='tag' target='_self'>AppleScript</a>, <a class='technorati-link' href='http://technorati.com/tag/Cocoa' rel='tag' target='_self'>Cocoa</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_self'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/netbeans' rel='tag' target='_self'>netbeans</a>, <a class='technorati-link' href='http://technorati.com/tag/screencast' rel='tag' target='_self'>screencast</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans, Java, AppleScript and iTunes &#8211; Part 1</title>
		<link>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-1.html</link>
		<comments>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-1.html#comments</comments>
		<pubDate>Thu, 24 Apr 2008 11:40:57 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-1.html</guid>
		<description><![CDATA[Part 1 of a series of screencasts working with NetBeans, Java and AppleScript to interact with iTunes on Mac OS X]]></description>
			<content:encoded><![CDATA[<p>A few weeks back I <a href="http://macdevelopertips.com/tools-utilities/netbeans-61-ruby-and-applescript.html" target="_blank">demonstrated</a> how to write Ruby code inside NetBeans to control scriptable applications on a Mac, that is, communicate between Ruby and the Apple Event system. In this post, I will turn things around a bit from the previous post and use NetBeans and Java to execute AppleScript.</p>
<p>There is a subtle difference, in the previous post the focus was on how to write code in Ruby (inside NetBeans) using the <a href="http://appscript.sourceforge.net/rb-appscript/index.html" target="_blank">rb-appscript</a> bridge. This time around the approach is to work with Java and pass AppleScript code to a set of Cocoa files (classes) that will act as the bridge between our application and the Mac system.</p>
<p><a href="javascript:lynkVideoPop(719,'1209037077');" class="lynkvp"><img src="http://macdevelopertips.com/wp-content/uploads/images/NetBeans-Tips-Intro-Click-Here.png" /></a></p>
<p>There is one caveat &#8211; the Cocoa-Java API is deprecated as of Mac OS X Tiger. The NSAppleScript and NSMutableDictionary classes are still available, however, they are no longer on the development path within Apple. There are <a href="http://devworld.apple.com/documentation/ScriptingAutomation/Reference/ScriptingBridgeFramework/index.html#//apple_ref/doc/uid/TP40005074" target="_blank">scripting bridges</a> that allow you to control scriptable applications using Python, Ruby, and Objective-C. Java Native Interface (JNI) is an additional option to call platform specific code. You can read more about JNI in this technical note: <a href="http://developer.apple.com/technotes/tn2005/tn2147.html" target="_blank">JNI development on Mac OS X</a>.</p>
<p>One more note, if you follow the steps in this video and the classes NSAppleScript and NSMutableDictionary are shown with lines through them (for example, <strike>NSAppleScript</strike>), this has to do with a preference setting inside NetBeans to show deprecated classes with a strike-through. You can change this as follows: From the Preferences dialog, choose Fonts/Colors; click the Syntax option; from the Language list choose Java; click on Deprecated Element; in the Effects option, choose None.</p>
<p>Join me in Part 2 of this tip where I&#8217;ll show a more comprehensive (read: interesting) example where it&#8217;s all about controlling iTunes using Java.</p>
<hr color="#00008b" size="1" /><img src="/images/blank.gif" border="0" height="1" />The music in the video is Led Zeppelin and the song: Moby Dick.<br />
Click the image to see more about about Led Zeppelin and the CD (at Amazon)<br />
<img src="/images/blank.gif" border="0" height="3" /><br />
<a href="http://www.amazon.com/gp/product/B000002J03?ie=UTF8&amp;tag=macdevelopertips-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B000002J03" target="_blank"><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/led-zep-ii.jpg" border="0" /></a><img src="http://www.assoc-amazon.com/e/ir?t=macdevelopertips-20&amp;l=as2&amp;o=1&amp;a=B000002J03" style="border: medium none  ! important; margin: 0px ! important" border="0" height="1" width="1" /><br />
<img src="/images/blank.gif" border="0" height="3" /></p>

<!-- start wp-tags-to-technorati 0.9 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/AppleScript' rel='tag' target='_self'>AppleScript</a>, <a class='technorati-link' href='http://technorati.com/tag/Cocoa' rel='tag' target='_self'>Cocoa</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_self'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/netbeans' rel='tag' target='_self'>netbeans</a>, <a class='technorati-link' href='http://technorati.com/tag/screencast' rel='tag' target='_self'>screencast</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://MacDeveloperTips.com/java/netbeans-java-applescript-and-itunes-part-1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selecting Java Version &#8211; Part 2</title>
		<link>http://MacDeveloperTips.com/java/selecting-java-version-part-2.html</link>
		<comments>http://MacDeveloperTips.com/java/selecting-java-version-part-2.html#comments</comments>
		<pubDate>Tue, 22 Apr 2008 12:03:02 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://MacDeveloperTips.com/java/selecting-java-version-part-2.html</guid>
		<description><![CDATA[In the previous post I showed how to configure and access the various Java versions installed on Leopard. In this post I want to dig a little deeper into what is going on behind the scenes as it relates to working with Java on Mac OS X. None of what I describe here will speed [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post I showed how to configure and access the various Java versions installed on Leopard. In this post I want to dig a little deeper into what is going on behind the scenes as it relates to working with Java on Mac OS X. None of what I describe here will speed up your development process, however, it may save you some time if/when the day comes that  something is amiss when working with Java.</p>
<p>Let&#8217;s begin by looking at the setting for <font color="#800000"><em>JAVA_HOME</em></font> on my system:</p>
<pre>JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home</pre>
<p>All works well, despite the fact that this <a href="http://developer.apple.com/qa/qa2001/qa1170.html" target="_blank">technical article on Apple</a> specifies that <font color="#800000"><em>JAVA_HOME</em></font> should point to:</p>
<pre>/Library/Java/Home</pre>
<p>So what&#8217;s up with that? Having a closer look at the file system will reveal what&#8217;s going on. The figure below shows a directory listing of the path <font color="#800000"><em>/Library/Java/Home</em></font>:</p>
<p><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/javahome-1.png" /></p>
<p>It&#8217;s all about <a href="http://en.wikipedia.org/wiki/Symbolic_link" target="_blank">symbolic links</a>, so effectively the path Apple recommends, is a link to the path that I have set as my <font color="#800000"><em>JAVA_HOME</em></font>.  If you look at the listing below you&#8217;ll notice that <font color="#800000"><em>/System/Library/Framework/JavaVM.framework/Home</em></font> is a link to <font color="#800000"><em>/System/Library/Framework/JavaVM.framework/Versions/CurrentJDK/Home</em></font>.</p>
<p><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/javahome-2.png" /></p>
<p>I think you can guess where I&#8217;m going with this next. If we look one level deeper, we&#8217;ll see that the reference to <font color="#800000"><em>/CurrentJDK/Home </em></font>includes a /bin directory, which is where all the  Java executables (see below):</p>
<p><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/javahome-4.png" /></p>
<p>The listing below shows the contents of the <font color="#800000"><em>/bin</em></font> again, a list of links:</p>
<p><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/javahome-5.png" /></p>
<p>Okay, we&#8217;ve got to be nearing the end here&#8230;if we list the files that are located at <font color="#800000"><em>../../Commands</em></font> we will finally see the executables, no more links:</p>
<p><img src="http://macdevelopertips.com/wp-content/uploads/2008/04/javahome-6.png" /></p>
<p>What do all the links accomplish versus a simply directory and path structure? In a word, flexibility. Using links, one can change the reference to the <font color="#800000"><em>/CurrentJDK</em></font> directory and in one fell swoop, change which executables files (that is, which version of Java is used). Thus, when a new version       of Java is downloaded and installed via the Mac OS X Software Update, or you upgrade to a new version of Mac OS X, getting the latest version of Java is nothing more than changing the appropriate symbolic links.</p>
<p>The good news is that unless you manually upgrade Java, all the work happens for you with no effort on your part. However, my intention in jumping through all these hoops is to show you how the linking process works, so if/when the day comes that you need to figure out why the &#8220;wrong&#8221; Java version is compiling or packaging your code, you have a path (no pun intended) to make some sense of where the &#8220;active&#8221; Java executables live.</p>

<!-- start wp-tags-to-technorati 0.9 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_self'>Java</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://MacDeveloperTips.com/java/selecting-java-version-part-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting Java Version &#8211; Part 1</title>
		<link>http://MacDeveloperTips.com/java/selecting-java-version-part-1.html</link>
		<comments>http://MacDeveloperTips.com/java/selecting-java-version-part-1.html#comments</comments>
		<pubDate>Mon, 21 Apr 2008 23:30:07 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://MacDeveloperTips.com/java/selecting-java-version-part-1.html</guid>
		<description><![CDATA[Mac OS X leopard includes multiple versions of Java, this tip shows you how to select the version of the JDK you prefer.]]></description>
			<content:encoded><![CDATA[<p>Mac OS X Leopard includes multiple versions of Java in the base install. This can be quite helpful if you need to compile and run Java code across more than one version of the JDK.</p>
<p>You can specify which installed version of Java you prefer to use as the default by tweaking the settings within the Java Preferences application, which is located in the Utilities folder under Java. See the figure below and notice the path reference on the bottom of the figure. The full path is:<font color="#800000"><em>/Applications/Utilities/Java/</em></font></p>
<p><img src="http://MacDeveloperTips.com/wp-content/uploads/2008/04/java-pref-app.png" /></p>
<p>From within the Java Preferences application, in addition to choosing the preferred Java version, there are a number of additional configuration options in the Security and Advanced tabs, with the later tab including a number of options that make it worth a visit.</p>
<p><img src="http://MacDeveloperTips.com/wp-content/uploads/2008/04/java-pref-app2.png" /></p>
<p>One last recommendation, if you compile from the command line you can select which version of the Java compiler you are after without having to change the preferred system setting. Open <font color="#800000"><em>~/.bash_profile</em></font> (in your home directory) and create aliases similar to the following:</p>
<pre>alias javac-15=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java
alias javac-14=/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Commands/java</pre>
<p>Check the Java version using the above aliases as follows:</p>
<p><img src="http://MacDeveloperTips.com/wp-content/uploads/2008/04/javac-ver.png" /></p>
<p>In the second part of this post I&#8217;ll show you some of the goings on behind the scenes of the Java configuration on Mac OS X.</p>

<!-- start wp-tags-to-technorati 0.9 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_self'>Java</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://MacDeveloperTips.com/java/selecting-java-version-part-1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
