Glossary
Accessor Method (Getter)
An accessor method, also known as a getter, is a public method used to retrieve the value of a private instance variable without directly exposing the variable itself.
Example:
The public String getName()
accessor method allows other parts of the program to safely get the name of a Student
object.
Class
A class is a blueprint or template for creating objects, defining their properties (variables) and behaviors (methods). It serves as a custom data type.
Example:
The Dog
class could define properties like name
and breed
, and behaviors like bark()
and fetch()
for all dog objects.
Comment
A comment is a non-executable piece of text in code, ignored by the compiler, used by programmers to explain code for human readability and documentation.
Example:
Adding // This method calculates the total price including tax
is a comment that helps others understand the code's purpose.
Constructor
A constructor is a special method used to create and initialize new objects of a class. It has the same name as the class and no return type.
Example:
When you write new Car("Toyota", "Camry")
, you are calling the Car
constructor to create and set up a new car object.
Ethical and Social Implications of Computing Systems
This concept encompasses the positive and negative impacts that computing technologies have on individuals, society, and the environment, including issues like privacy, security, inequality, and dependence.
Example:
Discussing how AI algorithms might perpetuate biases in hiring decisions falls under the ethical and social implications of computing systems.
Global Scope
Global scope refers to elements (like instance variables) that are visible and accessible throughout the entire class or program, from any method within that class.
Example:
An instance variable like private String userName;
has global scope within its class, allowing any method in that class to access or modify it.
Instance Variable
An instance variable is a variable declared within a class but outside any method, constructor, or block, meaning each object of the class gets its own copy of this variable.
Example:
For a Book
object, String title
and int pageCount
would be instance variables, unique to each specific book.
Local Scope
Local scope refers to elements (like variables) that are visible and accessible only within a specific block of code, such as a method, loop, or conditional statement.
Example:
A variable int tempResult
declared inside a calculateAverage()
method has local scope, meaning it only exists and can be used within that method.
Methods
Methods are blocks of code within a class that define the behaviors or actions an object can perform. They encapsulate specific functionalities.
Example:
A Robot
class might have a move()
method to control its movement or a chargeBattery()
method to replenish its power.
Mutator Method (Setter)
A mutator method, also known as a setter, is a public method used to modify or update the value of a private instance variable.
Example:
The public void setScore(int newScore)
mutator method enables updating a player's score after they complete a level.
Parameters
Parameters are variables listed in a method or constructor definition that receive values (arguments) when the method or constructor is called.
Example:
In public void setVolume(int level)
, level
is a parameter that specifies how loud the volume should be set.
Pass-by-value
Pass-by-value is a mechanism where a copy of the argument's value is passed to a method. For primitive types, the actual value is copied; for objects, a copy of the reference (memory address) is passed.
Example:
When you call calculateArea(5, 10)
, the numbers 5 and 10 are pass-by-value, meaning the method works with copies and doesn't change the original variables.
Scope
Scope refers to the region of a program where a variable, method, or other element is visible and accessible. It determines where an identifier can be used.
Example:
A variable declared inside a for
loop has a scope limited to that loop, meaning it cannot be accessed outside of it.
Static Method
A static method (or class method) belongs to the class itself and can be called directly using the class name, without needing to create an object of that class.
Example:
The Math.sqrt(25)
static method calculates the square root without needing to create a Math
object.
Static Variable
A static variable (or class variable) belongs to the class itself rather than to any specific object instance. All objects of the class share the same copy of a static variable.
Example:
In a Game
class, public static int totalPlayersOnline
could be a static variable tracking the total number of players across all game instances.
Variables
Variables are named storage locations in a class or method used to hold data. They can be instance variables (belonging to an object) or local variables (within a method).
Example:
In a Player
class, int score
and String username
would be variables storing player data.
this keyword
The `this` keyword in Java refers to the current instance of an object. It is used to distinguish between instance variables and local variables with the same name, or to pass the current object as an argument.
Example:
In a constructor public Student(String name)
, this.name = name;
uses the this keyword to assign the parameter name
to the object's instance variable name
.