Special variables: Difference between revisions
Content added Content deleted
(Special variables in FreeBASIC) |
|||
Line 1,018: | Line 1,018: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
Java is heavily object-oriented, and is mostly statically-typed. There aren't many special variables, or aggregates, similar to dynamically-typed languages.<br /> |
|||
There is ''null'', which is used to represent an object which has no reference assigned. |
|||
<syntaxhighlight lang="java"> |
|||
Object object = null |
|||
</syntaxhighlight> |
|||
There is ''true'' and ''false'' which are used to denote a ''Boolean'' value. |
|||
<syntaxhighlight lang="java"> |
|||
boolean value = true |
|||
</syntaxhighlight> |
|||
There is the ''this'' and ''super'' variables, used to reference the current class and parent class, respectively. |
|||
<syntaxhighlight lang="java"> |
|||
this.object |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="java"> |
|||
super(value) |
|||
</syntaxhighlight> |
|||
To avoid confusion to anyone unfamiliar with Java, there is the ability to import static, final, variables from other classes.<br /> |
|||
While these are not 'special variables' they may appear that way to a new user. |
|||
<syntaxhighlight lang="java"> |
|||
import static java.lang.Math.*; |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="java"> |
|||
double area = PI * (2 * 2); |
|||
</syntaxhighlight> |
|||
There is the first parameter of the ''main'' method, which is of type ''String[]''.<br /> |
|||
It is non-null and includes any arguments depicted during execution. |
|||
<syntaxhighlight lang="java"> |
|||
public static void main(String[] args) |
|||
</syntaxhighlight> |
|||
<br /> |
|||
Additionally ...<br /> |
|||
Java has only a few special variables. There is a <code>String</code>-Array for passing command-line-arguments to the program, and there is a <code>Class</code>-Object that can be accessed in a variable-like manner. It is used for reflection, (like examining and modifing class members, their type and modifiers during runtime). |
Java has only a few special variables. There is a <code>String</code>-Array for passing command-line-arguments to the program, and there is a <code>Class</code>-Object that can be accessed in a variable-like manner. It is used for reflection, (like examining and modifing class members, their type and modifiers during runtime). |
||
There is the <code>System</code>-"Object" that contains various (mostly static) data about the enviroment the Java VM runs on, and it's cousin <code>Runtime</code> that provides data that is more prone to change during runtime, like available CPU cores and RAM. |
There is the <code>System</code>-"Object" that contains various (mostly static) data about the enviroment the Java VM runs on, and it's cousin <code>Runtime</code> that provides data that is more prone to change during runtime, like available CPU cores and RAM. |