Introduction

This book is for Java programmers interested in developing OS X applications, but not interested in leaving Java behind. Java applications can look and feel just like other OS X programs. Your Java programs can take advantage of any OS X technology.

In this book, I describe the following:

  • Dock usage for Java applications

  • Help Viewer integration

  • Java application bundle creation

  • Adding NSViews to Java windows

  • Java screen saver creation

  • Java application deployment

  • Application menu implementation

  • Icon creation for Java applications

Apple welcomes Java development. Java programming is not an afterthought on Apple's computers. OS X was designed with Java development in mind. Java development on OS X has changed a great deal since the first computers shipped with OS X preinstalled, but the ability to create native feeling applications with Java on OS X has only improved.

This book is not an introduction to Java programming for first-time programmers. To read this entire book, you need some programming experience. Basic understanding of Java is required. Some of the more advanced chapters also require a very limited understanding of C. I make every effort to describe in detail any code that is not Java, so you do not need a great deal of knowledge about any languages other than Java.

If you are new to Java, or programming, keep an introductory manual close by as you work your way through the examples in this book. Many of the examples in this book will make sense to new programmers, as well as more experienced programmers. However, some of the advanced topics might be beyond the beginning programmer.

Understanding the Organization of This Book

This book is divided into three parts: Getting Started; Bringing Guidelines, APIs, and Languages Together; and Architecting Alternative Applications. The chapters progress from introductory material to standard integration topics to advanced integration topics.

Getting Started

Part I begins with the history of Java on Apple computers. Java and Apple actually predate the coming of OS X. Chapter 1 explores this fascinating history.

Chapter 2 jumps into a discussion of the Java environment on OS X. This includes setting preferences for preferred Java versions. Also, I explain the JAVA_HOME on OS X and JAR installation.

In Chapter 3, I give an overview of Xcode and other development tools available for free on OS X. Even if you use an IDE other than Xcode as your primary IDE, occasionally, you may want to start a Java project with one of Xcode's project templates. Understanding Xcode makes this task easier.

Code does no good until compiled. Complex projects can be time-consuming to build. Chapter 4 is all about automating builds of Java applications on OS X. I explore using Xcode, Ant, and shell scripts in the build process.

Deploying standard applications is quite different on OS X than other platforms. Chapter 5 explains details of icon creation, application bundling, and distribution unique to OS X. After reading Chapter 5, you can distribute your applications in style—the OS X style, that is.

Bringing Guidelines, APIs, and Languages Together

Part II explains the nuts and bolts of making your Java applications behave and look like real OS X applications. Chapter 6 reviews the architecture of OS X, along with an introduction to Apple's Human Interface Guidelines.

Chapter 7 contains information on implementing the application menu, the Help Viewer, and the Dock into your application. Also, this chapter explains usage of your application bundle to store your Java software's resources.

Did you know that you can add Cocoa widgets and components to your Java windows? Chapter 8 explains all about adding Objective-C NSViews to your Java Windows and JFrames. This chapter also begins the discussion of JNI as an interface to OS X technologies.

Architecting Alternative Applications

JNI is the official Apple-endorsed bridge between Cocoa and Java technologies. Part III begins with a detailed chapter explaining JNI on OS X. Chapter 9 explains using native features from Java. Chapter 9 also explains creating JVMs from inside native code. This is called the Invocation API.

Java applications can control any Objective-C framework. However, getting the JVM is the tricky part. Chapter 10 demonstrates wrapping the Screen Saver Framework with a Java controller. The JVM is invoked from the native framework and then takes over from there. After understanding this chapter, you will realize that Java has no limits on OS X.

In Chapter 11, I explain Terminal application User Interfaces. Many applications run from the Terminal. In fact some programmers prefer not to use GUI applications for controlling their servers. This chapter explains how to make respectable text-based UIs.

Using This Book

A minimum of Java 6 and Snow Leopard (Mac OS X 10.6) are required for making the most of this book. I created the source code in this book on Snow Leopard. Also, the screen captures in this book are from Snow Leopard. Earlier versions of OS X may be used for much of the book with minor alterations to the coded examples. Screenshots of earlier versions of OS X may also differ from Snow Leopard screenshots. Refer to Apple's developer documentation for details of changes to Java and OS X with the release of Snow Leopard.

I wrote this book so that reading it from cover to cover makes sense. Having said that, not everyone has time to read hundreds of pages of documentation. So you can take shortcuts if you are interested in reading only certain chapters.

For those interested in writing traditional applications for OS X, you definitely should read these chapters: Chapter 2 on OS X's Java environment, Chapter 5 on deploying applications, Chapter 6 on Apple's Human Interface Guidelines, and Chapter 7 on integrating OS X features into your Java application.

If you want to automate your complex Java project builds, then read Chapters 2 and 4. Chapter 2 explains the Java environment, and Chapter 4 explains Ant projects and shell scripting. You can completely automate your builds no matter how complex they are.

If your interests are in using JNI to integrate advanced OS X features into your Java applications, then read Chapters 8, 9, and 10. Chapter 8 gives an introduction to JNI in the context of Cocoa Components. Chapter 9 explains details of JNI on OS X, including use of the Invocation API. Chapter 10 gives an example of creating a Java application that wraps a native framework using the Invocation API. In this case, the example application is a Java screen saver.

Writers of servers and server utilities should look at Chapter 11, which describes text-based User Interfaces. Many servers are controlled via ssh or terminals, so Chapter 11 explains how advanced applications should interact with users on the command line.

Using the Companion Web Site

All programming examples in this book are on the book's companion Web site. Find the Web site at the following URL

www.wiley.com/go/javamacdevref

When reading a chapter, begin by downloading the source code for the projects in that chapter. Follow along with the chapter using the source from the Web site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.47.166