slug
type
status
category
date
summary
tags
password
icon
Java terms, definitions, and examples
Term | What it means (Java) | Minimal example |
Java | An object-oriented programming language used here to build classes like Turtle, Student, Course, Player. | public class Hello { public static void main(String[] a){ System.out.println("Hi"); } } |
Class | A blueprint that defines data and behavior. | public class Player { /* fields + methods */ } |
Object (Instance) | A runtime occurrence of a class created with new. | Player p = new Player("Ada", 1500); |
Attribute / Field | Data stored inside a class. (General word “attribute”; in Java code they’re fields.) | private String name; |
Instance variable (field) | A field whose value belongs to each object individually. | private int balance; |
Class variable (static field) | A field shared by all instances of the class; declared with static. | private static int playerCount = 0; |
Method | A function defined in a class that operates on its data. | public void payRent(Player owner, int amount){ ... } |
Method call | Invoking a method on an object or class. | p.payRent(owner, 200); |
Method signature | The method’s name + parameter types (and order). It’s what callers depend on. | void verse(String animal, String sound) |
Parameter | A named input in a method definition. | void verse(String animal, String sound) (animal, sound are parameters) |
Argument | The actual value passed to a method when calling it. | verse("duck", "quack"); |
Return type | The type a method returns. void means “returns nothing.” | public int getPrice() { return price; } |
Constructor | A special method used to create and initialize objects (same name as class, no return type). | public Player(String name, int balance){ this.name=name; this.balance=balance; } |
this keyword | Refers to the current object; used to disambiguate fields from parameters. | this.balance = balance; |
Access modifiers ( public, private) | Control visibility: public = visible to all; private = only inside the class. | private int balance; / public void buyProperty(...) { ... } |
static | Belongs to the class, not an instance (used for class variables or utility methods). | public static void intro(){ System.out.println("Old MacDonald"); } |
void | A return type meaning “no value returned.” | public void chorus(){ System.out.println("E-I-E-I-O"); } |
main method | Program entry point in a Java application. | public static void main(String[] args){ intro(); } |
System.out.println | Standard output method to print a line to the console. | System.out.println("Hello"); |
Type / Data type | Defines the kind of value a variable can hold (primitive or reference). | String name; int balance; |
Primitive type | Built-in value types ( int, double, boolean, etc.). | int balance = 1500; |
Reference type | Types that refer to objects (e.g., String, any class like Player). | String name = "Ada"; |
Encapsulation | OOP principle: keep fields private and expose behavior via public methods. | private int balance; public int getBalance(){ return balance; } |
Object-Oriented Design (OOD) | Process of identifying classes, their data (fields) and behaviors (methods) from a specification. | Nouns → Student, Course; verbs → enroll(), drop() |
Abstraction | Focus on essential ideas and hide unnecessary details (e.g., calling forward() without knowing animation internals). | turtle.forward(100); // don’t need to know how it draws |
Data abstraction | Use types and fields by what they represent, not how they’re stored/implemented. | Turtle t = new Turtle(); // use it without seeing its internals |
Procedural abstraction | Name a process as a method; callers know what it does, not how. | chorus(); // prints E-I-E-I-O |
Method decomposition | Split a big task into smaller methods to improve clarity/reuse. | intro(); verse("cow","moo"); |
UML class diagram (+ / −) | A design diagram: lists class name, fields, methods. + = public, − = private. (Not code, but commonly used for Java design.) | − name : String / + payRent(owner: Player, amount: int) : void |
Extra quick examples pulled from your text
- Creating classes from nouns (OOD):
class Student { private String name; private int grade; }class Course { private String courseName; private String teacher; }- Reusing methods with parameters (procedural abstraction):
- Encapsulation in
Player:
以下是 Java 相关术语、定义与示例的中文版,内容保持完整准确,便于学习与记忆👇
🧠 Java 相关术语、定义与示例
术语 | 定义(中文说明) | 示例 |
Java | 一种面向对象的编程语言,用于编写类(如 Turtle、Student、Player 等)。 | public class Hello { public static void main(String[] a){ System.out.println("Hi"); } } |
类(Class) | 定义对象的蓝图或模板,包含数据(属性)和行为(方法)。 | public class Player { /* 字段与方法 */ } |
对象(Object / 实例 Instance) | 类在运行时创建的具体实体。 | Player p = new Player("Ada", 1500); |
属性 / 字段(Attribute / Field) | 存储在类中的数据。 | private String name; |
实例变量(Instance Variable) | 每个对象都有自己独立的一份数据。 | private int balance; |
类变量(Class Variable / 静态变量) | 由所有对象共享的数据,用 static 声明。 | private static int playerCount = 0; |
方法(Method) | 类中定义的函数,用来实现行为。 | public void payRent(Player owner, int amount){ ... } |
方法调用(Method Call) | 调用某个对象或类的方法。 | p.payRent(owner, 200); |
方法签名(Method Signature) | 方法名称加上参数类型与顺序,决定唯一性。 | void verse(String animal, String sound) |
形参(Parameter) | 定义在方法中的输入变量。 | void verse(String animal, String sound) |
实参(Argument) | 调用方法时传入的实际值。 | verse("duck", "quack"); |
返回类型(Return Type) | 方法返回的数据类型; void 表示没有返回值。 | public int getPrice() { return price; } |
构造方法(Constructor) | 用于创建并初始化对象的特殊方法,与类名相同,无返回类型。 | public Player(String name, int balance){ this.name=name; this.balance=balance; } |
this 关键字 | 引用当前对象,用于区分同名变量。 | this.balance = balance; |
访问修饰符(public / private) | 控制成员的可见性: public 外部可见,private 仅类内可见。 | private int balance; public void buyProperty(...){...} |
static 关键字 | 表示属于类本身的成员,而非对象实例。 | public static void intro(){ System.out.println("Old MacDonald"); } |
void | 一种返回类型,表示方法不返回值。 | public void chorus(){ System.out.println("E-I-E-I-O"); } |
main 方法 | Java 程序的入口方法。 | public static void main(String[] args){ intro(); } |
System.out.println | Java 中用于在控制台输出一行文本的方法。 | System.out.println("Hello"); |
数据类型(Type / Data Type) | 定义变量能存储的数据种类。 | String name; int balance; |
基本类型(Primitive Type) | Java 内置的值类型,如 int、double、boolean 等。 | int balance = 1500; |
引用类型(Reference Type) | 引用对象的类型,例如 String 或自定义类。 | String name = "Ada"; |
封装(Encapsulation) | 将数据设为私有,并通过公共方法访问,保护对象内部状态。 | private int balance; public int getBalance(){ return balance; } |
面向对象设计(OOD) | 根据问题描述找出名词(类)和动词(方法)来构建系统。 | 名词→ Student、Course;动词→enroll()、drop() |
抽象(Abstraction) | 隐藏不必要的细节,只关注主要功能。 | turtle.forward(100); // 不必知道动画细节 |
数据抽象(Data Abstraction) | 只使用数据的名字而不关心其具体实现。 | Turtle t = new Turtle(); // 无需了解内部实现 |
过程抽象(Procedural Abstraction) | 将一段过程命名为方法,只需知道“做什么”,不需知道“怎么做”。 | chorus(); // 打印 E-I-E-I-O |
方法分解(Method Decomposition) | 把复杂任务分解为多个小方法,便于理解与复用。 | intro(); verse("cow","moo"); |
UML 类图(+ / −) | 一种类的结构图,展示类名、属性与方法; + 表示 public,− 表示 private。 | − name : String / + payRent(owner: Player, amount: int) : void |
🔹补充示例(来自原文)
- 面向对象设计:
- 方法与参数复用:
- 封装示例:
一个 示例 Java 类
Student,它能尽可能涵盖上面提到的 Java 核心面向对象术语(如类、对象、属性、方法、构造函数、访问修饰符、static、this、封装、抽象、方法调用、参数、返回类型、UML思想 等等)。下面是一份完整且带注释的 高质量示范代码👇
🧩 完整示例:Student.java
纯代码(敲三遍or more):
📘 代码中涉及的 Java 术语一览表
术语 | 在代码中的体现 |
class | public class Student |
object / instance | Student s1 = new Student(...); |
attribute / field | private String name; |
instance variable | private double gpa; |
class variable | private static int studentCount; |
constructor | public Student(String name, int gradeLevel, double gpa) |
this 关键字 | this.name = name; |
encapsulation 封装 | private 字段 + public getter/setter |
method 方法 | public void printInfo() |
method overloading 方法重载 | 两个 printInfo 方法 |
method call 方法调用 | s1.printInfo(true); |
parameter 参数 | String name, int gradeLevel, double gpa |
argument 实参 | "Alice", 11, 3.8 |
return type 返回类型 | public boolean isHonorStudent() |
access modifier 访问修饰符 | public, private |
static 静态 | public static int getStudentCount() |
void | public void printInfo() |
main 方法 | public static void main(String[] args) |
System.out.println | 控制台输出 |
abstraction 抽象 | 方法 isHonorStudent() 隐藏了实现细节 |
procedural abstraction 过程抽象 | printInfo()、setGpa() 等方法 |
method decomposition 方法分解 | 用多个方法分开职责 |
UML 思想 | 可以表示为: − name : String− gpa : double+ printInfo() : void |
UML 类图:
Class: Student
────────────────────────────────────────
«static» − studentCount : int
− name : String
− gradeLevel : int
− gpa : double
────────────────────────────────────────
- Student(name : String, gradeLevel : int, gpa : double)
- getName() : String
- setName(name : String) : void
- getGradeLevel() : int
- setGradeLevel(gradeLevel : int) : void
- getGpa() : double
- setGpa(gpa : double): void
- isHonorStudent() : boolean
- printInfo() : void
- printInfo(showHonorStatus : boolean) : void «static» + getStudentCount() : int «static» + main(args : String[]) : void
MCQs:
Here are 20 multiple-choice questions in English (no answers shown yet) to test your understanding of the Java terms and concepts from the content above 👇
1.
What is the main purpose of a class in Java?
A. To store data values directly
B. To define the blueprint for creating objects
C. To print information to the console
D. To manage exceptions
2.
Which line of code correctly creates an object of the
Student class?A.
Student s;B.
new Student();C.
Student s = new Student();D.
create Student();3.
Which statement about instance variables and class variables is true?
A. Instance variables are declared with
staticB. Class variables are shared among all objects of the class
C. Instance variables cannot be private
D. Class variables are local to each object
4.
Which of the following is not part of Object-Oriented Design (OOD)?
A. Identifying nouns as potential classes
B. Identifying verbs as potential methods
C. Writing the main method first
D. Designing fields and methods for each class
5.
Which of the following correctly defines a constructor?
A.
public void Student() { }B.
public Student() { }C.
void Student() { }D.
Student create() { }6.
What does the
this keyword refer to in Java?A. The parent class
B. The current object
C. The next method call
D. The class name
7.
Which declaration defines a private instance variable?
A.
int grade;B.
private int grade;C.
public int grade;D.
static int grade;8.
In the statement
System.out.println("Hello");, what is System?A. An object
B. A method
C. A class
D. A package
9.
What does the keyword
void mean in a method declaration?A. The method returns no value
B. The method returns a String
C. The method is private
D. The method can throw exceptions
10.
Encapsulation mainly helps to:
A. Speed up program execution
B. Reduce memory usage
C. Protect data by hiding internal details
D. Allow direct access to all fields
11.
If a variable is declared as
private static int count = 0;, it is:A. An instance variable
B. A class (static) variable
C. A local variable
D. A parameter
12.
Which of the following all represent valid method signatures in the same class (for overloading)?
A.
void print()B.
void print(int n)C.
void print(String s)D. All of the above
13.
How can you create a new
Player object using a constructor?A.
Player("Tom");B.
new Player("Tom");C.
Player p = Player("Tom");D.
Player.create("Tom");14.
What is the function of the
main method in Java?A. It defines object attributes
B. It is the program entry point
C. It prints results automatically
D. It declares all static methods
15.
Which of the following correctly calls a method named
showInfo?A.
showInfo;B.
showInfo[];C.
showInfo();D.
method showInfo();16.
Which of the following is a primitive type in Java?
A.
StringB.
intC.
StudentD.
Scanner17.
What does method overloading mean?
A. Two methods have the same name but different parameters
B. Two methods have the same name and same parameters
C. A method is called many times in a loop
D. A method returns more than one value
18.
The method below demonstrates which concept?
A. Data abstraction
B. Procedural abstraction
C. Encapsulation
D. Inheritance
19.
In a UML class diagram, what does the symbol “−” before an attribute mean?
A. Public
B. Private
C. Protected
D. Static
20.
What will the following program output?
A. 0
B. 1
C. 2
D. Compile error
Solutions:
Here are the correct answers and explanations for all 20 Java multiple-choice questions 👇
1. → ✅ B
Explanation:
A class defines a blueprint or template for creating objects—it specifies fields (data) and methods (behavior).
2. → ✅ C
Explanation:
Student s = new Student(); both declares and instantiates an object using the constructor.3. → ✅ B
Explanation:
A class variable (declared with
static) is shared among all instances; instance variables belong to individual objects.4. → ✅ C
Explanation:
OOD focuses on design—identifying classes and their behaviors, not immediately writing the main method.
5. → ✅ B
Explanation:
A constructor has no return type and shares the same name as the class.
6. → ✅ B
Explanation:
this refers to the current object—used to access instance variables or methods inside the class.7. → ✅ B
Explanation:
private int grade; defines an instance variable accessible only inside the class (encapsulation).8. → ✅ C
Explanation:
System is a built-in class in the Java API (java.lang.System) that provides access to system resources.9. → ✅ A
Explanation:
void means the method does not return a value.10. → ✅ C
Explanation:
Encapsulation hides internal implementation details and protects data by making fields private.
11. → ✅ B
Explanation:
A
static variable belongs to the class rather than individual objects—shared by all instances.12. → ✅ D
Explanation:
All listed methods have the same name but different parameter lists → valid overloading (different method signatures).
13. → ✅ B
Explanation:
Objects are created using the
new keyword: new Player("Tom");.14. → ✅ B
Explanation:
public static void main(String[] args) is the entry point of a Java application.15. → ✅ C
Explanation:
Parentheses
() are required to call a method—even when it has no parameters.16. → ✅ B
Explanation:
int is a primitive data type.String, Student, and Scanner are reference types (classes).17. → ✅ A
Explanation:
Method overloading = same method name, different parameter types or counts.
18. → ✅ B
Explanation:
isHonorStudent() hides internal logic (the GPA comparison). The caller just knows it checks for “honor student” → procedural abstraction.19. → ✅ B
Explanation:
In UML, “−” means private, “+” means public, “#” means protected.
20. → ✅ C
Explanation:
Each
new Student() increments the static count; two objects are created → output is 2.✅ Summary Table
# | Correct Answer | Concept Tested |
1 | B | Class purpose |
2 | C | Object instantiation |
3 | B | Static vs instance variables |
4 | C | OOD process |
5 | B | Constructor |
6 | B | this keyword |
7 | B | Access modifier |
8 | C | System class |
9 | A | void return type |
10 | C | Encapsulation |
11 | B | Class variable |
12 | D | Method overloading |
13 | B | Constructor call |
14 | B | Main method |
15 | C | Method call syntax |
16 | B | Primitive types |
17 | A | Method overloading definition |
18 | B | Procedural abstraction |
19 | B | UML visibility |
20 | C | Static field counting |
- 作者:现代数学启蒙
- 链接:https://www.math1234567.com/article/csawesome31
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。








