A class is a blueprint or a template for creating different objects which defines its properties and behaviors. Java class exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.
Identifiers in Java are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them. In the HelloWorld program, HelloWorld , String , args, main and println are identifiers.
Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte , char , short , int , long , float and double . These types serve as the building blocks of data manipulation in Java.
The values of these (static) variables;
Are the same for all objects;
They belong to the class (not to the objects);
And are only created/declared once;
Variables and object declarations in the body of a method have a scope that extends from the declaration to the end of the method body. These variables are said to be local to the method because the scope is limited only to that method.
Parameters are identifiers listed in parentheses beside the subprogram/sub-procedure/method name; sometimes called formal parameters. Parameters are used to accept values from the method call.
A parameter variable is a variable/value that is passed to a method. It is the value passed to a method in brackets/parentheses;
In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance. Each object, or instance, of a class has its own copy of variables called instance variables.
Show program code in Java
/*** Circle class. */
public class Circle {
private static final double PI = 3.14; //class constant private
double radius; //instance variable
//Constructor
public Circle(double radius){
this. radius = radius;
}
...rest of Circle class
In the statements below, two Circle objects are instantiated. Each instance has its own copy of the instance variable radius, but both objects refer to the same copy of the class constant PI:
/*** Instantiation */
Circle spot1 = new Circle(2); //radius is 2
Circle spot2 = new Circle(5) //radius is 5