Sunday, September 23, 2007

Error in Sun Java Exam?

I'm going up for Sun Java Engineer certification so I am practicing the exam. I found it a lot more difficult than I hoped. A lot of questions involve knowing Sun's definition of terms, such as 'Encapsulated'... Had to take a sneak peek at the book more often than I liked...

But then I encountered this question:

(WGS-PREX-J055-Form2: Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0, question 44)

Given:

1. class Alpha { void m1() {} }
2. class Beta extends Alpha { void m2() { } }
3. class Gamma extends Beta { }
4.
5. class GreekTest {
6. public static void main(String [] args) {
7. Alpha [] a = {new Alpha(), new Beta(), new Gamma() };
8. for(Alpha a2 : a) {
9. a2.m1();
10. if (a2 instanceof Beta || a2 instanceof Gamma)
11. // insert code here
12. }
13. }
14. }

Which code, inserted at line 11, will compile but cause an exception to be thrown at runtime?

A
B
C
D

I picked option D, and here is my reasoning:

Both objects of type Beta and Gamma will pass the if test (the Alpha object will not), but in option D we are casting to a Gamma. We can legally cast a Gamma object to a Beta (A Gamma is-a Beta), but the revers is not true; not every Beta is-a Gamma. So though this code will compile (Gamma has a method m2() we can call), it will fail at runtime, throwing ClassCastException when we encounter the second, Beta object in the array.


Here is the official explanation (that you get when pressing the 'Reference' button):

Option D is correct. Options A and C will NOT compile, option B will compile and run. Option D throws an exception because type Alpha has no m2 method.

Look at the last sentence:

Option D throws an exception because type Alpha has no m2 method

I think this is incorrect? I think the last sentence should read:

Option D throws an exception because type Beta cannot be casted to type Gamma.

Why would it matter that Alpha has no m2 method? No objects of type Alpha can get past the if check:

if (a2 instanceof Beta || a2 instanceof Gamma)


So no Alpha object will ever be cast to Gamma or invoked the m2 method on?
Who is right here, me or Sun?
Anyone care to comment?

Saturday, August 4, 2007

Not there yet... more chinese dialogs

Ok.. so different versions of my password give different error messages :-)

This is the one I get when I enter what I think is my correct password (i got a bit confused to be honest). It's different than the one I get when I type just garbage. I have the Text Services setting turned off (and even set my default language to chinese at one point). So.. I can't get past this one... does any one know what it says?

Thursday, August 2, 2007

I want my third life

Well.. I agreed, but settinh up HiPiHi turns out to be quite a challenge.
I am getting the login screen by now, but something goes wrong when trying to connect...


Does anyone know what this dialog says?

My third life

I am investigating a life next to my first, real one and my Second Life, called HiPiHi. It's a shameless chinese clone of Second Life. This could make it very appealing, as the chinese designers might have had the ability to build a great online world from the ground up, without having to go through the learning process LL had. Often, the first one to make a good clone of a great innovative software product becomes market leader.

Sow how does it compare with Second Life? Well, have a look at the license agreement in the englist setup program:



Well... I can't wait to Agree! Third brave new world, here I come! More reports will surely follow!

Saturday, July 28, 2007

Blog authors, be responsive!

I've been reading Linden Labs blog for a while now. They make many announcements there that could impact your second life, like the one a bout gambling becoming illegal in SL. But i noticed a trend. They will post an entry, people will respond and ask questions, but never does anyone actually respond to those questions. It almost seems like it is a policy of theirs to not respond to blog comments... strange don't you think?

If you use a blog to make announcements, then why not respond to those reading those announcements and having questions about it? C'mon Linden Labs, this makes you look like some slow moloch, taking weeks to respond. How hard is it to read the comments on your own messages and provide answers to very reasonable questions?

Friday, July 27, 2007

Casino's in Second Life forced to close!

Today i logged on to Second Life to play a game of Poker in my favourite casino, PokerPalace, owned by Amsterdam Alonzo. But to my astonishment, the building was almost entirely gone! I noticed Amsterdam standing there so I flew over to him to ask him what had happened, but I apparently intruded on a private conversation because he banned me from his land. I apologized over IM and asked him what happened to his casino, when he told me:

"All the casinos have to close in sl. They fucked us".

Aargh, Linden Labs what are you doing? The casino business was a profitable business in SL and has probably contributed greatly to it's success. This will cost them. What's next? Banning porn?

Here is a link to their blog posting concerning this.

Thursday, April 26, 2007

How Linden Labs becomes 'the next Google', by reducing lag.

This is the second article in a series. The first article can be found here

Lag in a sim is when time seems to slow down. Everyone is moving only very slowly. This happens because the server computer, the sim, cannot complete all necessary calculations within the allotted time. I have been trying to determine the causes of lag, but that is very difficult. Scripts can cause lag, that is for sure. But too many visitors seem to be able to cause lag too. At this point i suspect that maybe even the fact that some user in the sim has a very slow computer might affect lag.

Again we see something akin to the web. Sites used to go down because of their success. How ironic, you get so many visitors that the sim slows down to a crawl, so the visitors leave again.

But here the problem is more fundamental. I work at a web development company. Some of our clients' websites get hundreds of thousands of visitors per day. They have huge collections of servers, with load balancing, distributed databases and the lot, serving just a single website. The same should be possible in Second Life, a successful sim with lots of visitors might have dozens of servers backing it, while some other quiet sim might have only one.

Currently the system in place is pretty simple and intuitive (except for the separation between mainland and private estate, more about that later), tier fee is related to land, land is related to a sim, so you essentially buy hosting space, quite literally. Land can have only limited constructions on them (built of prims) and each prim can have only a limited amount of scripts in them. Each script has a maximum amount of memory it may use and the operations in a script can be executed only a limited amount of times per time unit, because of built in function delays.

I see two big problems.
The first is that if someone puts the maximum amount of scrips allowed in every prim on his land he can bring the simulator to a crawl. Worse is that people can wear prims on themselves, and have scripts running in them, bringing the simulator to a crawl even without owning any land there..
The second big problem is that if you have a successful sim, you might actually need those scripts to run, and the only way to get more computing power is to buy more land. But you can't share prims and scripts accross sims... Which leads to some peculiar constructions...


This is me standing in PokerPalace. Nothing peculiar yet, but wait until we check the map...



That is peculiar! Poker Palace is built at the center of 4 simulators! Most of the simulators are empty, apart from a small section in the corner of each sim. There is only one reason that the sim owner has built it this way: Lag.

This is a shame i think. The fact that the casino owner has to pay more to get more cpu power is no problem, but the way it is tied to the land is posing problems in scalability... Poker Palace essentially can't grow any further without having to set up a second casino... it already uses the maximum of 4 sims!

Now if Linden Labs could get that fixed, they would be one step closer to becoming the nex Google.