Cairo Jackson

+ Follow
since Jan 18, 2007
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cairo Jackson

Thank you Alex. You are correct.
14 years ago
Hello all,

Could anyone please tell me why the second method run slower than the first one?

The first one took 2078 milis, but second one took 3828 milis, about double the time.

14 years ago
Well, I have tried n-gram, lcs (longest common subsequence), Levenshtein and I found that Levenshtein is easier. In fact, they have their own weakness.

Try the code below. It will return a value between 0 and 1, where 1 if the text content exactly the same, and 0 if the content totally different.

As I say, it still has its weakness. If you are interested in this topic too, please come and work together for better solution.

Thank you.

[ July 30, 2008: Message edited by: Cairo Jackson ]
[ July 31, 2008: Message edited by: Ulf Dittmer ]
15 years ago
mm... no. What i mean is input two text files, compare them, and give "similarity". how much similarity of these two text contents. For example, i want to know if plagiarism happen.
15 years ago
Hello everyone,
Can anyone teach me, any algorithm that can calculate two text contents similarity? I need to write a class to compare two texts and give similarity, for example, 1 if two contents are exactly same.

Thank you.

[ July 29, 2008: Message edited by: Cairo Jackson ]
15 years ago

Originally posted by Stevi Deter:

Sorry for misunderstanding your constraints.

For the specific issue of logging, I would personally recommend a separation of concerns and using an existing package like Apache Commons Logging to avoid further reinventing the wheel.

Without a deeper description of why you're feeling like you must limit yourself to static methods, I can't give much more useful advice. I would recommend you think about using the static methods to create and use classes that aren't dependent on static methods, if you don't feel you can create your Server classes that way. A contrived example:

I thinks that's the only way. Thank you, Stevi Deter. Thank you, everyone.
16 years ago

Originally posted by Stevi Deter:
I think you're letting yourself get confused by the main method, which is static.

The following code example should show you how you can create the sort of inheritance structure and use it to get the desired results:

Thank you, Stevi Deter. OK... the story is I have two servers, namely UDPPortServer and TCPPortServer. Since they are servers, all the methods used are static by default. The main method will just be there listening command from prompt. But UDPPortServer and TCPPortServer shares many similar functions/methods, and now I want to put all these methods into a separate abstract class (one, i need to log these methods; two, I no need to modify the codes twice if something wrong) so these two servers can just share.

mm... how do you think?

Thank you again.
16 years ago

Originally posted by Vishal Matere:
I have very pathetic solution to this but atleast it will work...

I am so sorry for this solution ..

Thank you, Vishal Matere. I am thinking of this solution as well, but it lose the spirit/feel of inheritance. If I put ServerAlpha.class in parameter, it feels like they are different classes and I may just create an instance of ServerFunction and use it.
16 years ago
I have a question that I could not solve at the moment, since my codes are long and complicated, so I made a simple case, as the codes below:

OK.. the issue is I have different servers class share and use same functions. Additionally, I need to have something like central control over the functions, so I put these same functions into an abstract class called, ServerFunction.

Since the server (alpha and beta) are all static methods, so I must declare printMyName() as static. But I want the server print out their package class name when using printMyName(). Previously, if it is not the case of static, i use this.getClass(). Now I cannot. Can someone teach me how to solve this?
16 years ago
I am reading the book Effective Java, written by Joshua Bloch. Now, I'm with Item 32: Avoid strings where other types are more appropriate.

I can't understand the last point: Strings are poor substitutes for capabilities. I copied the part that I dun understand:

Occasionally, strings are used to grant access to some functionality. For example, consider the design of a thread-local variable facility. Such a facility provides variables for which each thread has its own value. When confronted with designing such a facility several years ago, several people independently came up with the same design in which client-provided string keys grant access to the contents of a threadlocal variable:

The problem with this approach is that the keys represent a shared global namespace. If two independent clients of the package decide to use the same name for their thread-local variable, they unintentionally share the variable, which will generally cause both clients to fail. Also, the security is poor; a malicious client could intentionally use the same key as another client to gain illicit access to the other client's data. This API can be fixed by replacing the string with an unforgeable key (sometimes called a capability):

While this solves both of the problems with the string-based API, you can do better. You don't really need the static methods any more. They can instead become instance methods on the key, at which point the key is no longer a key: it is a thread-local variable. At this point, the noninstantiable top-level class isn't doing anything for you any more, so you might as well get rid of it and rename the nested class to ThreadLocal:

This is, roughly speaking, the API that java.util.ThreadLocal provides. In addition to solving the problems with the string-based API, it's faster and more elegant than either of the key-based APIs.

I really dun understand what he wants to say, especially with the ThreadLocal sample. Can any one tell me what does "Strings are poor substitutes for capabilities" actually mean? in any easier sample codes?

Thank you very much.
17 years ago
I got a few questions here about SCEA exam:

1, SCEA exam requires 3 vouchers for 3 different parts or just 1 voucher?
2, Is the voucher same to the one we used for SCJP?
3, Any time limitation between different parts? (for example, I take second part a year after part 1)
4, How about if I pass the first part but fail the second part? Do I need to re-do the first part?
5, If I have passed SCWCD, with 2 years experiences in Java Programming, how long do I need to do the revision before taking SCEA exam? (I know it is hard to answer this question, but please advise. Thank you.)

Thank you very much.


the true runtime type of the instance is Dog

Yes, I got what you mean~ Thanks for your explanation. Thank you very much.
17 years ago
thanks, marc weber.

I can undertsand the article.

If myDog.sayHello() results "Dog says Hello", I can understand the theory behind.

But my doubt is a new Dog instance is created, and it implicitly got "super();" in its constructor, then inside Animal class constructor, it calls sayHello method. Why and how this superclass (Animal) knows to call its subclass (Dog)'s method, sayHello()? and print out "Dog says Hello" and not "Animal say Hello"?

In other words, how to write so in the same case, the Animal call it's own sayHello() method? I have tried to use "this.sayHello()" but it also print out "Dog says Hello".

Perhaps somewhere in my brain get stuck ~ sorry... but please tell me why.
17 years ago

May I know why the result is

instead of "Animal say Hello" ?
17 years ago