Java’s import vs C/C++’s #include

Vivlio
vivliograph
Published in
2 min readJul 19, 2018

(Welcome to the first article of our article series — “Codathon” where we would look at different programming languages and it’s different aspects)

(You can follow us on twitter , facebook , instagram & our telegram channel.)

There is a huge difference between these two concepts , even though their functionality is quite similar.

Though it seems like both import from Java and #include from C/C++ looks absolutely similar because of their similar functionalities, but there’s a humongous difference between the two concepts as one wastes resources and the other saves resources such as memory and we will understand the differences in this article -

C/C++’s #include -

In case of C/C++ , for using compiler defined functions , we have to include header file(s) , which we can do by the syntax -

#include <headerfile.h>

Where the header file contains all the required functions on which operations is to be performed and in fact for running any program .Let’s look at an example -

One of the most widely used header files is stdio.h or standard input/output header file which contains functions like printf() , scanf() , gets() , puts() , … Etc. For using any of these functions in our we have to include the header file stdio.h . Now , what happens is that in the process of compilation is that , all the functions which are part of the header file (even the ones we are not going to use) are included in the program and due to this reason the program size becomes unnecessarily big and along with it , it brings it’s problems of unnecessary memory and resource consumption but this problem gets solved in Java .

Java ‘s import -

In case of java , whenever we have to use a specific method or class then we have to import a specific package and we can do this by -

import JavaMainPackage.JavaSubPackage.classname;

In case of java , every time a method or a class or an interface has to be used in a program then the java virtual machine goes to the the Java API (Application Program Interface which contains all the packages 📦 which are formed out of classes and interfaces) , performs the operations , finds the result and returns to substitute the result in case of the required called method , this way JVM doesn’t needs to copy the output and thus it doesn’t necessarily increases the size of the memory and this it saves memory consumption and other resources.

So, because of this reason Java’s import is more efficient than C/C++’s #include.

For any additional information or corrections , you can mail to us at vivlio@protonmail.com

--

--

Vivlio
vivliograph

Publishers of the finest books for Internet 2.0 & Vivliograph - our article network .