iEntry 10th Anniversary Java Faqs RSS Feed

SCJP Input Output

By: admin - Tuesday, September 9th, 2008 at 10:54 am

QUESTION : 1
You can create a RandomAccessFile object in the following manner
FileInputStream fis = new FileInputStream("file path");
RandomAccessFile raf = new RandomAccessFile(fis , "rw");

1. False.
2. True

ANS : 1

QUESTION : 2

       What is the result of attempting to compile and run this ?
      public class Test {
           public static void main(String[] args){
           byte out = 0;
           RandomAccessFile raf;
                 try{
                 raf = new RandomAccessFile("test1.txt" , "rw");
                  for (int i=0; i<10; i++)
                 raf.write(i);
                 raf.seek(1);
                 out = raf.readByte();
                 raf.close();
                 System.out.println(out);
                 }
                 catch(IOException e){System.out.println("err");}
            }
         }

1. 1
2. 0

ANS : 1

QUESTION : 3

     What is the result of attempting to compile and run this ?
         public class Test {
           public static void main(String[] args){
           byte out = 0;
           String  f = "test.txt";
           RandomAccessFile raf;
                 try{
                 raf = new RandomAccessFile(f , "rw");
                 raf.write(1);
                 raf.close();
                 raf.open(f, true);
                 raf.seek(1);
                 out = raf.readByte();
                 raf.close();
                 System.out.println(out);
                 }
                 catch(IOException e){System.out.println("err");}
            }
         }

1. It will run and print "err"
2. It will run and print "1"
3. It will throw a runtime exception
4. It will not compile 

ANS : 4

QUESTION : 4

      Which of the fllowing will  create a file called test.txt
       in your current directory ?

1. File f = new File("test.txt");
2. FileOutputStream fos = new FileOutputStream("test.txt");
3. RandomAccessFile raf = new RandomAccessFile("test.txt", "r");
4. RandomAccessFile raf = new RandomAccessFile("test.txt", "rw");

ANS : 2,4

QUESTION : 5
       True or false.
     UTF characters are always 16 bits

1. True
2. False

ANS : 2

QUESTION : 6

        void aMethod(){
           File f = new File("test.txt");
	   try{ f.createNewFile();}
            catch(Exception e){System.out.println("err");}
        }

    Calling this method will overwrite the existing file an create
    a blank file in its place.     

1. True
2. False

ANS : 2

QUESTION : 7
    Which of the following are valid constructors for
    a DataInputStream ?

1. DataInputStream(FileInputStream fis)
2. DataInputStream(DataInputStream dis)
3. DataInputStream(File f)
4. DataInputStream(FilterInputStream fis)

ANS : 1,2,4

QUESTION : 8
        True or false ?

      InputStreamReader is a subclass of InputStream

1. True
2. False

ANS : 2

QUESTION : 9

    This is a valid constructor for a BufferedReader.
     BufferedReader(FileReader fr)

      True or false?   

1. True
2. False

ANS : 1

QUESTION : 10

      Now you get a bonus mark.  

ANS : 1

Stumble It!
 Digg!

Leave a Reply