Java Reference
In-Depth Information
Create a new object
Foo thing = new Foo();
, where
Foo
is the name of the class and
thing
is the
variable to be assigned to the new object.
Call a function
Use parentheses, as in
getServer()
, which returns a
Server
object for a plugin.
Java Visibility Modifiers
final
Don't let me—or anyone else—change this value once I set it.
static
Keep this data or function around outside any given object.
You can mix and match
final
and
static
as needed.
public
Anyone else can see and use this function or data.
protected
This class and other classes in this package can see and use this function
or data.
private
Only this class can see and use this function or data, not subclasses or
other classes in the same package.
You use either
public
or
private
per declaration, so this code would create a
publicly visible, unchangeable constant outside of any object:
public static final int
pi = 3.1415;
Java Data-Type Conversions
int to double
Assign it:
intnow=72;doubletemperature=now;
.
double to int
Cast it; the fractional part is discarded:
doublewhen=15.375;intday=(int)when;
.
String to int
Use
parseInt
:
intfoo=Integer.parseInt("365");
.
String to double
Use
parseDouble
:
doublefoo=Double.parseDouble("3.1415");
.