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.