Help coderanch get a
new server
by contributing to the fundraiser

David Duran

Ranch Hand
+ Follow
since Feb 11, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by David Duran

In the sample code below, only the short arithmetic is throwing a compiler error. Does anyone know why that is? Someone told me that it could be that adding two shorts can possibly be bigger than the maximum value that a short can hold. But if that's true, doesn't that apply to all the other primitive data types?

C:\Test.java:30: possible loss of precision
found : int
required: short
short s = short1.shortValue() + short2.shortValue();




One way to get around the compiler error is to do this but I'm wondering if this will give unexpected results, e.g. two maximum value short values being added together. Then again, I could be wrong-- any input?


[ August 31, 2004: Message edited by: David Duran ]
20 years ago
Let's say I have a Number array filled with different kinds of Numbers

Number[] numArray = {new Integer(6), new Long(10), new Float(5.9), new Double(10.1)};

How would I go about sorting through such a list WITHOUT knowing what datatype the number actually is? The Number class doesn't support the compareTo() method.

In other words:



The line in question is the "***".

Is there an easy way to compare Number objects that are of different subclasses? Perhaps there isn't or it's simply escaping me-- it's been a long day. Remember, I don't want to assume that the first Number is an Integer, the next one is a Long, etc. The order and types of Numbers in numArray can't be assumed.
20 years ago

Results in:
i:111111111
f:1.11111112E8
i_f:111111112
What's up with that? How can I do the conversion of an int to a float and back to an int such that the last int value is the same as the first?
20 years ago

Originally posted by Ilja Preuss:

Could you make use of the Strategy design pattern?


Thanks Ilja. I'll read up on it because I've never heard of it
20 years ago
Too bad no one ever answered this question because I'm finding myself in the same boat.
At the current moment, I use a technique borrowed from the JGuru Ant FAQ. I opted for "-prod"/"-dev" in the filename rather than as separate directories. I only do it for one configuration file, a log4j config file, so it works even though it may not be the best solution.
http://www.jguru.com/faq/view.jsp?EID=535861
But now I'm finding myself needing different code implementation (same classes) for development/production environments and that I'm not sure how to implement.
I would hate to support two types of Java classes, -dev/-prod between environments. But in my limited experience, this seems like one of the obvious solutions. This is where I wish there was a pre-processor in Java so I could do things like #DEV or #PROD and have them excluded depending on the environment the code is going to be used in.
If anyone has feedback, I sure would appreciate it.
20 years ago
Tomcat Version: 5.0.19
I want to be able to keep my $CATALINA_HOME/conf and $CATALINA_HOME/webapps directory separate from the rest of the $CATALINA_HOME stuff. Is the easiest (and safest) way to do this by moving them to their new location and setting the ENV var CATALINA_BASE to point to their new location?

I ran a quick test like that on my local machine and it seemed to work. The only thing that caught my attention was that Tomcat was trying to look for the admin and manager webapps under server/webapps relative to $CATALINA_BASE, not $CATALINA_HOME. So I got these exceptions but was able to get rid of them by moving $CATALINA_HOME/server/webapps to $CATALINA_BASE/server/webapps.
Might I add that I'm not using the admin and manager webapps, so I'm wondering if I could ignore the errors altogether.
I just don't know if that's safe to do that. Any insights? Thanks.
[ March 11, 2004: Message edited by: David Duran ]
20 years ago
Hi Candy,
Do you still get same compiler error if you shorten the code to one line?
LimitedTextContainer GrpAcctNumber = new LimitedTextContainer("1234567890");

Does the compiler error disappear when you comment out the second line (this will probably result in a NullPointerException during run-time, but the point is to get past the compiler error first)?
LimitedTextContainer GrpAcctNumber = null;
//GrpAcctNumber = new LimitedTextContainer ("1234567890");
20 years ago
Here's the solution:
http://www.jguru.com/faq/view.jsp?EID=1019053
http://ant.apache.org/manual/CoreTasks/basename.html

Resulting output:
C:\Projects\src\package1
package1
C:\Projects\src\package2
package2
C:\Projects\src\package3
package3
20 years ago
If you might be wondering why I need just the directory names and not the entire path, it's because I'm using the directory names by themselves as property values.
I want the property value to be "package1" and not "C:\Projects\src\package1"
20 years ago

basedir value: C:\Projects\
src.dir value: src
dirset looks in: basedir + src.dir == C:\Projects\src

Subdirectories in src:
package1
package2
package3

Resulting output:
C:\Projects\src\package1
C:\Projects\src\package2
C:\Projects\src\package3

Does anyone know how I can get a relative directory listing such that the output would be:
package1
package2
package3
20 years ago
A followup on what I've found out for turning on the default RMI logging:
1) Refer to RMI Implementation Logging for the list of RMI logging properties.
2) Pass "-C-Djava.rmi.server.logCalls=true" when you run the rmid program. You might also want to pass "-C-Dsun.rmi.log.debug=true" as well.
An example command looks like:
${JAVA_HOME}/bin/rmid -J-Djava.security.policy=mypolicy.file -C-Djava.rmi.server.logCalls=true -C-Dsun.rmi.log.debug=true &
* Note: This caused the RMI logging output to be printed via System.err on my console window which wasn't very helpful since I wanted it saved to a file. In my search I came across these 2 tidbits in a couple of RMI books:

The easiest way to get the "sun.rmi.*" logs to be saved to a log file is to redirect System.err


You have to set the logging destination before you invoke any RMI methods. Once RMI starts loggging to a particular PrintSteam, it keeps logging to that PrintStream.


Check this link for code on how to redirect to System.err: Redirecting streams
The conclusion:
The code that redirects System.err is run only when a remote method is called, mainly because I'm using Activatable objects (the implementation classes reference a constants class which has a static code block that has the redirection code). Because of that, I can't satisfy the condition stated in the second quote which means I still don't know how to get the RMI logging to be output to a file.
At the very least, I can at least see the RMI log output now.
Hope this helps anyone else.
[ February 18, 2004: Message edited by: David Duran ]
20 years ago
Well, I found this information: http://user-aecolley.jini.org/#rmi which seems to answer my above questions in regards to the "log" directory.
20 years ago
Okay, this might very well be a "Duh" question but I've noticed that when I run my RMI servers, a "log" directory is made with the following files:
Logfile.1
Snapshot.1
Version_Number
Does anyone know what those files are? I would think that they contain RMI logging output but none of the files are in a readable text format.
I need to turn on much of the RMI logging facilities to debug a problem and I'm trying to figure out where and how to read the log files. Any help would be appreciated.
I've never worked with 1.4's logging mechanism before. I use log4j.
20 years ago
I have a comma-delimited list of values that I'd like to be able to have tokenized and automatically placed into a list or an array. Is there such an object that will allow me to do that via the constructor or something?
The manual alternative would seem to be to use StringTokenizer, iterate over it's values, and insert them into a list. I'd like to have to avoid this and use the desired above solution if possible.
Thanks for the input.
20 years ago
I've put in some logging to catch the exception and log the input. I'll post it if I find out.
Thanks for the input guys.
20 years ago