This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!

Yu Chen

Greenhorn
+ Follow
since Dec 03, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yu Chen

True, I also tested, it runs a little bit faster w/o the nullity check. Null is not an instance of anything, so all instanceof tests with a null reference produce false.

Thanks!
16 years ago
So the answer is "NO". Here is a test program, any comments welcome.

/*
* TestString.java
* test | int | str eauals/hashcode ==
* 1 | 100,000 | 10/10 , 9/8
* 2 | 1,000,000 | 34/33
* 3 | 10,000,000 | 285/277, 265/260, 264/303, 263/259
*
* Created on March 7, 2005, 9:38 AM
*/

package examples.colorpicker;

public class TestString {
private String id = "This is a test.";

/** Creates a new instance of TestString */
public TestString() {
}

public boolean equals(Object obj) {
if(obj == this) return true;
if(obj == null || !(obj instanceof TestString)) {
return false;
}
TestString ts = (TestString) obj;
//return ts.id.equals(this.id); //compares str length, chars, or nullity.
return ts.id.hashCode() == this.id.hashCode();
}

public static void main(String[] args) {
TestString ts = new TestString();
String sample = "This is a test.";
long start = System.currentTimeMillis();
for(int i = 0; i<10000000; i++) {
ts.equals(sample);
}
long end = System.currentTimeMillis();

System.out.println("Programs runs for " + (end - start));
}
}
16 years ago
Here is equals method in a class Foo, will it run faster if I use the hashcode of String at line return obj.equals(this.id) ?

Public class Foo {
private String id = "";

public boolean equals(Object obj) {
if(obj == this) return true;
if(obj == null || !(obj instanceof(Foo))) {
return obj.equals(this.id);
}
}
}
[ March 07, 2005: Message edited by: Yu Chen ]
16 years ago
How to get access of a xml file inside a zip file? I have a staroffice 6.0 doc which a basically a zipped file containing a few xml files. What I want to do is to just process one xml file word by word as a inputstream.
Any ideas?
Thanks!!
-yu chen
18 years ago
I want to run a program on a client, but I don't want the user to have any way of knowing what the program does, by decompiling it, etc.
Are there (free) obfuscators out there that allow this to be done?
Is there any other way to do this? Somehow 'loading' a class remotely, but having it actually run within the client environment? It looks like RMI only runs on the remote (server side).

Thanks,
-yu chen
19 years ago
First, I think there is absolutely no point for a second grader to laugh at a first grader's achievement. If you think you are overqualified, find some other things that challenge you.
Second, I think the passing score is determined based on available statistical data, If I spent 2 months studying for the exam, and I know I worked hard for it, I believe it is NOT true that everybody can pass it. That is the first point I think you missed.
Third, If the purpose of the SCWCD is to test a programmer's fundamental knowledge of the J2EE web component, I think it is right on the target.
Fourth, most jobs requires a B.S degree, if only a small portion (say 10-20%) of the undergrad students can honorly get their diploma, then I think the degree would NOT be required for most of the job, same things applies to SCWCD certification. The certification does not and should not used to prove you a hardcore super Java web developer, nor can any working experience. I see people having years of java programming experiences and yet still had hard time understanding the basic OO concepts.
In addition, working for a particular exam did help me focus on the fundamental concepts and force me to think deeper.

Cheers,
-yu chen
19 years ago
Congratulations!!
I had minimal working experience on servlet/jsp and no experience on JavaBean/taglib. I spent altogether about 2 months, with averagely 2 hours each working day preparing for the SCWCD exam. I got 93%, it is indeed a valuable learning experience. I am more confident to take some real project, can better understand J2EE web services issues, and maybe take another job/position if needed.
Be proud of what you've done! If not, move on to some other things that interests you. :-)
-yu chen
19 years ago
I felt like this is easier than SCJP2. It rooks me about 2 months all together, very intense study in the last week.
My recommendations:
get the Manning's Study Kit, this is an excellent book,
- very facused on what the exam required;
- easy writing style;
- minimum errors;
- especially like the charts and tables in the Quick Review section.
- excellent Mock exams, which is very similar with the real exam I took today.
Things I've read:
- Jason Hunter's Java Servlet Programming;
- Marty Hall's Core Servlet and JSP;
- Servlet 2.3 Spec;
- Sun's free Mock;
- JavaRanch's Mock exams;
- Ken's Notes.
I've read always every postings in JavaRanch's SCWCD forum, so I sicerely thanks all the JavaRanchers.
Happy Friday!
-yu chen
19 years ago
Question ID :996245849311
Consider the code for two servlets of the same web application.
//In file LoginServlet.java
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
String userid = loginUser(req);
req.getSession().setAttribute("userid", userid);
}
}

//In file ReportServlet.java
public class ReportServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException
{
String userid = (String) req.getSession().getAttribute("userid");
if(userid != null) generateReport(req, res);
}
}
Assuming that loginUser() and generateReport() are valid methods, which of the following statements about these servlets is true?
--------------------------
I don't think the doPost() methods have the correct signature, will these really compile?
The answer says,
- The generateReport() method will be executed only if a post request is sent to the LoginServlet before ReportServlet.
Thanks,
-yu chen
Thanks, that is a important concept. It makes sense now.
-yu chen
Question ID :997967667647
For the JSP scopes of request and page, what type of object is used to store the attributes?
1. HttpServletRequest and ServletContext respectively
2. ServletRequest and ServletConfig respectively
3. ServletRequest and PageContext respectively
4. HttpServletRequest and PageContext respectively
5. ServletConfig for both
I would say (Http)ServletRequest and Object respectively, but the answer is 3?? In Manning's study kit, it states that the implicit variables are of type/class:
application: ServletContext
session: HttpSessoin
request: HttpServletRequest
response: HttpServletResponse
out: JspWriter
page: Object
pageContext: PageContext
config: ServletConfig
exception: Throwable

Any thoughts?
Thanks,
-yu chen
There are 2 ways to kill a session:
1) HttpSession.invalidate;
2) or session timeout has expired.
Another mock exam question states that even the container is shutdown and brought up again, the session still persists.
-yu chen
Yes, it makes sense if it asks for the servlet init parameters, but not the context parameters.
Thanks,
-yu chen
Question ID :994874119438
Which of the following lines can be inserted at line //1 to retrieve an initialization parameter "dbname" from the init() method of a servlet?
public void init()
{
//1
}
1. getServletConfig().getParameter("dbname");
2. getServletCofig().getInitParameter("dbname");
3. getServletContext().getInitParameter("dbname");
4. getInitParameter("dbname");
5. getParameterValue("dbname");
I would say (2, 3, 4) are all correct.
But the answer is (2, 4)???

Thanks,
-yu chen
What happens to a session if the containter is shutdown and then brought up again?
Thanks.
-yu chen