1.

What class (or which of its subclasses) do you use to read from a text file?


Answer:


2.

If storage of information in binary files is more compact and more efficient than storage in text files, why would you ever need to use text files? Explain your reasons. If there is no need for text files, please explain those reasons.


Answer:


3.

Both the Reader and InputStream classes have a read method to read either a single character (Reader) or a single byte (InputStream) at a time. However, the read method for Reader does not return a value of type char, and the read method for InputStream does not return a value of type byte. What type value do the read methods in both of these methods return? Why is this type returned, instead of the expected char or byte?


Answer:


4.

When you are done writing to a file, what method must you call to ensure that all changes are committed to the disk file?


Answer:


5.

Write a program to store multiple memos in a file, "memo.dat". Allow a user to enter a topic and the text of a memo (the text of the memo is stored as a single line and thus cannot contain a return character). Store the topic, the date stamp of the memo, and the memo message.

Use a text editor to view the contents of the "memo.dat" file and to check that the information is stored correctly.

Creating a java.util.Date object with no arguments will initialize the Date object to the current time and date. A date stamp is obtained by calling the Date.toString() method.


Answer:


6.

Modify your memo writing program to read multiple memos stored in a text file, "memo.dat", in addtion to allowing a user input and store memos.

Memos are stored in three lines. The first line is the memo topic, the second line is the date stamp, and the third line is the memo message. Display the memos one at a time, and allow the user to choose to view the next memo (if there is one).


Answer:


7.

Modify your simple memo writing program or write a new program to store multiple memos in a text file. Use the JFileChooser to allow the user to choose the file into which the memos will be saved or from which the files will be read.

Allow a user to enter a topic and the text of a memo. The text of the memo is stored as a single line and thus cannot contain a return character. Store the topic, the date stamp of the memo, and the memo message as three lines of text.

When opening a file, display the memos one at a time, and allow the user to choose to view the next memo (if there is one). Make sure that you check that the user specifies a file formatted properly for your program.


Answer:


8.

Modify your simple memo program or write a new program to allow a user to chose the file into which the memos will be saved or from which the files will be read, using the JFileChooser. Encrypt the file and save the file with the same file name, but with the extension .crp . You may choose your own encryption algorithm. Also allow a user to open a *.crp file and unencrypt the file.


Answer:


9.

In general, when you encrypt a text file, you do not use Reader and Writer objects. You use streams when working with encryption. Why is this the case?


Answer:


10.

Write a command line program to convert a text file to the "Ong" language. In the Ong language, each consonant in a word is converted to uppercase and appended with -ong and followed by a space. Vowels are not modified, only up-cased, and a space is placed after them. Spaces in the input file are removed. When reading Ong, and a vowel is encountered just provide the name of the vowel. For example, the text:

      Big Java.

      is converted to
   
      Bong I Gong Jong A Vong A.
 


Answer:


11.

Write a command line program that performs conversions on a text file.

java Convert [-uc] [-oc word] inputfile outputfile

Using the text,

      The mice will see you now

as an example, below is a description of parameters:

Parameter

Description

Example

-uc

finds each lowercase letter c in the text file, and converts it to uppercase

-uo

The mice will see yOu nOw

-oc word

finds each word in the file beginning with the character c (not case sensitive) and adds word after it separated by commas.

-oM ouch

The mice, ouch, will see you now

inputfile

name of the file to convert

 

outputfile

name of the file to save the converted file to

 


 Allow multiple parameters, such as

java Convert -uo -ui -om ouch -ow like mouse.txt changed.txt

Output to changed.txt :

The mIce, ouch, wIll, like, see yOu nOw


Answer:


12.

Write a program or convert your simple memo program to read and save memos as object streams.

Create a Memo object. The Memo object should have fields to store a topic, a date stamp and the memo message. Allow a user to enter multiple memos, supplying the topic and message. Your program should provide the date stamp using the java.util.Date object (creating a Date object with no arguments initializes the object to the current time and date).

Let the user choose the file name to which the memos are saved (or from which the memos are read). When reading from the file, display the memos one at a time, and allow the user to choose to view the next memo (if there is one).

Remember to implement the Serializable interface!


Answer:


13.

What is the keyword transient used for?


Answer:


14.

Create an object MyShape. MyShape has a color, a location and is either an Ellipse2D.double or a Rectangle (you can implement additional shapes if you wish). MyShape implements the Serializable interface.

Write a program that draws objects of type MyShape on a panel. Provide radio buttons to indicate whether an ellipse or rectangle should be drawn and provide some way for the user to select the color of the shape. Whenever the user clicks on the panel with the mouse, draw the selected shape at that point in the selected color. Provide a menu. If the user choose File->Save, save the MyShape objects on the panel to an object stream. If the user chooses File->Load, load a file containing MyShape objects and display them correctly on the panel.


Answer:


15.

Create a program that reads and stores memos in a RandomAccessFile.

A memo contains three fields: a topic, a date stamp and the memo message. Your program should provide the date stamp using the java.util.Date object (creating a Date object with no arguments initializes the object to the current time and date).

If an opened file contains memos, display a list of topics and allow the user to choose a topic. When the topic is chosen, move to the memo in the file and display the memo. Allow the user to edit the memo. If the memo is changed, produce a new date stamp for the memo and resave the memo (in the same location). If a user chooses to add a memo, append it to the end of the file. Do not allow the user to enter a memo longer than the fixed size of the message field. Use a menu to allow the user to Save or Load files.


Answer: