Chapter 2: Creating a Java Application and Applet 1
Using TextPad
• TextPad has several window areas
– Coding window
– Selector window
– Clip Library window
• TextPad can display line numbers
– Helpful for finding compiler errors
• TextPad has color-coding capabilities
– Save a document before entering code to
enable Java related color-coding
Chapter 2: Creating a Java Application and Applet 2
Coding the Program -
Comments as Documentation
• Purpose of comments
– Provides clear description when reviewing code
– Helps programmer think clearly when coding
• Placement of comments
– Use a comment header to identify a file and its
purpose
– Place a comment at the beginning of code for each
event and method
– Place comments near portions of code that need
clarification
Chapter 2: Creating a Java Application and Applet 3
Coding the Program -
The Class Header
• Identify how the code can be accessed with an
access modifier
– public indicates that the code can be accessed by all
objects in the program and can be extended for a
subclass
• Specify a unique name for the class
– The class name at the beginning of the program must
match the file name exactly
– Java is case-sensitive
– By convention, uppercase letters are used for class
names and to distinguish words in class names
Chapter 2: Creating a Java Application and Applet 4
Coding the Program -
The Class Header
• Use braces {} after the class header to enclose
the class body
Chapter 2: Creating a Java Application and Applet 5
Coding the Program -
The Method Header
• The method header contains modifiers, return value,
method name, and parameters along with their data type
• Every stand-alone Java application must contain a
main() method, which is the starting point during
execution
Chapter 2: Creating a Java Application and Applet 6
Coding the Program -
The Method Header
• Modifiers set properties for a method
– public allows other programs to invoke this method
– static means this method is unique and can be
invoked with creating an instance
• Parameters are pieces of data received by the
method to help the method perform its operation
– Identifiers are used to name the variable sent to the
method
• Return type is the data type of the data returned
by the method
– If no data is returned, the keyword void is used

Class method

  • 1.
    Chapter 2: Creatinga Java Application and Applet 1 Using TextPad • TextPad has several window areas – Coding window – Selector window – Clip Library window • TextPad can display line numbers – Helpful for finding compiler errors • TextPad has color-coding capabilities – Save a document before entering code to enable Java related color-coding
  • 2.
    Chapter 2: Creatinga Java Application and Applet 2 Coding the Program - Comments as Documentation • Purpose of comments – Provides clear description when reviewing code – Helps programmer think clearly when coding • Placement of comments – Use a comment header to identify a file and its purpose – Place a comment at the beginning of code for each event and method – Place comments near portions of code that need clarification
  • 3.
    Chapter 2: Creatinga Java Application and Applet 3 Coding the Program - The Class Header • Identify how the code can be accessed with an access modifier – public indicates that the code can be accessed by all objects in the program and can be extended for a subclass • Specify a unique name for the class – The class name at the beginning of the program must match the file name exactly – Java is case-sensitive – By convention, uppercase letters are used for class names and to distinguish words in class names
  • 4.
    Chapter 2: Creatinga Java Application and Applet 4 Coding the Program - The Class Header • Use braces {} after the class header to enclose the class body
  • 5.
    Chapter 2: Creatinga Java Application and Applet 5 Coding the Program - The Method Header • The method header contains modifiers, return value, method name, and parameters along with their data type • Every stand-alone Java application must contain a main() method, which is the starting point during execution
  • 6.
    Chapter 2: Creatinga Java Application and Applet 6 Coding the Program - The Method Header • Modifiers set properties for a method – public allows other programs to invoke this method – static means this method is unique and can be invoked with creating an instance • Parameters are pieces of data received by the method to help the method perform its operation – Identifiers are used to name the variable sent to the method • Return type is the data type of the data returned by the method – If no data is returned, the keyword void is used