Objektorienteeritud programmeerimine

Size: px
Start display at page:

Download "Objektorienteeritud programmeerimine"

Transcription

1 Objektorienteeritud programmeerimine 10. loeng, 16. aprill Marina Lepp 1

2 Eelmisel nädalal Loeng vood Lisapraktikum Praktikum sündmused Künnipäev (12.04) 2

3 Umbes mitu tundi tegelesite eelmisel nädalal selle ainega (loeng+praktikum+iseseisvalt)? tundi tundi tundi tundi tundi tundi tundi 8. üle 14 tunni 0-2 tundi 55% 23% 14% 4% 2-4 tundi 4-6 tundi 6-8 tundi 8-10 tundi 3% 0% 0% 0% tundi tundi üle 14 tunni 3

4 Kuivõrd olete selle ainega graafikus? 1. Isegi ees 2. Täiesti graafikus 3. Veidi maas, aga saan ise hakkama 4. Kõvasti maas, vajan abi 5. Ei oska öelda 43% 0% Isegi ees Täiesti graafikus 33% 21% 3% Veidi maas, aga saan ise... Kõvasti maas, vajan abi Ei oska öelda 4

5 Täna Vood Erindid 5

6 Voog (ingl. stream) osa lihtsalt kannab andmeid, osa ka töötleb ühendatakse Java I/O süsteemi abil füüsilise seadmega ühel pool tootja (allikas), teisel pool tarbija voo andmetele juurdepääs järjestikune 6

7 Jaotus Java seisukohalt jagunevad vood: sisendvoog (input stream) ja väljundvoog (output stream) vastavalt rollile "tootja-tarbija" suhtes baidivoog (byte stream) ja märgivoog (character stream) vastavalt andmete tüübile puhverdatud (buffered) ja puhverdamata voog efektiivsuse kaalutlustel puhverdada vastavalt voo kandjale failivoog (file stream) massiivivoog (array stream) toruvoog (piped stream) 7

8 Abstraktne Baidivoog InputStream FileInputStream AudioInputStream FilterInputStream DataInputStream ObjectInputStream OutputStream FileOutputStream PipedOutputStream FilterOutputStream DataOutputStream PrintStream ObjectOutputStream üks bait korraga binaarandmed (nt.class-failid) masinale orienteeritud 8

9 Baidivoog, failide kopeerimine InputStream sisse = new FileInputStream("pilt.png"); OutputStream välja = new FileOutputStream("koopia.png"); int c; // omistamine ja kontroll kombineeritud! while ((c = sisse.read())!= -1) { välja.write(c); //vood tuleb alati kinni panna sisse.close(); välja.close(); 9

10 Baidivoog, failide kopeerimine, v.2 InputStream sisse = new FileInputStream("pilt.png"); OutputStream välja = new FileOutputStream("koopia.png"); byte[] puhver = new byte[1024]; int loetud = sisse.read(puhver); while (loetud > 0) { välja.write(puhver, 0, loetud); loetud = sisse.read(puhver); //loeme järgmise tüki //vood tuleb alati kinni panna sisse.close(); välja.close(); 10

11 Abstraktne Märgivoog Reader InputStreamReader FileReader BufferedReader Writer OutputStreamWriter FileWriter BufferedWriter PrintWriter üks märk korraga tekst (nt.java-failid) inimesele orienteeritud

12 Märgivoog, failide kopeerimine Reader sisse = new FileReader("minemine.txt"); Writer välja = new FileWriter("koopia.txt"); int c; // omistamine ja kontroll kombineeritud! while ((c = sisse.read())!= -1) { välja.write(c); //vood tuleb alati kinni panna sisse.close(); välja.close(); 12

13 Märgivoog ridahaaval Võtame ridahaaval BufferedReader readline PrintWriter print println printf "\r\n" "\r" "\n"

14 Märgivoog, failide kopeerimine, v.2 BufferedReader sisse = new BufferedReader( new FileReader("minemine.txt")); PrintWriter välja = new PrintWriter( new FileWriter("koopia.txt")); String rida = sisse.readline(); while (rida!= null) { System.out.println("lugesin voost: " + rida); välja.println(rida); rida = sisse.readline(); // loeb järgmise rea //vood tuleb alati kinni panna sisse.close(); välja.close(); 14

15 Faili lõppu juurde 15

16 Väljundmärgivoogu saab realiseerida järgmise klassi alamklassidega 1.InputStream 2.OutputStream 3.Reader 4.Writer 5. muu 43% 51% 1% 3% 1%

17 Sisendbaidivoogu saab realiseerida järgmise klassi alamklassidega 1.InputStream 2.OutputStream 3.Reader 4.Writer 5. muu 82% 15% 1% 1% 0%

18 Kas meetodi System.out.println abil saab kirjutada faili? 1. jah 2. ei 88% 12% jah ei 18

19 Klass System System.in vaikimisi klaviatuurilt System.out, System.err vaikimisi ekraanile (konsoolile) 19

20 Muudame väljundit OutputStream output = new FileOutputStream("systemout.txt"); PrintStream printout = new PrintStream(output); System.setOut(printOut); System.out.println("Tere"); 20

21 Andmete kirjutamine faili DataOutputStream dos = new DataOutputStream( new FileOutputStream("andmed.bin")); dos.writeint(25); dos.writedouble(5.22); dos.close(); Java API write, writeutf 21

22 Andmed (teadaoleva struktuuriga) failist DataInputStream dis = new DataInputStream( new FileInputStream("andmed.bin")); int n = dis.readint(); double d = dis.readdouble(); dis.close(); System.out.println ("Loeti: " + n + " ja " + d); 22

23 Veebist String aadress = " InputStream sisse = new URL(aadress).openStream(); OutputStream välja = new FileOutputStream("uus.html"); 23

24 Otsejuurdepääsuga failid RandomAccessFile Osuti (ingl pointer) näitab, millises kohas ollakse seek(long pos) 24

25 import java.io.*; public class Otsejuurde { public static void main(string[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile("raf.dat", "rw"); raf.writedouble(3.1415); raf.writeint(25); raf.writedouble(2.7182); raf.seek(0); System.out.println(raf.readDouble() + " " + raf.readint()); Otsejuurdepääsuga failid raf.seek(8); System.out.println(raf.readInt()); Aga 6?

26 Mis ilmub ekraanile? 1.A 2.B 3.A B 4. mitte midagi 5. muu OutputStream output = new FileOutputStream("a.txt"); PrintStream printout = new PrintStream(output); System.setOut(printOut); System.out.println("A"); System.out.println("B"); 0% 2% 37% 55% 6%

27 Mis ilmub ekraanile? 1.A 2.B 3.A B 4. mitte midagi 5. muu PrintStream vana = System.out; OutputStream output = new FileOutputStream("a.txt"); PrintStream printout = new PrintStream(output); System.setOut(printOut); System.out.println("A"); System.setOut(vana); System.out.println("B"); 85% 5% 3% 3% 3%

28 Mis ilmub ekraanile? mitte midagi 6. muu RandomAccessFile raf = new RandomAccessFile("raf.dat", "rw"); raf.writeint(9); raf.writeint(4); raf.writeint(12); raf.writeint(18); raf.seek(12); System.out.println(raf.readInt()); 7% 2% 34% 33% 9% 16%

29 Objektid Olid võimalused algtüüpide jaoks int, double, boolean Objektid? ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("o.dat")); oos.writeobject(new int[] {1, 2, 3, 4, 5); oos.close(); ObjectInputStream ois = new ObjectInputStream( new FileInputStream("o.dat")); int[] a = (int[])ois.readobject(); ois.close();

30 Teeme ise klassi public class SKlass { String s; int i; double d; public SKlass(String s, int i, double d) { this.s = s; this.i = i; this.d = d; public String tostring() { return "s=" + s + "; i=" + i + "; d=" + d; 30

31 Proovime isendi faili saata SKlass sk = new SKlass("A", 1, 1.5); ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream ("o.dat")); oos.writeobject(sk); oos.close(); java.io.notserializableexception 31

32 Liides Serializable Java väljundvoogu saab kirjutada vaid neid objekte, mis realiseerivad liidest Serializable. Neid objekte nimetatakse serialiseeritavateks. Serialiseerimine andmejadana esitamine Liides Serializable ei ole meetodeid ega muutujaid kasutatakse vaid märkimiseks, et vastavat objekti on võimalik saata voogu Massiiv on serialiseeritav, kui tema kõik liikmed realiseerivad liidest Serializable Algtüüpidele vastavad mähisklassid realiseerivad liidest Serializable 32

33 Realiseerime liidese import java.io.serializable; public class SKlass implements Serializable { String s; int i; double d; public SKlass(String s, int i, double d) { this.s = s; this.i = i; this.d = d; public String tostring() { return "s=" + s + "; i=" + i + "; d=" + d; 33

34 Liides Serializable Saab anda indeksi Kui klass realiseerib liidest Serializable, siis kõik tema alamklassid on serialiseeritavad Kui klass realiseerib liidest Serializable, kuid sisaldab liikmeid, mis ei realiseeri liidest Serializable, siis isendit ei saa kirjutada väljundvoogu Mitteserialiseeritavate liikmete ignoreerimiseks tuleb kasutada piiritlejat transient Milleks? Midagi ajutisemat, mida pole mõtet alles hoida Kuidas? public class Klass implements Serializable { private int v1; private static double v2; private transient A v3 = new A(); 34

35 Kes need on? Dan Eliasson Generaldirektör, Myndigheten för samhällsskydd och beredskap Чечоткін Микола Олександрович Голова, Державна служба з надзвичайних ситуацій Пучков, Владимир Андреевич министр по делам гражданской обороны, чрезвычайным ситуациям и ликвидации последствий стихийных бедствий William B. Brock Long Administrator of the Federal Emergency Management Agency 35

36 Hädaolukorra seadus 1. Seaduse reguleerimisala (1)... Käesolev seadus reguleerib ka eriolukorra väljakuulutamist, lahendamist ja lõpetamist 24. Eriolukorra juht (1) Eriolukorra väljakuulutamisel määrab Vabariigi Valitsus ühe ministri, kes juhib ja koordineerib eriolukorra väljakuulutamise põhjustanud hädaolukorra lahendamist (edaspidi eriolukorra juht). 36

37 Erind? 1. Asula Albaania lõunaosas 2. India poliitik, parlamendi alamkoja liige 3. Programmi töö käigus tekkida võiv selline eriolukord, mis ei pruugi tingimata olla saatuslik programmi edasisele täitmisele

38 Näide import java.io.file; import java.util.scanner; public class Loeng10{ public static void main(string[] args) { File file = new File("andmed.txt"); Scanner sc = new Scanner(file); Information: java: Errors occured while compiling module 'Loeng10' Error:(6, 26) java: unreported exception java.io.filenotfoundexception; must be caught or declared to be thrown 38

39 Milleks? Loeme andmed failist sisse Aga kui faili polegi? Eriolukord nõuab teistsugust lähenemist Tava- ja eriolukorra kood eraldatud 39

40 Faili ei eksisteeri Eriolukorrad Faili ei saa kirjutada/lugeda Nulliga jagamine Järjendist vale indeksiga elemendi küsimine Ja veel palju teisi 40

41 Kas kompileerub? public class ErindiTest { public static void main(string[] args) { System.out.println(1/0); 1. Jah 2. Ei 78% 22%

42 Kompileerub, aga tööle ei hakka public class ErindiTest { public static void main(string[] args) { System.out.println(1/0); 42

43 Kas kompileerub? public class ErindiTest { public static void main(string[] args) { int[] arvud = {3, 7, 8; System.out.println(arvud[3]); 1. Jah 2. Ei 61% 39%

44 Kompileerub, aga tööle ei hakka public class ErindiTest { public static void main(string[] args) { int[] arvud = {3, 7, 8; System.out.println(arvud[3]); 44

45 Eriolukorrad Javas Tõrked (Throwable) vead (Error) erindid (Exception) mittekontrollitavad (RuntimeException) kontrollitavad (kompilaator leiab)

46 Throwable Error Exception LinkageError VirtualMachineError IOException MingiErind RuntimeException FileNotFoundException ArithmeticException NullPointerException IndexOutOfBoundsException mittekontrollitavad (RuntimeException) kontrollitavad (kompilaator leiab) 46

47 Eriolukorra lahendamine Lahendame probleemi kohapeal (erindi püüdmine) try { /* KOOD */ catch (Exception e){ /* LAHENDUS */ Suuname erindi edasi throws Exception{/*...*/ 47

48 Erindi püüdmata jätmine Kui erindit kinni ei püüa, siis püüab Java käituskeskkond ise Kontrollitavad erindid tuleb ise kinni püüda Mittekontrollitavaid erindeid (RuntimeException) ei pea ise kinni püüdma 48

49 Kontrollitavate ja mittekontrollitavate Kontrollitav erind erindite erinevused programm ei kompileeru, kui erindiga ei ole tegeletud throws Exception try-catch Mittekontrollitav erind programm kompileerub, aga tööle ei hakka

50 Kas Pärast ohtu ilmub ekraanile? public static void main(string[] args) { int[] arvud = {3, 7, 8; System.out.println(arvud[3]); System.out.println("Pärast ohtu"); 1. Jah 2. Ei 78% 22%

51 Kas Pärast ohtu ilmub ekraanile? public static void main(string[] args) { try { int[] arvud = {3, 7, 8; System.out.println(arvud[3]); catch (ArrayIndexOutOfBoundsException e) { //e.printstacktrace(); System.out.println("Pärast ohtu"); 1. Jah 2. Ei 82% 18%

52 Katsendidirektiiv try { /* Veaohtlik kood */ catch(erind1 e) { /* Erind1 püünis */ catch(erind2 e) { /* Erind2 püünis */ finally { /* Epiloog */ 52

53 Katsendidirektiiv try { /* Veaohtlik kood */ catch(erind1 Erind2 e) { /* Erind1 püünis ja */ /* Erind2 püünis koos */ finally { /* Epiloog */ 53

54 Katsendidirektiiv (voo sulgemisega) try(voog voog = new Voog()) { /* Veaohtlik kood */ catch(erind1 Erind2 e) { /* Erind1 püünis ja */ /* Erind2 püünis koos */ finally { /* Epiloog */ 54

55 Katsendidirektiiv (voo sulgemisega) try( Voog voog = new Voog(); Voog voog2 = new Voog() ) { /* Kood */ 55

56 Baidivoog, failide kopeerimine InputStream sisse = new FileInputStream("pilt.png"); OutputStream välja = new FileOutputStream("koopia.png"); int c; // omistamine ja kontroll kombineeritud! while ((c = sisse.read())!= -1) { välja.write(c); //vood tuleb alati kinni panna sisse.close(); välja.close(); 56

57 Baidivoog, failide kopeerimine, voo sulgemisega try ( InputStream sisse = new FileInputStream("pilt.png"); OutputStream välja = new FileOutputStream("koopia.png"); ) { int c; while ((c = sisse.read())!= -1) { välja.write(c); 57

58 Eriolukorras Pooleli jäänud töö käigus võib-olla muudeti muutujate väärtuseid avati vooge Erindi püüdmisel tuleb taastada normaalne seisund avatud vood sulgeda 58

59 Püünis (catch) Püüab kas ühe või mitu erindit Mitme erindi puhul ebavajalikud erindid keelatud Mitu püünist ühes katsendidirektiivis Ebavajalikud püünised keelatud 59

60 Throwable Error Exception LinkageError VirtualMachineError IOException MingiErind RuntimeException FileNotFoundException ArithmeticException NullPointerException IndexOutOfBoundsException mittekontrollitavad (RuntimeException) kontrollitavad (kompilaator leiab) 60

61 Mis ilmub ekraanile? try { System.out.println(1/0); int[] arvud = {3, 7, 8; System.out.println(arvud[3]); catch (ArrayIndexOutOfBoundsException e) { System.out.println("Indeks"); catch (ArithmeticException e) { System.out.println("Aritmeetika"); 1. Indeks 2. Aritmeetika 3. Indeks Aritmeetika 4. Aritmeetika Indeks 5. Midagi muud 44% 27% 19% 11% 0%

62 Mis ilmub ekraanile? try { System.out.println(1/0); int[] arvud = {3, 7, 8; System.out.println(arvud[3]); catch (RuntimeException e) { System.out.println("Käitusaegne"); catch (ArithmeticException e) { System.out.println("Aritmeetika"); 1. Käitusaegne 2. Aritmeetika 3. Käitusaegne Aritmeetika 4. Aritmeetika Käitusaegne 5. Midagi muud exception java.lang.arithmeticexception has already been caught 70% 19% 8% 2% 2%

63 Mis ilmub ekraanile? try { int[] arvud = {3, 7, 8; System.out.println(arvud[3]); System.out.println(1/0); catch (ArithmeticException e) { System.out.println("Aritmeetika"); catch (RuntimeException e) { System.out.println("Käitusaegne"); 1. Käitusaegne 2. Aritmeetika 3. Käitusaegne Aritmeetika 4. Aritmeetika Käitusaegne 5. Midagi muud 68% 20% 7% 2% 3%

64 Katsendidirektiivid Tavaline katsendidirektiiv Peab olema kas finally või vähemalt 1 catch try catch try catch catch try catch finally try catch catch finally try finally Voo sulgemisega katsendidirektiiv Ei pea olema ei finally ega catch 64

65 Katsendidirektiivid (voo sulgemisega) Tegelikult mitte tingimata voo sulgemine, vaid klassi, mis realiseerib liidest AutoCloseable Kutsutakse välja liidese AutoCloseable meetod close() 65

66 // Teeme ise suletava objekti class Suletav implements AutoCloseable { Suletav(){ System.out.println("Konstruktori public void close() { System.out.println("Sulgesin ennast!"); // Try ilma püüniseta? try(suletav suletav = new Suletav()){ System.out.println("Try sees"); Konstruktori sees Try sees Sulgesin ennast! 66

67 Epiloog (finally) Täidetakse alati (kui katsendidirektiivini jõuti ning kui JVM ja vastav lõim veel töötavad) Isegi, kui tekkis erind, mida kinni ei püütud Isegi, kui jõuti return-lauseni 67

68 Kui try-osas tekib erind, siis kõik try-osa käsud, mis asuvad peale seda, jäävad läbi vaatamata Kui try-osas erindeid ei teki, siis catch-osa juurde ei mindagi ja minnakse finally-osa juurde (kui see on olemas) ja siis minnakse nende käskude juurde, mis asuvad peale try-catch-finally Kui try-osas tekib erind ja on olemas vastav (esimene sobiv) catch-osa, siis minnakse sinna, siis minnakse finally-osa juurde (kui see on olemas) ja siis minnakse nende käskude juurde, mis asuvad peale try-catchfinally Kui try-osas tekib erind ja ei ole vastavat catch-osa, siis minnakse finally-osa juurde (kui see on olemas) ja lõpetatakse meetodi (programmi) tööd

69 Milline on täitmise järjekord, kui erindeid ei teki? try { // 1 kood, mis võib tekitada erindi // 2 catch (IOException e) { // 3 kood, mis võib tekitada erindi // 4 finally { // 5 // , 2, 3, 4, 5, , 3, 4, 5, , 2, 5, , 3, , 5 6. Mingi muu 81% 6% 4% 3% 4% 1%

70 Milline on täitmise järjekord, kui põhiplokis tekib erind, mida (selles programmis) ei püüta? try { // 1 kood, mis võib tekitada erindi // 2 catch (IOException e) { // 3 kood, mis võib tekitada erindi // 4 finally { // 5 // , 2, 3, 4, 5, , 3, 4, 5, , 2, 5, , 3, , 5 6. Mingi muu 60% 25% 6% 3% 5% 0%

71 Milline on täitmise järjekord, kui põhiplokis tekib erind, mis püütakse ja püünis ei tekita erindit? try { // 1 kood, mis võib tekitada erindi // 2 catch (IOException e) { // 3 kood, mis võib tekitada erindi // 4 finally { // 5 // , 2, 3, 4, 5, , 3, 4, 5, , 2, 5, , 3, , 5 6. Mingi muu 84% 5% 5% 5% 2% 0%

72 Milline on täitmise järjekord, kui põhiplokis tekib erind, mis püütakse ja püünises tekib ka erind? try { // 1 kood, mis võib tekitada erindi // 2 catch (IOException e) { // 3 kood, mis võib tekitada erindi // 4 finally { // 5 // , 2, 3, 4, 5, , 3, 4, 5, , 2, 5, , 3, , 5 6. Mingi muu 83% 15% 0% 0% 0% 2%

73 Katsendidirektiivid üksteise sees try { try { catch (Exception e) { catch (Exception e) { try { catch (Exception e) { finally { try { catch (Exception e) { 73

74 Katsendidirektiivid üksteise sees Kui sisemises katsendidirektiivis pole sobivat püünist, siis otsitakse püünist teda sisaldavast katsendidirektiivist Otsing jätkub kuni sobiva leidmiseni või kuni katsendidirektiivide lõppemiseni 74

75 Katsendi- või tingimusdirektiiv if(a.length > 0) { System.out.println(a[0]); else { või try {System.out.println(a[0]); catch (IndexOutOfBoundsException e){ 75

76 Loengu tempo oli 1. liiga kiire 2. paras 3. liiga aeglane 83% 13% 4% liiga kiire paras liiga aeglane 76

77 Materjal tundus 1. liiga lihtne 2. parajalt jõukohane 3. liiga keeruline 91% 1% 8% liiga lihtne parajalt jõukohane liiga keeruline 77

78 Suur tänu osalemast! Kohtumiseni! 78

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 10. loeng 15. aprill Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon J. Kiho Java Programmeerimise aabits Y. D. Liang Introduction to

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 10. loeng 9. aprill Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon J. Kiho Java Programmeerimise aabits Y. D. Liang Introduction to

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 9. loeng, 9. aprill Marina Lepp 1 Loeng Eelmisel nädalal sündmused, omadused Lisapraktikum Praktikum graafiline kasutajaliides 1. rühmatöö Rahvusvaheline spordipäev

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 11. loeng, 23. aprill Marina Lepp 1 Eelmisel nädalal Loeng vood, erindid 1. kontrolltöö järeltöö Praktikum vood Ülemaailmne maapäev (22.04) 2 Umbes mitu tundi tegelesite

More information

CS 251 Intermediate Programming Java I/O Streams

CS 251 Intermediate Programming Java I/O Streams CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package

More information

Objektorienteeritud programmeerimine. 5. märts, 4. loeng Marina Lepp

Objektorienteeritud programmeerimine. 5. märts, 4. loeng Marina Lepp Objektorienteeritud programmeerimine 5. märts, 4. loeng Marina Lepp 1 Loeng Möödunud nädalal Klassid. Isendid. Konstruktorid. Sõned. Mähisklassid Praktikum Objektid ja klassid. Muutujate skoobid. Objektide

More information

Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng. H e l le H e i n h e l l e. h ee

Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng. H e l le H e i n h e l l e. h ee Objektorienteeritud programmeerimine MTAT.03.130 (6 EAP) 9. Loeng H e l le H e i n h e l l e. h ein@ut. ee Täna loengus: Erindid Erindite töötlemine Võtmesõnad try, catch, throw, throws, finally, assert

More information

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003 Input, Output and Exceptions COMS W1007 Introduction to Computer Science Christopher Conway 24 June 2003 Input vs. Output We define input and output from the perspective of the programmer. Input is data

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 2. loeng 19. veebruar 2018 Marina Lepp 1 Möödunud nädalal Loeng Sissejuhatus Praktikum Paaristöö, algus Vastlapäev Sõbrapäev Hiina uusaasta 2 Umbes mitu tundi tegelesite

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 8. loeng 26. märts Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon Y. D. Liang Introduction to Java Programming 2 Eelmisel nädalal loeng

More information

Chapter 4 Java I/O. X i a n g Z h a n g j a v a c o s q q. c o m

Chapter 4 Java I/O. X i a n g Z h a n g j a v a c o s q q. c o m Chapter 4 Java I/O X i a n g Z h a n g j a v a c o s e @ q q. c o m Content 2 Java I/O Introduction File and Directory Byte-stream and Character-stream Bridge between b-s and c-s Random Access File Standard

More information

Exceptions and Working with Files

Exceptions and Working with Files Exceptions and Working with Files Creating your own Exceptions. You have a Party class that creates parties. It contains two fields, the name of the host and the number of guests. But you don t want to

More information

Object-Oriented Programming in the Java language

Object-Oriented Programming in the Java language Object-Oriented Programming in the Java language Part 5. Exceptions. I/O in Java Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Exceptions Exceptions in Java are objects. All

More information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan Institute of Engineering & Technology for Diploma Studies Streams A stream is a sequence of data. In Java a stream is composed of bytes. In java, 3 streams are created for us automatically. 1. System.out : standard output stream 2. System.in : standard input

More information

Object-Oriented Programming Design. Topic : Streams and Files

Object-Oriented Programming Design. Topic : Streams and Files Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams

More information

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

Software 1 with Java. Recitation No. 7 (Java IO) May 29, Software 1 with Java Recitation No. 7 (Java IO) May 29, 2007 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes

More information

Software 1 with Java. Recitation No. 9 (Java IO) December 10,

Software 1 with Java. Recitation No. 9 (Java IO) December 10, Software 1 with Java Recitation No. 9 (Java IO) December 10, 2006 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Data stored in variables and arrays is temporary It s lost when a local variable goes out of scope or when

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 2. loeng 18. veebruar Eno Tõnisson kasutatud ka Helle Heina ja Jüri Kiho materjale 1 Eelmisel nädalal loeng sissejuhatus praktikum paaristööna Asteroid 2012 DA14 möödus

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 7. loeng 25. märts Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon Y. D. Liang Introduction to Java Programming 2 Eelmisel nädalal loeng

More information

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1214

More information

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20 File IO Computer Science and Engineering College of Engineering The Ohio State University Lecture 20 I/O Package Overview Package java.io Core concept: streams Ordered sequences of data that have a source

More information

Software 1. Java I/O

Software 1. Java I/O Software 1 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams A stream

More information

Chapter 12. File Input and Output. CS180-Recitation

Chapter 12. File Input and Output. CS180-Recitation Chapter 12 File Input and Output CS180-Recitation Reminders Exam2 Wed Nov 5th. 6:30 pm. Project6 Wed Nov 5th. 10:00 pm. Multitasking: The concurrent operation by one central processing unit of two or more

More information

1.00 Lecture 30. Sending information to a Java program

1.00 Lecture 30. Sending information to a Java program 1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes

More information

Chapter 10. IO Streams

Chapter 10. IO Streams Chapter 10 IO Streams Java I/O The Basics Java I/O is based around the concept of a stream Ordered sequence of information (bytes) coming from a source, or going to a sink Simplest stream reads/writes

More information

COMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output

COMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output COMP 213 Advanced Object-oriented Programming Lecture 19 Input/Output Input and Output A program that read no input and produced no output would be a very uninteresting and useless thing. Forms of input/output

More information

输 入输出相关类图. DataInput. DataOutput. java.lang.object. FileInputStream. FilterInputStream. FilterInputStream. FileOutputStream

输 入输出相关类图. DataInput. DataOutput. java.lang.object. FileInputStream. FilterInputStream. FilterInputStream. FileOutputStream 输 入 / 输出 杨亮 流的分类 输 入输出相关类图 OutputStream FileOutputStream DataInputStream ObjectOutputStream FilterInputStream PipedOutputStream DataOutput InputStream DataInputStream PrintStream ObjectInputStream PipedInputStream

More information

I/O Streams. Object-oriented programming

I/O Streams. Object-oriented programming I/O Streams Object-oriented programming Outline Concepts of Data Streams Streams and Files File class Text file Binary file (primitive data, object) Readings: GT, Ch. 12 I/O Streams 2 Data streams Ultimately,

More information

PROGRAMACIÓN ORIENTADA A OBJETOS

PROGRAMACIÓN ORIENTADA A OBJETOS PROGRAMACIÓN ORIENTADA A OBJETOS TEMA8: Excepciones y Entrada/Salida Manel Guerrero Tipos de Excepciones Checked Exception: The classes that extend Throwable class except RuntimeException and Error are

More information

C17: File I/O and Exception Handling

C17: File I/O and Exception Handling CISC 3120 C17: File I/O and Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/24/2017 CUNY Brooklyn College 1 Outline Recap and issues Exception Handling

More information

Object Oriented Design with UML and Java. PART VIII: Java IO

Object Oriented Design with UML and Java. PART VIII: Java IO Object Oriented Design with UML and Java PART VIII: Java IO Copyright David Leberknight and Ron LeMaster. Version 2011 java.io.* & java.net.* Java provides numerous classes for input/output: java.io.inputstream

More information

Example: Copying the contents of a file

Example: Copying the contents of a file Administrivia Assignment #4 is due imminently Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in the front office for a demo time Dining Philosophers code is online www.cs.ubc.ca/~norm/211/2009w2/index.html

More information

Objec&ves. Review. Standard Error Streams

Objec&ves. Review. Standard Error Streams Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 Review What are benefits of excep&ons What principle of Java do files break if we re not careful? What class

More information

תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת

תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת A Typical Program Most applications need to process some input and produce some output based on that input The Java IO package (java.io) is to make that possible

More information

PIC 20A Streams and I/O

PIC 20A Streams and I/O PIC 20A Streams and I/O Ernest Ryu UCLA Mathematics Last edited: December 7, 2017 Why streams? Often, you want to do I/O without paying attention to where you are reading from or writing to. You can read

More information

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits) The Java I/O System Binary I/O streams (ASCII, 8 bits) InputStream OutputStream The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing binary I/O to character I/O

More information

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved. Chapter 10 File I/O Copyright 2016 Pearson Inc. All rights reserved. Streams A stream is an object that enables the flow of data between a program and some I/O device or file If the data flows into a program,

More information

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide Module 10 I/O Fundamentals Objectives Upon completion of this module, you should be able to: Write a program that uses command-line arguments and system properties Examine the Properties class Construct

More information

Chapter 17 Binary I/O. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.

Chapter 17 Binary I/O. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. Chapter 17 Binary I/O 1 Motivations Data stored in a text file is represented in human-readable form. Data stored in a binary file is represented in binary form. You cannot read binary files. They are

More information

Java Input/Output Streams

Java Input/Output Streams Java Input/Output Streams Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/essential/toc.html#io Input Stream Output Stream Rui Moreira 2 1 JVM creates the streams n System.in (type

More information

IT101. File Input and Output

IT101. File Input and Output IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents

More information

Special error return Constructors do not have a return value What if method uses the full range of the return type?

Special error return Constructors do not have a return value What if method uses the full range of the return type? 23 Error Handling Exit program (System.exit()) usually a bad idea Output an error message does not help to recover from the error Special error return Constructors do not have a return value What if method

More information

WOSO Source Code (Java)

WOSO Source Code (Java) WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the

More information

Data Structures. 03 Streams & File I/O

Data Structures. 03 Streams & File I/O David Drohan Data Structures 03 Streams & File I/O JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN 0132162709 2012 Pearson Education, Inc., Upper Saddle River, NJ.

More information

Java Input/Output. 11 April 2013 OSU CSE 1

Java Input/Output. 11 April 2013 OSU CSE 1 Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter

More information

Basic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)

Basic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO) I/O and Scannar Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 I/O operations Three steps:

More information

Stream Manipulation. Lecture 11

Stream Manipulation. Lecture 11 Stream Manipulation Lecture 11 Streams and I/O basic classes for file IO FileInputStream, for reading from a file FileOutputStream, for writing to a file Example: Open a file "myfile.txt" for reading FileInputStream

More information

7 Streams and files. Overview. Binary data vs text. Binary data vs text. Readers, writers, byte streams. input-output

7 Streams and files. Overview. Binary data vs text. Binary data vs text. Readers, writers, byte streams. input-output Overview 7 Streams and files import java.io.*; Binary data vs textual data Simple file processing - examples The stream model Bytes and characters Buffering Byte streams Character streams Binary streams

More information

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2 Java IO - part 2 BIU OOP Table of contents 1 Basic Java IO What do we know so far? What s next? 2 Example Overview General structure 3 Stream Decorators Serialization What do we know so far? What s next?

More information

Software 1. תרגול 9 Java I/O

Software 1. תרגול 9 Java I/O Software 1 תרגול 9 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams

More information

BBM 102 Introduction to Programming II Spring Exceptions

BBM 102 Introduction to Programming II Spring Exceptions BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom

More information

C17: I/O Streams and File I/O

C17: I/O Streams and File I/O CISC 3120 C17: I/O Streams and File I/O Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/9/2018 CUNY Brooklyn College 1 Outline Recap and issues Review your progress Assignments:

More information

Java Input / Output. CSE 413, Autumn 2002 Programming Languages.

Java Input / Output. CSE 413, Autumn 2002 Programming Languages. Java Input / Output CSE 413, Autumn 2002 Programming Languages http://www.cs.washington.edu/education/courses/413/02au/ 18-November-2002 cse413-18-javaio 2002 University of Washington 1 Reading Readings

More information

Sri Vidya College of Engineering & Technology Question Bank

Sri Vidya College of Engineering & Technology Question Bank 1. What is exception? UNIT III EXCEPTION HANDLING AND I/O Part A Question Bank An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program s instructions.

More information

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes.  Debugging tools Today Book-keeping File I/O Subscribe to sipb-iap-java-students Inner classes http://sipb.mit.edu/iap/java/ Debugging tools Problem set 1 questions? Problem set 2 released tomorrow 1 2 So far... Reading

More information

Introduction Unit 4: Input, output and exceptions

Introduction Unit 4: Input, output and exceptions Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Introduction Unit 4: Input, output and exceptions 1 1.

More information

Objekt-orienteeritud programmeerimine MTAT (6 EAP) 5. Loeng. H e l l e H e i n h e l l e. h e i e e

Objekt-orienteeritud programmeerimine MTAT (6 EAP) 5. Loeng. H e l l e H e i n h e l l e. h e i e e Objekt-orienteeritud programmeerimine MTAT.03.130 (6 EAP) 5. Loeng H e l l e H e i n h e l l e. h e i n @ut. e e Täna loengus: Abstraktsed klassid Liidesed Mähisklassid 2 Abstraktsed klassid Meetodit nimetatakse

More information

Lecture 11.1 I/O Streams

Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam

More information

File. Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices

File. Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices Java I/O File Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices Magnetic disks Optical disks Magnetic tapes Sequential

More information

Input-Output and Exception Handling

Input-Output and Exception Handling Software and Programming I Input-Output and Exception Handling Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Reading and writing text files Exceptions The try block catch and finally

More information

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file

More information

Lecture 7. File Processing

Lecture 7. File Processing Lecture 7 File Processing 1 Data (i.e., numbers and strings) stored in variables, arrays, and objects are temporary. They are lost when the program terminates. To permanently store the data created in

More information

Files and Streams

Files and Streams Files and Streams 4-18-2006 1 Opening Discussion Do you have any questions about the quiz? What did we talk about last class? Do you have any questions about the assignment? What are files and why are

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)

More information

Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja.

Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja. Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Sub prog1() Msgox "Tere" Sub prog2() a = si(1) Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja. a = Sin() Protseduuri

More information

CSD Univ. of Crete Fall Files, Streams, Filters

CSD Univ. of Crete Fall Files, Streams, Filters Files, Streams, Filters 1 CSD Univ. of Crete Fall 2008 Introduction Files are often thought of as permanent data storage (e.g. floppy diskettes) When a file is stored on a floppy or hard disk, the file's

More information

ITI Introduction to Computer Science II

ITI Introduction to Computer Science II ITI 1121. Introduction to Computer Science II Laboratory 8 Winter 2015 [ PDF ] Objectives Introduction to Java I/O (input/output) Further understanding of exceptions Introduction This laboratory has two

More information

CS Week 11. Jim Williams, PhD

CS Week 11. Jim Williams, PhD CS 200 - Week 11 Jim Williams, PhD This Week 1. Exam 2 - Thursday 2. Team Lab: Exceptions, Paths, Command Line 3. Review: Muddiest Point 4. Lecture: File Input and Output Objectives 1. Describe a text

More information

What is Serialization?

What is Serialization? Serialization 1 Topics What is Serialization? What is preserved when an object is serialized? Transient keyword Process of serialization Process of deserialization Version control Changing the default

More information

Software Practice 1 - File I/O

Software Practice 1 - File I/O Software Practice 1 - File I/O Stream I/O Buffered I/O File I/O with exceptions CSV format Practice#6 Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee 1 (43) / 38 2 / 38

More information

Objec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1

Objec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1 Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 STANDARD ERROR Oct 5, 2016 Sprenkle - CSCI209 2 1 Standard Streams Preconnected streams Ø Standard Out: stdout

More information

File Operations in Java. File handling in java enables to read data from and write data to files

File Operations in Java. File handling in java enables to read data from and write data to files Description Java Basics File Operations in Java File handling in java enables to read data from and write data to files along with other file manipulation tasks. File operations are present in java.io

More information

CS 200 File Input and Output Jim Williams, PhD

CS 200 File Input and Output Jim Williams, PhD CS 200 File Input and Output Jim Williams, PhD This Week 1. WaTor Change Log 2. Monday Appts - may be interrupted. 3. Optional Lab: Create a Personal Webpage a. demonstrate to TA for same credit as other

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Files Two types: Text file and Binary file Text file (ASCII file) The file data contains only ASCII values

More information

The I/O Package. THE Java platform includes a number of packages that are concerned with the CHAPTER20

The I/O Package. THE Java platform includes a number of packages that are concerned with the CHAPTER20 CHAPTER20 The I/O Package From a programmer s point of view, the user is a peripheral that types when you issue a read request. Peter Williams THE Java platform includes a number of packages that are concerned

More information

String temp [] = {"a", "b", "c"}; where temp[] is String array.

String temp [] = {a, b, c}; where temp[] is String array. SCJP 1.6 (CX-310-065, CX-310-066) Subject: String, I/O, Formatting, Regex, Serializable, Console Total Questions : 57 Prepared by : http://www.javacertifications.net SCJP 6.0: String,Files,IO,Date and

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception

More information

CS Programming I: File Input / Output

CS Programming I: File Input / Output CS 200 - Programming I: File Input / Output Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624

More information

Chapter 12 Exception Handling

Chapter 12 Exception Handling Chapter 12 Exception Handling 1 Motivations Goal: Robust code. When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can

More information

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output. CSE 143 Java Streams Reading: 19.1, Appendix A.2 GREAT IDEAS IN COMPUTER SCIENCE REPRESENTATION VS. RENDERING 4/28/2002 (c) University of Washington 09-1 4/28/2002 (c) University of Washington 09-2 Topics

More information

Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu.

Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu. Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu enn.ounapuu@ttu.ee Millest tuleb jutt? Kuidas ma näen, millises sammus erinevad protsessid parasjagu on? Kuidas ma aru saan, kas protsess töötab

More information

Simple Java Input/Output

Simple Java Input/Output Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it

More information

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction COMPSCI 230 S2 2016 Software Construction File Input/Output 2 Agenda & Reading Agenda: Introduction Byte Streams FileInputStream & FileOutputStream BufferedInputStream & BufferedOutputStream Character

More information

CS Programming I: File Input / Output

CS Programming I: File Input / Output CS 200 - Programming I: File Input / Output Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455

More information

Byte and Character Streams. Reading and Writing Console input and output

Byte and Character Streams. Reading and Writing Console input and output Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates

More information

CSB541 Network Programming 網路程式設計. Ch.2 Streams 吳俊興國立高雄大學資訊工程學系

CSB541 Network Programming 網路程式設計. Ch.2 Streams 吳俊興國立高雄大學資訊工程學系 CSB541 Network Programming 網路程式設計 Ch.2 Streams 吳俊興國立高雄大學資訊工程學系 Outline 2.1 Output Streams 2.2 Input Streams 2.3 Filter Streams 2.4 Readers and Writers 2 Java I/O Built on streams I/O in Java is organized

More information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 11 I/O File Input and Output Reentering data all the time could get tedious for the user. The data can be saved to

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Lecture Note 29 Streams and Exceptions We saw back in Lecture Note 9 how to design and implement our own Java classes. An object such as a Student4 object contains related fields such as surname,

More information

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling CS115 Pi Principles i of fcomputer Science Chapter 17 Exception Handling Prof. Joe X. Zhou Department of Computer Science CS115 ExceptionHandling.1 Objectives in Exception Handling To know what is exception

More information

Writing usable APIs in practice

Writing usable APIs in practice Writing usable APIs in practice SyncConf 2013 Giovanni Asproni gasproni@asprotunity.com @gasproni Summary API definition Two assumptions Why bother with usability Some usability concepts Some techniques

More information

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R. Structural Programming and Data Structures Winter 2000 CMPUT 102: Input/Output Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection

More information

Core Java Contents. Duration: 25 Hours (1 Month)

Core Java Contents. Duration: 25 Hours (1 Month) Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java

More information

Software 1 with Java. The java.io package. Streams. Streams. Streams. InputStreams

Software 1 with Java. The java.io package. Streams. Streams. Streams. InputStreams The java.io package Software with Java Java I/O Mati Shomrat and Rubi Boim The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for

More information

Lab 2: File Input and Output

Lab 2: File Input and Output Lab 2: File Input and Output This lab introduces how to handle files as both input and output. We re coming back to Tracery (which you implemented in Lab 1) with this assignment but instead of always reading

More information

More on Exception Handling

More on Exception Handling Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

Streams. Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa

Streams. Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa Streams Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa Pedro Alexandre Pereira (palex@cc.isel.ipl.pt) 4 hieraquias de streams em Java Escrita Leitura

More information

Streams and File I/O

Streams and File I/O Chapter 9 Streams and File I/O Overview of Streams and File I/O Text File I/O Binary File I/O File Objects and File Names Chapter 9 Java: an Introduction to Computer Science & Programming - Walter Savitch

More information

Exceptions Binary files Sequential/Random access Serializing objects

Exceptions Binary files Sequential/Random access Serializing objects Advanced I/O Exceptions Binary files Sequential/Random access Serializing objects Exceptions No matter how good of a programmer you are, you can t control everything. Other users Available memory File

More information