Methods in Java


Static things can only access static things.

When you declare a static variable, whether int, double, float, long, it will be defaulted to zero, with boolean false, idk char.

One way to “stop” yourself is using constants
If the final value is later, initialized in main, it won’t work, since it is already set to zero if not declared.

Methods/functions

Pretty similar to functions, but you need public static only for now(there are others, like private, etc.)


Wrapper functions similar to onss in C but also can be used. In java, looks like there are no pointers

Didn’t know about system.exit, essentially, the program will shutdown the JVM, so it might appear it ran fine, but in reality, it didn’t it’s like turning off the computer before completing a task.
Like in the past, don’t use return in void functions, nor main.

You can use the same method name for different functions, as long as the parameters are different.
With float, since it has f at the end, it can distinguish between float and double. (same as back then)
IF you send one that doesn’t exist, like a float without the method for it, it will translate to the most adjacent/equivalent one.
Tricky Questions
1)Can you return a method in a method in Java?
No, you can in C, but not here.
2) Can we write implement method inside a method in JAva?
No, since it is line by line, can’t really make sense.
3) Can a method return 2 values in Java?
No, pairs exist, but not in the base libraries, so no.
4) Can we swap parameters inside a function in JAva?
Inside the function, yes, but not out of scope, i beleive not when calling
5) Can we change parameter of a function in Java for the outer scope?
No, given a parameter, you can’t pass it by reference; you can only pass by value.
6) Can static methods access non static variables?
No, static only works with other static ones, including non static variables.