Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
Our one and only Instant.class file has now been copied to your station's memory.
Two instances of it are running in your browser's JVM.
There's also only one java.awt.Button.class file.
( inside rt.jar, java40.jar, classes.zip or some other zip-file on your station )
This Button class file has been loaded in memory.
Ditto for java.awt.Textarea.class .
Our class contains methods....
.... and data descriptions .
A fundamental type variable ...
and four reference variables.
In both applets, two instances of the Button class have been made.
Different labels, different widths.
Each applet also contains two instances of the TextArea class, that have different widths, heights and colours.
In memory, there are two randomnumber variables, one for each applet instance.
As you operate the applets in turn, you can track their different values in the TextAreas.
A class can be instantiated many, many times, as long as memory allows, each instance having its own data values, like name, percentage, colour, label, font and whatever other data is important for that class.
Each time you make an instance of a class, a block of memory is set aside for the instance's data.
Each method is in memory only once.
If you have difficulty grasping this, for now just think of a Java class as a record description and instances to actual records containing data ( that can be changed ).
A Java class, however, is much more than that. It contains methods, for starters.
Fundamental data types are int, long, byte, boolean, char ...etc.
A reference type variable is meant to contain a pointer to an instance, so the instance can be identified/found and used.
If the pointer isn't valid and you try to use it, a NullPointer Exception arises, meaning that the pointer contains null .
This happens, for example, when you try to add a non-existing Button instance, one that hasn't been created ( yet ).
jar is Java Archive, can be viewed with a zip-tool.
Integer.MAX_VALUE is a constant in the java.lang.Integer class, value 2,147,483,647 .