Monday, October 29, 2007

An example of Regular Expression search and replace program

This Java tip illustrates an example of Quintessential Regular Expression search and replace program. This program finds all matches to a regular expression pattern and replaces them with another string.

import java.util.regex.*;

public class BasicReplace {

public static void main(String[] args) {

CharSequence inputStr = "p q r p q r ";
String patternStr = "q";
String replacementStr = "s";

// Compile regular expression
Pattern pattern = Pattern.compile(patternStr);

// Replace all occurrences of pattern in input
Matcher matcher = pattern.matcher(inputStr);
String output = matcher.replaceAll(replacementStr);
// p s r p s r
}
}

Saturday, October 27, 2007

Review: BlackBerry Curve 8330




BlackBerryToday > Hardware Reviews > Review: BlackBerry Curve 8330

Review: BlackBerry Curve 8330

By Gerry Blackwell
August 18, 2008

Page 1 | 2 | Next

Click to View
Rejoice o ye CDMAites! The Curve is come! Praise the lord and pass the PDAs!

Customers of Verizon and other North American CDMA-based cellular providers can finally lay their hands on one of the hottest PDA phones, Research in Motion's (RIM) BlackBerry Curve, the smallest, lightest cell phone with a full QWERTY keyboard.

The original Curve 8300, which we reviewed here, is a GSM device. It took almost six months for a CDMA version to become readily available. Telus and Bell in Canada introduced the Curve 8330 earlier this year and Verizon launched it in May. Sprint and Alltel now have it as well.

Verizon sells the 8330 for $200 with a two-year contract, $300 with a one-year contract. Bell and Telus in Canada sell it with one-, two- or three-year contracts, or no contract, for $200, $400, $500 or $550 (Bell), $200, $450, $500 or $550 (Telus). Voice, e-mail and data packages are, needless to say, extra.

The Curve 8330 is not significantly different from the original 8300 model. It's not a quad-band world phone, of course, but it is a dual-band 800/1900 MHz device. Best of all, it works on super-fast CDMA-based EVDO networks.

Like most Curve models, the 8330 includes an on-board GPS receiver, and the carriers are offering turn-by-turn navigation services. Verizon has VZ Navigator, which is based on the AtlasBook platform from Networks in Motion (NIM). Telus is also using NIM. Bell uses technology from TeleNav Inc.

Unlike the Curve 8320, a GSM model available from T-Mobile and Wirefly in the U.S. and directly from RIM in Canada, the 8330 does not include Wi-Fi, which is a great pity.

Though it's not a lot different from the original Curve, we wanted to try out the 8330's GPS navigation features and test network connectivity over EVDO - and generally take a second look at a product that has had a lot of hype, and some criticism.

We originally reviewed the Curve as a better - if not as sleek - version of the BlackBerry Pearl, RIM's first foray into the consumer/business market.

The Pearl had a crummy 1.3-megapixel camera, you couldn't plug in standard stereo headphones to take full advantage of its music playing ability and its 20-key SureType keyboard, while impressive technology, was slower to type on than a QWERTY keyboard. With the Curve, RIM appeared to be trying to correct these problems.

The video-capable camera is 2 megapixels, which is an improvement, but it's a long way from the best in phone cameras. The Curve also lets you use standard headphones, although listening on the 8330 confirms our belief that all-in-one devices are not the way to go if you care at all about music. The 8330 sounds tinny and digital. That said, it's fine for spoken-word recordings.

The QWERTY keyboard is good, a definite improvement over the Pearl's Sure-Type keyboard, although the keyboard on the Motorola Q 9h is marginally better if only because bigger.

The Q 9h, a Windows Mobile device often compared to the Curve, is bigger all over, although slightly thinner. The Curve, in fact, is nothing if not a marvel of miniaturization: 4.2 x 2.4 x 0.6 inches (107x15.5mm) and about 3.9 ounces (111g).

We still like the screen, a backlit TFT LCD (240 x 320 pixels, 65,000 colors). And we like the fact that the Curve includes a microSD card slot (in the battery compartment). But my goodness! Could they not have included at least a 1GB card? Two-gigabyte microSDs sell for as little as $15 online, so how much would RIM (or Verizon) have to pay for bulk purchase 1GB cards?

For more about the generally excellent Curve interface and RIM-provided bundled software - about which there is little new to add - see our original review.

We had heard complaints recently about voice quality on BlackBerries in general, so wanted to pay closer attention when making calls on the 8330. The trouble is, there are a few variables involved. At the simplest level, is it the network or is it the device?

We tested the 8330 on the Telus network in Canada. Yes, it did sound a bit tinny and digital - hmmm, didn't we just say that about music playback? - but all the calls were perfectly clear and audible. The Curve, as noted in the original review, also has a pretty decent, relatively distortion-free speaker phone. And it works well with Bluetooth hands-free headsets.

One of the things we particularly wanted to test on the 8330 was its performance as a tethered modem on the EVDO network, providing - or so RIM and operators claim - broadband wireless connectivity for laptops. After all, who needs a PC card modem, or even a Boingo Wi-Fi subscription, if they have a phone that can do the job?

Tuesday, October 23, 2007

How to detect Proxy Settings for Internet Connection

ava SE 1.5 provides ProxySelector class to detect the proxy settings. If there is a Direct connection to Internet the Proxy type will be DIRECT else it will return the host and port.

Example below illustrates this functionality:

public class testProxy {

public static void main(String[] args) {
try {

System.setProperty("java.net.useSystemProxies","true");
List l = ProxySelector.getDefault().select(
new URI("http://www.yahoo.com/"));

for (Iterator iter = l.iterator(); iter.hasNext(); ) {

Proxy proxy = (Proxy) iter.next();

System.out.println("proxy hostname : " + proxy.type());

InetSocketAddress addr = (InetSocketAddress)
proxy.address();

if(addr == null) {

System.out.println("No Proxy");

} else {

System.out.println("proxy hostname : " +
addr.getHostName());

System.out.println("proxy port : " +
addr.getPort());

}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Friday, October 19, 2007

How to use Robot class in Java

Java.awt.Robot class is used to take the control of mouse and keyboard. Once you get the control, you can do any type of operation related to mouse and keyboard through your java code. This class is used generally for test automation.

This sample code will show the use of Robot class to handle the keyboard events. If you run this code and open a notepad then this code will write ‘hi budy’ in the notepad.

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class RobotExp {

public static void main(String[] args) {

try {

Robot robot = new Robot();
// Creates the delay of 5 sec so that you can open notepad before
// Robot start writting
robot.delay(5000);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_Y);

} catch (AWTException e) {
e.printStackTrace();
}
}
}

Thursday, October 18, 2007

Review: BlackBerry Pearl Skins

By Melissa Oxendale
June 27, 2007

Having a new BlackBerry Pearl on hand means it's time to try out some new accessories. I recently got some protective skins for the BlackBerry from RIM. And, being indecisive, I went with a three pack; this way, if my mood changes, so does my color of my Pearl.

To start off with, these skins ($9.99) do not cover the keys nor the screen. If you want the display covered, a screen protector will be needed. Although I was using a case that covered the Pearl before - with plastic for protection - I found I can type much better with the bare keys under my fingers.

As for the skins, protection really aren't their forte; they don't really protect the tender parts: screen, buttons, keys, or camera. They basically takes a black or silver Pearl and gives it a different hue.

The one big bonus, the skins don't slide around like the smooth Pearl is prone to do. On a slight down side, this means the skin sometimes picks up bits of dust and other particles lying around. So far, I've found a swift wipe and it comes clean.

Another side effect to the non-slide skins, they can be a little tougher to get in and out of one's pocket, especially tight ones as we ladies often have. This can be nice, no worries about the Pearl falling out, but can be a pain when trying to get the Pearl out fast to answer a call.

All of the buttons and needed plugs are left uncovered by the skin, as is the camera, offering easy access. If you truelly want them protected, you'll need a case in addition to the skin.

The back of each skin has BlackBerry written across it, otherwise there are no markings or writing on any of them. I noticed the skins were snug around the top and bottom, but just a little lose on the sides. This ensures the skins can come on and off fairly easily. However, sometimes I found my fingers catching on the sides when using the phone.

Overall, I really liked the skins, especially because they enabled me to personalize my BlackBerry to fit me.

Monday, October 15, 2007

Use of clone method - cloning objects

The reason for making a local copy of an object is if you’re going to modify that object and you don’t want to modify the caller’s object. If you decide that you want to make a local copy, you simply use the clone() method to perform the operation. For example, the standard library class ArrayList overrides clone(), so we can call clone() for ArrayList:
import java.util.*;

class Int {

private int i;

public Int(int ii) { i = ii; }

public void increment() { i++; }

public String toString() {
return Integer.toString(i);
}
}

public class DemoCloning {

public static void main(String[] args) {
ArrayList al = new ArrayList();

for(int i = 0; i < 10; i++ )
al.add(new Int(i));

System.out.println("al: " + al);

ArrayList al1 = (ArrayList)al.clone();

// Increment all al1's elements:
for(Iterator e = al1.iterator(); e.hasNext(); )
((Int)e.next()).increment();

// See if it changed al's elements:
System.out.println("al: " + al);
}
}

The clone() method produces an Object, which must then be recast to the proper type. This example shows how ArrayList’s clone() method does not automatically try to clone each of the objects that the ArrayList contains—the old ArrayList and the cloned ArrayList are aliased to the same objects. This is often called a shallow copy, since it’s copying only the “surface” portion of an object. The actual object consists of this “surface,” plus all the objects that the references are pointing to, plus all the objects those objects are pointing to, etc. This is often referred to as the “web of objects.” Copying the entire mess is called a deep copy. You can see the effect of the shallow copy in the output, where the actions performed on al1 affect al:

al: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
al: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Friday, October 12, 2007

BlackBerry Pearl Coming to Sprint, Verizon Soon

By James Alan Miller
November 1, 2007
Click to View
For over a year, you’ve only been able to get the BlackBerry Pearl through GSM carriers like T-Mobile and AT&T Wireless, leaving customers of operators like Verizon Wireless and Sprint out of luck. This will change soon. Both of America's two largest CDMA operators are both slated to ship this smartphone this month.

First up is Verizon, which is now taking pre-orders for the BlackBerry Pearl 8130. Verizon is due to ship the 8130 on November 8th for $200 with 2 year contract after discounts.



As for Sprint, it is supposed to start offering the Pearl a couple of weeks later, on November 23rd, the same day it is rumored the carrier will start shipping its latest Motorola Q model, the Q9c. There's been no word yet regarding Sprint's asking price for the Pearl.

Here's what we know about the Verizon/Sprint Pearl so far:

It will support those carriers’ EV-DO 3G data networks, far faster than the 2.5G EDGE technology used by Pearls from the GSM operators. It also integrates GPS to support location-based services.

The Pearl 8130 measures 4.2 x 1.97 x .55 inches and weighs 3.4 ounces, slightly heaver than the GSM Pearl, the 8100, which only hits 3.1 ounces on the scale.

RIM says the Pearl 8130's battery last 9 days in standby to the 8100's 15 days and 220 minutes of talk time, the same as the GSM version.



As with the 8100 the 8130 sports a microSD expansion slot. It supports the SDHC variety of microSD card, which currently top out at 4GB and will someday reach 32GB. There's also 64MB f internal Flash memory.

For picture and video there's a 2 megapixel camera with what RIM is calling an enhanced flash. There's a 3.5mm stereo headset jack and support for Bluetooth stereo audio.

Verizon says it will carry the 8130 in silver. Sprint will offer it in amethyst.

Wednesday, October 10, 2007

Merge Sort Implementation in Java

In computer science, merge sort or mergesort is a sorting algorithm for rearranging lists (or any other data structure that can only be accessed sequentially, e.g. file streams) into a specified order. It is a particularly good example of the divide and conquer algorithmic paradigm. It is a comparison sort.

Conceptually, merge sort works as follows:

1. Divide the unsorted list into two sublists of about half the size
2. Sort each of the two sublists
3. Merge the two sorted sublists back into one sorted list.

The algorithm was invented by John von Neumann in 1945.

The following code shows how to implement merge sort in Java.
/**
* Mergesort algorithm.
* @param a an array of Comparable items.
*/
public static void mergeSort( Comparable [ ] a ) {
Comparable [ ] tmpArray = new Comparable[ a.length ];
mergeSort( a, tmpArray, 0, a.length - 1 );
}

/**
* Internal method that makes recursive calls.
* @param a an array of Comparable items.
* @param tmpArray an array to place the merged result.
* @param left the left-most index of the subarray.
* @param right the right-most index of the subarray.
*/
private static void mergeSort( Comparable [ ] a, Comparable [ ] tmpArray,
int left, int right ) {
if( left < right ) {
int center = ( left + right ) / 2;
mergeSort( a, tmpArray, left, center );
mergeSort( a, tmpArray, center + 1, right );
merge( a, tmpArray, left, center + 1, right );
}
}

/**
* Internal method that merges two sorted halves of a subarray.
* @param a an array of Comparable items.
* @param tmpArray an array to place the merged result.
* @param leftPos the left-most index of the subarray.
* @param rightPos the index of the start of the second half.
* @param rightEnd the right-most index of the subarray.
*/
private static void merge( Comparable [ ] a, Comparable [ ] tmpArray,
int leftPos, int rightPos, int rightEnd ) {
int leftEnd = rightPos - 1;
int tmpPos = leftPos;
int numElements = rightEnd - leftPos + 1;

// Main loop
while( leftPos <= leftEnd && rightPos <= rightEnd )
if( a[ leftPos ].compareTo( a[ rightPos ] ) <= 0 )
tmpArray[ tmpPos++ ] = a[ leftPos++ ];
else
tmpArray[ tmpPos++ ] = a[ rightPos++ ];

while( leftPos <= leftEnd ) // Copy rest of first half
tmpArray[ tmpPos++ ] = a[ leftPos++ ];

while( rightPos <= rightEnd ) // Copy rest of right half
tmpArray[ tmpPos++ ] = a[ rightPos++ ];

// Copy tmpArray back
for( int i = 0; i < numElements; i++, rightEnd-- )
a[ rightEnd ] = tmpArray[ rightEnd ];
}

Tuesday, October 09, 2007

Red-Black Tree Implementation in Java

A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science, typically used to implement associative arrays. The original structure was invented in 1972 by Rudolf Bayer who called them "symmetric binary B-trees", but acquired its modern name in a paper in 1978 by Leo J. Guibas and Robert Sedgewick. It is complex, but has good worst-case running time for its operations and is efficient in practice: it can search, insert, and delete in O(log n) time, where n is the number of elements in the tree.

A red-black tree is a special type of binary tree, which is a structure used in computer science to organize pieces of comparable data, such as numbers. Each piece of data is stored in a node. One of the nodes always functions as our starting place, and is not the child of any node; we call this the root node or root. It has up to two "children", other nodes to which it connects. Each of these children can have children of its own, and so on. The root node thus has a path connecting it to any other node in the tree.

If a node has no children, we call it a leaf node, since intuitively it is at the periphery of the tree. A subtree is the portion of the tree that can be reached from a certain node, considered as a tree itself. In red-black trees, the leaves are assumed to be null or empty.

As red-black trees are also binary search trees, they must satisfy the constraint that every node contains a value greater than or equal to all nodes in its left subtree, and less than or equal to all nodes in its right subtree. This makes it quick to search the tree for a given value.

The following code shows how to implement a red-black tree in Java:
// RedBlackTree class
//
// CONSTRUCTION: with a negative infinity sentinel
//
// ******************PUBLIC OPERATIONS*********************
// void insert( x ) --> Insert x
// void remove( x ) --> Remove x (unimplemented)
// Comparable find( x ) --> Return item that matches x
// Comparable findMin( ) --> Return smallest item
// Comparable findMax( ) --> Return largest item
// boolean isEmpty( ) --> Return true if empty; else false
// void makeEmpty( ) --> Remove all items
// void printTree( ) --> Print all items
// ******************ERRORS********************************
// Exceptions are thrown by insert if warranted and remove.

/**
* Implements a red-black tree.
* Note that all "matching" is based on the compareTo method.
* @author Mark Allen Weiss
*/
public class RedBlackTree {
/**
* Construct the tree.
*/
public RedBlackTree( ) {
header = new RedBlackNode( null );
header.left = header.right = nullNode;
}

/**
* Compare item and t.element, using compareTo, with
* caveat that if t is header, then item is always larger.
* This routine is called if is possible that t is header.
* If it is not possible for t to be header, use compareTo directly.
*/
private final int compare( Comparable item, RedBlackNode t ) {
if( t == header )
return 1;
else
return item.compareTo( t.element );
}

/**
* Insert into the tree.
* @param item the item to insert.
* @throws DuplicateItemException if item is already present.
*/
public void insert( Comparable item ) {
current = parent = grand = header;
nullNode.element = item;

while( compare( item, current ) != 0 ) {
great = grand; grand = parent; parent = current;
current = compare( item, current ) < 0 ?
current.left : current.right;

// Check if two red children; fix if so
if( current.left.color == RED && current.right.color == RED )
handleReorient( item );
}

// Insertion fails if already present
if( current != nullNode )
throw new DuplicateItemException( item.toString( ) );
current = new RedBlackNode( item, nullNode, nullNode );

// Attach to parent
if( compare( item, parent ) < 0 )
parent.left = current;
else
parent.right = current;
handleReorient( item );
}

/**
* Remove from the tree.
* @param x the item to remove.
* @throws UnsupportedOperationException if called.
*/
public void remove( Comparable x ) {
throw new UnsupportedOperationException( );
}

/**
* Find the smallest item the tree.
* @return the smallest item or null if empty.
*/
public Comparable findMin( ) {
if( isEmpty( ) )
return null;

RedBlackNode itr = header.right;

while( itr.left != nullNode )
itr = itr.left;

return itr.element;
}

/**
* Find the largest item in the tree.
* @return the largest item or null if empty.
*/
public Comparable findMax( ) {
if( isEmpty( ) )
return null;

RedBlackNode itr = header.right;

while( itr.right != nullNode )
itr = itr.right;

return itr.element;
}

/**
* Find an item in the tree.
* @param x the item to search for.
* @return the matching item or null if not found.
*/
public Comparable find( Comparable x ) {
nullNode.element = x;
current = header.right;

for( ; ; ) {
if( x.compareTo( current.element ) < 0 )
current = current.left;
else if( x.compareTo( current.element ) > 0 )
current = current.right;
else if( current != nullNode )
return current.element;
else
return null;
}
}

/**
* Make the tree logically empty.
*/
public void makeEmpty( ) {
header.right = nullNode;
}

/**
* Print all items.
*/
public void printTree( ) {
printTree( header.right );
}

/**
* Internal method to print a subtree in sorted order.
* @param t the node that roots the tree.
*/
private void printTree( RedBlackNode t ) {
if( t != nullNode ) {
printTree( t.left );
System.out.println( t.element );
printTree( t.right );
}
}

/**
* Test if the tree is logically empty.
* @return true if empty, false otherwise.
*/
public boolean isEmpty( ) {
return header.right == nullNode;
}

/**
* Internal routine that is called during an insertion
* if a node has two red children. Performs flip and rotations.
* @param item the item being inserted.
*/
private void handleReorient( Comparable item ) {
// Do the color flip
current.color = RED;
current.left.color = BLACK;
current.right.color = BLACK;

if( parent.color == RED ) // Have to rotate
{
grand.color = RED;
if( ( compare( item, grand ) < 0 ) !=
( compare( item, parent ) < 0 ) )
parent = rotate( item, grand ); // Start dbl rotate
current = rotate( item, great );
current.color = BLACK;
}
header.right.color = BLACK; // Make root black
}

/**
* Internal routine that performs a single or double rotation.
* Because the result is attached to the parent, there are four cases.
* Called by handleReorient.
* @param item the item in handleReorient.
* @param parent the parent of the root of the rotated subtree.
* @return the root of the rotated subtree.
*/
private RedBlackNode rotate( Comparable item, RedBlackNode parent ) {
if( compare( item, parent ) < 0 )
return parent.left = compare( item, parent.left ) < 0 ?
rotateWithLeftChild( parent.left ) : // LL
rotateWithRightChild( parent.left ) ; // LR
else
return parent.right = compare( item, parent.right ) < 0 ?
rotateWithLeftChild( parent.right ) : // RL
rotateWithRightChild( parent.right ); // RR
}

/**
* Rotate binary tree node with left child.
*/
private static RedBlackNode rotateWithLeftChild( RedBlackNode k2 ) {
RedBlackNode k1 = k2.left;
k2.left = k1.right;
k1.right = k2;
return k1;
}

/**
* Rotate binary tree node with right child.
*/
private static RedBlackNode rotateWithRightChild( RedBlackNode k1 ) {
RedBlackNode k2 = k1.right;
k1.right = k2.left;
k2.left = k1;
return k2;
}

private static class RedBlackNode {
// Constructors
RedBlackNode( Comparable theElement ) {
this( theElement, null, null );
}

RedBlackNode( Comparable theElement, RedBlackNode lt, RedBlackNode rt ) {
element = theElement;
left = lt;
right = rt;
color = RedBlackTree.BLACK;
}

Comparable element; // The data in the node
RedBlackNode left; // Left child
RedBlackNode right; // Right child
int color; // Color
}

private RedBlackNode header;
private static RedBlackNode nullNode;
static // Static initializer for nullNode
{
nullNode = new RedBlackNode( null );
nullNode.left = nullNode.right = nullNode;
}

private static final int BLACK = 1; // Black must be 1
private static final int RED = 0;

// Used in insert routine and its helpers
private static RedBlackNode current;
private static RedBlackNode parent;
private static RedBlackNode grand;
private static RedBlackNode great;


// Test program
public static void main( String [ ] args ) {
RedBlackTree t = new RedBlackTree( );
final int NUMS = 400000;
final int GAP = 35461;

System.out.println( "Checking... (no more output means success)" );

for( int i = GAP; i != 0; i = ( i + GAP ) % NUMS )
t.insert( new Integer( i ) );

if( ((Integer)(t.findMin( ))).intValue( ) != 1 ||
((Integer)(t.findMax( ))).intValue( ) != NUMS - 1 )
System.out.println( "FindMin or FindMax error!" );

for( int i = 1; i < NUMS; i++ )
if( ((Integer)(t.find( new Integer( i ) ))).intValue( ) != i )
System.out.println( "Find error1!" );
}
}


/**
* Exception class for duplicate item errors
* in search tree insertions.
* @author Mark Allen Weiss
*/
public class DuplicateItemException extends RuntimeException
{
/**
* Construct this exception object.
*/
public DuplicateItemException( )
{
super( );
}
/**
* Construct this exception object.
* @param message the error message.
*/
public DuplicateItemException( String message )
{
super( message );
}
}

Sunday, October 07, 2007

ser Guide Presents Overview of New BlackBerry Facebook Application

By James Alan Miller
November 8, 2007
Click to View
RIM surprised many a couple of weeks ago with the welcome introduction of an application to access Facebook from a BlackBerry. The blog BBGeeks.com has posted a comprehensive overview of this software. If you're interested in downloading Facebook to your BlackBerry, you may want to check it out first.

Keep in mind, RIM's Facebook app is initially only available to T-Mobile customers. And the software only supports devices running on BlackBerry OS 4.2 or greater.

It should ship with the new BlackBerry Pearl 8130 when it becomes available from Verizon and Sprint later this month, however. After all, the version of this new BlackBerry offered by Telus in Canada has it.

In addition to RIM's standard array of push e-mail and personal information management software, the new BlackBerry will be pre-loaded with RIM's new Facebook application, which allow you to tag and upload images, poke and message your Facebook friends, add new friends, check the status of your friends, etc.

Here's some of things you can do with Facebook for BlackBerry:

With it, Facebook users can wirelessly send and view messages, photos, pokes and Wall posts. And, as with BlackBerry-based e-mail, Facebook notifications are pushed to the user's smartphone. It also allows users to take a picture, upload it to Facebook with captions and tags; send out invitations to friends; as well as manage events, photo albums, and status.

The Facebook application isn't browser based. Rather, it runs directly on a BlackBerry, which is more efficient and allows RIM to better integrate the new software into its BlackBerry architecture.

As for Facebook, it is the number two social networking destination, behind MySpace, and falls well within the top ten for all sites on the Web.

Friday, October 05, 2007

Character Escape Codes in Java

provides escape sequences for several non-graphical characters. All characters can be specified as a hexidecimal Unicode character (\uxxxx) with some as an octal character (\ddd where the first d is limited to 0-3, and the others 0-7 - same as \u0000-\u00ff).

\n New line
\t Tab
\b Backspace
\r Carriage return
\f Formfeed
\\ Backslash
\' Single quotation mark
\" Double quotation mark
\d Octal
\xd Hexadecimal
\ud Unicode character