Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java 101 study hall

Brush up on Java terms, learn tips and cautions, and enter the first <strong>Java 101</strong> reader challenge

  • Print
  • Feedback

Glossary of terms

polymorphism
The quality or state of assuming different forms (or shapes)


Tips and cautions

These tips and cautions will help you write better programs and save you from agonizing over error messages produced by the compiler.

Tips

  • Don't call class methods via object reference variables. Doing so clouds the fact that those methods are class methods.


Cautions

  • If a class declares an abstract method, the class signature must include the abstract keyword. Otherwise, the compiler reports an error.
  • If a subclass inherits an abstract method from an abstract superclass and does not provide a code body for that method, the compiler regards the subclass as abstract. Attempts to create objects from that subclass will cause the compiler to report errors.


Miscellaneous notes and thoughts

Just as it is unwise to add new constants and/or method signatures to an interface, it is also unwise to remove those members. To see why, consider the following example:

Create an X.java source file that contains Listing 1's source code. That source file holds an interface declaration named X:

Listing 1. X.java

// X.java
interface X
{
   void foo ();
}


Create a UseX.java source file that contains Listing 2's source code. That source file holds a class declaration that implements X:

Listing 2. UseX.java

// UseX.java
class UseX implements X
{
   public static void main (String [] args)
   {
      X x = new UseX ();
      x.foo ();
   }
   public void foo ()
   {
      System.out.println ("foo");
   }
}


Compile both source files. Assuming you use the SDK tools for Windows, type javac UseX at the command line to create X.class and UseX.class.

Run UseX (by typing java UseX) and the program should run correctly.

Comment out void foo (); in X.java and recompile that source file (i.e., javac X.java).

Attempt to run the previously generated UseX.class file. This time, you will receive a runtime error message stating that a method -- foo(), to be exact -- cannot be found.

Homework

Now that the object-oriented language basics series has ended, it is time to test your knowledge of series material. To add some incentive for completing the quiz below, I've fashioned the questions into a reader challenge. Challenge winners will receive JavaWorld sweatshirts and t-shirts.

Here are the rules:

  • All entries must be submitted no later than 12:00 p.m. Central Daylight Time on October 15, 2001.
  • Please email your answers to Java 101 Challenge (no attachments). You can include either a copy of the questions with your answers or just the answers. However, I must be able to associate your answers with the respective questions.
  • You must answer all questions.
  • I will sort entries by submission date/time stamp. The first three individuals to achieve a score of 100 percent will receive sweatshirts. If only one person gets 100 percent, the first two individuals who achieve 99 percent will each receive a t-shirt. If no one achieves 100 percent, the first three individuals who achieve 99 percent will receive t-shirts. This process will continue until I find the first three individuals with the highest scores.
  • Entries will not be returned.
  • Winners will be contacted.
  • The names of the three winners will appear in the November Java 101 column.
  • This challenge is open to anyone.
  • Neither JavaWorld nor Jeff Friesen will be held liable for any misunderstanding of challenge rules.


I've divided the quiz into four sections:

  • Print
  • Feedback

Resources