Home
|
Java Menu
|
Java Applets
|
Java Tips
|
E-mail Us
Do's and Don't
Common Problems
Programming Standards
E-mail us your tips
Do's and Don't
Take extra time to develop a good structure for your program. Incorporate the idea that it may need to expand in the future.
Create local variables over global variables. Do not create global variables unless they need to be shared. This minimizes the scope of your variables which makes it easier to debug.
Code one piece of the program at a time. Compile and test it. Code another piece. Compile and test it. Continue this process for the rest of your program. Do not write the entire program at once before compiling it for the first time.
When creating a package class, add a test driver to it. A test driver can be a simple print statement test to ensure that the class is being called.
When creating Threads, use the
wait()
and
notify()
methods along with the
synchronized
keyword instead of
stop()
and
suspend()
to ensure a lock is placed on a commonly shared object.
stop()
,
suspend()
, and
resume()
methods are deprecated because they are unsafe and can cause a deadlock in your program.
Avoid declaring the same variable names.
Use abstract classes to generalize common properties and methods of subclasses. Use abstract methods to define the common methods that must be implemented in subclasses.
Common Problems
If you updated your
.class
file, you need to shut down your internet browser and reopen it to see the new updates. Clicking the "Refresh" button on your Web browser will not work.
A variable must be declared before it can be assigned a value, and it must be assigned a value (initialized) before it can be read. Try to declare a variable and assign its initial value in one step.
Java source programs are case sensitive. Using
Main()
instead of
main()
will give you an error message.
Do not use the extension
.class
in the command line when executing the program.
If you modified your
CLASSPATH
variable in Windows 95 or Windows NT, you must restart the system in order for the new changes to take effect.
You must use the
equals()
method to test whether two objects have the same contents. The
==
comparison operator is used for comparing two primitive data type values, or for determining whether two objects have the same references.
Do not add media files in Java archive (.jar) files.
In a non-abstract subclass extended from an abstract class, all abstract methods must be implemented, even if they are not used in the subclass.
Programming Standards
Add appropriate comments throughout your program. You should include a summary to explain what the program does, its key features, its supporting data structures, unique techniques it uses, each major step, and anything that is difficult to read. Write comments in a way that someone else can pick up where you stopped.
Use descriptive identifiers for naming variables, constants, methods, classes, and packages. Here are some guidelines for naming conventions:
» For variables and methods, always use lowercase. If the name consists of several words, concatenate all in one, making the first word lowercase and capitalizing the first letter of each subsequent word in the name.
» For class names, capitalize the first letter of each word in the name.
» For constants, all letters should be capitalized.
Use a consistent indentation style to make your programs clear and easy to read.
Home
|
Java Menu
|
Java Applets
|
Java Tips
|
Legal
© 1999-2003 Complete e Solutions, Inc.