• 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

www.valoxo.ch mock01a.html Q12

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:
__________________________________________________
import java.io.*;
public class Question12 {
public static void main(String[] args) throws IOException{
RandomAccessFile raf = new RandomAccessFile("test.dat","rw");
raf.writeInt(0x01);
raf.writeShort(0x23);
raf.writeByte(0x45); //line1
raf.seek(3);
short a1 = raf.readShort();
short a2 = raf.readShort();
System.out.println("0x"+Integer.toHexString(a1)+", 0x"+Integer.toHexString(a2));
}
}
__________________________________________________
Hi friends! Thanks for previous help!
What is a full presentation of raf after line 1?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
www.valoxco.ch ???
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Warning MFU!
This is wrong (I should have read the API and run the code ):

[ August 26, 2002: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could help :
http://www.valoxo.ch/jr/mocks/mock01a.html
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dmitry,
please find below the explanation I have included in my mock exam about Question 12:


We write one int (4 bytes), one short (2 bytes) and one byte (1 byte). Then, we read 2 shorts. What you should do in cases like this is write what is actually written in the file. Here goes: First an int 0x00000001 (remember that an int is 32 bits long), then a short 0x0023 and finally a byte 0x45. test.dat now contains 00000001002345. We place the file pointer on the 3rd byte, let's say we remove what comes before the 3rd byte, we end up with 01002345. Now we read 2 shorts, that is, 0100 and 2345.
Remember that all this is in hexadecimal notation and thus 0x45 represents 1 byte (that is 8 bits). Moreover, when using hexadecimal notation, remember that each digit stands for 4 bits, thus 0x45 is actually 0100 0101.

 
Dmitry Golynkin
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Valentin.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Val:
Under which test objective this question will fall? How many such questions we can expect in 1.4 exam?
Thanks
Barkat
[ August 26, 2002: Message edited by: Barkat Mardhani ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those kinds of questions will not appear in the 1.4 version since IO has been dropped...
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Val:
If I am not conversant of Hex, binary, octal codes, Would that be ok for exam 1.4 as well?
Thanks
[ August 26, 2002: Message edited by: Barkat Mardhani ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The new objectives for SCJP 1.4 state:


State the range of all primitive formats, data types and declare literal values for String and all primitive types using all permitted formats bases and representations.


which makes clear that you have to know how to represent integer values in hexadecimal, octal and binary forms.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Writes an int to the file as four bytes, high byte first. The write starts at the current position of the file pointer.
That high byte first got me, folks!
-Sorry
[ August 26, 2002: Message edited by: Barry Gaunt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic