Lecture Date: Friday, February 27
For the email hunt project you’ll want to manipuate
The best way to find out how to manipluate some type of object in Java is to search for “java 8 api ClassName.
The page you’ll find (from docs.oracle.com) will start with a summary of the class and its purpose,
then have a list of all the methods you can use, each with a link to a more in-depth description.
Each longer description will start with the header you’d use to write the method yourself; for example,
public int lastIndexOf(String str, int fromIndex)
publicmeans any part of java may call the method; we’ll use
publicfor all methods for the next few weeks.
static(if present) means “it’s just a method we can run” instead of “it’s a behavior that needs a particular object to run on”.
staticbecause you don’t need to do
staticbecause you do need to do
new Scannerfirst. We’ll only write
staticmethods for the next week or so
- The return type, which is the type of value that comes back when you run the method.
intreturn type, meaning you can write
int i = s.lastIndexOf("x",3);Other examples:
mainboth return nothing (denoted by using the
- The name of the method. You pick this.
- Zero or more parameters. Each parameter looks like a variable definition: type name.
- Code. If the return type was not
void, you must include a return statement in the code, which looks like
return "hi";or the like.
In lecture we played with some of
String’s methods and wrote some of our own as well.