

Java Programming Pitfalls
When debugging Java code, watch out for the following tricky spots:- You can't define multiple constructors or overloaded methods for the classes WebApplication, WebSession, Component, or any other class that originates as an Objective-C class. For example, the following code causes your application to crash:
public class MyComponent extends Component { public void myMethod() { .... }
//WRONG! Overloaded method causes runtime error. public void myMethod(int anInt) { ... } } - The pageWithName method creates the page by looking up and instantiating the component class that has the same name as the argument you provide to pageWithName. For this reason, your subclass of Component shouldn't be given a package name. For example, if you create a component named MyPage.wo and place its Java file in the package myClasses.web, pageWithName won't find the MyPage.class file.
- Java is a more strictly typed language than is Objective-C or WebScript. If you're more familiar with Objective-C, you'll find that you need to cast the return types frequently. For example, suppose you define a method named verify in the file Session.java and you want to invoke that method from a component's Java file. To do so, you must cast the return type of the component's session method as in the following:
// From a component's Java file. ((Session)session()).verify();
By definition, session returns a WebSession object. Because WebSession does not define a method named verify, your code won't compile unless you cast the return value of session to your WebSession subclass.