Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Random access IO and printing to a laser printer

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random access IO and printing to a laser printer

    Hello

    At 72, I may be the most clueless newbie this forum has seen! I started programming in 1980 with BASIC, actually sold some financial programs, then moved to QBasic (compiled) and programmed in it for years. Moved to Visual Basic 6 some years ago and have written many programs in this, including a major accounting suite that's in use every day.

    Have looked at dot.net but I mistrust Micro$oft and wonder when they will ditch it. Hence contemplating the move to Java.

    Before embarking on the relearning exercise I have two queries.

    1) Can I write in Java to create and access Random Access files? I am comfortable with these. Where will I find the syntax for open, get, put, close (or whaetver the Java terms are)?

    2) Can I write in Java to print financial reports (formatted) to a laser printer? Printing to a console is far too primitive for my needs. Again, where can I find the syntax?

    Many thanks in advance
    Alan


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random access IO and printing to a laser printer

    There is a RandomAccessFile class. See the API doc for its methods:
    Java Platform SE 7
    Find the class name in lower left, click on the link and the doc is shown in the main frame.

    I don't know anything about using laser printers.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random access IO and printing to a laser printer

    Thank you Norm. Wow! That's a lot of info!

    In Visual Basic we have a thing called User Defined Type, which in Dot Net is Structure. For example, if I have a lot of records in my random access file, each record may have name, dob, membership number, syntax rather like this:-

    Stucture Bloggs
    Name As String * 30 //the max length of the string
    dob As Date //fixed length designated by type
    membershipNo As Int //same as above
    End structure

    (Note: I indented the lines between the start and end lines, but the forum machine discarded the indents!)

    We can address a given field in a given record by Bloggs.Name = "Smith" or Bloggs.dob = Now or Bloggs.membershipNo = Counter. Then Put #1,4 where #1 is the file number and 4 is the record no. Where can I find info about the java equivalent?
    Last edited by alan1; March 10th, 2013 at 08:20 PM. Reason: clarify syntax

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random access IO and printing to a laser printer

    The tutorial has a lot of info: The Really Big Index

    Your data description reminds me of a class with member variables: classreference.member
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Random access IO and printing to a laser printer

    Quote Originally Posted by alan1 View Post
    Thank you Norm. Wow! That's a lot of info!

    In Visual Basic we have a thing called User Defined Type, which in Dot Net is Structure. For example, if I have a lot of records in my random access file, each record may have name, dob, membership number, syntax rather like this:-

    Stucture Bloggs
    Name As String * 30 //the max length of the string
    dob As Date //fixed length designated by type
    membershipNo As Int //same as above
    End structure

    (Note: I indented the lines between the start and end lines, but the forum machine discarded the indents!)

    We can address a given field in a given record by Bloggs.Name = "Smith" or Bloggs.dob = Now or Bloggs.membershipNo = Counter. Then Put #1,4 where #1 is the file number and 4 is the record no. Where can I find info about the java equivalent?
    Have you looked at Java enums?
    Java Enum Tutorial: 10 Examples of Enum in Java

    The syntax seems similar to what you describe.

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random access IO and printing to a laser printer

    Thanks. I had trouble following that tutorial owing to the bad grammar, spelling and punctuation. I can't help feeling that there must be a closer equivalent to vb6's UDT or dot.net's Structure if only I can find it.

    Would love to get an answer on laser printers too. Surely, if Java is used for financial applications then printing (hardcopy) formatted financial reports must be a well used feature?

    I am very keen to get started on Java, but not if after masses of study and practice I still cannot use random access files or printers, both absolutely central to the accounting application that I would like to port from vb6!

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random access IO and printing to a laser printer

    Classes are a user defined type. The syntax to access a class's data is similar to what you posted:
    classRef.memberVar
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random access IO and printing to a laser printer

    Thanks Norm. I'll have to get my head around what classes actually are! Any luck with printing formatted data to laser printers?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random access IO and printing to a laser printer

    I don't do any printing so I have no info about that.

    Look at the PrinterJob class.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random access IO and printing to a laser printer

    Norm, is there someone at Oracle I could ask? I really need to know if this requirement can be met before embarking on learning Java. (BTW, I'll also be interested to get anyone's recommendation of a *real* beginners book that assumes nothing and *really* explains classes without just a heap of jargon!

    Cheers
    Alan

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random access IO and printing to a laser printer

    OOP (and Java) is full of jargon.

    I don't know where you could ask your questions other than on the many java forums.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Random access IO and printing to a laser printer

    Quote Originally Posted by alan1 View Post
    1) Can I write in Java to create and access Random Access files? I am comfortable with these. Where will I find the syntax for open, get, put, close (or whaetver the Java terms are)?
    You can use the RandomAccessFile class found in the java.io. package. Here is a link containing the syntax and its methods. You may also want to look at the File class, which is treated as a representation of a given file or directory. It is also part of the java.io. package.

    Quote Originally Posted by alan1 View Post
    2) Can I write in Java to print financial reports (formatted) to a laser printer? Printing to a console is far too primitive for my needs. Again, where can I find the syntax?
    I've never done this before (nor thought about it actually) so I did some Googling and it is pretty interesting. I found 2 links from Oracle that would be of some help:
    Lesson: Printing (The Java™ Tutorials > 2D Graphics) (describes the steps you'll need to take)
    javax.print (Java Platform SE 7 ) (details of the javax.print. package in detail)

Similar Threads

  1. Printing with Dot Matix Printer
    By TheQuickBrownFox in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: November 9th, 2012, 02:04 AM
  2. Printing in a thermal printer?
    By rosseldrintaupa in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: September 29th, 2012, 05:08 AM
  3. Random Access File
    By Wish.. in forum Java Theory & Questions
    Replies: 2
    Last Post: March 12th, 2012, 02:40 PM
  4. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 12th, 2009, 01:51 AM
  5. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2009, 10:44 PM