Friday, January 18, 2008

Top Buzzwords which make you Expert

Here is a top five buzzwords which developer needs to know in order to make himself an expert

  1. Scalability - Means that the application can handle a growing amount of work in a graceful manner, Usage Example: "I don't think that this system is scalable, A raise in my salary might encourage me to make it scalable"
  2. Robustness - Means that the application can withstand stress and can continue to operate despite ourside or inside errors, Usgae Example "This application is robustness, One time I explode it with Dynamic and it continued to run"
  3. High Availability - Means that the application ensures a certain amount of operational continuty during a given period, Usage Example: "This application high availability stinks, we need to build a cluster of servers to make it high avilable"
  4. Interoperability - Means that the applications can exchange data in commonn set of exchange format. Example: "We should expose the application service with Web Services this would make our application interoperabale"
  5. Portability - Means that the application can run on a different operating system, Example: "In a team meating I told my boss that we should write a portable application beacuse the application needs to run also in Unix, He promote me to team leader"

Thursday, January 17, 2008

Sun agrees to pay $1b for MySQL

Sun Microsystems Inc., the third-largest maker of server computers, agreed to buy software company MySQL AB for about $1 billion.

MySQL is the world's most popular open source database, over 100 million copies of its software downloaded or distributed throughout its history, It is mainly used by web sites and it is used also by Google Inc.

What is the interest of Sun to buy MySQL, well Sun unlike IBM/Oracle/Microsoft doesn't have it's own Database, Sun has its own Application Server and this would create a more complete product solution which would be supply by Sun.
The profits for Sun will come from the support for MySQL installations.

The question now when Sun would be bought and by who?

Wednesday, January 16, 2008

Oracle to Pay $8.5 Billion for BEA

Another acquestion by Oracle, this company just swallow all the other competitions.

The big question what is now what would be now with BEA WebLogic application server? Since Oracle has it's own application server 10g, would they stop to develop it? My guess is that they will continue to support old 10g customers and would offer new customer BEA WebLogic application server.

Oracle profits are just continue to grow and this cause Oralce competitiors to afraid, Now that there are now only two major J2EE Application - IBM and Oracle it would be intrest to see what would be the next acqusiton

Google Interview Questions Part 8

This questions are a bit tricky, lets see if you can solve it.




First question:

        1
       1 1
       2 1
    1 2 1 1
  1 1 1 2 2 1

What is the next number?

Second question:


What number comes next in the sequence: 10, 9, 60, 90, 70, 66, ?

A) 96
B) 1000000000000000000000000000000000\
0000000000000000000000000000000000\
000000000000000000000000000000000
C) Either of the above
D) None of the above




And here are the answers:

First question answer is:

one
one one (Since the previous line has one time one number)
two ones (Since the previous line has two time one number)
one two one one
one one one two two ones

So the next line answer is 3 1 2 2 1 1


Second question answer is:

ten, nine, sixty, ninety, seventy, sixty-six,

Each number has one letter more than the previous number, ten has 3 letters, nine has 4 letters etc'

Since "sixty-six" has 8 letters the next number need to have 9 letters which is
ninety-six

You can find more questions here:

Google Interview Questions Part 1
Google Interview Questions Part 2
Google Interview Questions Part 3
Google Interview Questions Part 4
Google Interview Questions Part 5
Google Interview Questions Part 6
Google Interview Questions Part 7

GWT vs. Flex

This article would compare Google GWT (Google Web Toolkit) and Adobe Flex 2 and would describe the advantages and disadvantages of each of these technologies.
This two technologies are both Rich Internet Application (RIA) frameworks.

GWT Advantages:

  • Doesn't require plug in installation on the client side
  • GWT doesn't require the user to know JavaScript since the code is written in Java
  • GWT doesn't cost money since it is Open Source.
  • Changes in the Client side are immediately shown on the browser by using refresh, no need to restart the server.
  • GWT can be easily debugged in hosted mode.
  • There is compatible between different web browsers.

GWT Disadvantages:

  • The html and JavaScript code which GWT generates is pretty heavy and not necessary fully optimized.
  • GWT doesn't come out of the box with all the possible widgets, there is a need to use extra components

Flex Advantages:

  • The UI looks nicer then plain HTML/JavaScript code, It contains huge amount of animations, widgets etc'
  • Compatible between different web browsers
  • Flex 2 SDK and Flex Builder 2 for Education are both free
  • Google can index SWF files

Flex Disadvantages:

  • It requires plug in installation on the client side , however this may not be disadvantage since Adobe claims that Flash is installed on more then 99% percent of users.
  • Flex Builder 2 costs some money






Friday, January 11, 2008

Improve SOA Performance

SOA Applications Performance are disaster.

Lets assume you want to buy a book using SOA, this means you need to access several times a remote server using web service to complete the transaction, If you work with java then for each web service request you need to parse you java objects to XML objects send the request to the remote server on the other side the XML is parsed back to java objects it do it's stuff and then return a response parse it back to XML you get the XML and parse it back to java objects.

Lets assume that each of this horrible way takes 2 seconds, if you need to send 4 requests to complete the transaction it would take 8 seconds for one small transaction!!!

To improve the performance you would first need to set a well done granularity for your web services if it is possible, For example if to buy a book you first send a request to get the book name by book if and then you send a request with the book name to check if the book exists and then you send another request to buy the book, a better way would be to send one web service request which would do all of the above this would reduce the round trips between the client and the remote server, Instead of parsing XML files 2*3=6 times you would parse only 2 times.

A second way to improve the performance is to cache locally all the read only data which exists in the remote server, so instead of accessing the server using web service you would just read the data from the cache, You can also cache not read only data if you don't necessary need the last-to-update date.

Technical ways to improve the performance is to choose a good performance web service package, some packages take a lot of CPU/Memory to parse the XML to objects and vice-verse.

I recommend this SOA book to learn more:

Tuesday, January 8, 2008

Flex vs. JSF

This article would compare Flex and JSF technologies and would describe the advantages and disadvantages of each technology.

JSF Advantages:

  • Doesn't require plug in installation on the client side
  • JSF has a standard specification and it has several implementation
  • JSF has Open Source implementations which doesn't cost money.
  • Changes in the JSP files are immediately shown on the browser, no need to restart the server.

JSF Disadvantages:

  • Very complicate to develop because the basic implementation is pretty basic and for complicated UI screens need to have additional component libraries
  • Doesn't compatible between different web browsers

Flex Advantages:

  • The UI looks much nicer then JSF UI
  • Flex looks like more simple to develop rather then JSF
  • Compatible between different web browsers
  • Flex 2 SDK and Flex Builder 2 for Education are both free

Flex Disadvantages:

  • It doesn't has standard specification
  • Adobe is the only provider of Flex
  • It requires plug in installation on the client side , however this may not be disadvantage since Adobe claims that Flash is installed on more then 99% percent of users.
  • If you build a web site which users would need to search in some search engine the search engine would not be able to understand the content of the flash files (search engines can only understand standard html files/pdf files etc')
  • Flex based pages takes a lot of time to get loading compare to JSF pages
  • Flex Builder 2 costs some money

Both JSF and Flex integrate very well with java.

In summary, if you build an simple enterprise application which requires nice UI I would recommend using Flex, if you build an complicated application which requires good performance or application which is open to all the Internet users I would recommend using JSF.





Sunday, January 6, 2008

GWT Proxy

Here is a nice way to write GWT Proxy to call the server services using the proxy design pattern:

The advantages of this proxy are:

  • The client call the service as it's a local call
  • The proxy hides the difference between calling the services in hosted and development modes.
  • It improves performance since the end point is set only once

First write this Client util class:

public class ClientUtil {
private static final String PRODUCTION_URL = "http://www.koko.com";

/**
* Check if the code run in production or development mode
* @return true if we run in production mode (i.e. Ruler.html is called)
*/
public static boolean isProduction() {
return GWT.isScript();
}

/**
* Set endpoint for service which want to access the server
* @param service the service class
* @param name the name of the service
*/
public static void setEndpointForService(Object service, String name) {
ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = getRelativeURL() + name;
endpoint.setServiceEntryPoint(moduleRelativeURL);
}

public static String getRelativeURL() {
String moduleRelativeURL = null;

if (!isProduction) {
moduleRelativeURL = GWT.getModuleBaseURL();
} else {
moduleRelativeURL = PRODUCTION_URL;
}

return moduleRelativeURL;
}
}

Then write your proxy class, for example:

package com.mycompany.client.util;

import com.google.gwt.core.client.GWT;

public class MyProxy {

private static MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);

static {
// serviceName is the name which define in app.gwt.xml file
ClientUtil.setEndpointForService(myService, "serviceName");
}

public static void foo() {
MyCallback myCallback = new MyCallback();
myService.getServerLog(myCallback);
}
}

finally to call the server use:

MyProxy.foo();



You can read more at:

GWT Development or Production Mode

Here is a nice trick to know if your GWT application runs on hosted mode (development mode) or does it runs in production mode on a real web site.

Why do you need this? Because your access to the server side is different between development and production modes, and because you might your application behave differently between this two modes.

So to do this you would need to have two main html files one for development mode and another one for production mode, the two html are the same expect in the production mode you would put this following line:

‹iframe id="production" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; WIDTH: 0px; BORDER-BOTTOM: 0px; HEIGHT: 0px"›‹/iframe›

and you can also put your advertisements like Google AdSense and Google analytics and other production stuff.

after you put this write this code in your main module class:

public void onModuleLoad() {
Object isProduction = RootPanel.get("production");

if (isProduction!=null) {
ClientUtil.setProduction(true);
}

Also create this ClientUtil class:


public class ClientUtil {
private static boolean isProduction = false;

public static boolean isProduction() { return isProduction; }

public static void setProduction(boolean isProduction) {
ClientUtil.isProduction = isProduction;
}
}

Now in every place in the code user ClientUtil.isProduction() to know if you are in production or not.

Tuesday, January 1, 2008

Java becoming old?

Some "experts" claiming that Java becoming old and that it would reach it's end in a few years,
Some of these "experts" claim that java would end as Cobol, and new technologies would be adopted such as "Ruby On Rails", PHP and Ajax.

I completely disagree with this statements, First of Cobol is still one of the most common software programming languages. Beside that other new technologies such as Ruby still doesn't mature - we've tried several projects with it and have reverted to Java.
PHP is cool, but doesn't scale as well as Java for large user base applications.
AJAX -is like Javascript and CSS; It intended to be used with JSP/ASP/HTML etc.
Java still is the best choice - by far - for development. It runs on virtually any platform and doesn't lock you in to one OS vendor or flavor. It works, and it's fast. It's a great tool for back-end and web development. Yes, it's not the newest kid on the block, and frankly that doesn't matter much - It has solid performance and results pretty well in production

Saturday, December 29, 2007

Google Interview Question - Part 7

Here is another question:

Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N.

And here is the answer:

A:

private static String match(String a, String b)

{

String result = "";

Set lettersSet = new HashSet(26);

for (int i=0; i

lettersSet.add(new Character(b.charAt(i)));

}

for (int i=0; i

if (lettersSet.contains(new Character(a.charAt(i)))) {

result=result+a.charAt(i);

}

}

return result;

}

Thursday, December 27, 2007

Hibernate .vs. Pure JDBC

There is a wrong assumption that Hibernate is slower then JDBC, this is not true.
For the tests that I have done I had found that Hibernate performance are not less then Pure JDBC.

I had compared the performance between Hibernate and Pure JDBC for writing 10,000 rows to the DB table, The results are really surprising.

The test run on a single thread which write in a loop the rows in bulk update, the JDBC used batch update processing with prepared statement, the Hibernate run on a single session which flush the inserts to the DB every 100 rows (Bulk Updates).

I had worked with Hibernate 3.0 on a regular Pentium Pentium 4 2.66GHz with 2GB RAM, The DB was remote Oracle 9 DB.

Well are are the surprising, Hibernate and Pure JDBC results are completely the same !!!
Hibernate doesn't have a huge overhead as you expect it to have.

For the results I manage to write 10,000 rows to the DB in 1.5 Seconds !!!

Here are some tips for improve your Hibernate performance are:

  • Try to reduce the number of open and close of hibernate sessions
  • Using Hibernate bulk updates were possible
  • When using Hibernate bulk updates try to separate the SQL Insert/Update/Delete statements to groups, the DB would process this groups faster (For example 20 SQL inserts then 40 SQL updates and then 25 SQL delete statements)

Wednesday, December 26, 2007

SAP licenses NetWeaver to developers

I found this nice article which says that SAP netweaver can be now used by individuals:
http://www.regdeveloper.co.uk/2007/10/03/sap_netweaver_developer_license/

As I had experience working the the SAP netweaver J2EE Engine - AS (Application Server), I can tell you about my impressions.

The disadvantages are:

  • It take a lot of time to startup the server and to deploy applications (depend on the application size)
  • There are a lot of missing infrastructures which exists in other application servers (such as inline scheduler, cluster singleton, hot deployment) and many open source frameworks wouldn't work properly with the server.
  • All the infrastructures in the server a propriety of SAP (Logging, Security etc')
  • Except SDN there isn't huge community which can help with the development, Other J2EE Engines like JBoss has a lot of forums with questions and answers inside them.

The advantages are:

  • There is a good administrator GUI to manage the server.
  • It is possible to deploy several applications with references between them
  • There is a good JCA, JCO, Web Services infrastructure to connect to the ABAP world.

Again this list are from my personal experience.

Sunday, December 23, 2007

Build Web Application

The big question is the technology is ready to build web application, there are many web applications out there, word processing, spreadsheet, CRM, mail reading and more...



Until now the only application that really succeed running in web is mail reading like http://www.gmail.com/ and CRM application like http://www.salesforce.com/ why is that?



GMail succeed because you want to read you mail from anywhere in world, It has a very good spam filter which and it run pretty fast on the web, the disadvantages which it has are:

  • It is limited in storage space
  • It can't run offline and the data is not private.
  • Download/upload huge file can take a lot of time

So what the the characteristics which are require by a good web application:

  • It should run offline, so if the connection to the Internet is closed it would be possible to keep working on the application, This can be done by using Google Gear technology for example.
  • It should be able to synchronise the files on the local machine with the server if the user wants to share his own local private data with other users.
  • The Application would be able to know that there is a new software release on the server and upgrade to the new release offline.
  • The initialize of the web application would take long time only on the first time accessing the application, since then it should cache on the browser cache directory and run locally.
  • The user would be able to save his own private work data locally on the machine, the web application would know to synchronize it with the server in asynchronise way.

Saturday, December 22, 2007

XA Two Phase Transactions doesn't work

When you use XA or in it's second name Two Phase Commit Transaction and the transaction doesn't work it can be cause by one of the following reasons:

  • You didn't declare transaction manager in your application server or in your spring XML configuration file
  • You declared transaction manager but no annotation was defined for the EJB or the annotation was defined NOT_SUPPORTED
  • There is annotation but if you call from some method in the EJB to another method in the same EJB the second method can't open transaction since it is a local call which doesn't execute through the j2ee engine interpreter and therefore not transaction is opened. A Possible solution for that is to use UserTransaction and open the transaction pragmatically or to move the second method to another EJB.

Google Interview Question - Part 6

Continue with the question in the previous post:
http://j2ee-now.blogspot.com/2007/12/google-interview-questions-part-5.html

Here is the answer to the question,
If two threads would run in parallel and call this method with values 10 and 7,
The first thread would create the array with size 10 and then thread 2 would re-initialize the same static array with size 7, then the fist thread would run on the array from 0 to 9 and would put values inside however the array size is now 7 so on list[7] it would throw the exception.

Wednesday, December 19, 2007

Runtime Exception or Regular Exception

This is the question that asked often, when should I throw RuntimeException and where should I throw regular Exception, this is the answer:

  • If you exception which is thrown is pure technical exception from which the client can't recover from then throw RunTime Exception in case you run in J2EE server with Transaction Manager set then it would also rollback the transaction. Even that this exception doesn't have to be declared as part of the function exception signature it is advice to declare it so the client would be aware for this exception.
  • If your exception is pure business applicative exception then this exception should be regular not RunTime exception so this exception would be displayed for the user in the end and he would be able to change something to fix it, when throwing this exception in J2EE server with Transaction Manager the transaction doesn't rollback.

Google Interview Questions Part 5

Here is a snippest of code, how it is possible that the code would throw ArrayIndexOutOfBoundsException ?

private static String[] list = null;

public static String[] getArray(size) {
list= new String[size];
for (int i = 0; i < size; i++) {
list[i] = "a" + i
}
return list;
}

This question is a bit tricky

Tuesday, December 18, 2007

Google Interview Questions Part 4

Here are some other questions and solutions

Q: N threads .. n resources .. what protocol do you use to ensure no deadlocks occur?
A1: Avoiding Deadlocks with Lock Leveling, each thread would have different level, thread with high level would be able to lock thread with lower level but not contrary.
A2: Avoid acquiring more then one lock at a time.
A3: Acquire the lock always in the same order. A4: Shrink synchronized blocks.

Q: You are given a the source to a application which is crashing when run. After running it 10 times in a debugger, you find it never crashes in the same place. The application is single threaded, and uses only the C standard library. What programming errors could be causing this crash? How would you test each one?
A1: It might be using time, or perhaps random numbers. Or it does nasty things with memory. Or it could be running under windows.
A2: There might be multiple recursions in the code which are causing a stack overflow, cause "Out Of Memory" exception
A3: A probable cause would be an uninitialized pointer/variable being used

Monday, December 17, 2007

Google Interview Questions Part 3

Q: Here are some more questions and answers:
Which bits are on in the three packets of the handshake?

A: it’s SYN, SYN+ACK, ACK, The source want to send data to he destination, In first step it sends SYN to ask the desination if he is ready to receive data, then the destination wants to answer that he is ready for receiving bits
so he sends SYN+ACK, then the source need to confirm to the destination that he got is request so he send back ACK.

TCP is connection oriented while UDP is not.
TCP: connection establishment -> data transfer -> connection termination

1. The initiating host (client) sends a synchronization (SYN flag set) packet to initiate a connection. Any SYN packet holds a Sequence Number. The Sequence Number is a 32-bit field in TCP segment header. For example let the Sequence Number value for this session be x.
2. The other host receives the packet, records the Sequence Number of x from the client, and replies with an acknowledgment and synchronization (SYN-ACK). The Acknowledgment Number is a 32-bit field in TCP segment header. It contains the next sequence number that this host is expecting to receive (x + 1). The host also initiates a return session. This includes a TCP segment with its own initial Sequence Number value of y.
3. The initiating host responds with a next Sequence Number (x+1) and a simple Acknowledgment Number value of y + 1, which is the Sequence Number value of the other host + 1.



Q: What is Karatsuba algorithm?
A: It's algorithm to do mulipilacation of two large positive numbers with n digits in the complexity of O(n^2)


Q: Tell me what happens when you type www.google.com into a web browser
A1: Explaining that DNS operates via UDP, port 53, and so forth …, the ip address is returned from the DNS
(Sometimes the ISP cache this URL->IP mapping and this save the time of accessing the DNS).
and HTTP GET request is send to google.com server, which return the HTML of the google.com homepage.
A2: Google's DNS servers perform load balancing to allow the user to access Google's content most rapidly. This is done by sending the user the IP address of a cluster that is not under heavy load, and is geographically proximate to them. Each cluster has a few thousand servers, and upon connection to a cluster further load balancing is performed by hardware in the cluster, in order to send the queries to the least loaded Web Server

Google Interview Questions Part 2

Well here is the solution for the question from

http://j2ee-now.blogspot.com/2007/12/google-interview-questions-part-1.html

First you should pass on the list and create a new list with the summary of the numbers till now, for example if the list is:

-7 12 -5 13 -2

Then the new list would be:

-7 5 0 13 11

The subset with holds the largest sequential sum is the subset from the lowest number in the new list plus index 1 (In our case -7 (index 0) is the lowest so we start from 5 (index 1)) till the highest number in the list which is 13 (index 3) so the result is (12, -5, 13) which it's sum is 20.

Why does it work? because if we went from he lowest sum till now to the highest sum till now this is the biggest different of the numbers in the summary therefore this numbers sum would be the largest in the list.



You can find more Google Interview Questions here:

Google Interview Questions Part 3
Google Interview Questions Part 4
Google Interview Questions Part 5
Google Interview Questions Part 6
Google Interview Questions Part 7

Sunday, December 16, 2007

Google Interview Questions Part 1

A friend of mine was interview for a position in Google, he got this hard question asked:

"You have a list of numbers which some of them are negative and some of them are positive, find out the largest sum of sequential subset of numbers from this list."

For example:

-5, 20, -4, 10, -18

The solution is the subset [20, -4, 10] which its sum is 26

The solution for this question is not summary the positive numbers or sort the list because the subset needs to be sequential.

A possible not efficient answer would be to to calculate the summary of all the possible subsets in the list but the complexity of this solution is O(N^2)

However the interviewer wanted a solution of O(N) !!!

Let see you solve this problem in few minutes...

In the next post I would publish the solution

Saturday, December 15, 2007

GWT Instnace Messaging 2

In the previous post I described a simple way to implement instant messaging using GWT, the technique was to use polling which every few seconds look for a new chat message.

However this technique is not efficient, I had found a better implementation which use "push" from the server to the client to implement the instant messaging.
You can read more about it at:

http://code.google.com/p/google-web-toolkit-incubator/wiki/ServerPushFAQ

Friday, December 14, 2007

Eclipse Debugger Influence

Here is a nice example of how debugging in eclipse would ruin your application flow.

Suppose you add the following varilable watch: "iterator.next()" because you want to see the value of the list.

After each time you would press "step into" or "step over" in the debugger the iterator would advance to the next element beacuse the debugger invoke next() method.

In this case with debugger it wouldn't run right, but without debugger it would run fine.

Thursday, December 13, 2007

Google Maps using GWT

There is a nice project which allow to use google maps in GWT,
You can download it from:

http://sourceforge.net/projects/gwt/

This project is really great, hoever The API allow you to convert Location to Lat/Lng coords, but it doesn't allow to convert Lat/Lng coords to Location.

So the solution here is to use SOA, there is a nice WebService which allow you to convert Lat/Lng to Location, it can be download from:

http://www.geonames.org/source-code/

After installing it you can write this code to convert Lat/Lng to Location/Country:

List places = WebService.findNearbyPlaceName(lat, lng);

if (!places.isEmpty()) {
Toponym toponym = (Toponym) places.iterator().next();
String countryName = toponym.getCountryName();
}

Links

 
RSS Feeds Submission Directory