2

I have created a simple java file having compilation error(Removed ; in 4th line).

    public class Test {

public static void main(String args[])
{
    System.out.println("Hi")
}
    }

After saving If I see bin folder I can see class file(Test.class) being created.Whereas if we compile the same java code through windows command prompt class file is not created.

Eclipse generated compiled class file (below)

    public class Test
    {
    public static void main(String[] paramArrayOfString)
    {
    throw new Error("Unresolved compilation problem: \n\tSyntax error, 
    insert \";\" to complete BlockStatements\n");
    }
    }

Can you please let know why we see 2 different behavior for the file having compilation error in it.

  • because an IDE is more focussed on Java compared to the command prompt – Stultuske Feb 11 '19 at 12:49
  • 1
    Eclipse has its own Java compiler, which compared to `javac` is able to partially compile a Java file with compile errors. For example, a compile error in a method does not prevent execution and an error is thrown only when the method is called (if the method is not used at all, no error would be thrown). – howlger Feb 11 '19 at 13:28

1 Answers1

1

Eclipse's focus is allowing you to do software development. The behavior you've seen allows you to e.g. start unit tests on parts of the class that doesn't have compile errors to check if existing behavior is still the same at that part of the class while you refactor other parts or add new functionality.

Lothar
  • 5,323
  • 1
  • 11
  • 27