Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!

Ian Yang

Ranch Hand
+ Follow
since Nov 27, 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 Ian Yang

Is there anybody who is SCJP, SCWCD, SCJD, SCEA ?
I guess there are < 5% of java people get all four ? If you are, could you share with us how long it took you to accomplish all these four titles ?
19 years ago
Hello,
I read the instruction on submission and it says "all deliverables will be accepted as HTML only and each diagram must be UML compliant." "
build a jar archive that contains all html files".
But as I understand, we need to have several .gif or .jpg type image files anyway, so does that requirement actually mean that we can build a jar archive that includes "index.html" and those few image file(.gif) and submit it ? Then when grader opens it, he/she just reads the index.html and can navigate to the image files.
Does this make sense ? can somebody help ?
Thanks,
Ian
Hi,
I have a question about using package for servlets. Suppose I have the following package structure:
Inside the application directory my-app/, I want to put a java class myServlet.class which belongs to the package my-pack/, so I create the following structure:
my-app/my.jsp
my-app/WEB-INF/classes/my-pack/myServlet.class
my-app/WEB-INF/web.xml
What this is doing is to go from "my.jsp" and then click a SUBMIT button to go to "myServlet" page. But, the interesting thing I noticed is -- If I do NOT define "myServlet" in the <servlet> part of web.xml, it works fine. However, if I defined it, it failed. I tried the follwoing two ways to define the <servlet-calss> for "myServlet"
a) <servlet-class> myServlet </servlet-class>
b) <servlet-class> my-pack.myServlet </servlet-class>
but none of them works. So, question is -- if we have packaged servlet, do we need to define them in the web.xml and how to reflect their package structure in the <servlet-class> part ?
Thank,
Ian
19 years ago
Do you know what Java API handles the "ftp" type of work like download/upload ? I used to have some Korn shell script do this kind backgroud work, do you know if it is feasible to use java to do it ? will it be much slower ?
Thanks,
Ian
19 years ago
If I want to draw an exact sequence diagram it will be like seven or eight page wide and can't print it out. How do you guys handle this situation ? Should I
1. just draw out those significant objects that consist of the main framework of the flow so that other "trivial" or helper clas objects will be be in the picture and thus it can be put in a page.
2. still draw everything, but use some sort of printing skills to print it out.
I want to know:
A. what kind of printing option can I use to print the whole thing out ?
B. If I can only use normal size page to print then is using my choice (1) (only draw significant ones) a reasonable and common choice ?
Thanks,
Ian
Thanks. In the following class
public class Class_A {
public void doIt() {
Class_B b = new Class_B();
....
}
}
Since Class_B instance b is not Class_A's instance variable and no method in Class_A has a return type of Class_B, we should think there is no association relation between Class_A and Class_B assuming Class_B doesn't have any instance variable or method whose type is Class_A.
Is that right ?
Thanks,
Ian
public class Class_A {
private Class_B b;
.....
// some methods
}
*****************************
public class Class_A {
private String abc;
public Class_B do() {
...
}
}
***************************
For the first code's case, should I draw A-->B
as the unidirectional association between A and B ? For the second code's code, I don't have Class_B type instance variable, but I have a method whose return type is Class_B, how should I draw the association between A and B ?
Thanks,
Ian
In "MyServlet.java" 's doGet method, I called another class's method which utilizes the following codes
FileInputStream file = new FileInputStream("inputFile"); Properties p = System.getProperties();
p.load(file);
System.setProperties(p);
String var = System.getProperty("VAR");
...
....
Notice the above codes are in ANOTHER class's method and "MyServlet.java" just called it, but I found immediately after it calls this method, the HttpServletResponse object is no longer functioning properly. For example,
response.sendRedirect("URL");
has not ANY effect at all.
By the way, i found the "var" does get the correct results. So the "System.getProperty()" does get right result.
Do you know what's the reason for the response object's lost ?
Thanks lot,
Ian
20 years ago
In principle, if I write a code using JDk1.1, it should always be compiled and run successfully using jdk1.3, right ?
Now, if it uses some depracate methods, will JDK1.3 just give warning but still compile/run well, or will JDK1.3 make the compilation completely fail ? Is there any web site resource giving a list of any deprecate method/class for jdk1.1 ?
Thanks,
Ian
20 years ago
Suppose I have a super abstract class "Employee" and two subclasses "Worker" and "Manager" that implement some functions defined in "Employee".
I have a "EmployeeFactory" class to generate an instance of either "Worker" or "Manager". it simply takes a parameter variable "title" and do
*******************
public Employee get_Instance(String title) {
Employee e;
if(title.equals("manager"))
e = new Manager();
if(title.equals("worker"))
e = new Worker();
return e;
}
************************
Can this be called using Factory pattern ? does the method need to handle the case when 'title" is any sort of strange input ?
Thanks,
yang
In "Input.jsp" page, we have a form including a text box field for user to enter their name, like <INPUT TYPE="text" NAME="userName" ...>, when user clicks the submit button, it goes to "ProcessServlet.java". Now in the receiving servlet, if we use
String name = req.getParameter("userName");
it should get the input string, but we also need to handle a case when user does NOT enter anything in the box, we want to redirect to an error page. but, I found the code
if(name == null)
res.sendRedirect("errorPage.htm");
does NOT work though.
Is it because the "req.getParameter("userName")" is NOT returning a null string even user doesn't enter anything ? then what's the easiest way to detect if user enters anything using the .getParameter() ?
Thanks,
Ian
20 years ago
JSP
In a java code, it has following:
public void method_A() {
try {
...
...
}catch(Exception_1 e ) {
...
}catch(Exception_2 e) {
...
}
}
Now if I have another method called "method_B()" in the same class:

public void method_B() {
method_A();
}
this method_B only calls method_A. Then how should I handle the exception in this method, which one(s) of the following is(are) correct ?
1. public void method_B() throws Exception_1, Exception_2 {
method_A();
}
2. public void method_B() {
try {
method_A();
}catch(Exception_1 e ) {
...
}catch(Exception_2 e) {
...
}
}
3. public void method_B() {
mthod_A();
}
Thanks,
Ian
20 years ago
In "MyServlet.java" it invokes some classes which throws out some special exceptions that can be caught in "MyServlet.java". Then some customized exception (subclass of ServletException) is thrown from "Myservlet.java"'s doGet() and doPost() method. Eventually "MyServlet.java" does "forward(req, res)" to send results to "My.jsp" page, I try to catch ALL the exception in "My.jsp" using "errorpage = ..".
But, it seems once the "MyServlet.java" finds any error it goes to a server 500 default page without goes to my special jsp error page. Is it because the exception happened BEFORE the "forward()" ? If so, then how could I make it go to the jsp's special error page ?
Thanks,
Ian
20 years ago
JSP
In "MyServlet.java" it invokes some classes which throws out some special exceptions that can be caught in "MyServlet.java". Then some customized exception (subclass of ServletException) is thrown from "Myservlet.java"'s doGet() and doPost() method. Eventually "MyServlet.java" does "forward(req, res)" to send results to "My.jsp" page, I try to catch ALL the exception in "My.jsp" using "errorpage = ..".
But, it seems once the "MyServlet.java" finds any error it goes to a server 500 default page without goes to my special jsp error page. Is it because the exception happened BEFORE the "forward()" ? If so, then how could I make it go to the jsp's special error page ?
Thanks,
Ian
20 years ago
struts framework usually uses a centrilized ActionServlet as a controller, it goes to different action class and forwards the results to different jsp pages. In Apache jarkata it briefly talks about it but has not too much good details/examples. Anybody has any examples URL ?
Thanks.
20 years ago