Save
comprog
midterm
Save
Share
Learn
Content
Leaderboard
Learn
Created by
Andrei velasco
Visit profile
Cards (45)
Exception
An event that occurs during the execution of a program that disrupts the normal flow of instructions
Exception handling
The process used to change the normal flow of code execution if a specified exception occurs
Checked exceptions
ClassNotFoundException
IllegalAccessException
InstantiationException
NoSuchMethodException
Unchecked exceptions (runtime exceptions)
ArithmeticException
ArrayIndexOutOfBoundsException
ArrayStoreException
InputMismatchException
NullPointerException
NumberFormatException
StringIndexOutOfBoundsException
try block
A block of code that might throw an exception that can be handled by a matching catch block
catch block
A segment of code that can handle an exception that might be thrown by the try block that precedes it
getMessage()
Method to determine Java's message about the exception
Only
one (1)
try block is accepted in a program but there can be multiple catch blocks
User-defined exception
Created by extending the Exception class
finally block
Contains statements which are executed whether or not an exception is thrown
There can only be one (1) finally block after a
try-catch
structure but it is not required
throw statement
Sends an exception out of a block or a method so it can be handled elsewhere
Volatile storage
Temporary storage, values stored in variables are lost when the computer loses power
Non-volatile storage
Permanent storage, a Java program that is saved on a disk uses
non-volatile
storage
Types of files
Text file
Binary file
The common characteristics of a text file and binary file are
size
,
name
, and
date
and
time of creation
Path
The complete list of the disk drive plus the hierarchy of directories in which the file is located
Absolute path
A complete path, it does not require any other information to locate a file on a system
Relative path
Depends on other path information
Path methods
toString()
getFileName()
getNameCount()
getName(int
)
Converting a relative path to an absolute path
Use the
toAbsolutePath()
method
checkAccess()
Method to verify if a file exists and if a program can access it when needed
Arguments of the checkAccess() method
None
READ
WRITE
EXECUTE
delete()
Method to remove the last element (file or directory) in a path
Exceptions thrown by delete()
NoSuchFileException
DirectoryNotEmptyException
SecurityException
IOException
deleteIfExists()
Method to remove a file without encountering an exception if the file does not exist
readAttributes()
Method to retrieve useful information about a file
BasicFileAttributes methods
size()
creationTime()
lastModifiedTime()
compareTo()
Character
The smallest useful piece of data, can be a letter, number, or special symbol
Field
A group of characters that has some meaning
Record
A collection of fields that contain data about an entity
File
A collection of related records
Sequential access file
A file where each record is accessed one after another in the order in which it was stored
Comma-separated values
Values in a record that are separated by commas
Stream
A flow of data, input stream is from a source to a program, output stream is from a program to a destination
Buffer
A memory location into which you can write data, which you can read again later
Flushing
Clears any bytes that have been sent to a buffer for output but have not yet been displayed on a hardware device
Input and Output Classes
InputStream
FileInputStream
BufferedInputStream
OutputStream
FileOutputStream
BufferedOutputStream
PrintStream
Reader
BufferedReader
BufferedWriter
Common OutputStream methods
close()
flush()
write
(byte[] b)
write
(byte[] b, int off, int len)
newOutputStream
()
Method to create a writeable file
See all 45 cards