Home > Preview
The flashcards below were created by user
on FreezingBlue Flashcards.
What are the 2 java packages dealing with IO
- original java.io package
- updated java.nio
what does java.nio.file.FileSystem do?
allows you to create an object that will encapsulate your computer's file system and then manipulate it
what method to call to get the default file system on your computer returned to you
as a FileSystem object
What is a FileStore object?
used to identify the various partitions and devices on your file system
What is a Path object? how do you call it?
- used to encapsulate and represent a path to a file in your program.
what is the difference between an absolute path and a relative path?
- absolute path =any path string that begins with a drive letter or root prefix(C:/crap/butt.txt)
- relative path = the path string does not have a drive letter prefix ("output.txt")
returns true is the file or directory in the argument exists on the disk
returns true if the file or dir in the arg list DOES NOT exist
returns true is the file has its "hidden" attribute turned on
returns true is the path object is a directory
returns true if the path ends with a file name
How do you create a directory?
- createDirectory(Path p)
- createFile(Path p)
used to both create a file on disk and then send text data stream to it
How to avoid deleting and creating a new file each time you write run your program?
add the 'true' arg to new Filewriter("names.txt", true);
What is the difference between writing text files and writing binary files?
- text files - bytes are encoded using scheme such as ASCII or unicode
- Binary file - raw bytes are send to and read from disk
How do u create a PrintWriter object?
- FileWriter writer = new FileWrite("names.txt", true);
- PrintWriter output = new PrintWriter(writer);
What does FileInputStream read?
What does DataInputStream read?
ints, longs, or Strings, ect.
what is the "block" metaphore?
used for moving bytes that are assembled into block then moved down "channels"
describe a buffer
a linear, finite sequence of element of a specific primitive type(an array)
what is the difference between a stream and a channel?
a stream is 1 way and a channel is 2 come
What are the essential properties of a buffer?
What is the 3 step process in reading or writing data to or from a channel?
- 1. get a Channel object from FileInputStream
- 2. create a Buffer object as a data container
- 3. read from the Channel into the Buffer object
allows you to create a file with a pointer that allows random access to any bytes stored in the file
What data structure is the RandomAccessFile
allows you to position the pointer anywhere in the file
which classes of stream objects from he java.io package can be used to serialize objects?
ObjectOutputStream and ObjectInputStream
describe an problem you might encounter when serializing objects and how to solve it.
- problem: try writing to disk more than once in a program
- solution: make the object forget by calling reset()
how to deal with an object that has a super class that does not implement the serializable interface
- use the keyword "transient"
- private transient SomeserilizeableClass objectOne;
- now the compiler will skip objectOne during the serialization process
what is a JAR file and what is it used for
Java Archive file: a zipped file format based on pkzip compression
what is a package
what is the standard naming convection
- they ensure that the class that is written to a large application will have a unique identifier
- reverse domain name format
Java application vs Java applet
- applications: run by themselves, process at main(), System.out.println()
- applet: must be loaded using a web page, no main()(gang of 4)
what is the gang of four?
what is the "sandbox" security model
- applets not allowed to read or write to the file system of a local machine
- applets cannot run other programs on the local machine
- applets are not allowed to create new connections between local machine and any other server except the applet's host server
2 different ways of creating a threadable object
- ThreadExecutor service
why should you never explicitly call the run()
the code will just run inside the current thread, and no new thread is used
why should you not call stop(), suspend() and resume()
they are unstable
what is the best way to stop a thread object?
what is thread priority and how can it affect thread operation
- priority: gives a thread a value from 1 to 10.
- lower priority can only run if the higher priority has already run
- when a lower priority thread never gets to run because there is always a higher priority thread in queue.
- avoid with sleep()
a class that creates a thread pool manager which can then only allow a certain amount of threads in the "water" at the same time
how to start threads so they are in a runnable state
- when 2 users tried to modify and access the same data and one was unable to complete the process in one time slice
- prevent with transaction rules(locks)
- data corruption because thread access is not synchronized.
- solution: prevent more than one thread at a time from entering the critical region of the program
how to prevent race conditions
- keyword "synchronized"
when the longest waiting thread will be the first to object the lock and do its business
what lock mechanisms do
limit access to one thread at a time and put others in a wait state
what are the 3 staes of a thread's life cycle
create a thread object
alerts the CPU that the thread's start() has been invoked
thread is sleeping or waiting
thread is dead
- does not do any locking.
- it informs the JVM that this variable will be accessed concurrently by multiple threads.
- will always read it from the main memory area
What would you like to do?
Home > Flashcards > Print Preview