Identifiers and Program Names

File Simple.java contains a simple Java program that prints a message. The identifier that represents the name of this program is Simple, but we could have chosen a different identifier subject to certain rules and conventions. An identifier may contain any combination of letters, digits, the underscore character, but cannot begin with a digit (the dollar sign character is technically legal, but is reserved for special use). Furthermore, by convention, identifiers that represent class names (which includes program names) begin with a capital letter. This means that you won't get an error if your program name doesn't start with a capital letter (as long as what it starts with is legal for an identifier), but it's better style if you do. This may seem arbitrary now, but later when you have lots of identifiers in your programs you'll see the benefit. Of course, the program name should always be reasonably descriptive of the program.

Copy and paste the 7 lines below into your lab document. In the document indicate whether each name below is a legal identifier, and if so, whether it is a good choice as a name for this program. If the answer to either question is no, explain why. Then save Simple.java to your Eclipse directory and check your answers by modifying the variable matt to be each of the following. For each of the seven cases that is illegal in your lab document provide the error message that BlueJ generates.

  1. Matt

  2. MattIsGreat

  3. 1matt

  4. _matt_

  5. *matt*

  6. 123-45

  7. matt!


To hand in:

A copy of the 7 lines above, detailing which of the above identifiers are legal, and explaining why they aren't (along with Eclipse's error messages), where necessary. (You don't aubmit any version of Simple.java.)