gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Promotional Products
Cell Phones
Imprinted Gifts
Promotional Golf
Best Price
Laptop Batteries
Condos For Sale
Web Hosting Directory
Online Education
Find Software
Promote Your Website
Holiday Gift Ideas
Auto Insurance Quote
Shop Online

 


Untitled table test
Register here for your free Internet.com membership to download your Justifying and Funding Infrastructure Investments report.

This independent report will help you make the case for your IT investments. Topics covered include:

Measuring Infrastructure Value
Justifying New Investments
Establishing an Infrastructure Value Chain and More.
Register now for your free Internet.com membership to download your complimentary Forrester report.
Limited Time Offer!
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Switching to the Mac for the Java Developer, Part 1
By Benoît Marchal

You might have been tempted by Apple ads on switching to Macintosh (www.apple.com/switch/ads). I was tempted enough to add two Macs to my network. I bought them primarily for digital photography, but I was also interested in the new, UNIX-based, Mac OS X.

In this series of articles, I will explore porting Java applications to Mac OS X. I assume you already are familiar with Java, Swing, and AWT, so I will concentrate on the Mac OS X aspects only. The series will be useful to Java developers who want to write more portable applications.

Why Java?

I chose Java as my primary programming language on Mac OS X for three reasons:

  1. It is portable.
  2. Mac OS X has excellent support for Java.
  3. I already know Java.

Portability is important because I own both Macs and PCs. Furthermore, most of my customers have Windows and Linux boxes. Java is the most sensible choice in a mixed environment.

Java is an excellent language for Mac development. Apple provides four main APIs for Mac OS X:

  • Cocoa, which is unique to Mac OS X
  • Carbon, which simplifies porting existing Mac applications
  • UNIX through a subset of POSIX
  • Java. Unlike other platforms, Java is not a layer on top of the operating system, but one of the primary APIs.

Finally, learning a new language and a new API is not necessarily difficult but it takes time. It makes more sense to use a language (Java) and APIs (AWT/Swing) with which I am already familiar.

User Interface Innovation and Java

Apple's old slogan was "Think different" and that certainly applies to Aqua, the user interface for Mac OS X. Although Aqua uses menus, dialogs, and windows, it differs significantly from the more common Windows or KDE/Gnome interfaces. Unfortunately, AWT and Swing were designed for those more common interfaces and are severely underpowered with Aqua.

In practice, pure Java applications under Mac OS X behave like crude Windows ports. One can take advantage of various Apple extensions to smoothen the user experience. We will study those extensions in this series. In this article, we will start by packaging a Java application for Mac OS X.

Application Package

One of the most visible differences between Aqua and Windows/KDE/Gnome is the absence of a Start menu. Aqua does not need one. The Start menu exists because what the user thinks of as an application is often a directory with several files (binaries, shared libraries, resources, JARs, and more). If one file is missing, it does not work. The Start menu associates an icon to the directory.

The Mac proposes a more intuitive solution called application bundles, which really are clickable directories. On the file system, an application bundle is a directory (with the .app extension). It contains the application files (binaries, shared libraries, resources, JARs, and more) and has its own icon. When the user double-clicks the bundle, it launches the application.

Application bundles are more intuitive if only because copying or moving the bundle copies or moves the entire application directory. No more invalid shortcuts and, in most cases, you don't need an installer. The user simply copies the bundle (the application) to his or her hard disk.

Bundles for Java Applications

The least you can do to make a well-behaved Mac application from an existing Java application is to create an application bundle. You will need MRJAppBuilder, a utility that should ship with your Mac (look for a "Developer Tools" CD or a "Developer Tools" directory). Alternatively, you can download it from developer.apple.com.

MRJAppBuilder proposes a dialog box with four tabs, as illustrated in Figure 1. On the first tab, you specify the application's main class, its classpath, the resulting application bundle, and its icon (click on the icon in the "output file" section to choose the icon).

Entries in the classpath are relative to the application bundle. You can add JAR files through the "Merge Files" tab. The classpath will be of the form Content/Resources/Java/myjar.jar.

On the Mac OS tab, you want to enter the application name in the CFBundleName property.

Finally, in the Merge Files tab, list the application files, including JAR files and other resources (images, HTML, and more). These files are copied in the Content/Resources/Java directory in the application bundle. Click the "Build Application" button to create the bundle.

Figure 1

Next Steps

Congratulations! You have taken the first step to distribute Java applications on the Mac. In the next articles, we will see how to improve the application so it integrates more nicely with Aqua.

Benoît Marchal is a Belgian developer. He is the author of XML by Example and other XML books. He was originally attracted to the Mac for digital photography but he has learned to enjoy the robust Java implementation on Mac OS X.


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Other Java Archives

Whitepaper: Enterprise Information Integration--Deployment Best Practices for Low-Cost Implementation
Learn about expanding business opportunities for the reseller channel. Visit IT Channel Planet.
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES