Commanding The Demons

From Huben's Wiki
Jump to: navigation, search

The-shadows-of-goetia.gif

Today we will study the basic principles by which we command demons, and make them dance to our whims!

Contents

(A) The Anatomy Of Demon Commands

Consider this, our SimpleDemon from before.

1   public class SimpleDemon                          // class name
2   {                                                 // start of class body
3
4     static public void main(String[] args)          // method signature
5     {                                               // start of method body
6       System.out.println("Hello world!");           // statement in method body
7     }                                               // end of method body
8
9   }                                                 // end of class body
  • The class is the type of demon, as you can see from line 1. The curly braces on lines 2 and 8 start and end the class body. As we have see before, curly braces make a block and so the class body is a block.
  • The class body contains the commands with which we order demons to do our bidding. These commands are called methods.
  • A method is a contract with a demon composed of two parts. The first part is called the signature.
    • The signature has several parts. These include:
      • What the demon will give you when you invoke this method. This is called the return value, and for this demon it is 'void'. We shall speak more of this anon.
      • The name of the method. That is our primary concern today! The only method for this demon is 'main'.
      • What you will pay the demon. This price is called the arguments of the method, and for this demon there is a standard price. Not blood as you may think, but 'String[] args'. These too shall be made clear as we progress. You will notice that the arguments are enclosed in ordinary parentheses. If there is more than one argument, they are separated by commas.
    • A signature can be recognized by residing within the class body and having a name followed by arguments enclosed in parentheses. Betimes there will be a long list of arguments inside the parentheses. Other times there will be no arguments but still there will be parentheses to show where they might be: '()'. Fear not the complexity of the arguments; recognize only that they are enclosed in parentheses and separated by commas.
    • Other important names of the signature include declaration and header: these are synonymous.
  • The second part of the method is called the body.
    • Just as the class body is enclosed in curly braces, so a method body is enclosed in curly braces. And again, curly braces make a block and so a method body is a block.
    • Method bodies contain statements and perhaps more blocks. We will not concern ourselves with these now, except to use the ' System.out.println' incantations.

(B) Discovering The Commands Of Other Demons

Refer once again to The Mystery Of The Curly Braces.

  • What is the name of the class of this demon?
  • If you compiled this class, what would the name of the object file be?
  • Seek ye the names of the three commands (methods) that this demon will obey! What demands (arguments) do the demons require to do your bidding?
  • Gaze upon the names of the class and the methods: are there differences in the first letters?

(C) A Profusion Of Demons

  • Download ye the dread Student Disk, and install it upon your H drive.
  • Explore the myriad demons which reside therein, and examine their commands (methods.) Can you delve into their mysteries?
  • Peer into studentdisk/Ch11/Exercises/Triangle.java, and seek ye the five methods therein. One of them is different: it bears the same name as the class and thus has yet another difference from all the other methods? Know thou this difference?
  • We call such methods constructors: they are special, and we will learn of them later.

(D) After Class Demonology

  • Peer into studentdisk/Ch20/Teletext/TeletextList.java, and list the methods therein. List also the number of arguments for each method.
Personal tools
translate