Even Better IO - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Even Better IO

Description:

... a double value out of a string d, use. myDouble = Double.parseDouble ... This of course will throw an exception if the value in d is not a double. Other methods ... – PowerPoint PPT presentation

Number of Views:8
Avg rating:3.0/5.0
Slides: 8
Provided by: scie261
Category:
Tags: better | double | even

less

Transcript and Presenter's Notes

Title: Even Better IO


1
Even Better IO
  • Getting stuff other than Strings

2
Problem
  • Most programs work with data other than strings.
  • So far all we have seen is how to read strings
  • What do we do?

3
Java has an answer
  • Of course, Java has an answer
  • Java supplies methods for converting strings to
    each of the built-in types.
  • For example to get a double value out of a string
    d, use
  • myDouble Double.parseDouble( d )
  • This of course will throw an exception if the
    value in d is not a double

4
Other methods
  • All of the object types that mirror the built-in
    types have methods that are similar to
    parseDouble
  • For example, the Integer has parseInteger()
  • These methods require that you know what type of
    value is stored within the string
  • Which you will have a lot of the time

5
But wait, how can we use these methods
  • You may be asking yourself, how can we use these
    methods without an object around.
  • If you noticed in both of those last examples,
    the object name started with a capital letter
  • That is not the usual style
  • Hmmwhat does that mean.

6
Static methods
  • These methods that we are using are called static
    methods
  • That means we dont need an object of that class
    to use the method.
  • A static method is shared among all instances of
    that class, just like static members.
  • Static methods can only operate on parameters and
    static members.

7
What does this mean for me?
  • Now, we can actually process a file and do stuff
    with whats inside, other than count.
  • We can expect to open a file, read the
    information out, and compute some result based on
    what was inside.
  • This will require either knowing what is inside,
    or a lot of trial and error in the code.
  • We will work with the former
Write a Comment
User Comments (0)
About PowerShow.com