Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Wednesday August 30 , 2000
 
Introduction to Programming in Java  

 
  Class Notes  -- Wednesday August 30 , 2000

   
   CSC212 - August 30, 2000
   ======================================
  
   Lecture Topic: INTRODUCTION TO PROGRAMMING
  
   DEF: The "Computer" is a general purpose machine which 
        can be made to act like a special purpose machine 
        by means of a  program.
    
     A suggestive picture
                     __________
             5       | The    |  5,16,8,4,2,1 
         -------->   |Collatz |  ------------>
       input stream  |Program | output stream
                     |________|       
  
                     __________
      red,white,blue |        |  blue,red,white
      ----------->   | Sort   |  ------------->
       input stream  | Words  |  output stream
                     |________|
  
   Remark
    
      We want to write programs in Java to render the 
      computer a special purpose problem solver.
  
    The approach we will adopt
  
      We will write Java programs (text) by means of a 
      "template based slot and filler" scheme.
  
   Basic application template
  
      Write code which can be read & reused by others.
  
      //    Documentation - line
         _
      /*  |
          | Documentation - multiline 
      */ _|
        
      <?Class> Slot to fill in
  
      <?Author> Programmer
  
        Example:  <?Class>.Java
                  HelloApp.java
    
                  <?Author> Byron Bahr 
  
                  <?Line> Classical First Program
    
                  <?Program> IO.println("Hello World!")
  
         Word
                 Java HelloApp.java
                 Java HelloApp
                 Hello World!
  
   DEF: A Java Application Template is a test which is a 
        Java program except for "slots" which must be filled.+
  
  
        These templates contain five textural sections:
  
      1. General Information
      2. Application Description
      3. Required Packages
      4. Program Section / Application Class
      5. Demo
  
    Remark: A concise way of presenting a program in class
            is simply to display slots & fillers since most
            of the other stuff is invariant technical 
            information.
  
   A presentation of "Hello World" using slots & fillers:
  
     <?Class>       --> HelloApp
     <?Author>      --> My Name
     <?Line>        --> A Classical First Program
     <?Description> --> ---------
                        ---------
     <?Needs>       --> import IO.
     <?Program>     --> IO.Println ("Hello World!")
                        // Println = print & line feed
     <?Demo>        --> Hello World!
  
    Remark: On the previous program, one can interpret 
            the line -
  
              IO.println("Hello World!")
  
            In the following way - 
    
              IO is an Object
  
              Println("Hello World!") is a message.
  
    Remark: The basic mechanism of computation of Object-
            Oriented programming (OOP) is the sending of
            messages to objects which respond with some 
            form of behavior.
  
    Remark: In the sole executable instruction of the Hello
            World program
  
            The message println("Hello World!") is sent to
            the object "IO" which responds behaviorly by
            printing the string "Hello World!" to the 
            standard output file.
  
   DEF: Object-Oriented Programming is a style of 
        programming which features the modeling of objects 
        in a hierarchical fashion and the sending of 
        messages to appropriately behaving objects.
  
   DEF: A Message Send is a construct of the form - 
     
          <Object>.<Message>
  
        which tells the computer to "send the message to 
        the object (which knows how to process it".
  
        Hypothetical message sends:
  
           Poker  hand.display()
  
           Money  dime.area()
    A Java program to read two integers display their sum:
  
        <?Program> --> 
  
     //  Read the two integers and store them in memory
     //  Declare Variable
  
         int n1 = IO.read_int();
         int n2 = IO.read_int();
  
     //  Compute the sum
  
         int sum = n1 + n2:
  
     //  Display the Sum, Labeled
  
         IO.print ("The Sum is: ");
         IO.print (sum);
         IO.println();
  
   DEMO:
  
     //  Java Compiler
  
       > javac SumOfTwoIntsApp.java
       > java  SumOfTwoIntsApp
  
         12 Ret
          7 Ret
         The Sum Is: 19
  
   Environment: Bindings in memory
  
       n1  --> 12
       n2  -->  7
       sum --> 19
     
   Message Sends:
  
       5 in Program
    
         2 obiedient
         3 prints
  
   =========================================================
   123456789112345678921234567893123456789412345678951234567