SlideShare ist ein Scribd-Unternehmen logo
1 von 33
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

Weitere ähnliche Inhalte

Was ist angesagt?

Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門S Akai
 
Session 15 - Collections - Array List
Session 15 - Collections - Array ListSession 15 - Collections - Array List
Session 15 - Collections - Array ListPawanMM
 
An Overview of the Java Programming Language
An Overview of the Java Programming LanguageAn Overview of the Java Programming Language
An Overview of the Java Programming LanguageSalaam Kehinde
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabszekeLabs Technologies
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swingNataraj Dg
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javacAnna Brzezińska
 
J query introduction
J query introductionJ query introduction
J query introductionSMS_VietNam
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3PawanMM
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scalaRuslan Shevchenko
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-CollectionsMohammad Shaker
 
C++ nothrow movable types
C++ nothrow movable typesC++ nothrow movable types
C++ nothrow movable typesarvidn
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 

Was ist angesagt? (19)

Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
 
Session 15 - Collections - Array List
Session 15 - Collections - Array ListSession 15 - Collections - Array List
Session 15 - Collections - Array List
 
Scala: A brief tutorial
Scala: A brief tutorialScala: A brief tutorial
Scala: A brief tutorial
 
An Overview of the Java Programming Language
An Overview of the Java Programming LanguageAn Overview of the Java Programming Language
An Overview of the Java Programming Language
 
Lesson3
Lesson3Lesson3
Lesson3
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
Java Advanced Features
Java Advanced FeaturesJava Advanced Features
Java Advanced Features
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
 
J query introduction
J query introductionJ query introduction
J query introduction
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
 
C++ nothrow movable types
C++ nothrow movable typesC++ nothrow movable types
C++ nothrow movable types
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 

Andere mochten auch

รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)
รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)
รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)ภูชคุณ ดาวไธสง
 
Practical Online Reputation Management
Practical Online Reputation ManagementPractical Online Reputation Management
Practical Online Reputation ManagementGradiva Couzin
 
Melhorandoasdinmicas prgeorge-120813142517-phpapp02
Melhorandoasdinmicas prgeorge-120813142517-phpapp02Melhorandoasdinmicas prgeorge-120813142517-phpapp02
Melhorandoasdinmicas prgeorge-120813142517-phpapp02Mariano Silva
 
International SEO Best Practices
International SEO Best PracticesInternational SEO Best Practices
International SEO Best PracticesGradiva Couzin
 
Northwestern technologies media design concepts
Northwestern technologies media design conceptsNorthwestern technologies media design concepts
Northwestern technologies media design conceptsnikki6311
 
Disaster Preparedness: What Renters Need to Know
Disaster Preparedness: What Renters Need to KnowDisaster Preparedness: What Renters Need to Know
Disaster Preparedness: What Renters Need to KnowGradiva Couzin
 
2015展新綠能_LED燈具型錄
2015展新綠能_LED燈具型錄2015展新綠能_LED燈具型錄
2015展新綠能_LED燈具型錄Carrie Davalos
 
Library Websites: Are You Meeting Your SEO Goals?
Library Websites: Are You Meeting Your SEO Goals?Library Websites: Are You Meeting Your SEO Goals?
Library Websites: Are You Meeting Your SEO Goals?Gradiva Couzin
 
India vs china Comparison
India vs china Comparison India vs china Comparison
India vs china Comparison Manish Jain
 
極短篇故事文案寫作 徐苙萍
極短篇故事文案寫作  徐苙萍極短篇故事文案寫作  徐苙萍
極短篇故事文案寫作 徐苙萍Carrie Davalos
 
樂水智者要知道的事
樂水智者要知道的事樂水智者要知道的事
樂水智者要知道的事Carrie Davalos
 

Andere mochten auch (15)

Mcm2
Mcm2Mcm2
Mcm2
 
รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)
รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)
รูปภาพกิจกรรมโครงการฯพระราชดำริ(รากเทียม)
 
Practical Online Reputation Management
Practical Online Reputation ManagementPractical Online Reputation Management
Practical Online Reputation Management
 
Melhorandoasdinmicas prgeorge-120813142517-phpapp02
Melhorandoasdinmicas prgeorge-120813142517-phpapp02Melhorandoasdinmicas prgeorge-120813142517-phpapp02
Melhorandoasdinmicas prgeorge-120813142517-phpapp02
 
ย อย6
ย อย6ย อย6
ย อย6
 
2
22
2
 
International SEO Best Practices
International SEO Best PracticesInternational SEO Best Practices
International SEO Best Practices
 
Northwestern technologies media design concepts
Northwestern technologies media design conceptsNorthwestern technologies media design concepts
Northwestern technologies media design concepts
 
Disaster Preparedness: What Renters Need to Know
Disaster Preparedness: What Renters Need to KnowDisaster Preparedness: What Renters Need to Know
Disaster Preparedness: What Renters Need to Know
 
2015展新綠能_LED燈具型錄
2015展新綠能_LED燈具型錄2015展新綠能_LED燈具型錄
2015展新綠能_LED燈具型錄
 
Library Websites: Are You Meeting Your SEO Goals?
Library Websites: Are You Meeting Your SEO Goals?Library Websites: Are You Meeting Your SEO Goals?
Library Websites: Are You Meeting Your SEO Goals?
 
India vs china Comparison
India vs china Comparison India vs china Comparison
India vs china Comparison
 
완성2
완성2완성2
완성2
 
極短篇故事文案寫作 徐苙萍
極短篇故事文案寫作  徐苙萍極短篇故事文案寫作  徐苙萍
極短篇故事文案寫作 徐苙萍
 
樂水智者要知道的事
樂水智者要知道的事樂水智者要知道的事
樂水智者要知道的事
 

Ähnlich wie Java (20)

TDD and mock objects
TDD and mock objectsTDD and mock objects
TDD and mock objects
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
오브젝트C(pdf)
오브젝트C(pdf)오브젝트C(pdf)
오브젝트C(pdf)
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Java I/O
Java I/OJava I/O
Java I/O
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Files io
Files ioFiles io
Files io
 
25csharp
25csharp25csharp
25csharp
 
25c
25c25c
25c
 

Mehr von JAy YourJust'one

งานย อยท _ 6 ต__งคำถาม java
งานย อยท _ 6 ต__งคำถาม javaงานย อยท _ 6 ต__งคำถาม java
งานย อยท _ 6 ต__งคำถาม javaJAy YourJust'one
 
ซัมซุงนัดต้นปีเปิดตัว
ซัมซุงนัดต้นปีเปิดตัวซัมซุงนัดต้นปีเปิดตัว
ซัมซุงนัดต้นปีเปิดตัวJAy YourJust'one
 
เกมจับคู่5
เกมจับคู่5เกมจับคู่5
เกมจับคู่5JAy YourJust'one
 
เกมจับคู่4
เกมจับคู่4เกมจับคู่4
เกมจับคู่4JAy YourJust'one
 
เกมจับคู่4
เกมจับคู่4เกมจับคู่4
เกมจับคู่4JAy YourJust'one
 
เกมจับคู่3
เกมจับคู่3เกมจับคู่3
เกมจับคู่3JAy YourJust'one
 
เกมจับคู่2
เกมจับคู่2เกมจับคู่2
เกมจับคู่2JAy YourJust'one
 
เกมจับคู่1
เกมจับคู่1เกมจับคู่1
เกมจับคู่1JAy YourJust'one
 
แต่งกลอนภุชงคประยาตฉัน11
แต่งกลอนภุชงคประยาตฉัน11แต่งกลอนภุชงคประยาตฉัน11
แต่งกลอนภุชงคประยาตฉัน11JAy YourJust'one
 
ฮาร์ดไดรฟ์ปลอม
ฮาร์ดไดรฟ์ปลอมฮาร์ดไดรฟ์ปลอม
ฮาร์ดไดรฟ์ปลอมJAy YourJust'one
 
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์JAy YourJust'one
 
การค้นหาข่าวสารในแวดวง I
การค้นหาข่าวสารในแวดวง Iการค้นหาข่าวสารในแวดวง I
การค้นหาข่าวสารในแวดวง IJAy YourJust'one
 

Mehr von JAy YourJust'one (15)

งานย อยท _ 6 ต__งคำถาม java
งานย อยท _ 6 ต__งคำถาม javaงานย อยท _ 6 ต__งคำถาม java
งานย อยท _ 6 ต__งคำถาม java
 
It
ItIt
It
 
ซัมซุงนัดต้นปีเปิดตัว
ซัมซุงนัดต้นปีเปิดตัวซัมซุงนัดต้นปีเปิดตัว
ซัมซุงนัดต้นปีเปิดตัว
 
เกมจับคู่5
เกมจับคู่5เกมจับคู่5
เกมจับคู่5
 
เกมจับคู่4
เกมจับคู่4เกมจับคู่4
เกมจับคู่4
 
เกมจับคู่4
เกมจับคู่4เกมจับคู่4
เกมจับคู่4
 
เกมจับคู่3
เกมจับคู่3เกมจับคู่3
เกมจับคู่3
 
เกมจับคู่2
เกมจับคู่2เกมจับคู่2
เกมจับคู่2
 
เกมจับคู่1
เกมจับคู่1เกมจับคู่1
เกมจับคู่1
 
แต่งกลอนภุชงคประยาตฉัน11
แต่งกลอนภุชงคประยาตฉัน11แต่งกลอนภุชงคประยาตฉัน11
แต่งกลอนภุชงคประยาตฉัน11
 
3
33
3
 
ฮาร์ดไดรฟ์ปลอม
ฮาร์ดไดรฟ์ปลอมฮาร์ดไดรฟ์ปลอม
ฮาร์ดไดรฟ์ปลอม
 
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์
Samsung nc215 โน้ตบุ๊คพลังงานแสงอาทิตย์
 
Fdf
FdfFdf
Fdf
 
การค้นหาข่าวสารในแวดวง I
การค้นหาข่าวสารในแวดวง Iการค้นหาข่าวสารในแวดวง I
การค้นหาข่าวสารในแวดวง I
 

Java

  • 2.
  • 3. OOP • • Problem Space)
  • 4. class) object) • scripting language Perl PHP • class members) properties) member functions) class { ... } class constructor new class constructor
  • 5.
  • 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
  • 11.
  • 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) } }
  • 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()
  • 22.
  • 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. • Write • • WriteLine • • WriteBlankLines •
  • 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 •