public staticint, or void if nothing returnedsquare(int number)return if non-voidRandom.nextInt(n) gives 0 to n-1 → shift with +1 for dice-style rangesenum defines a fixed, named set of constants — safer than raw ints for "modes" or "states"A variable declared inside a method (or block) exists only within that block.
Instance variables declared in a class are visible to all of that class's methods.
A local variable with the same name as a field hides the field inside that method.
Multiple methods can share the same name as long as their parameter lists differ (number or types of params). The compiler picks the right one to call based on the arguments given — this is called the method's signature.
| Math method | Purpose |
|---|---|
Math.sqrt(x) | square root |
Math.pow(x,y) | x raised to power y |
Math.abs(x) | absolute value |
Math.max/min(a,b) | larger/smaller value |
java.util, java.math)import java.util.Random;Math's methods are static — call them via the class name, no object neededStack classStackOverflowErrorA smaller/less-precise type widens automatically to match a parameter — e.g. passing an int where a method expects a double.
LocalDate — a calendar date, no time/timezoneLocalTime / LocalDateTime — time-of-day / both combinedPeriod / Duration — amounts of timeDate/Calendar classes| Method | Purpose |
|---|---|
Math.abs(x) | absolute value |
Math.ceil(x) | rounds up to nearest whole |
Math.floor(x) | rounds down to nearest whole |
Math.round(x) | rounds to nearest whole |
Math.max(a,b)/min(a,b) | larger/smaller value |
Math.pow(x,y) | x raised to power y |
Math.sqrt(x) | square root |
Math.random() | double in range [0.0, 1.0) |
| Random Class Method | Purpose |
|---|---|
nextInt() | random int, full range |
nextInt(n) | random int from 0 to n-1 |
nextDouble() | random double [0.0, 1.0) |
nextBoolean() | random true/false |