Sunday, 11 September 2011

Java: Data Files (Intro)

Introduction

   As you could imagine, a program with no output of any kind is generally useless, which is why they need to be able to write data, and, slightly less commonly, read it in from some source. It's fine with the programs we've seen so far to not have reading/writing capability, but what happens when you want to keep the data past the program terminating time, such as for use with another program? Or the same program at a later date? Even with testing (which I know I haven't done a lot of, but it is really quite important), it's easier to be able to read in test cases from a file than to type in the data each time you test the program.

    Data files are just files stored independently on your computer that are accessed by the program in question when run. It's not part of the code, and can be in whatever format you need. For examples, we'll just use txt files.


Text Data


    Text data is, as the name implies, data represented through characters. Easily read, with int and double types being displayed as standard numbers, and char/String types being regular text, like what you're reading right now. However, something we can't see is the end of line character, but we already know what this looks like from our System.out.print(), "\n". There are other whitespace characters, most notable "\t" for a tab-space.





    That's it for tonight. Follow, subscribe, share etc, and see you tomorrow! We'll be doing some input/output methods. Sorry it was short today!

    And as part of a shameless plug for a friend, if you're interested in classic movies/books/music, visit his site here, and feel free to throw loads of criticism at us.     
     Mostly me, since he put me in charge of new uploads.

1 comment:

  1. This might be helpful for me as I'm trying to learn Java as well.

    ReplyDelete