Small Java Programs

This chapter discusses naming and coding conventions as well as reserved words in Java. When you go through this chapter, you'll get some hands-on experience with writing in Java.

3. Identifiers and Reserved Words


    1. What should the source file be named?
    2. What is the name of the bytecode file the compiler creates?
      • AddUpNumbers.class

Identifiers and Reserved Words

public class Hello
  public static void main ( String[] args )
    System.out.println("Hello World!");

Most classes contain many more lines than this one. Everything that makes up a class is placed between the first brace  {  and its matching last brace  } .

The name of the class (and therefore the name of the file) is up to you. In programming, the name for something is called an identifier. An identifier is one or more characters long.

The first character of an identifier cannot be a digit. The remaining characters can be a mix of alphabetic characters, digits, underscore, and dollar sign $. No spaces are allowed inside an identifier.

It is conventional for a class name to start with a capital letter, but this is not required by the compiler. However, follow this convention so your programs are easier to understand. A source file should always end with .java in lower case.

reserved word is a word like class that has a special meaning to the system. For example, class means that a definition of a class immediately follows. You must use reserved words only for their intended purpose. (For example, you can't use the word class for any other purpose than defining a class.)

Question 3:

Which of the following look like good identifiers?

Lady Luck