Skip to content

YuriiJavaDev/JavaBasics_Task_18

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Movie Year Extractor (JavaBasics_Task_18)

📌 Description

This project demonstrates how to convert numeric data stored as a String into a primitive int type to enable mathematical operations.

🚀 Task Requirements

  • Create a String variable filmYearStr containing a year (e.g., "1999").
  • Convert (parse) this string into an int variable.
  • Output the resulting integer to the console to verify successful conversion.

🛠 Technical Stack

  • Language: Java 23 (Current version).
  • IDE: IntelliJ IDEA.
  • Concepts: Type Parsing, Integer.parseInt(), Primitive vs. Object types.

⌨️ Practical Implementation

This task applied the clean code explicit conversion principle. Instead of relying on risky implicit behaviors, we use the Integer.parseInt() method, which is the standard Java way to transform text into an integer.

Why this approach?

  1. Readability: Using Integer.parseInt() clearly signals the intent to extract a numeric value from a string.
  2. Performance: This is a static method optimized by the JVM for fast string-to-primitive conversion.
  3. Safety: This method ensures that the input is a valid number; if the string contains letters, it will throw a NumberFormatException.

📋 Example Output

Extracted film year: 1999

💻 Code Example

package com.yurii.pavlenko;

/**
 * Task 18: Converting string-based year to an integer.
 * Demonstrates explicit parsing for numeric operations.
 */
public class Task_18_App {
    public static void main(String[] args) {
        // 1. Create a String variable containing the year
        String filmYearStr = "1999";

        // 2. Parse the string into an integer (Clean Code approach)
        int filmYear = Integer.parseInt(filmYearStr);

        // 3. Output the result to the screen
        System.out.println("Extracted film year: " + filmYear);
    }
}

⚖️ 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 learning project. JavaBasics_Task_18: Implementing string-to-int parsing for film year extraction. 170126_0950

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages