Gary Mann

Ranch Hand
+ Follow
since Jun 05, 2003
Merit badge: grant badges
For More
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 Gary Mann

You don't - the server takes care of serialization and deserialization for you. The programmer's responsibility is to make sure that all the objects saved as session attributes are serializable. If your app may be deployed as distributable, make sure you test that sessions are recreated accurately.
20 years ago
You could use a FileOutputStream:
20 years ago
Interesting stuff, although perhaps only from an academic point of view. Given the arguments, does this mean there is no such thing as a platform independent language?
20 years ago
You probably already have this, but the link for various Jason Hunter / O'Reilly classes including the file upload is:
http://www.servlets.com/cos/index.html
Gary
20 years ago
Mike,
Since servlets run on the server the only way to process the file is to upload it, process it and then return the results as HTML or as a downloaded file.
If you want to process on the client, then check out signed applets. Frankly, I think these have limited use as the user must have the correct JVM version to run applets and must grant the appropriate permissions.
20 years ago
Integer[] integerArray = new Integer[10]; // define
// populate
for (int i = 0; i < integerArray.length; ++i) {
integerArray[i] = new Integer(i * 10);
}
20 years ago
1. I agree with you. An object of type "MyClass" only exists once it's been instantiated. The fact there there may be an associated object of type "Class" doesn't mean that "MyClass" exists.
2. IMHO, debates like this can be interesting, but are largely irrelevant. For practical purposes, the life cycle of an object is well understood so why complicate things? Perhaps your classmates could also debate whether an object really "exists" once there is no reference to it. Is it in some O-O purgatory waiting for the Garbage Collector to come and finalize it? Does an object have a soul?
20 years ago
As described above, the "new" method requires that the class name be known at compile time and creates an instance, whereas forName is used at runtime and only loads a class. This is not just useful for jdbc drivers, it is useful for whenever you want to specify a class name dynamically. e.g. on initializing a web app, you could read the names of classes as parameters and load them via forName. This enables different implementations to be used without code changes.

forName also allows specification of the class loader and whether the class is initialized.
20 years ago
Sorry - none of this means anything to me. There is info on the net regarding the W function but that is advanced Mathematics. If that's what you're doing, a Java forum probably isn't the place to find answers. It may be time to check in with your teacher! Good Luck.
20 years ago



Can we use Struts framework for Swing. Can anybody explain it how it will be useful. I feel struts can be used only with web applications. if i am wrong please correct it.


No - Struts and Swing run in different environments. Struts runs on the server as part of a web app. You could write a Swing client that communicated with a servlet in the web app, but the Swing code and the Struts code would be completely separate.
20 years ago
I can't think of a way either. It's a shame though, because the code to match the params and find the best fitting method must exist within the JVM because it occurs at runtime when you call a method directly. It wouldn't be too hard to write an algorithm - I bet someone's already done it.
20 years ago
You're right - I thought this would work but it doesn't. Obviously the Java API looks for an exact match. I tried to check out the code but it's a native method.

The following code works for your specific example. It would be more complex if there were multiple params or if we needed to consider interface references.
20 years ago
It should work - can you show the code?
Does it work when you specify Object.class as the parameter type? If so, you could use that to get the method and then invoke with the subclass.
20 years ago
Check out the java.lang.Math class. It has a method for raising powers (pow) plus lots of other useful stuff.
I suspect your homework is a programming exercise rather than a Math problem, but I think there is a simple way to calculate this. It's a long time since I was at high school, but to determine "n", can't you just calc the log to base 2 of the target and take the integer part? e.g. log to base 2 of 100 is 6.629 so n = 6.
In Java, a method to do this would be:


This runs into trouble for very large numbers due to the size of a double. e.g. 1 followed by 1000 digits is too large. If the target is always a power of 10, then you could use:
20 years ago
Glad it helps. You're right about the StringBuffer - definitely more efficient.
20 years ago