1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Why do we use methods in Java programming?
Break down our program into smaller parts
Avoid repeating code
Make our program more readable
What is the general way for writing a method?
private void myMethod()
{
// Code goes here
}
How would you call a method named “printLineBreak”?
printLineBreak();
What are parameters?
The formal names given to the data that gets passed into a method; names of the variables in the method signature
In the method randomMethod(String someString), what would be the parameter?
someString
How would you write a method named “printLineBreak” when passing the parameter length, such that length is an integer?
private void printLineBreak(int length)
{
// Code goes here
}
What is a return value?
The value that a method outputs.
How would you return the sum of two integers using a method?
private int sum (int first, int second)
{
int total = first + second;
return total;
}
What is a method signature?
The name of the method and parameter list.
For example for private int square(int x), “square (int x)” would be the signature.
In “private int square (int x)” what is the visibility?
private
In “private int square (int x)” what is the return type?
int
In “private int square (int x)” what is the method name?
square
In “private int square (int x)” what is the parameter?
int x
What is a Javadoc?
A comment that clearly states the functionality and usage of a class or method.
What are comments?
Notes on our code to help other people understand it.
What is the Javadoc General Method Format?
/**
*Description of method
*
*@param paramName1 description
*@param paramName2 description
*@return Description of return value
*/
private int sum(int x, int y)
{
return x + y;
}
Are strings primitives?
No, they are objects (It’s why they’re capitalized)
How would you compare strings?
string1.equals(string2)
What is general way to find char value at specific index?
string.charAt(int index)
What is the general way to compare strings to one another?
string.equals(other)
What is the general way to compare strings, ignoring case?
string.equalsIgnoreCase(other)
What is the general way to return the index of a string?
string.indexOf(“Hello'“)
*This would return 4 because the first letter is always 0
What is the general way for finding the length of a string?
string.length()
What is the general way for finding a part of a string?
string.substring(int beginIndex, int endIndex)
When using substrings, are the beginning/ending indexes included or exluded?
Beginning index = inclusive
End index = exclusive
What does immutable mean and how does it relate to strings?
When you make a String, you can’t change it, so calling a substring creates a NEW String.
Immutable (never-changing)
How do you loop over a string?
for (int i = 0; i < string.length(); i++)
{
char cur = string.charAt(i);
System.out.println(cur);
}
Is char primitive?
Yes
What types of quotes do we use for Strings and characters?
Strings - Double quotes “"
Char - Single quotes ‘'
How would you find the ASCII value of a char?
Cast it as an integer. For example:
(int) lowercaseA
What are Escape Sequences?
Characters with special meaning; treated like one character
What is the escape character for both single quote and double quotes?
Single quote: \’
Double quote: \”