sylvia weller

Greenhorn
+ Follow
since Jan 07, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by sylvia weller

Hi Kishore,


I have to retrieve information from a datastructure (resident in a java list)
based on value entered in the form.


First, I would copy the java data structure into a JavaScript object when the jsp file gets loaded. (don't put it inside a js function, just inside the <SCRIPT> tags) For example, if the java data structure is an array:
<SCRIPT>
var arr = Array();
<%
String[] s = (String[])request.getAttribute("string array");
for(int i=0; i < s.length; ++i ) {
%>
arr[i] = '<% s[i]%>';
<% } %>
</SCRIPT>
Then, when the user does onChange, you pass a value to a js function which serves as an index into the js array.
As far as this goes

I need to initialize
the variable _in java_ to value from the form(in the onchange funtion).


I'm pretty sure you can't do this kind of assignment dynamically inside a javascript function. The js function is running purely on the clientside and has no dynamic access to java (serverside) stuff.
To update java values you need to _submit_ the html form with form values set. For example, if you're using purely jsp and your file is called "test.jsp", you can do <form action="test.jsp"> with <Input name="varx"> set to your computed value.
Then, when the form is submitted and "test.jsp" is loaded 'varx' is an input param and you can do an assignment something like this -


<% String selectedDate =%> = (String) request.getParameter("varx"); %>


Good luck.
Sylvia

23 years ago
JSP
Hi Bill -
Thanks for your helpful response.
Sylvia
23 years ago
Hi -
I am writing an uncomplicated servlet-based application which queries one db table and retrieves a subset of its data for JSP/HTML display.
I was thinking about saving the entire table (a few thousand rows) to the ServletContext at application startup time. Then, subsequent retrievals could run against this saved version. I'm pretty sure this would be _much_ faster than doing dbio for each retrieval.
So here's my question - is there any reason not to save 'lots' of data - thousands of lines - on the ServletContext? and why? I actually don't know anything about how memory is allocated and how much is available, within the servlet container (tomcat in my case). I just naively came up with this idea and want to know if it was a bad or good one.
Also, if anyone knows of a good reference on this topic please let me know. Thanks.
Sylvia
23 years ago
Hi -
Here's a good question from JQPlus:
class Test {
public static void main(String[] args) {
String s = "going";
print(s, s = "gone");
}
static void print(String a, String b){
System.out.println(a +", "+ b );
}
}
What is the output? The answer is "going gone".
(I tested it.) I actually do not understand what is happening. Here's the official explanation:
----------------
The assignment of the string "gone" to s occurs after the first argument to print has been evaluated. If evaluation of an argument expression completes abruptly, no part of any argument expression to its right appears to have been evaluated.
----------
I still don't understand. WHAT evaluation are they are talking about? Aren't _references_ to s passed to print(..). Can anyone explain how and in what order the s arguments get evaluated?
Thanks, Sylvia
Rob
You are right. Thanks for thinking about it.
Sylvia
Hi -
Here's a question from JQPlus: Which of the given statements are correct for a method that overrides the following method:
public void add(int a) {...}
Choose 3 correct answers:
1. It must return void
2. It may return int
3. It can declare any Exception in throws clause
4. It can declare any RuntimeException in throws clause
5. It can be abstract.
Correct answers: 1. 4. and, I am losing my mind, 5. How can 5. be remotely correct?
Thanks, Sylvia
This is a question from the RHE final exam:


What is the value of the following expression?
Math.round(Math.random() + 2.50001);
A) 2
B) 3
C) It is impossible to say


The correct answer is B)3 and here's the explanation:

Math.random() returns a double greater than or equal to 0.0 and less than 1.0. Math.random() + 2.50001 is a double greater than 2.5 and less than 3.5. Math.round() of any number between but not including 2.5 and 3.5 is 3.


Couldn't Math.random() return, say, .999999, in which case 2.50001 + .999999 = 3.500009. And wouldn't that round up to 4? What am I getting wrong?
Thanks, Sylvia
23 years ago

...Java Math.round() which by the way returns long...


This is not always the case. There are two 'round' methods:
int <- Math.round(float)
long <- Math.round(double)
Sylvia
Sun,
I got "10 and 10.0" - I think that's the same as you.
This is my theory: The return type of the an expression is determined at compile time. In the second expression (i>15 ? 10.0 : 10) the result is promoted up to the broader of the two possibilities, double (10.0) vs. int (10) => double. So you and I are both getting 10 promoted to 10.0.
In the first expression the compiler is able to fully evaluate the result - because there's no variable data. So I think there's a good chance, in your compiler and mine, that the compiler just inlined the result - the same false 10 as in expr2, but no promotion applied because the result was known at compile time. (The is similar to how C macro works).
For others who are not getting same output as we are, I would think their compilers are not inlining the first expression but evaluating both via promotion.
Just a theory. Anyone, please correct if it is wrong -- don't want to confuse people.
Sylvia
Hi -
I found this question in a practice exam too and thought the way it is written is confusing. That aside, I think the important point is that after animT has (1) entered wait() it gives up the lock on the animC object. As far as we know from the code given, the lock on animC is up for grabs until after (2) new animation is shown, when the lock is acquired again in the 'synchronized(this)' block. So animC is open (not locked) between (1) or (2) and is available for hypothetical updates via synch or unsyhronized methods.
Sylvia
Michael, what's the URL please for this defn of Component()(lines 447-450). Thanks.
Michael, you're right - "protected Component();" is not abstract. Dumb mistake on my part.
The "();" at the end of it threw me - it looks the same as a bodyless abstract method. But I'm now seeing that this is just the notation used in the API for not providing the implementation for a method. Amazing that I never noticed this before.
Thanks.
Sylvia
Thanks Mark. What you say makes sense, and I didnt' know that an empty constructor would compile.
But still --- purely syntactically, how is it possible that Component has this abstract body-less constructor? (when shape(); will not compile?) Does anyone know?
Sylvia