Albany Programming Course Supplement

Complete Applications

A complete application is a program that a person can command to run after he or she writes it or downloads it into a computer.  Commanding to run a program is variously called "running", "executing", "launching", and "opening an application".  It means that somehow the program code is readied inside the computer so that code begins to control what the computer does. 

Usually, what the computer does when controlled by a complete application is useful. However, a program is still considered a complete application when what it makes the computer do is nonsensical, is merely amusing, or is only a partial or incorrect version of what the programmer or the person running the application desires. Often people are told that computers do what they are programmed to do, not what we want them to do.  That is hard to believe because most people see computers doing what people want most of the time.  Also, most people cannot clearly account for why or how computers fail or behave unexpectedly.  However, a computing professional or serious hobbyist or student takes very seriously the maxim that computers do only what they are programmed to do.     

    It is absolutely critical to realize that what an application makes the computer do is determined by and only by the program code1  plus the interactions or data input that the application encounters when it is run.  The desires, wishes, intentions, goals, dreams, nightmares, or anything else the programmer's or the person choosing the application thinks about in no way determine what the computer does!

Example:

Consider this program:

class AddTwoPlusThree
{
  public static void main(String[] aasasdf)
    {
      int answer;
      answer = 2 + 3;
      System.out.println("Two plus three equals " + answer);
    }
}


 Question:  When this application is run, it prints "Two plus three equals 5".  Why?

  1. The name of the program is AddTwoPlusThree.
  2. It is supposed to demonstrate how arithmetic calculations and printing is programmed in Java.
  3. We know it because when we run the program, that is what it prints.
  4. The author of this book told us.
  5. According to the rules of Java, which we assume the computer follows, application code begins to run by calling the main method.  The main method in this program first declares an int variable named answer.  When the main method runs, the arithmetic expression 2 + 3 directs the computer to add the literal values 2 and 3.  The computer calculates 5 for the result.  The assignment operation then directs the computer to copy 5 into the variable named answer.  The last line in main first directs the computer to generate a string by concatenating the literal string "Two plus three equals " (note the space after equals) to the string form "5" of the value of the variable named answer.  Second, it directs the computer to print the generated string, which we realize is "Two plus three equals 5".
Every one of the proposed answers is true.  However, the only one that is correctly answers, from the point of view of computer science the question "Why?" is the last one, the long explanation numbered 5.  Whether an answer is true is completely different from whether the answer answers a given question satisfactorily.  The computer prints "Two plus three equals 5" because the computer follows the rules of Java when it runs this application's code, and the rules of Java applied to this particular program code can be easily checked to produce this result by any person who understands those rules. 

Computer science graduates are expected to be able to transform a concept or a description of what a complete application is supposed to do when it runs into the actual code of an application that does it acceptably.


  1. Besides the rather short codes that students write when they program, the computer has installed in it lots of program code, written by other people, that also determines what student programs do. This is the code in the "libraries", including for example the code run when the println() method of the System.out object is called. ^

Question: Mustn't the argument list of main be (String[] args)? That's the way it's written in every textbook and program I've seen.

The following step-by-step account of facts answers the question:

  1. main is a method.
  2. Every method has an argument list.  The argument list specifies zero or more names of variables with their types.
  3. The name of a variable can be anything, as long as it follows the rules of Java that say what kind of first character it can have and what kinds the subsequent characters it can have.  The name must also not be a keyword (like "if" and "class"). 
  4. "aasadf" satisfies these rules just as well as "args".

 The idea that rules apply independently of the context of their use is a kind of "context-freeness". 

Question: So why does everybody spell the argument to their programs main function "args"?

(answer and example)

Question: So why can't we use a method name like "startHere" instead of "main"?

 We answer by asking another question.

Question like a computer scientist would ask:  A method is called by code with the method's name written in another method (or the same method, if it is recursive). So how can the first method call be made?

Answer: The Java virtual machine treats the first method call as a special case. Otherwise, the answer would be "It can't, so the Java system is useless."  (maybe elaborate after reseaching Java documentation).

The analogous problem arises in every programming system.  At the operating system's executable file loading level, every executable file has data in it at a specific place that determines the address of the first instruction to be executed after the program is loaded into memory.  At the elementary C or C++ programming level, the function named "main" is called shortly after execution begins.

There is a difference for interpreted languages such as Python, Perl, or Scheme.  The interpreter reads the source file each time the program is run and it executes the statements in the order they are read.  Some statements operate to define methods (also called functions) or declare variables, and others command the interpreter to do an executable operation (write better or simplify? or omit this point?) 

 



There has been error in communication with booki server. Not sure right now where is the problem.

You should refresh this page.