Kinesia Online Course
Object Oriented Programming
Kinesia LLC, 2003
    1. A Little Taste of Java
    2. Abstraction and Modeling
    3. Objects and Classes
    4. Object Interactions
    5. UML and Relationships between Objects
    6. Collection of Objects
    7. Some Final Concepts
    8. Object Modeling and Use Cases
    9. Modeling of Dynamic Behavaior and Sequence Diagrams
    10. A Deeper Look at Java
    11. Java Layout
    12. Java Events
    
    The top software developers are more productive than
    average software developers not by a factor of 10X or
    100X or even 1000X but by 10,000X.
    					
    					Nathan Myhrvold
    
    
    A Little Taste of Java
    1. Why Java ?

    2. Java is Architecture Neutral

      Question: If we compile a Java source program in MS Windows to binary code, can we ftp the binary code to Linux and execute it?
      How about C++?

      	//Java program
      	public class Csusb {
      	  public static void main( String [] args ) {
      	    System.out.println( "CSUSB the Beautiful!" );
      	  }
      	}
          
      Platform
      independent
      Java source code..
       
      Java Compiler
      for Linux
      Java Compiler
      for Windows
      Java Compiler
      for Mac OS
      ...yields...
       
      
      
      	...............
      
          
      Platform
      independent
      byte code..

      Byte code can be run on any computer that supports a Java Virtual Machine ( JVM ) , which is a special piece of software that knows how to interpret and execute Java byte code.

    3. Works seamlessly with World Wide Web

      An applet is a 'mini' Java program that can be embedded in a Hyper Text Markup Language ( HTML ) page.

        <html>
          <head>
            <title>My Home Page</title>
          </head>
          <body>
            <applet code=MyApplet width=80 height=100></applet>
          </body>
        </html>
        

    4. Provides One Stop Shopping
      • has extensive set of application programming interfaces (APIs )
      • java.io -- used for file system access
      • java.sql -- Java Database Connectivity ( JDBC ) API
      • java.awt -- Abstract Windowing Toolkit, for GUI development
      • javax.swing -- Swing components, for GUI development
      • Others -- imaging APIs, audio APIs, communication APIs ....

    5. Gives better language features
      • has made significant improvement over languages ( e.g. C++ ) that have preceded it
      • similar syntax to the popular C++ language

    6. Is Heavily Object Oriented
      • Except a few simple data types, all data are objects
      • All GUI building blocks are objects
      • All functions are class member functions known as methods; no standalone function allowed; even main() function is bundled within a class

    7. Is an Open Standard
        Source codes of the libraries are available

    8. Is Free
    9. Anatomy of a Simple Java Program

      //Csusb.java
      /*
        A simple Java Program
      */
      public class Csusb {
        public static void main( String [] args ) {
          System.out.println( "CSUSB The Beautiful!" );
        }
      }
      
      Compile: javac Csusb.java   → Csusb.class

      Execute: java Csusb

    10. Built-in Java Data Types

    11. byte: 8 bits
    12. short 16 bits
    13. int: 32 bits
    14. long: 64 bits
    15. float: 32 bit floating point
    16. double: 64 bit floating point
    17. char: a single character, stored using 16 bit Unicode encoding
    18. boolean: can be true or false
    19. String: character string
    20. Examples:

        String s = "CSUSB the Beautiful!";
        String s1 = "Java the Tasteful";
        String s2 = s + s1;
        String name = null;
      
        char c = 'A';			//single quote
      
        boolean error = false;
        ....
        if ( error )
          ...
      
        boolena done = false;
        ....
        if ( done )
          ...
      
        if ( done == true )
          ....
      
        while ( !done ) {
          ....
        }
       
        

    21. Creating an Applet

        //Csusb.java
      import java.applet.Applet;
      import java.awt.Graphics;
                                                                                      
      public class Csusb extends Applet {
          public void paint(Graphics g) {
              g.drawString("CSUSB the Beautiful!", 50, 25);
          }
      }
        
      javac Csusb.java → Csusb.class

      create a file called csusb.html

      <HTML>
      <HEAD>
      <TITLE>A Simple Program</TITLE>
      </HEAD>
      <BODY>
      Here is the output of my program:
      <APPLET CODE="Csusb.class" WIDTH=250 HEIGHT=30>
      </APPLET>
      </BODY>
      </HTML>
        

    22. Autoincrement and Autodecrement Operators

      autoincrement     ++

      autodecrement     --

      	int i, j, k;
      	
      	i = 1;
      	j = i++;	//j ← 1, i ← 2
      	i = 1;
      	j = ++i;	//j ← 2, i ← 2
        

    23. Automatic Type Conversions and Explicit Casting

      	int x;
      	double y;
      
      	x = 1;
      	y = x;		//O.K.
      
      	x = y;		//NO, won't compile; O.K. in C++
      
      	x = ( int ) y;	//O.K. explicit casting
      
      	float z = 3.5;	//Error!	Why?
      
      	float z = ( float ) 3.5;	//O.K.
      
      	float z = 3.5F	//O.K.
        

    24. The For Statement

      // Print a Fahrenheit to Celsius table
      
      class FahrToCelsius  {
      
        public static void main (String args[]) {
        
          int fahr, celsius;
          int lower, upper, step;
      
          lower = 0;      // lower limit of temperature table
          upper = 300;  // upper limit of temperature table
          step  = 20;     // step size
      
          for (fahr=lower; fahr <= upper; fahr = fahr + step) {  
            celsius = 5 * (fahr-32) / 9;
            System.out.println(fahr + " " + celsius);
          } // for loop ends here
      
        } // main ends here
      
      }
        

      Outputs:

      0 -17
      20 -6
      40 4
      60 15
      80 26
      100 37
      120 48
      140 60
      160 71
      180 82
      200 93
      220 104
      240 115
      260 126
      280 137
      300 148
        

      -----------------------------------------------------------------------------------------------------------------

      //Count to ten
      
      class CountToTen  {
      
        public static void main (String args[]) {
          int i;
          for (i=1; i <=10; i++) {  
            System.out.println(i);
          } 
          System.out.println("All done!");
        }
      }
        

      Outputs:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      All done!
        

      -----------------------------------------------------------------------------------------------------------------

      class CountToTwentyByTwos  {
      
        public static void main (String args[]) {
          int i;
          for (i=0; i <=20; i += 2) {  
            System.out.println(i);
          } 
          System.out.println("All done!");
       } //main ends here
      }
        

      Outputs:

      0
      2
      4
      6
      8
      10
      12
      14
      16
      18
      20
      All done!
        

    25. While Loop

      class Hello {
      	public static void main(String[] args) {
      		int i = 0;
      		while (i < 5) {
      			System.out.println("Hello, world!");
      			i++;
      		}
      		System.out.println("Goodbye!");
      	}
      }
        

      Outputs:

      Hello, world!
      Hello, world!
      Hello, world!
      Hello, world!
      Hello, world!
      Goodbye!