Object methods
- Change an object's state.
-
Example: Scale a rectangle.
- Get dependent values
-
Example: Calculate a rectangle's perimeter.
- Combined
-
Scale a rectangle and calculate its new perimeter.
|
|
|
width=66 height=44 |
|
|
Optional access
control modifier either of |
|
The method's return type either of:
|
|
The method's name. |
|
Arguments being required for execution. |
|
Start of method's body. |
|
The method's implementation. |
|
|
|
Perimeter=110 |
No. 88
Compile time error
Q: |
Try to compile the following snippet:
You'll encounter a “Missing return statement” error. What's wrong here? On contrary the following code compiles and executes perfectly well:
|
A: |
The compiler effectively complains about a missing
On the other hand the return statement in
Albeit executing well the above code is flawed: Calling e.g.
|
No. 89
Static code analysis
Q: |
Consider the following snippet:
This Java™ code resembles the Apple
goto fail SSL bug's structural problem. Since Java™ does not (yet) offer Copy this code into your IDE and:
|
||
A: |
ImportantConclusion: Watch out for compiler warning messages and do not ignore them! In many cases compiler warnings reveal serious flaws. Correction on average will save you cumbersome time debugging your code. Set your compiler / IDE's warnings to a yet tolerable higher level. In case of IntelliJ IDEA you may want to activate various settings in your project's “Java” section below Editor --> Inspections. |