Social Icons

twitterfacebookgoogle pluslinkedinrss feed

Sunday, April 20, 2008

Creating a State Diagram

A State diagram is a visual representation of an application's state machines. It shows the life of an object from birth to death. In this type of diagram, you see the behavior specifying the sequence of states that the object goes through in response to events over its lifetime, and you see the object's responses to those events.

You can use a State diagram when you are working on a real-time process-control application or a subsystem that involves concurrent processing, or when you want to express the behavior of a class over several use cases.

1. Create a UML Project and add a State diagram

1. Choose File New Project.

2. In the New Project wizard:
1. Select Categories UML.
2. Select Projects Platform-Independent Model.
3. Click Next.

3. In the New Platform-Independent Model panel:
1. Type a name for the UML project, such as MyUMLProject.
2. Choose a directory where the project will be stored.

4. Click Finish.

5. In the opened New Wizard window:
1. Select State Diagram for the Diagram Type.
2. Type in a name for the diagram, such as SodaMachineStateDiagram.
3. Accept the default value for namespace.
4. Click OK.

The IDE does the following:

* Creates a platform-independent project especially designed to handle UML modeling work.
* Displays the project icon in the Project window.
* Generates a State diagram in the project.
* Displays the State diagram icons under both Project Model and Project Diagrams.
* Opens and displays the State diagram in the diagram editor.
* Opens the modeling palette to display the particular icons that are used to build State diagrams.

Next, we will draw a State diagram for a simple soda-machine application.
2. Identify State elements and add them to the State diagramHEADER

1. Add an Initial State: Click the Initial State icon in the palette, then click the upper left corner in the State diagram.
2. Add a Simple State: Click the Simple State icon in the palette, then click the State diagram to the right of the Initial State.
3. Right-click to deselect element-creation mode.
4. Double-click the Simple State and name it: Type Displaying, then press the Enter key.
5. Add three more Simple States and name them Refunding, Calculating, and Processing.
6. Add a Final State: Click the Final State icon in the palette, then click at the bottom of the State diagram.
7. Right-click to deselect element-creation mode.
8. Right-click and select Labels Final State Name to toggle the name label off. (In this particular example, the Final State does not need a name.)


3. Identify events, and connect states with State Transition

An event causes an object to transition from one state to another. In a State diagram, an event is represented by an arrow connecting the two states; this is called a State Transition element. As we continue our example, we will create a State Transition between the Initial State and the State we have called Displaying. Then, we will add several other State Transitions.

1. Add a State Transition element:
1. Click the State Transition icon in the palette.
2. Go to the State diagram and click the Initial State.
3. Click the Displaying State.

2. Add a State Transition element from the Displaying State to itself:
1. Click the State Transition icon in the palette.
2. Go to the diagram and click the Displaying State.
3. Move the mouser pointer up a bit, click the diagram, then move the pointer to the right a bit and click the Displaying State in the diagram.

3. Place a Horizontal Join/Merge element just below the Displaying State:
1. Click the Horizontal Join/Merge icon in the palette.
2. Click the State diagram below the Displaying State element.

4. Add eight more State Transition elements:
* From the Displaying State to the Horizontal Join/Merge
* From the Horizontal Join/Merge to the Refunding State
* From the Horizontal Join/Merge to the Calculating State
* From the Calculating State to the Processing State
* From the Calculating State to the Displaying State
* From the Processing State to the Refunding State
* From the Refunding State to the Final State
* From the Processing State to the Final State


4. Label State Transition with a name, and with a pre-condition or post-condition

Now we'll give the State Transition an event name and, where necessary, add a pre- or post-condition.

1. Right-click the State Transition (the linking arrow) between the Initial State and the Displaying State.
2. Choose Label Name, and type Coins Entered.
3. In the same way, label other State Transitions:

Label Name State Transition
Coins Entered Displaying State to Displaying State
Button Pressed Displaying State to Horizontal Join/Merge
Calculating Finished Calculating State to Displaying State
Calculating Finished Calculating State to Processing State
Soda Ejected Processing State to Final State
Soda Ejected Processing State to Refunding State
Coins Refunded Refunding State to Final State

Some State Transitions are subject to conditions, and these need to be labeled. A condition is shown in square brackets on the State Transition link.

1. Right-click the State Transition link between Horizontal Join/Merge and Refunding.
2. Choose Label Pre Condition, and type button=refund.
3. Repeat these steps to label pre-conditions on other State Transitions.

Pre-Condition State Transition
button!=refund Horizontal Join/Merger to Calculating State
cost<=coin value Calculating State to Processing State
cost>coin value Calculating State to Displaying State
cost cost=coin value Processing State to Final State

Sunday, April 13, 2008

NetBeans IDE Keyboard Shortcuts



Ctrl-Space
Code completion
Esc
Close code completion
Shift-Space
Enter a space without expanding
an abbreviation
Alt-F1
Display Javadoc
Shift-F1
Search Javadoc
Alt-Shift-I
Import class
Alt-U, G
Append get to identifier
Alt-U, S
Append set to identifier
Alt-U, I
Append is to identifier
Ctrl-Shift-F
Reformat selection
Ctrl-T Shift
one tab to the right
Ctrl-D
Shift one tab to the left
Ctrl-Shift-T
Comment out with line comments
("//")
Ctrl-Shift-D
Remove line comments ("//")
Ctrl-W
Delete current or previous word
Ctrl-E
Remove the current line
Ctrl-J, S
Start recording macro
Ctrl-J, E
Stop macro recording
Ctrl-[
Move insertion point to matching
bracket
Ctrl-L
Word match - forward
Ctrl-K
Word match - back
Ctrl-F
Find
Ctrl-H
Replace
F3
Find next
Shift-F3
Find previous
Ctrl-F3
Search for word that insertion
point is on
Alt-Shift-H
Turn off search result highlighting
Alt-Shift-O
Fast Open class
Alt-O
Go to source
Alt-G
Go to declaration
Ctrl-M
Select next parameter
Ctrl-F2
Add/remove bookmark
F2
Next bookmark
Alt-L
Next in jump list (present file)
Alt-K
Previous in jump list (present file)
Alt-Shift-L
Next in jump list (all files)
Alt-Shift-K
Previous in jump list (all files)
Ctrl-Shift-J
Insert internationalized string
Ctrl-Minus (-)
Collapse (hide) a block of code
Ctrl-Plus (+)
Expand a collapsed block of code
Ctrl-Shift-Minus (-)
Collapse all code blocks
Ctrl-Shift-Plus (-)
Expand all code blocks



Tuesday, April 01, 2008

Java 1.5 Language Features

Generics

This long-awaited enhancement to the type system allows a type or method to operate on objects of various types while providing compile-time type safety. It adds compile-time type safety to the Collections Framework and eliminates the drudgery of casting.

Enhanced for Loop

This new language construct eliminates the drudgery and error-proneness of iterators and index variables when iterating over collections and arrays.

Autoboxing/Unboxing

This facility eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer).

Typesafe Enums

This flexible object-oriented enumerated type facility allows you to create enumerated types with arbitrary methods and fields. It provides all the benefits of the Typesafe Enum pattern ("Effective Java," Item 21) without the verbosity and the error-proneness.

Varargs

This facility eliminates the need for manually boxing up argument lists into an array when invoking methods that accept variable-length argument lists.

Static Import

This facility lets you avoid qualifying static members with class names without the shortcomings of the "Constant Interface antipattern."

Metadata (Annotations)

This language feature lets you avoid writing boilerplate code under many circumstances by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it. Also it eliminates the need for maintaining "side files" that must be kept up to date with changes in source files. Instead the information can be maintained in the source file.