Even though Java (and other C-based languages like JavaScript) has a similar C syntax, not all C features are available; like pointer operators, static local variables, etc.
In Java we can have static fields, methods, classes; but neither local variables nor parameters can be declared static.
The general approach for Processing sketches is just declare global variables.
But if you prefer better separation of concerns you’re gonna need to create a class to place both the variables (fields) and their related functions (methods) grouped together as 1 structure, like @paulgoux already posted.
Here’s another example:
void setup() {
frameRate(1);
}
void draw() {
background((color) random(#000000));
print(Value.nextValue(), TAB);
}
static class Value {
static int a;
static int nextValue() {
return ++a;
}
}
Basically the name of the class Value becomes the global “variable” now.
So it isn’t that much better than vanilla global variables; unless you need so many global variables that grouping them in classes is the sane thing to do.