Java Final

Card Set Information

Java Final
2013-08-17 20:55:14
java final

java final
Show Answers:

  1. What are the 2 java packages dealing with IO
    • original package
    • updated java.nio
  2. 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
  3. what method to call to get the default file system on your computer returned to you
    as a FileSystem object
  4. What is a FileStore object?
    used to identify the various partitions and devices on your file system
  5. What is a Path object? how do you call it?
    • used to encapsulate and represent a path to a file in your program.
    • getPath()
  6. 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")
  7. exists(Path p)
    returns true is the file or directory in the argument exists on the disk
  8. notExists(Path p)
    returns true if the file or dir in the arg list DOES NOT exist
  9. isHidden(Path p)
    returns true is the file has itsĀ  "hidden" attribute turned on
  10. isDirectory(Path p)
    returns true is the path object is a directory
  11. isRegularFile(Path p)
    returns true if the path ends with a file name
  12. How do you create a directory?
    a file?
    • createDirectory(Path p)
    • createFile(Path p)
  13. PrintWriter object
    used to both create a file on disk and then send text data stream to it
  14. 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);
  15. 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
  16. How do u create a PrintWriter object?
    • FileWriter writer = new FileWrite("names.txt", true);
    • then
    • PrintWriter output = new PrintWriter(writer);
  17. What does FileInputStream read?
  18. What does DataInputStream read?
    ints, longs, or Strings, ect.
  19. what is the "block" metaphore?
    used for moving bytes that are assembled into block then moved down "channels"
  20. describe a buffer
    a linear, finite sequence of element of a specific primitive type(an array)
  21. what is the difference between a stream and a channel?
    a stream is 1 way and a channel is 2 come
  22. What are the essential properties of a buffer?
    • capacity
    • limit
    • position
  23. 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
  24. RandomAccessFile class
    allows you to create a file with a pointer that allows random access to any bytes stored in the file
  25. What data structure is the RandomAccessFile
    byte array
  26. seek(int index)
    allows you to position the pointer anywhere in the file
  27. which classes of stream objects from he package can be used to serialize objects?
    ObjectOutputStream and ObjectInputStream
  28. 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()
  29. 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
  30. what is a JAR file and what is it used for
    Java Archive file: a zipped file format based on pkzip compression
  31. 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
  32. 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)
  33. what is the gang of four?
    • init()
    • start()
    • stop()
    • destory()
  34. 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
  35. 2 different ways of creating a threadable object
    • Runnable
    • ThreadExecutor service
  36. why should you never explicitly call the run()
    the code will just run inside the current thread, and no new thread is used
  37. why should you not call stop(), suspend() and resume()
    they are unstable
  38. what is the best way to stop a thread object?
    • yield()
    • sleep()
  39. 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
  40. thread contention/starvation
    • when a lower priority thread never gets to run because there is always a higher priority thread in queue.
    • avoid with sleep()
  41. ExecutorService
    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
  42. how to start threads so they are in a runnable state
  43. lost update
    • 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)
  44. race condition
    • 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
  45. how to prevent race conditions
    • keyword "synchronized"
    • locks
  46. fairness policy
    when the longest waiting thread will be the first to object the lock and do its business
  47. what lock mechanisms do
    limit access to one thread at a time and put others in a wait state
  48. what are the 3 staes of a thread's life cycle
    • new
    • runnable
    • blocked
    • dead
  49. new state
    create a thread object
  50. runnable state
    alerts the CPU that the thread's start() has been invoked
  51. blocked state
    thread is sleeping or waiting
  52. dead state
    thread is dead
  53. volatile
    • 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