HTML5 WebSockets build Real Time Web

HTML5 WebSockets is a solution to drive the real time web. The common use case says a real time stock application, online collaboration (multi-user sketching)

Refer: http://websocket.org/quantum.html for the introduction of WebSockets.

Currently, only Google Chrome the client browser supports HTML5 WebSockets natively. There is also less server support for HTML5 WebSockets, since this specification still new. Jetty WebSocket Server is one of an open source solution built on top of Java EE.

iOS5 iCloud Storage API

Apple announced iCloud service part of the features built in with iOS5. iCloud sync automatically the content across all your devices, you can take a photo on your iPhone and immediately share it to your friends using iPad, or store anything, your photo, music, calendar notes, mail, messages on iCloud. It is completely free to use.

Apple allows iOS and Mac Developer Program members utilized this great feature iCloud integrated into their apps by providing iCloud Storage API. Utilizing iCloud Storage API the developers can store the user documents on iCloud, or storing key-value data for small amount information. Developers need not worry about the background operation of iCloud service, as iCloud service resolved all the possible conflicts may happened. iCloud also provides auto notification of file changes to your apps.

Your apps may be a document-based application. You sure familiar with document-based application existed on both desktop and mobile application such as word processors, spreadsheets and drawing program. In iOS5, you can easily implement a document-based application by subclassing UIDocument class, and providing any details of your document structure, while iCloud technology takes care of the background reading and writing of data asynchronously.

Your apps can store key-value data to share small amount of information, you may store integer, string, or date data in the key-value pair. The key-value data is stored in iCloud and shared across all user devices and all the apps. Any changes of data from one apps will automatically reflected in changes into other apps that using that data. Therefore, you may configure your bundles of apps to share certain key-value data to store some configuration or else.

iOS5 New feature added on Reminder with Geofence

iOS5 will be released on 12 October 2011 which released 200 more new features.

I love one of the feature, said set up a geofence around an area, your device will set off a reminder once you enter or leave the place.

Sometimes I passed by MRT station and wanted to insert money into my EZ-link card I will always forgotten and I got a similar idea if I can set up a reminder when I passed by MRT station then the device will remind me to insert money. I found this updated feature is very convenient for me.

Replicate Imgshow Sandbox into iPhone Apps

In my journey learning developing iPhone Apps, I try to replicate Imgshow Sandbox feature into iPhone Apps.

Imgshow Sandbox is a feature to test it out the services provided by Imgshow Platform. It is a web page integrated inside Help Content of Discuz Plugin of Imgshow Platform.

The original sample of Imgshow Sandbox can be found here:
Chinese Site: http://www.qxinnet.com/misc.php?mod=faq&action=plugin&id=qx_imgshow:help&topic=sandbox
English Site: http://www.discuz.my/misc.php?mod=faq&action=plugin&id=qx_imgshow:help&topic=sandbox

I am going to use Titanium API to make Imgshow Sandbox on iPhone Apps. The results would like this:

In the first screen, it shows a list of Imgshow Sandbox supported Services, with a thumbnail icon, name and description of the service.

Then, clicked on ‘youtube’ service, it brings us to a new window showing the parameters.

Enter a keyword, e.g. ‘Avril I love you’, a youtube song title, then click on ‘Show’ button. It will make an API request to Imgshow Platform and redirect you to the related Youtube video. In the back end, actually it sent an Imgshow Query to the Imgshow Platform server, in the form of (q:name=youtube,k=Avril I love you). You can however preview this Imgshow Query at this website, http://apps.facebook.com/imgshow/q:name=youtube,k=Avril I love you.

Here open the Youtube video in the iPhone embedded browser.

Back to the apps, we choose another service, such as ‘twitter’.

We enter a keyword, ‘Steve Job’, then click ‘Show’ button.

It will then open embedded browser to show the Twitter conversation box where back end it actually issued an API request to the Imgshow Platform. The example of this Imgshow query is in this form: (q:name=twitter,k=Steve Job)

This apps is just an experiment for imgshow API integration.

New Java Certification Question For You Guys

Today, fyhao gives you another Java Certification Question, see if you can answer it right. More practice before you earn a certification.

Q4

Develop code that implements all forms of loops and iterators, including the use of for, the enhanced for (for-each), do, while, labels, break, and continue; and explain the values taken by loop counter variables during and after loop execution.

2) Given:

5. public class Buddy {

6.   public static void main(String[] args) {

7.     def:

8.     for(short s = 1; s < 7; s++) {

9.       if(s == 5) break def;

10.       if(s == 2) continue;

11.       System.out.print(s + “.”);

12.     }

13.   }

14. }

 

 

What is the result?

a) 1.

 

b) 1.2.

c) 1.3.4. (*)

d) 1.2.3.4.

e) 1.3.4.5.6.

f) 1.2.3.4.5.6.

g) Compilation fails.

Q5

What will happen when you attempt to compile and run the following code?

 

public class Agg{

static public long i=10;

public static void main(String argv[]){

switch(i){

default:

System.out.println(“no value given”);

case 1:

System.out.println(“one”);

case 10:

System.out.println(“ten”);

case 5:

System.out.println(“five”);

}

}

}

 

A. Compile time error

B. Output of “ten” followed by “five”

C. Output of “ten”

D. Compilation and run-time error because of location of default

Is it simple to you?

Read Java Certification Question Q1 to Q3

Java Certification Question (20111003)

Q1

QUESTION: What happens when you attempt to compile and run these two files in the same directory?

 

//File P1.java

package MyPackage;

class P1{

void afancymethod(){

System.out.println(“What a fancy method”);

}

}

//File P2.java

public class P2 extends P1{

public static void main(String argv[]){

P2 p2 = new P2();

p2.afancymethod();

}

}

 

A. Both compile and P2 outputs “What a fancy method” when run.

B. Neither will compile.

C. Both compile but P2 has an error at run time.

D. P1 compiles cleanly but P2 has an error at compile time.

Answer: D

Noticed that these two files said to be in the same directory, but second file didn’t have package declaration while first file have. Therefore, P2 will prompt error at compile time.

Q2

What will be the output of the following code?

 

public class Sample {

 

public String getCountryName(){

return “USA”;

}

 

public StringBuffer getCountryName(){

StringBuffer sb = new StringBuffer();

sb.append(“UK”);

return sb;

}

 

public static void main(String[] args){

Sample s = new Sample();

System.out.println(s.getCountryName().toString());

}

}

 

A. Compile with error

B. USA

C. UK

D. Runtime Exception

Answer: A.

Java allows overloading method, meant with same method name, but having different parameters. However, Java does not allow overloading method with different returned types if the parameter list is the same. Because you see, it is contradicted themselves.

Q3

What will be the result of attempting to compile and run the following code?

 

abstract class MineBase {

abstract void amethod();

static int i;

}

public class Mine extends MineBase {

public static void main(String argv[]){

int[] ar = new int[5];

for(i=0;i < ar.length;i++)

System.out.println(ar[i]);

}

}

 

A. A sequence of 5 0’s will be printed.

B. Error: ar is used before it is initialized.

C. Error: Mine must be declared abstract.

D. IndexOutOfBoundes Error

Answer: C.

The answer is C, Mine must be declared abstract, or Mine must implements the method abstract void method().

Java 8 geared up to cloud and its feature

Java SE 8 is geared up to the cloud. Multi-tenancy and modularity is featured.

Multi-tenancy is considered as one of the main components characteristics of cloud computing, as single instance of software application runs on the server but served multiple clients.

Modularity is reorganization of JDK into a set of clearly defined though interdependent modules.

Java 8 also decides to include C# / Scala’s Lambda style which worked pretty well in subjective measure. Java 7 should have Lambda but its construct is weird.

JSR TBD is included as language support for collections, where literal expressions for immutable lists, sets, and maps, and indexing-access syntax for lists and maps.

Below codes are possible when define a Set or List.

List<Integer> aListOfNumber = [1,2,3,4,7,2,4,6,7];

Set<Integer> aSetOfNumber = {1,5,34,45645,23};

Map<Integer, String> aHashMap = {5 : “fyhao”, 6 : “bmwjob”, 18 : “Singapore”};

Virtual extension method is included as providing default implementation for interface virtual methods. If you are not afford an implementation of method, one will providing you an implementation with no charge.

Sharing state often introduce complexity in concurrency programming. If the state is not shared, or said immutable state, it will not brought trouble because it has fixed input-output pair. Functional language comes with this benefit, but Java is not going to switch language but just adopt the principle functional language based on, seek to increase immutability and decrease sharing. Fork-join decomposition introduced in Java SE 7 to easily write algorithm that parallelized automatically across wide range of hardware configurations.