Skip to content

YuriiJavaDev/JavaBasics_Task_4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Compilation Error Analysis & Clean Code (JavaBasics_Task_4)

📌 Description

This project focuses on debugging a non-compilable Java program. The objective was to identify, analyze, and comment out lines that cause compilation errors or violate task constraints, ensuring the program runs without.

🚀 Task Requirements

As per the assignment instructions:

  1. Identify and comment out all lines that prevent the code from compiling.
  2. Ensure the program is executable.

🛠 Compilation Errors Explained

The following issues were identified and resolved through code blocking:

  • Variable Redeclaration: Attempting to declare multiple variables with the same name (number) in the same scope.
  • Lack of Initialization: Trying to access a local variable (uninitialized) before assigning it a value.
  • Type Mismatch: Assigning an integer value directly to a String variable without proper conversion.
  • Unresolved Symbols: Referencing a variable (undeclaredVariable) that has never been defined.
  • Unused Code: Removing empty declarations to follow Clean Code principles.

🛠 Technical Stack

  • Language: Java 23
  • IDE: IntelliJ IDEA
  • Concepts: Compilation lifecycle, variable scope, initialization, and strong typing.

⌨️ Practical Implementation

The code was processed using IntelliJ IDEA to ensure strict adherence to Java syntax rules. All problematic lines are now documented with explanations for why they were disabled.

💻 Final Code Structure

The implementation ensures that only the valid, required logic remains active:

package com.yurii.pavlenko;

/**
 * Task 4: Identifying and explaining compilation errors.
 */

public class Task_4_App {
    public static void main(String[] args) {

        int number = 10;

        // int number = 20;
        // Error: Variable redeclaration. In Java, you cannot declare two variables with the same name in the same scope.

        // int uninitialized;
        // Optimization: Unused variable. While the declaration itself is technically valid,
        // using it without initialization causes a compilation error (Variable might not have been initialized).
        // It is removed to comply with Clean Code principles as it serves no purpose.

        // System.out.println(uninitialized);
        // Error: Local variable not initialized. Local variables must be assigned a value before they can be read.

        // String text = 123;
        // Error: Type mismatch. Java is a strongly typed language; an 'int' cannot be directly assigned to a 'String' variable.

        // System.out.println(undeclaredVariable);
        // Error: Cannot resolve symbol. You cannot use a variable that has not been declared.

        System.out.println(number);
    }
}

⚖️ 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

Completed JavaBasics_Task_4: debugged code and add documentation. 140126_1404

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages