4/29/2016

iMessage not working over LTE/3G

I can't believe there are certain things that Apple has been so stupid about. Needless to say the iMessage fiasco. But wait, there is more.

There is no Cellular Data setting for Messages - the app that handles your SMSs. However, the USP of the app is that it intercepts your messages and sends them over a data connection to the recipient's Apple Id, when both sender and receiver are registered for iMessages.

However, whether to use SMS service or data, is determined based on sender's connection state, not on recepient's. That's STUPID.  Imagine you're out in the woods where there is no wifi or cellular data available. Or maybe you turned off data because you were about to cross the monthly limit.
Now, a friend, who is also registered for iMessage, sends you a message. Guess what! you will NOT receive the message until you get a working data connection.

And if that's not stupid enough, get this. To bypass the problem I just described above, you may decide to turn on Cellular Data, just for iMessages. But there is no such option. NONE.

Alternatively, you could also fall into another trap. You turn on Cellular Data assuming thats all it takes for iMessages to work. WRONG AGAIN.



Turns out that the Settings app needs a data connection enabled, if you ever want iMessages to work reliably.

Now who would have thought that ....


10/23/2015

This Week at Apple Store


Interesting week this was for my Apple devices. 

Event 1

My iPhone 5S's home button crumbled under it's own weights. Lucky, it was still under warranty. But wait, mine was a Insurance Replaced Unit and the Genius told me if there was any 3rd party modification done on internals, the warranty would be invalid and I would have to pay for repair. Interesting that we must give consent to this even before they open-up the device.

I took the chance. It took the Geniuses 3 hours to find that 
  1. The warranty was valid.
  2. Device couldn't be repaired.
  3. Device must be replaced.
At least I came back with a new working device.

Event 2

Much has been written about the Apple Refurbished program. Hey you get a like new device for a bit less. Then Why not!


Beware, as you must always, the devices could still be possessed by the angry souls of their previous owners, despite all the Apple Kaboom wash.

As you can see in this video that I uploaded, my iPad had a mind of it's own.


Good thing, I took it to an Apple Store where a Genius opined that "Refurbished" weren't really worth it :)

Note that, per Apple, refurbished items go through the same quality control as new items.
Sorry Apple, but something isn't right about that statement.


10/05/2015

Apple Pay at Macy's (Freehold) - NO GO

If cashier can't tell Apple Pay from Pay Pal you know there is a problem.
The indicator at the NFC payment terminal was green and the phone beeped and vibrated
but no payment was registered. I tried it a few times, got frustrated. The cashier was not sure how 'phone' payments work. So I took out my card and swiped the old fashioned way.

Macy's was one of the first stores to support Apple Pay and it's been about a year since then.
Also, this method of payment is anything but faster. Every store where it "worked" required me to select Credit/Debit and then sign using the stylus.

So if you still remember the "demo" http://www.cnet.com/videos/apple-pay-demo-on-iphone-6-and-new-ipad/, just remember this is NOT how it works in real life.

UPDATE:

9/23/2015

How to not use Apple Maps in iOS9


It might be a subtle way to push users to Apple's own Maps app. The option to pick one of other Routing apps (e.g. Google Maps) have been pushed down. One needs to open the share sheet and tap "Routing Apps". 




9/20/2015

Disable news from iOS 9 Proactive search

Hey, who is not annoyed by the "News Suggestions" in the new Proactive search in iOS9?



Just go to "Spotlight Search" in settings and disable "Spotlight Suggestions"


7/02/2015

iOS WiFi Network Selection

It's a shame that iOS doesn't have a provision to set priority on WiFi networks. In case there are multiple networks available, there is no guarantee that the strongest network will be chosen. In my case it was between optimumwifi, the public network and my private network. My iPhone would always prefer connecting to the weaker network. How annoying!

So I renamed my private network to optimulwifi, just to make it appear before optimumwifi in alphabetical ascending order. And so far, that seems to have "fixed" it. 

11/05/2013

Activate Nexus 5 on a Secondary Sign-On Wifi Network

Google's newest gadget in town, that I ordered within a few minutes of its launch, landed in my hands a few minutes ago.

That was quite fast. But wait...

I turned on the device, and after a few clicks it wanted to connect to a WiFi network. So I happpily selected the access point that I normally use.

There comes the catch ...

My WiFi network has a secondary sign-on meaning after connecting to the network, one needs to open a web-page and enter some information. It's only after that the Internet Connection is established.

However ...

The OS hadn't finished the initial setup so none of the apps were available. There was no way to launch Chrome which made it a chicken and egg situation. How to sign-on to the WiFi?

Well... Here's the how-to.

There is a Terms & Conditions screen that comes right after you select the WiFi network. In it lies a door!

There are two hyperlinks on the T&C page. Click on of those and it should open ... your WiFi login page! Awesome, isn't it.

Not yet...

You cannot enter any text on this page. Buttons can be clicked, thankfully.

There's a way out...

Long press on the text field. That should open the Cut/Copy/Paste/Share controls. Click the Share button and select Gmail.

It's getting weird. Gmail! No internet yet, remember!

Android will ask for your Gmail credentials. Enter them NOT!

Instead enter your WiFi credentials that you use on the Secondary authentication page, all on the same line separated by a space. So, in the Gmail Id field you will enter
wifiuser wifipassword .

Long press on the text field and select+copy the entire text. Now cancel/go back to the T&C screen. Click one of the hyperlinks and on the WiFi login page that opens, paste the just copied value by long pressing on a text field. Your 'wifiuser wifipassword' is now in one text field. Once again, use the long press to split this text and user/password paste into their own respective boxes.

And click your way to Internet!
























7/06/2013

Making AirPlay work with Raspbmc (Mac OS X)

Raspbmc, the Raspberry PI port of the popular XBMC software allows the Pi to receive AirPlay audio content (e.g. from iTunes).

To make this work you need to change XBMC settings to allow AirPlay content.
Go to Settings - Services - AirPlay and enable "Allow XBMC to receive AirPlay content".

Once you do this, Pi will show up as an AirPlay device.



Click XBMC and you get this error:

"An error occurred while connecting to the AirPlay device
"XBMC (raspbmc). An unknown error occurred (-15000).



To fix this, on your Mac go to
Settings - Sound - Output and select XBMC as the output.


And voila!


Linux raspbmc 3.6.11 #2 PREEMPT Sat Jun 15 21:45:28 UTC 2013 armv6l GNU/Linux
OSX 10.8.4
iTunes 11.0.4



1/05/2013

Making Pogoplug work with OS X Mountain Lion

Samba 2 are shares not accessible from Mac OS X Mountain Lion 10.8.2
"The version of the server you are trying to connect to is not supported."

I am using Pogoplug (E02)  2.6.22.18 #81 armv5tejl + optware as my NAS and I have mounted a 1 TB NTFS drive on it, along with a 16 GB Ext3 drive to host optware. I exported these mount points using Samba. Both these drives are R/W accessible from Windows. Not from Mac. It seems that Mac OS X Lion has withdrawn support for earlier versions of Samba.

There is a workaround. NFS comes to rescue:
(The recommended package nfs-utils is not available for optware, hence I used unfs3)

bash-3.2# ipkg install unfs3 portmap

mkdir /opt/etc/unfs
touch /opt/etc/unfs/exports

Add volumes to be shared in 'exports' file; a sample file looks like this:

cat /opt/etc/unfs/exports
/mnt 192.168.1.0/10(rw,no_root_squash)

1.0/10 : Specifies the range of IPs allowed to access the exported resources.

To start:
bash-3.2# /opt/sbin/portmap
bash-3.2# /opt/sbin/unfsd -e /opt/etc/unfs/exports

To view exported volumes on Client: (192.168.1.5 is the IP of the server)

macair:~ as$ showmount -e 192.168.1.5
Exports list on 192.168.1.5:
/mnt                                192.168.1.0/24

Credits:

http://www.openstora.com/wiki/index.php?title=Installing_userland_NFS_(UNFSD)
http://www.nslu2-linux.org/wiki/Optware/Unfs3

With these settings, shared content will be read-only when accessed from Mac. (NFS works best with a central user directory... but that's an overkill on a home network). If you need to be able to modify a file, use sudo.

There is another great app called muCommander which allows you to browse different kinds of networks. Interestingly, where Mac OS X declined to mount Samba shares, muCommander worked.



12/19/2012

Disappointed in Mac (but more in Win 8)

I have been looking for a new laptop. My current one is a (HP) Compaq Presario, bought in 2003.
Still running strong on WinXP, I upgraded the Disk and RAM midway.



I can tell about this model - the exterior build quality was not good. But the computer was damn fine. So before you make arguments about Mac's build quality, note that exterior and interior are two different things. Mac's do have better exterior quality, all five of them. Interiors - they are all the same - if you know what you are buying.



The hottest new item in the Mac world is the Retina display, so I wanted to check it out. Crisp fonts and lovely, bright screen. I was sold.

But wait!

Crisp fonts yes, but Windows always have had crisp fonts. It's only Mac's fonts which need Retina. Don't give me the true-to-design argument. I don't want it to be fuzzy on my monitor. If Mac users have gotten used to it, good for them. I will not settle for less.

Retina is great, but a 1920x1080 on Windows will do just as fine.

Don't even get me started on Finder. Explorer beats it any day. Explorer is what is Simple and Intuitive. Mac's philosophy is 'Machine knows better than you'. In other words - users are dumb.

Mac (OS X) is "Intuitive". Really! Name ONE function which more "intuitive" in Mac than in Windows.

Windows beats Mac just on the software choices alone. For one $30 Mac package, there will be at least 10 Windows programs, 5 of them - free/open source.

Apple made great products in iPad and iPhone. Their hardware is nice, exterior build is top notch. But OS is a letdown. Preciesly why bootcamp was needed.


Update 12/24/2012

Ordered myself a MacBook Air.




It was a tough call between Retina and Air. In the end the $300, performance and weightlessness of the Air won me over.

Got mine for USD 1299 + 95 (3 Year Apple Care) + Free Parallels from BHPhotoVideo.com

Now, all my criticisms of Mac are still valid. Windows 8 however, is a disgrace to design. I have 'tried' many laptops over the last few weeks but none felt as solid as one from Apple. All you get are poor touchpads, ergonomics and confusing user experience (in contrast to Windows 7). One might get a 1080p display, though Windows doesn't scale it the way Apple scales it on Retina. What that means is that higher the resolution, smaller the text. My other complaint with PCs is the 16:9 aspect. A laptop is not a TV, for Christ's sake. A 16:10 such as that on Air still gives a more useful work-area on the screen.







12/15/2012

Getting started with Raspberry Pi (without needing a separate keyboard)

The wonderful little Raspberry Pi



Purchased from http://www.newark.com/


RASPBRRY-MODB-512M - MODEL B


  •  Silicon Manufacturer: Broadcom
  •  Core Architecture: ARM
  •  Core Sub-Architecture: ARM11
  •  Silicon Core Number: BCM2835
  •  Kit Contents: Assembled Board Only
  •  RoHS Compliant: Yes

Ports on Board:
  • Ethernet
  • 2 USB
  • 1 Micro USB for power (5v 1A)
  • 1 HDMI (full-size)
  • GPIO
  • Coaxial Audio Out

Accessories required

SD Card
Full Size SDHC Card  minimum 2 GB storage (I used 4 GB Kingston MicroSD with Adapter). The advantage of MicroSD over SD is that you can swap it out eassily while the adapter stays put in the motherboard.

Power Adapter
I have used the Nexus 7 Power adapter with ratings 5V 2A. RPi is finicky about power so  choose a "good" power source.

HDMI Cable
Bought it real cheap from Amazon.  HDMI Cable Link

TV/Display
For your visual gratification only.

Keyboard
Not really required, I will explain how your existing computer's keyboard can be used.

Ethernet Cable
Required.

Router and Internet Connection
Your existing Wireless Router should work.

Installation

Download the Raspbian Wheezy image from http://www.raspberrypi.org/downloads and write it to the SD card. Instructions are given on the download page.

Plug the HDMI cable into your Display and the other end into RPi.

Plug the Ethernet cable into RPi and the other end into one of LAN ports available on the router.

Slide the SD Card into RPi.

Power on the Display.

Attach the MicroUSB power cable and power it on.

You will see some text scrolling on your display. 

The first time boot will end up in a "blue" raspi-config screen asking you to configure some settings. But, hey, there is no keyboard! 

Before you can use PuTTy, you need to find the IP of RPi. If you can access the admin console of your router (usually available at http://192.168.1.1) navigate around and find the page when all computers in the network are shown.
In my case the RPi shows up as

PC Name:raspberry
Connection Type:
Ethernet
IP Address:192.168.1.6
Status:Active

Now start putty and SSH your way into RPi. Default user/password in given in the RPi download page.
After you have successfully logged in, run the following:

raspi-config

This will open up the same window which is showing up on your display right now. Use Tab, Up/Down and Enter keys to make your selections.

Most important are:
  • Resize Partitions to fill the space.
  • Enable SSH on startup.
  • Desktop Mode.
Make your selection and reboot. RPi will restart and your SSH connection will be lost. When it boots up, you have to reconnect using PuTTy.

Now you can install some utilities.

To be able to connect to other shared folders on the network.
apt-get install cifs-utils
To be able to remotely control the RPi User Interface (that's how you don't need a Keyboard!)
apt-get install x11vnc
Light DM
apt-get install lightdm
During the installation of LightDM, it will prompt you to choose a default login-manager. Use LightDM.

Reboot. (reboot command on PuTTy).

Once RPi is back up, reconnect PuTTy. (Meanwhile, your display should have a Login screen, asking you to enter User Id).

Execute this command on PuTTy:

x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage

You also need to install a Vncviewer on your computer. I used TightVNC http://tightvnc.com/download.php

Start the VNC Viewer on your computer. There would be an option to enter the Remote Host information.
Specify 192.168.1.6::5900

Note the IP 192.168.1.6 is same as the IP of RPi that we found out earlier.

This will take you straight to the Linux UI where you need to enter the UserId and Password. Whatever you do on your computer int the VNC Viewer window will also be visible on the Display attached to RPi. (See, no extra keyboard necessary!).

For playing Audio/Video on your Display/TV use this command from the PuTTy window:

omxplayer -o hdmi /path/to/your/media/file

And voila.

Want more fun, install the VNC Viewer App from Android Market on your Phone/Tablet.
Want even more fun, install XBMC, the full feature media console. We'll talk about that some other time.




















  






8/09/2012

JAX-WS client throwing java.lang.NoClassDefFoundError: com/sun/xml/ws/spi/ProviderImpl

I had generated and tested my JAX-WS client using Weblogic 10 libraries on Java 6 update 16.
Tested this on JRE Update 25, no additional jars were required. Not even wseeclient or wlclient. Apparently the default JAX-WS runtime was doing its job.

However, when I tried to run the same application on JDK 6 update 10, I got the following:


Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/ws/spi/ProviderImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:630)
....

Apparently com/sun/xml/ws/spi/ProviderImpl was nowhere to be found. On some forums I found that this could be resolved by using "endorsed" option. For some reason that didn't work for me  and I kept getting the same error.

I tried to force-load the weblogic provider, but in vain. Same error. Needless to say this was very annoying and I was almost on the verge of switching to Axis.


So, as a last resort, I tried to do things the old fashioned way. Downloaded the JAX-WS RI (http://jax-ws.java.net/2.1.3/) .


Added libraries to classpath as given in its installation guide. No endorsements, just plain old classpath.

And voila. It worked like charm.



So I'm thinking if Java is turning into a Jar hell (as opposed to the DLL hell). Java definitely need a better way to manage library dependency something like Maven. Right now, if it's not for Google, some problems will never get fixed!


5/02/2012

Restoring iPad after password lock-out.

Restoring an iPad after its password is lost and account locked out. (Repeated attempts to log-in with wrong passwords result in lock-out).

I tried this on iPad 64 GB Wifi+3G First Generation model. Should work on other models too.

THE EASY WAY: The easy way out of this situation is to use iTunes to reset the password,  however this works when done from the same computer which was used for last sync.

THE HARD WAY: This invariably erases everything on the device and installs the latest version of iOS.

Here's how-to:
  1. Plug iPad into your computer, open iTunes. Note that iTunes would either not recognize the iPad or decline to read it as it is locked-out.
  2. Press and hold Power and Home keys simultaneously on your iPad.
  3. When the "Slide to Power Off" screen comes up; release the Power Key. Continue holding the Home Key.
  4. When the Apple logo is displayed, release the Home Key.This would initiate the restoration and a message would be displayed in iTunes on your computer.
  5. Once you initiate the Restoration thru iTunes, it gets messier. This is when iTunes downloads the iOS software to your computer before the actual restoration begins.
  6. 10 out of 10 times, when iTunes tried to download the OS, it timed out. So I had to look for alternatives  like downloading the OS myself. (You can get the download links from osxdaily.com).Tried downloading the file using Chrome or IE - both s(t)uck! Then I used Download Accelerator (DAP), it was a breeze. Highly Recommended.
  7. Once you have the OS software (*.ipsw) on you local drive, go back to step 2 above.
  8. Just this time, hold the Shift Key down when you click the "Restore" button. This will let you use your downloaded"ipsw" files for restoration instead of trying to download it from Apple.
  9. Also, you should download the most recent version of OS software or you will run into a "1394" error. (There are some hacks to get around that too...).
  10. From here onwards - the existing software, data, music, games, movies and anything that was stored on the iPad before will be permanently erased and the new iOS will be installed. Not to mention, the password lock will also be gone.
To be able to download any apps on iPad or iTunes on your computer, you will need an Apple Id. However, the registration process "requires" that you put down your credit card details. Which is both ridiculous and ludicrous.

But there is hope. Only at the time of setting up a new Apple Id, you will have the option of not providing your Credit Card info. But if you have already created an Apple Id, and even though you can use that to log into the Apple Store, you would not be able to download any apps until you link a Credit Card to your account. Which is again both ridiculous and ludicrous. 

8/26/2008

What is going on with DATE and TIMESTAMP

What is going on with DATE and TIMESTAMP?

Prior to 9.2, the Oracle JDBC drivers mapped the DATE SQL type to java.sql.Timestamp. This made a certain amount of sense because the Oracle DATE SQL type contains both date and time information as does java.sql.Timestamp. The more obvious mapping to java.sql.Date was somewhat problematic as java.sql.Date does not include time information. It was also the case that the RDBMS did not support the TIMESTAMP SQL type, so there was no problem with mapping DATE to Timestamp.

In 9.2 TIMESTAMP support was added to the RDBMS. The difference between DATE and TIMESTAMP is that TIMESTAMP includes nanoseconds and DATE does not. So, beginning in 9.2, DATE is mapped to Date and TIMESTAMP is mapped to Timestamp. Unfortunately if you were relying on DATE values to contain time information, there is a problem.

There are several ways to address this problem:

*

Alter your tables to use TIMESTAMP instead of DATE. This is probably rarely possible, but it is the best solution when it is.
*

Alter your application to use defineColumnType to define the columns as TIMESTAMP rather than DATE. There are problems with this because you really don't want to use defineColumnType unless you have to (see What is defineColumnType and when should I use it?).
*

Alter you application to use getTimestamp rather than getObject. This is a good solution when possible, however many applications contain generic code that relies on getObject, so it isn't always possible.
*

Set the V8Compatible connection property. This tells the JDBC drivers to use the old mapping rather than the new one. You can set this flag either as a connection property or a system property. You set the connection property by adding it to the java.util.Properties object passed to DriverManager.getConnection or to OracleDataSource.setConnectionProperties. You set the system property by including a -D option in your java command line.

java -Doracle.jdbc.V8Compatible="true" MyApp

1/29/2008

Where does Linux stand today?

I have been running Windows last 7 years and I didn't have a single crash or virus infection. So, it depends on how one uses his/her computer. Of course I am a techie so that helps. I first installed Red Hat in 1999 and after that Ubuntu just earlier this month. Linux still has a long way to go. You Linux is just too much configurable and that would take its toll on average user. If you don't have Internet, forget that you can do anything with it and still keep it running.
There are 2 package managers on my system and one doesn't know what the other has installed. How do you install plug-ins for your browser, is it even close to how it works on Win. Or think about editing conf files manually or even to 'make'. Wow, its like Windows telling you to compile C code to make it work!

I am not bashing Linux or favoring Windows. I am just saying that there are zealots on the Linux side who are claiming left and right how infallible and Utopian Linux is. It is not. Someday it may be on par with Windows. Not today.

And the day it becomes as popular as Windows is today, only then you should compare how safe it is against viruses.
Today, it might seem safer but that's at the cost of usability. Linux is great for techies, who like to experiment with their system. Average users want a system that does all things a Windows system can do, out of the box.

1/28/2008

Desktop going slick for what?

With Visa going all slick and translucent with 3D rendering of windows and Linux
following suit and matching Microsoft, My question is simple... WHY!!!
What is the usefulness of these new adonrments. Really, are they anything more than attractive packaging. How do they make the computer more usable? And to top it off, they also need better (read expensive) hardware like memory and grpahics capabilities. Also hog the CPU. For what? Just so that the title bar is transparent, or you can see a window in 3D. Or that your desktop looks good. Really, how does that make you more productive? Unless you have a weird habit of ogling at your desktop, and you are concentrating more on how the windows' look than what they contain.
Give me a better word-processor, I can live with Win 95 decorations.

11/12/2007

Double Dispatch

A typical runtime polymorphism works on method invocations where the call is on supertype but the actual method comes from the runtime subtype. However, the method selection is not polymorphic in itself, meaning only the method whose signature exactly matches the signature of the call can be invoked.

Double dispatch is a way to achieve runtime polymorphism where method implementation is selected based on both the callee object and actual argument object.

e.g. Consider this class hierarchy:

class A { method(E){} method(F){} }<--class B<--class C
class E<-- class F


A, B, C have overloaded methods. Note that overloading is early-binding (compile-time polymorphism).

So, a call like

A a = new B();
E e = new F();
a.method(e);

would result in B.method(E) invocation. Which is a classic runtime polymorphism case. A double dispatch would however would result in B.method(F) invocation.

Implementation of Double Dispatch
The idea is to use reference-types for callee and the argument before the method call is dispatched to its implementation, as every invocation on the reference-type would show a runtime polymrphism.

In order to do this, we introduce a new method in E/F as follows:

method(A a) {
a.method(this);
}

and change the calling program to

A a = new B();
E e = new F();
e.method(a);


This would first dispatch the call to F's implementation of method(A) and from there B's implementation of the method where the argument type is F i.e. B.method(F) .

thats all we set out to do!

Visitor Pattern and Double Dispatch
A visitor pattern is applicabe where we want to add a method to elements of a object hierarchy without changing the classes of the constituents.

We add methods to the visitor not to the classes it visits. The visited objects call back the visitor passing themselves. The visitor would have implementations for all the classes it can visit.

In the example given above A,B,C act as visitors to E,F.
If you have added a new type (e.g. G) in the structure, all you need is to add a method that accepts that type as argument in one of the visitors or a new visitor (e.g. method(G){}) and this method will be invoked whenever an object of G is visited.

Typically, the methods take the following form

visitable.accept(visitor);
...
accept(Visitor vistitor) {
visitor.visit(this);
}

Which is analogous to

e.method(a);
...
method(A a) {
a.method(this);
}

10/01/2007

unix shellscript for renaming multiple files by removing a string from all filenames


# folder: no trailing slash $1
# str: string to remove $2

folder=$1
str=$2
echo $folder $str

files=`ls -1 $folder`
for file in $files ; do
echo $file
tc=`echo $file | sed s/$str//`
echo $tc
if [ -f $folder/$file ];
then
mv $folder/$file $folder/$tc
#echo $tc
#echo $folder/$file $folder/$tc
fi
done

exit 1

8/26/2007

Factory Method Pattern

If you are asked to create a simle factory for creating objects,
you would start (or rather end up ) with something like this:
ProductFactory {
Product getProduct(int case) {
if(case== 1)
return new getProduct1();
else
return new getProduct2();
}
}

However, more often than not, from a requester's perspective, the product that he is looking for will be more polished than 'new Product()' that is to say the 'new Product()' would undergo some process before it is delivered.
ProductFactory {
Product getProduct(int case) {
Product ins = null;
if(case== 1)
ins = new Product();
else
ins = new Product1();
doSomethingWithProduct(ins);
doSomethingElseWithProduct(ins);
return ins;
}
doSomethingWithProduct(AbstractProduct ... ) {
}
doSomethingElseWithProduct(AbstractProduct ... ) {
}
}

We are using AbstractProduct instead of the actual Product, why?
It's for the same reason that we prefer
List l = new ArrayList() to
ArrayList l = new ArrayList();

AbstractProduct is an abstraction of Product which is of interest to the factory and
its users. It makes sure the same factory can work when new Products are introduced as long as they are instances of the same abstraction. It also means the factory returns abstractions not actual implementations so users of this factory are also lightly coupled.
Once we have an implementation like above, it can be used as
ProductFactory pf = new ProductFactory();
pf.getProduct();

Observe that the factory is tightly coupled with actual implementations of Products.
Now consider introducing a new factory, so that a client (requester) has the option to choose one of these factories where he wants the product from. That choice should be construed as the Context in which the product is created/requested.
e.g. a Spreadsheet instance from MSOffice or one from OpenOffice. Client would makje a decision to go for one of these. The choice is basically boils down to selecting one of MSOfficeSpreadsheetFactory or OOfficeSpreadsheetFactory.
However, before the spreadsheet is returned, it should be assigned a default name and should also be saved in a temporary location (this post-process is henceforth referred as polishing). This has to happen irrespective of whether it is MSO or OO spreadsheet.
At this stage we will have these two factories:
class MSOfficeSpreadsheetFactory {
...
}
class OOfficeSpreadsheetFactory {
...
}

We can also see two methods working on spreadsheets:
assignName(Spreadheet ...){}
tempSave(Spreadsheet ...){}

As we can see these methods work on Spreadsheet (an abstraction like AbstractProduct)
so we should definitely abstract it out of MS and OO factory classes and thus make it reusable.
SpreadsheetFactory {
assignName(Spreadheet ... ) {
}
tempSave(Spreadheet ... ) {
}
}
MSOfficeSpreadsheetFactory extends SpreadsheetFactory {
Spreadsheet createSpreadsheet(int type) () {
Spreadsheet s = new Excel();
assignName(s);
tempSave(s);
}
}
}
OOfficeSpreadsheetFactory extends SpreadsheetFactory {
Spreadsheet createSpreadsheet(int type) () {
Spreadsheet s = new Calc();
assignName(s);
tempSave(s);
}
}

At this stage, the requester would look something like this:
MSOfficeSpreadsheetFactory msf =
new MSOfficeSpreadsheetFactory();
Spreadsheet spr1 = msf.createSpreadsheet(...);
OOfficeSpreadsheetFactory osf =
new OOfficeSpreadsheetFactory();
Spreadsheet spr2 = osf.createSpreadsheet(...);

If we abstract out createSpreadsheet(...) we can reduce our dependency on actual Factory implementations.
SpreadsheetFactory {
assignName(Spreadheet ... ) {
}
tempSave(Spreadheet ... ) {
}
public abstract Spreadsheet createSpreadsheet(...);
}
...
SpreadsheetFactory msf =
new MSOfficeSpreadsheetFactory();
Spreadsheet spr1 =
msf.createSpreadsheet(...);
SpreadsheetFactory osf =
new OOfficeSpreadsheetFactory();
Spreadsheet spr2 =
osf.createSpreadsheet(...);

So far so good. Lets take a moment and analyze where things could get complicated with this approach.
What happens when a new Factory is introduced and/or and new polishing procedure is introduced. This would require a change in the SpreadsheetFactory and all its concrete implementations as implementations are using superclass methods. We can work this out by moving the polishing out of implementations and thus leaving them responsible for creation alone.
Instead of invoking createSpreadsheet() which is implemented in the subclass
introduce another method getSpreadsheet() in SpreadsheetFactory. This moves back the creation control to the SpreadsheetFactory, the superclass.
SpreadsheetFactory {
assignName(Spreadheet ... ) {
}
tempSave(Spreadheet ... ) {
}
public Spreadsheet getSpreadsheet() {
Spreadsheet s = createSpreadsheet();
assignName(s);
tempSave(s);
return s;
}
abstract Spreadsheet createSpreadsheet();
}

What we gain from this approach:
The factory SpreadsheetFactory is not dependent on actual implementations of Spreadsheets. Still, the factory knows how to create and return implementations of Spreadsheets. How does that happen...
The factory is delegating the actual instantiation to its subclass. The subclass is selected by the requester (which is basically the Context selection). The SpreadsheetFactory class would not be impacted by addition of new implementations.
It's important to note that the essence of this pattern lies in how the factory should be designed so that the factory itself is not coupled with what it creates and hence can be used to create products depending on the context that it operates in. See it from the point of view of the getSpreadsheet() method, not from the point of view of the client.
This pattern is usually applied to scenarios where factories return a certain type of product.

8/15/2007

JavaBeans

JavaBeans technology is the component architecture for the Java Platform. The other component architecture is EJB, but JavaBeans and EJBs are entirely different beasts.

A JavaBean is a reusable software component. It is a Java class that defines properties and that communicates with other Beans via events. Properties can be defined within the JavaBean class definition, or they can be inherited from other classes. A Bean, however, is not required to inherit from any particular class or interface. The idea behind JavaBeans is to help develop and use reusable components and that is backed by specifications by which 'beans' abide. It's
the specification that ensures 'beans' integrability. Apart from the sepcificaitons, beans are just regular java classes (unlike ejbs!).

The major benifits of JavaBeans is that beans' properties can be manipulated in a visual builder tool like NetBeans. It can be simple, such as buttons, text fields, list boxes, scrollbars, and dialogs. Or they may be more complex software components to handle business logic or a spell-checker.

You certainly can use other pre-built objects in Java, but for that we must have an intimate knowledge of the object's interface at the code level. Additionally, you must integrate the object into your code programmatically.

JavaBeans components expose their own interfaces visually, enabling you to edit their properties without programming. Furthermore, you can use a visual editor to simply "drop" a JavaBeans component directly into an application without writing any code. This is an entirely new level of flexibility and reuse not previously attainable in Java alone.

The real value of JavaBeans is while designing/developing a software which uses these components, you can visually integrate these components with the rest of the system.The component need not be visible in a running application; they only need to be visible in the builder tools when the application is constructed by a builder tool. A programmer can move, query, or visually hook together components while operating a builder tool. Often, such components do their work while the application is running, though they are invisible to the user.

JavaBeans that represent graphical components and that are meant to be visible must inherit from a java.awt. Component such as the java.awt.Canvas class, so that they can be added to visual containers.

The following list briefly describes key bean concepts:

Introspection: Builder tools discover a bean's features (that is, its properties, methods, and events) by a process known as introspection. Beans support introspection in two ways:
By adhering to specific rules, known as design patterns, when naming bean features. The Introspector class examines beans for these design patterns to discover bean features. The Introspector class relies on the core reflection API.
By explicitly providing property, method, and event information with a related bean information class. A bean information class implements the BeanInfo interface. A BeanInfo class explicitly lists those bean features that are to be exposed to application builder tools.

Properties: Properties are the appearance and behavior characteristics of a bean that can be changed at design time. Builder tools introspect on a bean to discover its properties and expose those properties for manipulation.

Customization: Beans expose properties so they can be customized at design time. Customization is supported in two ways: by using property editors, or by using more sophisticated bean customizers.

Events: Beans use events to communicate with other beans. A bean that is to receive events (a listener bean) registers with the bean that fires the event (a source bean). Builder tools can examine a bean and determine which events that bean can fire (send) and which it can handle (receive).

Persistence: Persistence enables beans to save and restore their state. After changing a bean's properties, you can save the state of the bean and restore that bean at a later time with the property changes intact. The JavaBeans architecture uses Java Object Serialization to support persistence.

References:
java.sun.com  docs.rinet.ru  forum.java.sun.com

Property, Attribute and Field
(This is just an opinion and there is no Standard way of distinguishing the three.)
JavaBeans conventions for getters and setters allows us to expose properties. Those properties don’t have to be backed up by fields, but in many cases they are.
e.g. Circle's radius, diameter, circumference. We may have only one variable (field) 'radius' and can still expose all other properties. Attribute is more synonymous to Property.

References:
clintshank.javadevelopersjournal.com