Static Properties and Methods and Strings (Oh My!) – Day 8
Last week the phrase public static void main meant pretty much nothing to me. Now I understand the whole phrase and what it means:
public – this class or method is publicly accessible to other classes and methods
static – this means the data in this method is going to persist throughout the program, allowing you to keep the variables active and usable for longer before Java clears then, and provides a shared environment
void – this method returns a void value when it is run, can be used for when values need to be output or when internal calculations and changes need to be made, but not passed back after being called
main – the main method is the first method of any Java program which sets the foundation for the rest of the methods and variables
Knowing all the parts now gives me significantly more insight into which methods do what, and why.
Strings
Words are complicated, and as such there is a lot of different methods that can be called and used. Here’s a list of the ones we went over:
- contains()
- endsWith()
- equals()
- length()
- startsWith()
- toLowerCase()
- toUpperCase()
- trim()
- String.format()
- String.valueOf()
They are actually pretty straight forward in terms of their name and their functions. The ones that are a little vague are trim() which removes white space around a string, String.format() which allows you a shortcut to format a string to include other data easier than having to go piece by piece and add them together, and String.valueOf() which takes a value and converts it to a string in order to have it act in a different way (such as using the above methods to obtain more specific information about it).
440