aspose file tools*
The moose likes Beginning Java and the fly likes private static final object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "private static final object" Watch "private static final object" New topic
Author

private static final object

Farid Abdi
Greenhorn

Joined: Dec 25, 2012
Posts: 12

Hi
I am learning Java . In the book that I am reading is said about private and static fields and methods . But in a example code I saw a stange code :

private static final Random randomNumbers = new Random();

randomNumbers is an object of class Random

I am confused . Are there private and static objects ?? and if there are , What they mean ?? What is the meaning of a private or static object ??
I know the meaning of private or static fields and methods but I don't know the meaning of private and static objects .
Please help me...Thanks
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

There's no difference. In that example randomNumbers is a private static field. So if you understand private and static fields you already understand it. In this case, the field holds a reference to a Random object, but if it held an int or a reference to a String the principle would be the same.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Objects do not have the property of being public or private, or static or non-static, final or non-final. Those concepts simply don't apply to objects. What you're seeing is a private static final variable.

private method: Cannot be accessed outside the class (or possibly "compilation unit"--have to check the JLS) where it's declared.
private variable: Cannot be accessed outside the class (or possibly "compilation unit"--have to check the JLS) where it's declared.

static method: Associated with the class as a whole, not with any particular instance. No "this" during execution.
static variable: Associated with the class as a whole, not with any particular instance. No associated "this".

final method: Cannot be overridden.
final variable: Cannot have its value changed after initialization.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: private static final object