Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2012, 10:59 AM
Registered User
 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 11, P436: reading randomly

In the code section, there are these lines:
Code:
final int PRIMESREQUIRED = 10;
final int LONG_BYTES = 8;                           // Number of bytes for type long
ByteBuffer buf = ByteBuffer.allocate(LONG_BYTES*PRIMESREQUIRED);
indicating a buffer size for buf of 80. In the text on page 437 it says "Because buf has a capacity of 8 bytes, only one prime is read each time."

So I recompiled it with
Code:
ByteBuffer buf = ByteBuffer.allocate(LONG_BYTES);
and it seems to work fine. Am I just getting lucky or am I right that there is a minor inconsistency in the definition of buf?
 
Old February 24th, 2013, 03:56 PM
Registered User
 
Join Date: Jun 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default same thing

Did you ever figure this out? I have the same thing.
 
Old February 25th, 2013, 09:44 AM
Registered User
 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I concluded that it was an error in the code. When you randomly read a prime from the file, the buffer as in the example will have the number you want plus the next seven numbers from the file which are not required. A buffer of 8 bytes seems to me to be sufficient. I left it at
Code:
ByteBuffer buf = ByteBuffer.allocate(LONG_BYTES);





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 11 Ex 1 fiddley BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 2 June 25th, 2011 12:33 PM
Ch 11 AgrumentOutOfRangeException AZSooner BOOK: Beginning Visual C# 2010 1 February 10th, 2011 05:28 PM
Ch 11 Question tixrus BOOK: Beginning JavaScript and CSS Development with jQuery 0 April 11th, 2010 05:23 PM
Ch 11 Pg459 Exercise 5 C# brivad BOOK: Beginning ASP.NET 1.0 0 September 10th, 2007 08:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.