Sun Java Solaris Communities My SDN Account Join SDN
 
Java Technology Fundamentals Newsletter Index

How "Exceptions" Work, How to Create JavaBeans and Design with MVC, and Getting Started with the NetBeans Visual Web Pack 5.5

 
In This Issue

Welcome to the Java Technology Fundamentals Newsletter

This monthly newsletter provides a way for you to learn the basics of the Java programming language, discover new resources, and keep up-to-date on the latest additions to Sun Developer Network's New to Java Center.

Note: For the code in this issue of Fundamentals to compile, use the JDK 6 software.

Basic Java Technology Programming
Making Sense of the Java Platform Classes and Tools
Desktop Java Platform Development
Server-Side Java Platform Development
Free Developer Tools
Java Technology Courses
For More Information

 
Basic Java Technology Programming

What Is an Exception?

The term "exception" is shorthand for the phrase "exceptional event."

An exception is an event that occurs during the execution of a program and that disrupts the normal flow of the program's instructions.

When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack (see the next figure).


The runtime system searches the call stack for a method that contains a block of code that can handle the exception. This block of code is called an exception handler. The search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which the methods were called. When an appropriate handler is found, the runtime system passes the exception to the handler. An exception handler is considered appropriate if the type of the exception object thrown matches the type that the handler can handle.

The exception handler chosen is said to catch the exception. If the runtime system exhaustively searches all the methods on the call stack without finding an appropriate exception handler, the runtime system (and the program) terminates.

Read the rest of this tutorial 

Making Sense of the Java Platform Classes and Tools

Trail: JavaBeans

JavaBeans is a portable, platform-independent component model written in the Java programming language. The JavaBeans architecture was built through a collaborative industry effort and enables developers to write reusable components in the Java programming language.

With the JavaBeans API, you can create reusable, platform-independent components. Using JavaBeans-compliant application builder tools, you can combine these components into applets, applications, or composite components.

JavaBean components are known as beans. Beans are dynamic in that they can be changed or customized. Through the design mode of a builder tool, you use the property sheet or bean customizer to customize the bean and then save (persist) your customized beans.

This trail is represented in the following lessons:

JavaBeans Concepts describes the basic notion of JavaBeans and what makes a bean.

Using the NetBeans GUI Builder

This section describes the NetBeans GUI Builder within the scope of operating with bean objects.

Writing a Simple Bean

This section walks you through creating a rudimentary bean, saving the bean, adding the bean to the Palette of the NetBeans GUI Builder and inspecting the bean's properties and events.

Bean Properties

This section explains how to give your beans properties -- bean appearance and behavior characteristics that are customizable at design time.

Manipulating Events

This section describes the JavaBeans event-manipulating capabilities. If you are not familiar with event handling, you might want to read the "Event Handling" section to prepare for this material.

Bean Persistence

This section explains how to save and restore beans to their customized state.

Long-Term Persistence

This section explains how to save and load your beans in the XML format using the XMLDecoder and XMLEncoder classes.

Introspection

This section describes how methods, properties, and events are discovered in the beans that you write.

Bean Customization

This section introduces you to property editors and to the Customizer interface.

Using the BeanContext API

This section covers the Extensible Runtime Containment and Services Protocol, also known as beancontext.

Read the rest of this tutorial  

Desktop Java Platform Development

Java SE Application Design With MVC by Robert Eckstein

What Is Model-View-Controller (MVC)?

If you've programmed with graphical user interface (GUI) libraries in the past 10 years or so, you have likely come across the model-view-controller (MVC) design. MVC was first introduced by Trygve Reenskaug, a Smalltalk developer at the Xerox Palo Alto Research Center in 1979, and it helps to decouple data access and business logic from the manner in which it is displayed to the user. More precisely, MVC can be broken down into three elements:

  • Model. The model represents data and the rules that govern access to and updates of this data. In enterprise software, a model often serves as a software approximation of a real-world process.

  • View. The view renders the contents of a model. It specifies exactly how the model data should be presented. If the model data changes, the view must update its presentation as needed. This can be achieved by using a push model, in which the view registers itself with the model for change notifications, or a pull model, in which the view is responsible for calling the model when it needs to retrieve the most current data.

  • Controller. The controller translates the user's interactions with the view into actions that the model will perform. In a stand-alone GUI client, user interactions could be button clicks or menu selections, whereas in an enterprise web application, they appear as GET and POST HTTP requests. Depending on the context, a controller may also select a new view -- for example, a web page of results -- to present back to the user.

Although different architectures allow the three components to interact in different ways, Figure 1 shows a common implementation of the MVC design pattern, as shown in the Sun BluePrints Catalog.


This section will take a closer look at one way to implement Figure 1 in the context of an application in the Java Platform, Standard Edition 6 (Java SE 6). Once the model, view, and controller objects are instantiated, the following occurs:

  1. The view registers as a listener on the model. Any changes to the underlying data of the model immediately result in a broadcast change notification, which the view receives. This is an example of the push model described earlier. Note that the model is not aware of the view or the controller -- it simply broadcasts change notifications to all interested listeners.
  2. The controller is bound to the view. This typically means that any user actions that are performed on the view will invoke a registered listener method in the controller class.
  3. The controller is given a reference to the underlying model.

Once a user interacts with the view, the following actions occur:

  1. The view recognizes that a GUI action -- for example, pushing a button or dragging a scroll bar -- has occurred, using a listener method that is registered to be called when such an action occurs.
  2. The view calls the appropriate method on the controller.
  3. The controller accesses the model, possibly updating it in a way appropriate to the user's action.
  4. If the model has been altered, it notifies interested listeners, such as the view, of the change. In some architectures, the controller may also be responsible for updating the view. This is common in Java technology-based enterprise applications.
Read this article  

Server-Side Java Development

Getting Started With NetBeans Visual Web Pack 5.5
Contributed by the Visual Web Pack Tutorials Team

This tutorial gives you a whirlwind tour of the NetBeans Visual Web Pack. The tutorial shows you how to use the Visual Web Pack features to perform the typical phases of web application development.

The tutorial is designed so that you do not need to go through it in any particular order. You might want to skim over it quickly and then return to each section as time allows. If you prefer a step-by-step tutorial, you might want to first try "Developing a Web Application"

Contents
  • Software Needed for This Tutoria
  • Starting a Project
  • Creating Web Pages
  • Adding Components to a Web Page
  • Getting Help
  • Building and Testing a Web Application
  • Connecting Web Pages and Handling User Actions
  • Editing Java Code
  • Handling User Inputl
  • Storing and Passing Data
  • Connecting to Databases
  • Debugging a Web Application

Content on this page applies to NetBeans 5.5 Visual Web Pack

This tutorial works with the following technologies and resources: JavaServer Faces Components/Java EE Platform and the Travel Database.

As of December 2006 only the Sun Java System Application Server supported Java EE 5.

This tutorial has been tailored for use with the Sun Java Application Server PE 9.0 Update Release 1 and with Tomcat 5.5.17. If you are using a different server, consult the Release Notes and FAQs for known problems and workarounds. For detailed information about the supported servers and Java EE platform, see the Release Notes.

Read this tutorial  

Free Developer Tools

Sun is offering the award-winning Sun Java Studio Enterprise, Sun Java Studio Creator, and the NetBeans IDE and NetBeans Mobility Pack at no cost to all developers worldwide who join the Sun Developer Network (SDN).

Get your free tools  

Java Technology Courses

Self-Paced Web, CD, and Virtual Courses

Java Complete Learning Solution (CDJ-JAVA-ALL)
The Java Total Knowledge Solution is a collection of courses in CD-ROM format designed to provide students a complete path from entry-level skills through advanced Java technology topics, including Java mobile. It also supports various certification exams.

Java Programming Language Workshop (VC-SL-285)
Students use graphical user interface (GUI) design principles and network communications capabilities to code a functional Java technology-based application that interacts with a networked database server. The significant amount of lab time illustrates the workshop nature of this course.

Developing Applications for the J2EE Platform (CDJ-310A)
This course provides students with the knowledge to build and deploy enterprise applications that comply with Java 2 Platform, Enterprise Edition (J2EE) standards. Students are taught how to assemble an application from reusable components and how to deploy an application in the J2EE platform runtime environment.

See the course catalog  

For More Information

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.