Unit 3 - Methods

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/31

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:32 PM on 10/7/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

32 Terms

1
New cards

Why do we use methods in Java programming?

Break down our program into smaller parts

Avoid repeating code

Make our program more readable

2
New cards

What is the general way for writing a method?

private void myMethod()

{

// Code goes here

}

3
New cards

How would you call a method named “printLineBreak”?

printLineBreak();

4
New cards

What are parameters?

The formal names given to the data that gets passed into a method; names of the variables in the method signature

5
New cards

In the method randomMethod(String someString), what would be the parameter?

someString

6
New cards

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

}

7
New cards

What is a return value?

The value that a method outputs.

8
New cards

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;

}

9
New cards

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.

10
New cards

In “private int square (int x)” what is the visibility?

private

11
New cards

In “private int square (int x)” what is the return type?

int

12
New cards

In “private int square (int x)” what is the method name?

square

13
New cards

In “private int square (int x)” what is the parameter?

int x

14
New cards

What is a Javadoc?

A comment that clearly states the functionality and usage of a class or method.

15
New cards

What are comments?

Notes on our code to help other people understand it.

16
New cards

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;

}

17
New cards

Are strings primitives?

No, they are objects (It’s why they’re capitalized)

18
New cards

How would you compare strings?

string1.equals(string2)

19
New cards

What is general way to find char value at specific index?

string.charAt(int index)

20
New cards

What is the general way to compare strings to one another?

string.equals(other)

21
New cards

What is the general way to compare strings, ignoring case?

string.equalsIgnoreCase(other)

22
New cards

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

23
New cards

What is the general way for finding the length of a string?

string.length()

24
New cards

What is the general way for finding a part of a string?

string.substring(int beginIndex, int endIndex)

25
New cards

When using substrings, are the beginning/ending indexes included or exluded?

Beginning index = inclusive

End index = exclusive

26
New cards

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)

27
New cards

How do you loop over a string?

for (int i = 0; i < string.length(); i++)

{

char cur = string.charAt(i);

System.out.println(cur);

}

28
New cards

Is char primitive?

Yes

29
New cards

What types of quotes do we use for Strings and characters?

Strings - Double quotes “"

Char - Single quotes ‘'

30
New cards

How would you find the ASCII value of a char?

Cast it as an integer. For example:

(int) lowercaseA

31
New cards

What are Escape Sequences?

Characters with special meaning; treated like one character

32
New cards

What is the escape character for both single quote and double quotes?

Single quote: \’

Double quote: \”