Why are java header files not used in C++ ?

360    Asked by AishwaryaJhadav in Java , Asked on Oct 10, 2022

I have a question that I did not find an answer for except the following answer that does not meet my requirements:


"Because James Gosling didn't want to"


I know that Java can have interfaces (only pure virtual functions, no attributes), but it is not the exact same thing as class definitions.

Answered by Anisha Dalal

There is no real need in C++ to have the class definitions and declarations in separate java header files. It just means that you could, at least back in the C days, do the parse in a single top-bottom scan of the code. On machines without random access storage this was a big deal!


Having headers also allowed you to publish the interface to your code library by supplying the header without needing to reveal the source code. Unfortunately in C++ you also have to reveal the private data members which has led to solutions like the horror of pimples.

There have been attempts to make a C++ environment where everything was stored in a database type structure and there are no files but it didn't catch on.



Your Answer

Interviews

Parent Categories