Question: Given the follow program, answer the questions below. import java.io.*; public class RAFQuestion { public static void main(String[] args) throws IOException { final int CHAR_SIZE

Given the follow program, answer the questions below.

import java.io.*; public class RAFQuestion { public static void main(String[] args) throws IOException { final int CHAR_SIZE = 2;

char ch1; char ch2; char[] letters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; RandomAccessFile randomFile = new RandomAccessFile("Letters.dat", "rw"); for (int i = 0; i < letters.length; i++) randomFile.writeChar(letters[i]); randomFile.seek(CHAR_SIZE * 10); ch1 = randomFile.readChar(); System.out.println(ch1); randomFile.seek(CHAR_SIZE * 3); ch2 = randomFile.readChar(); System.out.println(ch2); randomFile.close(); } }

1. What is the purpose of the CHAR_SIZE constant?

2. Explain what the purpose of the two parameters in the constructor: RandomAccessFile randomFile = new RandomAccessFile("Letters.dat", "rw");

3. Explain in your own words how the seek method works and what the parameter represents: randomFile.seek(CHAR_SIZE * 10);

4. Explain in your own words how readChar method works: ch1 = randomFile.readChar();

5. What is the output of this code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!