In a multi-user system, a single class must support many independent objects. This project demonstrates how to use the Student blueprint to register two distinct individuals. By creating separate instances for "Hana" and "Greg," we illustrate how Java manages unique data for each object in the heap memory, ensuring that updating one student's information does not affect the other.
- Class Definition: Created a
Studentclass withstudentNameandenrollmentYear. - Multiple Instantiation: Successfully created two separate objects in the
mainmethod. - State Management: Assigned unique values to each student's fields.
- Data Output: Displayed the information for both students in the required format.
- Naming Conventions: Used PascalCase for the class and camelCase for variables.
- Java 8+ (Object Instantiation and Field Access)
When we write new Student(), Java carves out a new block of memory. In this task, we have two such blocks. The variable firstStudent points to one block, and secondStudent points to another. This is the core of how software scales: one blueprint, thousands of unique records.
Name: Hana, enrollment year: 2022
Name: Greg, enrollment year: 2023
Project Structure:
src/com/yurii/pavlenko/
├── Student.java
├── StudentDataInitializer.java
├── StudentReporter.java
└── StudentRegistrarApp.java
Code
package com.yurii.pavlenko;
public class StudentRegistrarApp {
public static void main(String[] args) {
StudentDataInitializer initializer = new StudentDataInitializer();
StudentReporter reporter = new StudentReporter();
Student firstStudent = initializer.createHana();
Student secondStudent = initializer.createGreg();
reporter.printStudentDetails(firstStudent);
reporter.printStudentDetails(secondStudent);
}
}package com.yurii.pavlenko;
public class StudentDataInitializer {
public Student createHana() {
Student student = new Student();
student.studentName = "Hana";
student.enrollmentYear = 2022;
return student;
}
public Student createGreg() {
Student student = new Student();
student.studentName = "Greg";
student.enrollmentYear = 2023;
return student;
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT