Java Header files

I'm learning Java this term. What I've realized is that all of the header files we create in C++ is now provided to us free of charge in Java. However, is there a website where these files can be viewed as a means to improve my C++ coding
Not sure what you mean. Java doesn't have header files.
The Java equivalent to header files for example the files that say are contained in the Swing class
or lets say i'm using max(a,b) or max(a,(max(b,c)) thats contained in the Math class in C++ I have to write either the constructor or write a header file that performs this function. In Java it's already provided
C's (and C++'s) compilation model is designed so that compilers can operate without having to look at the entire program's code-base, or indeed to read through any given source file (really, any translation unit) more than once. C's an old language, and it's designed with constraints that don't usually apply on modern development machines.

Java only has source files - the compiler doesn't need to be told about things before they are used. C and C++ don't work that way, so header files are required to tell the compiler about (declare) things that aren't defined in the translation unit being processed.

In C++, we wouldn't make a pure function named max() a member of a class. That's plainly bad design. If we ignored that issue and did it anyways, we still wouldn't write a constructor for that class. You would need a declaration of that max() function before it was used, however; that would go in the header file, which other source files could copy/paste in through an #include preprocessor directive.

The Swing source code can be found in your copy of the JDK.
Or, online:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/swing/
Last edited on
Topic archived. No new replies allowed.