Discussion Locked

Java Forum

0 helpful
29 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Welcome to the Java Forum. This is the place to post your Java questions, share your best techniques, develop your coding skills, and express your opinion on topics that impact IT development.

We also encourage you to post your comments about the Java TechMail.

If you haven't subscribed to the Java TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:
http://builder.com.com/techmails.jhtml?repID=u001

29 replies

by maryweilage

Use inheritance to improve your Struts applications

The Mar. 6, 2003, Java TechMail discusses the use of a base action class to better implement Struts. Do you use Struts in your application development? Will this tip help improve your use of Struts?

This discussion question was derived from a Java TechMail. If you would like to receive Builder.com Java e-newsletters in your inbox twice a week, visit our e-newsletter subscription center to subscribe today:
http://builder.com.com/techmails.jhtml?repID=u001

by thedew

A base action class is definately useful when all of your actions depend on the execute method, but what happens when many of your actions are doing dispatched execution?

The problem I run across is that my action classes define their own methods to call in their keyMethod map, so its base class would have no idea what method will be executed and nothing guarantees that the base action's execute method will ever be called.

Any suggestions for creating a useful base action class in this case?

by muzammil786

The important point is that you declare one abstract method in Base class which is to be implemented in all child action classes. Now if your action class needs to call other different methods, thus invoke all such methods in implemented abstruct method. Your Base class is not to check what business logic is implemented in child classes

by johnzoet

The email suggests to use an abstract base class for logging purposes.
I definitely do not recommend this method.
It is far better to centralize logging in a filter servlet.
That way you do not mix administrative and business logic.
The filter servlet can be changed independently from the base class which avoids possible problems in the production environment.

by reassembler

centralizing logging is definitely a good idea. i suggest using log4j's socket server and socket appender (wrong names, i'm sure), rather than writing a servlet to do it. there's also a buzz about using jms to centralize logging, but i've haven't tried that yet.

by maryweilage

The Mar. 10, 2003, Java e-newsletter, discusses how to manipulate large bits with the BigInteger class. BigInteger allows you to manipulate numbers with more than 64 bits.

Have you used BigInteger? If so, tell us what your experience was like.

by reassembler

i'm with shabaz. your abstract class should always call the one method that your subclass must define. if you want to map method calls, do it in the subclass. if your subclass does not override the struts action method, the your base classes method will always be called.

hope i'm not missing your point. let me know. if you have a code example you could send, that might clear things up.

dave

by thedew

This is a good idea to me, but I don't see how you could implement this using the structure provided by LookupDispatchAction (see http://jakarta.apache.org/struts/api/org/apache/struts/actions/LookupDispatchAction.html) because it's not my subclass's implemented abstract method that determines which method to call but this LookupDispatchAction's execute method.

Right now all my Action classes extend this base class:
------------------------------------------
public abstract class ActionBase extends
LookupDispatchAction {

protected Map getKeyMethodMap() {
return null;
}

public ActionForward execute(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

// if there is no dispatch map, return the
// default execute method
if (getKeyMethodMap() == null) {
//DO USEFUL STUFF
return defaultExecute(mapping, form,
request, response);
} else {
return super.execute(mapping, form,
request, response);
}
}

public abstract ActionForward defaultExecute
(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception;
}
---------------------------------------
The only problem is defaultExecute only gets called when there is no dispatch map.

by Mark W. Kaelin

Make mundane dev tasks easier with Ant:

The March 13, Java TechMail discusses Ant as a Java build tool. Do you use Ant to build your Java applications? If not, what tools do you use? Why?

If you haven't subscribed to the Java TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by avia

Granted, I haven't looked at the latest version of "ant" -- I tried using versions 1.1, 1.2 and 1.3 (I think) and had a _bad_ experience. The documentation was terrible (in my opinion), backward compatibility was non-existent, there is no DTD (or schema or whatever) for the XML build files -- since they're not valid XML files, anyway -- and "ant" will happily print out "Build Successful", when it wasn't!
[Of-course, when it fails, and "ant" succeeds in figuring out it failed, it prints out, "there should have been error messages" -- that doesn't really assure me of the author's confidence in the tool!]

On the opening page of the "ant" Web site, they talk about cross-platform (i.e. non-UNIX) portability being an advantage of using "ant", but with linux and cygwin and the new MacOS, how many non-UNIX platforms are there?

So PLEASE convince me that "ant" is good!

Avi.

by suneeshvr

Ant is really cool . I can update the files from my CVS and compile and place appropriately in my working environment .I can also create javadocs. And there are alot .please search in the net

by aballew2002

Everytime I try and do any activity on by computer, I have error messages that come up concerning Java. I know nothing about it. I thought maybe there was software I needed that I didn't have. When I pull up web pages, sometimes I get pictures, sometimes I don't. If I don't, I get a white box with an 'X' in it. Please help!

by caloizky

Dude, it would help if you tell us a little about your environment. Like say, what operating system, browser and what error do you see? Dig?

by Mark W. Kaelin

Test for object type with isInstanceOf():

The March 17, Java TechMail discusses using the java.Beans class to test for object type. Have you used the isInstanceOf() method to text for object type in your Java applications?

If you haven't subscribed to the Java TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by Mark W. Kaelin

Retrieve lost source code:

The March 20, Java TechMail discusses the Java Decompiler (JAD). Have you used a decompiler to recover Java source code? Which compiler did you use? Tell us what you liked and disliked about it.

If you haven't subscribed to the Java TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by caloizky

I still think that people shouldn't decompile programs. It's just another form of piracy. Sure, it's fun to know how things works, but how would you feel if somebody starts poking around your trade secrets? I guess people who decompile's other person's programs are just people that can't make a program. Dig?

by Mark W. Kaelin

That is an interesting point.

Are there no legitimate uses for decompiling classes? The associated TechMail indicated a few reasons for decompiling, including backup failures. But I wonder if decompiling is practical for those circumstances?I'd like to hear some more opinions on this.

by java guru

You are taking the point of view of the vendor. That is great, because that is exactly why customers MUST be able to decompile code when no source is provided.

When you are just one customer, your problems are not always the vendor's highest priority. Sometimes it helps to be able to tell the vendor exactly where their problem is. They have much more time to fix a problem when the solution is known than it is to research a hard-to-duplicate problem.

As an example, when I worked at TechRepublic, there were several instances where we were pushing our vendor's product harder than any other customer. However, we were not the largest customer that they had. In the beginning, 80% of the vendor's patches were in response to problems that we encountered before any of their other customers.

It proves so much easier to get a vendor to fix a problem when you can say in this class/method, this condition is possible.

They may not like you snooping in their code, but you are payingthem for a service and you are helping them provide a higher level of service.

by Mark W. Kaelin

Let XDoclet write your stub classes:

The March 24, Java TechMail discusses automated code generation with XDoclet. Have you used XDoclet to write your stub classes? Have you used a different tool for this purpose? Share your opinion on the best productivity tool for automated Java code generation.

If you haven't subscribed to the Java TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

by jay_shree

I have added a shutdown hook in my application to perform some clean up actions while shutting down my application.I find that the shutdown hook is not being called when users shutdown the application by doing a CTRL_C.It is working fine when they do a CTRL_ALT_DEL.Is there any workaround for this?
Thanks in advance.

by avia

It looks to me like the hyperlink for listing A (in the article) has been swapped with the hyperlink for listing B. In other words, when I click on the hyperlink for listing B, it shows the code for the "MemoryBlock" class, but the article text refers to listing A as containing that code, whereas the hyperlink for listing A shows the sample application code while the article text indicates that listing B contains that code.

Thankyou (in advance for sorting that out :-),
Avi.

by kingjr3

I agree totally with Java Guru.

We have a product that doesn't scale well, and not know the internal workings of the EJBs I decided to decompile and "help" them along in researching the problems.

To date, we haven't found anything that cures our problems, however, we did find many inefficiencies that could be addressed. Without my assistance, the vendor wouldn't even know about these issues.

caloizky, your comment about decompiling is so narrow minded, that I question your experience in the Java world.

by frank

I am looking for a script to build an Affordability Calculator. Can anyone help me locate one. I play around with JAVA but I am no expert. As a small business just starting up, any help I can get would be appreciated

by virbc

You can try using javascript (http://javascript.internet.com) instead of java. Do a search for calculator, you might find one that has the features/functions you have in mind. If not, choose the closest then modify to suit your needs.

by johnzoet

Did anybody get the Java example from builder.com working ?

I downloaded the JPCAP from SourceForce.
To my surprise I could not find these imports:
import jpcap.JpcapHandler;
import jpcap.Jpcap;
import jpcap.Packet;

I searched all JAR files in folder jars and thirdParty.

by reuben

The July 10 Java Tech Newsletter featured the article:
"Don't call overrideable methods from constructors, When initialized isn't"

I thought this was a very interesting article that illustrates an important mistake people can easily make, especilly if they come from a C++ background, where constructors always call methods of the same class, even if they are overridden. But I'd like to offer a suggestion that would have made the article a bit more helpful. The article concluded:

"What's the lesson? Don't call overrideable methods from constructors. ... Save yourself a lot of time and effort by following the simple rule of not calling overrideable methods from constructors."

But the article did not mention how to ensure that methods are not overrideable. The correct solution is to mark any methods called from the constructor as 'final'.

-Reuben Fisher

by reassembler

thanks for the catch. i should have mentioned how to make methods final.

i can't recommend automatically making all methods final because i believe that behaviour as well as attributes should be overrideable by default. though i might be persuaded to go this route if anyone has other good reasons for declaring all methods final by default?

thanks

This discussion is closed to new replies.