Skip to content

YuriiJavaDev/JavaBasics_Task_392_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sensor Data: Shallow Immutability (JavaBasics_Task_392_V0.1)

📖 Description

Understanding the boundaries of immutability is critical for processing streaming data. This project explores Shallow Immutability in Java Records. While a record's components are final and cannot be reassigned to new objects, if a component is a mutable object (like an array), its internal state can still be modified from the outside. This demonstration shows how a record stores a reference to an existing array, allowing external changes to reflect inside the record, highlighting the importance of defensive copying in secure system design.

📋 Requirements Compliance

  • Reference Handling: Implemented a record that stores a reference to an integer array.
  • State Observation: Demonstrated how modifying an external array impacts the record's data.
  • Structural Integrity: Followed the Java 16+ record specification for data containers.

🚀 Architectural Stack

  • Java 16+ (Records, Arrays, Reference Types)

🏗️ Implementation Details

  • IntArrayRecord: A record containing a single integer array component.
  • SensorLauncherApp: The entry point simulating real-time data modification.

📋 Expected result

99

💻 Code Example

Project Structure:

JavaBasics_Task_392/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── SensorLauncherApp.java
│                 └── sensor/
│                     └── models/
│                         └── IntArrayRecord.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.sensor.models.IntArrayRecord;

public class SensorLauncherApp {

    public static void main(String[] args) {

        int[] readings = {10, 20, 30};

        IntArrayRecord container = new IntArrayRecord(readings);

        readings[0] = 99;

        System.out.println(container.values()[0]);
    }
}
package com.yurii.pavlenko.sensor.models;

public record IntArrayRecord(int[] values) {
}

⚖️ License

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

About

This is a tutorial project. JavaBasics_Task_392_V0.1 Sensor Data Processing: demonstrating shallow immutability and reference behavior within Java Records. 060526_1336

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages