Skip to content

YuriiJavaDev/JavaBasics_Task_379_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Math Utility: Instance vs. Static Methods (JavaBasics_Task_379_V0.1)

📖 Description

In engineering applications, distinguishing between object-specific behavior and global utility functions is vital for code organization. This project demonstrates the coexistence of Default Methods and Static Methods within a single interface. The printSquare method provides a default instance-level implementation, while printCube acts as a global static utility. This separation allows for flexible inheritance patterns while maintaining a centralized repository for common mathematical operations.

📋 Requirements Compliance

  • Instance Logic: Implemented printSquare as a default method accessible via object instances.
  • Global Utility: Developed printCube as a static method accessible directly through the MathHelper interface.
  • Implementation Mapping: Created the NumberPrinter class to bridge the interface logic with executable code.

🚀 Architectural Stack

  • Java 8+ (Default Methods, Static Interface Methods)

🏗️ Implementation Details

  • MathHelper: The interface container for both instance and static mathematical logic.
  • NumberPrinter: A concrete class that inherits the default squaring behavior.
  • MathLauncherApp: The entry point demonstrating both invocation styles.

📋 Expected result

25
27

💻 Code Example

Project Structure:

JavaBasics_Task_379/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── MathLauncherApp.java
│                 └── math/
│                     ├── contracts/
│                     │   └── MathHelper.java
│                     └── modules/
│                         └── NumberPrinter.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.math.contracts.MathHelper;
import com.yurii.pavlenko.math.modules.NumberPrinter;

public class MathLauncherApp {

    public static void main(String[] args) {
        NumberPrinter printer = new NumberPrinter();
        printer.printSquare(5);
        MathHelper.printCube(3);
    }
}
package com.yurii.pavlenko.math.contracts;

public interface MathHelper {

    default void printSquare(int n) {
        System.out.println(n * n);
    }

    static void printCube(int n) {
        System.out.println(n * n * n);
    }
}
package com.yurii.pavlenko.math.modules;

import com.yurii.pavlenko.math.contracts.MathHelper;

public class NumberPrinter implements MathHelper {
    // Inherits printSquare by default
}

⚖️ 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_379_V0.1 Math Utility System: integrating default instance methods for squaring and static interface methods for cubing operations. 030526_1125

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages