[personal profile] fardell24

Digital and Interactive Games 2015 – Term 2, Week 4, Session 1
Today
ArrayList
Date and Time (new from Java 8)
Exception Handling

Chapter 9

try {
Intention
}
catch {
if exception is thrown
}
finally {
After the catch of the first block if there is no error
}


ErrorHandlingSample
int numbers = new int(4);

try {
// Force an error
numbers[7] = 34;
}
catch (ArrayIndexOutOfBoundsException except) {
System.out.println(“Index out of range”);
}


 photo W12001_zpsqa1i6eui.png


ExceptionCase.java
public class ExceptionCase {




Digital and Interactive Games 2015 – Term 2, Week 4, Session 2
Chapter 10

Today: I/0
Byte Stream
– InputStream – Buffer InputStream
– OutputStream

Character Stream

 photo W11S0032_zpsdhs0vup9.png

in java.io

{
h ()
}
catch (h) {
}
finally {
.close
}


Classpath


fin = null;

try {
open
}
catch (file not found) {
}

try {
read
}
catch (IOException)


A.txt
Read

Writing
B.txt


IOSample04

– Test 04 and 05

1) in bin folder

2) in data folder


scores.dat
int: player-id
double: scores
double: health
int: check


2 8 0 6 61 0 5 9 : 4
| | | | | | | | :
1) 4 0 12 0 1.8 :
:
2) 4 0 3 0 9 :
| :
36 15 :
36 →: 4


Checksum

[80]
[16]
normal : 888
vertex 1 888
2 888
3 888

 photo W12005_zpsnei7lzx6.png

> 10 differences → files are
< 10 differences → print where the differences are


YouTube Tutorials : TheNewBoston (C++, web, etc)

Next Week
Wed: Java
Thurs: C++ Dungeon Game

IOSample06

// Read and Write Binary Data

int i = 34;
double d = 3.4505;
try (DataOutputStream fout = new DataOutputStream(new FileOutputStream(“myData”))) {
fout.writeInt();
fout.writeDouble();
}
catch(IOException except) {
System.out.println(“Error when reading data”);
}

// Read the data back
try (DataInputStream fout = new DataInputStream(new FileInputStream(“myData”))) {
i = fin.readInt();
d = fin.readDouble();
System.out.println(“i = ” + i);
System.out.println(“d = ” + d);
}
catch (IOException except) {
System.out.println(“Error when reading data”);
}




This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

May 2025

S M T W T F S
     1 23
45 6 78910
11 12 13 141516 17
1819 2021 22 23 24
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 25th, 2025 11:25 pm
Powered by Dreamwidth Studios