java
OOP
•




•

          Problem Space)
class)
                                   object)
•                     scripting language

               Perl        PHP

•                                                     class
    members)                  properties)
                          member functions)
                               class { ... }

                                          class constructor
                                                       new
                           class constructor
•

                          static
               instance
    instance
•            MyClass
           n     x             n
      static      Method 1         getX()
       instance
•

• MyClass a = new MyClass();
• MyClass b = new MyClass();
•                 instance
           x                                instance
                                              x

    instance)           n
                      static

       instance                         n
    reference                MyClass
          n
                                n              Class
    Variable"                                      n

    MyClass.n                instance
•               Method

    reference      Method


                    Method

                  MyClass)             instance
                             Method
    instance                     reference
                   Method
                                   static
•                   static             Method
• static                      Method
                        Method
                   instance

•                                printCircle
           TestPass1              instance
              printCircle            static
constructor)
constructor)
•
          constructor)



    new
•   //DriveAcar05.java
    class Vehicle {
        int numberOfWheels ;
        boolean hasEngine ;
       //constructor
        Vehicle() {       // (1)
           numberOfWheels = 6 ;
           hasEngine = true ;
        }
        void run() {
            System.out.println("I am running") ;
       }
    }
    public class DriveAcar05 {
        public static void main(String[] args) {
           Vehicle myCar = new Vehicle() ;
           System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; // (2)
           System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; // (3)
        }
    }
•


                    void

•



                            DriveAcar05.java
       main()
          Vehicle          Vehicle myCar = new
    Vehicle();              Vehicle()

       numberOfWheels = 6       hasEngine =
•
•   //DriveAcar06.java
    class Vehicle {
        int numberOfWheels ;
        boolean hasEngine ;
       //constructor
        Vehicle() {
           numberOfWheels = 6 ;
           hasEngine = true ;
          System.out.println("A car has been built") ; // (1) notice this line
        }
        void run() {
            System.out.println("I am running") ;
       }
    }
    public class DriveAcar06 {
        public static void main(String[] args) {
           Vehicle myCar = new Vehicle() ;
           System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; // (2)
           System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; // (3)
        }
    }
Overloading Constructor)
•
•   //OverloadConstructor.java
    class Vehicle {
        int numberOfWheels ;
        boolean hasEngine ;
       //constructor and Overload Constructor
        Vehicle() {
            numberOfWheels = 6 ;
            hasEngine = true ;
           System.out.println("A car has been built") ; //notice this line
        }
        Vehicle(int number, boolean engine) {      // (1)
            numberOfWheels = number ;
            hasEngine = engine ;
           System.out.println("A car has been built") ; //notice this line
        }
        void run() {
             System.out.println("I am running") ;
       }
    }
    public class OverloadConstructor {
        public static void main(String[] args) {
            Vehicle myCar = new Vehicle(4,true) ;    // (2)
            System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ;
            System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ;
        }
    }
•   //TestThis.java                                this()
    class A {
       int a ;
       A() {
          a=0;
          System.out.println("Default constructor") ;
       }
       A(int i) {
           this() ;
           a=i;
          System.out.println("constructor 1 ") ;
       }
        A(int i, int j) {
            this(i+j) ;
            System.out.println("constructor 2 ") ;
•    }
    }
    public class DriveAcar06 {
       public static void main(String[] args) {
          System.out.println("Instantiate x");
          A x = new A() ;
          System.out.println("Variable a is "+ x.a) ;
          System.out.println("Instantiate y ");
           A y = new A(5) ;
          System.out.println("Variable a is "+ y.a) ;
           System.out.println("Instantiate z ");
           A z = new A(5,6) ;
           System.out.println("Variable a is "+ z.a) ;
       }
    }




               this()
• static            File System          File System

                                     File Access
• File Access Component


• Set Fso= CreateObject("Scripting.FileSystemObject")
•                                      Fso
       File Access Component                Fso

• Open Text File Method
•


• Object.openTextFile(filename[,iomode][,create][,Format]
•
• Object
•   Filename
•   (          Required)
•   iomode
•   (            Optional)

• ForReading(1)
• ForWriting(2)
• ForAppending(8)

• Create
• (              optional)

• True

• False
                              Error
                             False
• Format
• (                  optional)                              Tristate
  UseDefault(-2)                                         ASCII
        ASCII
• Tristate True(-1)                    Unicode
• Tristate False(0)                    ASCII
•                                            ASCII
•
• Set fso= CreateObject("Scripting.FileSystemObject")
• Set Myfile=fso.openTextfile("c:testfile.txt",1, True)
•                                        fso
                 File Access                   fso
  OpenTextFile                 testfile.txt

•                                              OpenTextFile
                                MyFile                             Text
  Stream Object
• TextStream Object (                       Text)
                   TextStream
•   Close
•       TextStream Object
•   Read
•
•   ReadAll
•
•   ReadLine
•
•   Skip
•
•   SkipLine
•
• Write
•
• WriteLine
•
• WriteBlankLines
•
•   Sample1.asp
•   <% if request.form("message") = "" then %>
•   <html>
•   <body>
•   <form action="sample1.asp" method="post">
•   <font size=+1>
    text</font><br>
•   Name:
•   <input type=text name=message size=30>
•   <input type=submit value=
•     form>
•   <%
•   else
•   Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
•   MsgFile = Server.MapPath ("Text.txt")
•   Set OutStream= FileObject.CreateTextFile (MsgFile, True)
•   OutStream.WriteLine Request.Form("message")
•   Set OutStream = Nothing
•   Set MessageStr =Nothing
•   %>
•              a href="sample2.asp">sample2.asp</a>
•     body>
•   </html>
•   <% end if %>
•

•   Out Put
•   Sample1.asp
•

•   <html>
•   <body>
•               br>
•   <%
•   Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
•   MsgFile = Server.MapPath ("Text.txt")
•   On Error Resume Next
•   Set InStream= FileObject.OpenTextFile (MSGFile, 1, False, False)
•   Response.Write Instream.ReadALL & "<BR>"
•   Set Instream=Nothing
•   %>
•   </body>
•   </html>
•

•

•   Out Put
•
Java
Java
Java

Java

  • 1.
  • 3.
    OOP • • Problem Space)
  • 4.
    class) object) • scripting language Perl PHP • class members) properties) member functions) class { ... } class constructor new class constructor
  • 6.
    static instance instance
  • 7.
    MyClass n x n static Method 1 getX() instance • • MyClass a = new MyClass(); • MyClass b = new MyClass();
  • 8.
    instance x instance x instance) n static instance n reference MyClass n n Class Variable" n MyClass.n instance
  • 9.
    Method reference Method Method MyClass) instance Method instance reference Method static
  • 10.
    static Method • static Method Method instance • printCircle TestPass1 instance printCircle static
  • 12.
  • 13.
    constructor) • constructor) new
  • 14.
    //DriveAcar05.java class Vehicle { int numberOfWheels ; boolean hasEngine ; //constructor Vehicle() { // (1) numberOfWheels = 6 ; hasEngine = true ; } void run() { System.out.println("I am running") ; } } public class DriveAcar05 { public static void main(String[] args) { Vehicle myCar = new Vehicle() ; System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; // (2) System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; // (3) } }
  • 15.
    void • DriveAcar05.java main() Vehicle Vehicle myCar = new Vehicle(); Vehicle() numberOfWheels = 6 hasEngine =
  • 16.
  • 17.
    //DriveAcar06.java class Vehicle { int numberOfWheels ; boolean hasEngine ; //constructor Vehicle() { numberOfWheels = 6 ; hasEngine = true ; System.out.println("A car has been built") ; // (1) notice this line } void run() { System.out.println("I am running") ; } } public class DriveAcar06 { public static void main(String[] args) { Vehicle myCar = new Vehicle() ; System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; // (2) System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; // (3) } }
  • 18.
  • 19.
    //OverloadConstructor.java class Vehicle { int numberOfWheels ; boolean hasEngine ; //constructor and Overload Constructor Vehicle() { numberOfWheels = 6 ; hasEngine = true ; System.out.println("A car has been built") ; //notice this line } Vehicle(int number, boolean engine) { // (1) numberOfWheels = number ; hasEngine = engine ; System.out.println("A car has been built") ; //notice this line } void run() { System.out.println("I am running") ; } } public class OverloadConstructor { public static void main(String[] args) { Vehicle myCar = new Vehicle(4,true) ; // (2) System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; } }
  • 20.
    //TestThis.java this() class A { int a ; A() { a=0; System.out.println("Default constructor") ; } A(int i) { this() ; a=i; System.out.println("constructor 1 ") ; } A(int i, int j) { this(i+j) ; System.out.println("constructor 2 ") ;
  • 21.
    } } public class DriveAcar06 { public static void main(String[] args) { System.out.println("Instantiate x"); A x = new A() ; System.out.println("Variable a is "+ x.a) ; System.out.println("Instantiate y "); A y = new A(5) ; System.out.println("Variable a is "+ y.a) ; System.out.println("Instantiate z "); A z = new A(5,6) ; System.out.println("Variable a is "+ z.a) ; } } this()
  • 23.
    • static File System File System File Access • File Access Component • Set Fso= CreateObject("Scripting.FileSystemObject") • Fso File Access Component Fso • Open Text File Method • • Object.openTextFile(filename[,iomode][,create][,Format] • • Object
  • 24.
    Filename • ( Required) • iomode • ( Optional) • ForReading(1) • ForWriting(2) • ForAppending(8) • Create • ( optional) • True • False Error False
  • 25.
    • Format • ( optional) Tristate UseDefault(-2) ASCII ASCII • Tristate True(-1) Unicode • Tristate False(0) ASCII • ASCII • • Set fso= CreateObject("Scripting.FileSystemObject") • Set Myfile=fso.openTextfile("c:testfile.txt",1, True) • fso File Access fso OpenTextFile testfile.txt • OpenTextFile MyFile Text Stream Object • TextStream Object ( Text) TextStream
  • 26.
    Close • TextStream Object • Read • • ReadAll • • ReadLine • • Skip • • SkipLine •
  • 27.
  • 28.
    Sample1.asp • <% if request.form("message") = "" then %> • <html> • <body> • <form action="sample1.asp" method="post"> • <font size=+1> text</font><br> • Name: • <input type=text name=message size=30> • <input type=submit value= • form>
  • 29.
    <% • else • Set FileObject = Server.CreateObject("Scripting.FileSystemObject") • MsgFile = Server.MapPath ("Text.txt") • Set OutStream= FileObject.CreateTextFile (MsgFile, True) • OutStream.WriteLine Request.Form("message") • Set OutStream = Nothing • Set MessageStr =Nothing • %> • a href="sample2.asp">sample2.asp</a> • body> • </html> • <% end if %> • • Out Put
  • 30.
    Sample1.asp • • <html> • <body> • br> • <% • Set FileObject = Server.CreateObject("Scripting.FileSystemObject") • MsgFile = Server.MapPath ("Text.txt") • On Error Resume Next • Set InStream= FileObject.OpenTextFile (MSGFile, 1, False, False) • Response.Write Instream.ReadALL & "<BR>" • Set Instream=Nothing • %> • </body> • </html> • • • Out Put •