• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RAF question from javacaps mock, help requested

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
60. What is the output displayed by the following code?
import java.io.*;
public class TestIPApp {
public static void main(String args[]) {
RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
file.writeBoolean(true);
file.writeInt(123456);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.0001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
Select correct answer:
A) 123456
B) 7890
C) 1000000
D) .0001

THE CORRECT ANSWER IS B, HOWEVER I THOUGHT THAT SEEK(5) WOULD START INDEXING FROM 0 AND WOULD STOP AT THE FLOAT VALUE OF .0001.
PLEASE CLEAR MY CONCEPTIONS OF THIS SEEK METHOD, THANKS !
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarim,
boolean takes 1 byte, int takes 4 and long takes 8 bytes.
so file.seek(5) is at the 5th byte in the file which is nothing but 7890.
the file looks like this
true 123456 7890 1000000 and so on
1byte]4byte]4byte]------
1 + 4 ] 5th byte starts right at 7 and the whole int is printed - 7890
 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS A LOT RAVI, THAT WAS GREAT !!
 
reply
    Bookmark Topic Watch Topic
  • New Topic