This project demonstrates how to convert primitive numeric data types into string representations for data transmission or messaging purposes.
- Create an
intvariable to store a secret access code. - Convert this numeric value into a
Stringobject. - Print the resulting string to the console.
- Language: Java 23 (Current version).
- IDE: IntelliJ IDEA.
- Concepts: Primitive vs. Object types, Clean Code (Explicitness).
This task applied the clean code explicit conversion principle. Instead of relying on an implicit conversion (e.g. "" + number), which is considered a "code smell", the String.valueOf() method was used.
- Readability: It clearly states the intent to transform data.
- Performance: It avoids creating temporary
StringBuilderobjects that can occur during string concatenation in some JVM versions. - Safety: This approach ensures that the conversion is handled by the standard library's optimized methods.
Secure access code for message: 774109
Length of the shared code: 6
package com.yurii.pavlenko;
public class Task_16_App {
public static void main(String[] args) {
// 1. Create a secret access code as an integer
int accessCode = 774109;
// 2. Convert the integer to a String explicitly (Clean Code approach)
String sharedCode = String.valueOf(accessCode);
// 3. Output the result to the screen
System.out.println("Secure access code for message: " + sharedCode);
// Let's verify it's a String by checking length (int doesn't have .length())
System.out.println("Length of the shared code: " + sharedCode.length());
}
}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