Glossary
Class
A class in Java is a blueprint or template for creating objects, defining their attributes (variables) and behaviors (methods).
Example:
The Car class defines what all car objects will have, like make and model, and what they can do, like drive().
Class body
The class body is the section of a class definition enclosed in curly braces `{}`, containing all the variable declarations, constructors, and methods that define the class.
Example:
Everything inside the {} after the *public class MyClass* line constitutes the class body.
Class header
The class header is the first line of a class definition, specifying its access modifier (e.g., `public`), the `class` keyword, and the name of the class.
Example:
*public class Square* { is the class header for the Square class.
Class writing
Class writing involves designing and coding a Java class, including defining its variables, constructors, and methods, to accurately model a real-world or abstract entity.
Example:
When you are doing class writing for a Student class, you decide it needs name, gradeLevel, and methods like submitAssignment().
Client
In object-oriented programming, a client refers to another class or piece of code that uses or interacts with objects of a particular class.
Example:
A Main class that creates and uses *Student* objects is considered a client of the Student class.
Constructor Overloading
Constructor overloading is the ability to define multiple constructors within the same class, each with a different set of parameters (different number, type, or order of arguments), allowing objects to be initialized in various ways.
Example:
Having both public Square(int sideLength) and public Square() in the same class demonstrates constructor overloading.
Constructors
Constructors are special methods used to create and initialize new objects of a class, often setting initial values for the object's instance variables.
Example:
new *Square*(5); calls a constructor to create a Square object with a side length of 5.
Default constructor
A default constructor is a constructor that takes no parameters, either implicitly provided by Java if no other constructors are defined, or explicitly written to initialize an object with standard values.
Example:
public Square() { *side = 0*; } is a default constructor for the Square class, setting the side to zero.
Encapsulation
Encapsulation is an object-oriented programming principle that involves bundling data (variables) and the methods that operate on the data within a single unit (a class), and restricting direct access to some of the object's components.
Example:
Making instance variables private and providing public getter/setter methods demonstrates encapsulation, protecting the internal state of an object.
Instance variables
Instance variables are variables declared within a class but outside any method, constructor, or block, representing the unique characteristics or state of each individual object (instance) of that class.
Example:
In a Dog class, *name* and *age* would be instance variables, as each dog object has its own name and age.
Main method
The `main` method is a special static method in Java that serves as the entry point for program execution, where the Java Virtual Machine (JVM) begins running the code.
Example:
public static void *main*(String[] args) is the signature for the main method, where your program typically starts.
Method body
The method body is the section of a method definition enclosed in curly braces `{}`, containing the executable statements that are performed when the method is called.
Example:
The code *return side * 4;* inside the getPerimeter() method is its method body.
Method header
The method header is the first line of a method definition, specifying its access modifier, return type, name, and parameters.
Example:
*public int getSide()* is the method header for the getSide method.
Methods
Methods are blocks of code within a class that define the behaviors or actions that objects of that class can perform, or ways to access and modify an object's data.
Example:
The *getArea*() method in a Rectangle class calculates and returns the area of that specific rectangle object.
Object
An object is a specific instance of a class, created from its blueprint, possessing its own unique set of attribute values and capable of performing the behaviors defined by the class.
Example:
myCar is an object of the Car class, representing a specific car with its own color and mileage.
Variable declarations
Variable declarations are statements within a class that define the attributes or data fields that objects of that class will possess, specifying their data type and name.
Example:
private int *side*; is a variable declaration inside a Square class, indicating each square object will have a side length.