• 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

B&S: Beginner Questions

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings to all JavaRangers,
upto now using rafReadLine(), i could see how my db2x1 looks like.
But i still donot understand what they mean by header information. Do they mean the name, location, size.... aso? if not:
Q1. how do i find out the header info then?
using rafReadShort() i had magicCookieNumbers some are too BIG some like just zero. I have seen some of you just make it to a constant which is 512. I am given:
4 byte for magicCookie
4 byte for totalOverAllLengthof each record
2 byte for No. of fields in each record
Q2. what is a magicCookie at all? I mean it identifies the data file. Please can any one tell me more and what to do with the magicCookie when writing a code like Data.java? Where did you all take the value 512 for it?
Q3.Is it right to think when it is 4Byte to readShort(), and when it sais 2Byte then readInt()? I tried all.
Q4.the owner field is blank meaning that record is available. But how do i determine the 8 digit No. for customer who booked?
Q5. Though it is not mentioned in the Assignment, is it a good Idea to have a DOSClient.java like in the Max Habiby�s book? or is it just wasting time?
Thankx in advance
Regards
nathnael
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. The header information should be part of your assignment specs.
2. The magic cookie has been an issue for a long time. You can search the forum for past postings. It seems to mostly be a preference how you treat it.
3. All primitives in Java are a fixed-length. Therefore you can use readShort(), etc ... to read whatever number of bytes you want if it is a numeric value.
4. Your spec most likely states that the 8-digit customer number is actually a string. So, read it just like any array of chars using the IO classes.
5. I didn't read his book, so I don't really know about this one.
One last point: reading entire lines into your application from the db probably isn't the approach you're looking for.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nathnael,


Q5. Though it is not mentioned in the Assignment, is it a good Idea to have a DOSClient.java like in the Max Habiby�s book? or is it just wasting time?


Having a command line executable will help you throughout your application.
Many candidates start with a simple application that just reads the records in from their supplied database, just to prove that they can read the data. This can be much quicker and easier to write as a DOS application than a full blown GUI. The same goes as you add more functionality to your Data class: you may find it quicker and easier to write a test program that can be run from the command line than adding all the functionality in the GUI.
Finally when you get to test the multiple concurrent connections, it is better to have automated threads running, than to try and run multiple instances of your GUI application.
Regards, Andrew
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathnael,
For the header and Meta data section, I read field by field.
For the DataSection, I read record by record, as I know the record size from the Meta Data Section.
It isn't really difficult to understand the Database format instructions except for the magic cookie and the data record offset fields. I used a hex editor to open the database file and verified it.
If you still have any questions, you can refer to this
thread: DB format , where George has explained it quite clearly.
I have done something similar to what Andrew has suggested. A simple DOS program that reads/writes the records to the db file, just to feel comfortable with the database. I plan to re-use some of the code in this program later in my main Data class.
 
Nathnael Haile-Mickael
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nathaniel, Andrew and vish,
Thank you to all of you for the quick reply and explaining things.
Nathaniel, for the primitives, yes i know that i should use readShort(), etc.. and when let`s say if magicCookie is 4 Bytes, reading it with readShort() or with Int and Long is always gives me very different results. Taht is exactly what cofuses me, because i dont know which one is right or am i missing some thing around here? That is why i needed some Help. Sorry for the ERROR on the Site Question- next time i know where to ask.
Andrew and vish thanks a lot for the advise i am trying to do so. I hope i will be back soon with some positive results.
It was nice of you all Thanx again
Regards
Nathnael
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nathnael Haile-Mickael:
for the primitives, yes i know that i should use readShort(), etc.. and when let`s say if magicCookie is 4 Bytes, reading it with readShort() or with Int and Long is always gives me very different results. Taht is exactly what cofuses me, because i dont know which one is right or am i missing some thing around here?


RandomAccessFile is very useful to read/write bytes in the db file. This implements DataInput and DataOutput interfaces which have convenient methods to read/write bytes in the form of primitive types int, long, float, boolean etc.....
For fields with 2 bytes of data, I use readShort()
- which reads only 2 bytes
For fields with 4 bytes of data, I use readInt()
- which reads only 4 bytes
So reading 4 bytes of data is different from reading 2 bytes of data.
For magic cookie, try reading 4 bytes of data and you might get some value like 512, 514 or something like that...

For fields with n bytes of data, I use read read(byte[] buffer)
where buffer's length is 'n' bytes.
For more info, refer Java 1.4 API of RandomAccessFile, that might help you solve your problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic