Saturday, November 22, 2025
HomeLanguagesJavaDifference between #include in C/C++ and import in JAVA

Difference between #include in C/C++ and import in JAVA

#include in C/C++: In the case of C language, #include is a standard or user-defined file in a program that tells the preprocessor to insert the internal contents of another file into the source code of the program.

Syntax:

#include<stdio.h>

Program 1:
Below is a C Program to demonstrate the use of #include:

C




// C Program to demonstrate use of #include
#include <stdio.h>
  
// Header file loads all the
// necessary Input output
// file at beginning only
  
// Driver Code
int main()
{
    printf("Lazyroar");
    return 0;
}


Output:

Lazyroar

import in Java: In JAVA, the import statement is used to load the entire package or some classes in a package. It is written before the definition of the class and after the package statement(if present).

Syntax:

import java.util.*;

Program 2:
Below is a Java program to demonstrate the use of the import statement:

Java




// Java program to demonstrate use of import
import java.io.*;
  
// import statement doesn't load
// all the necessary files at
// beginning rather it loads
// only those files which it
// needs at the runtime
class GFG {
    public static void main(String[] args)
    {
        System.out.println("Lazyroar");
    }
}


Output:

Lazyroar

Both #include in C/C++ and import in Java is used to load predefined header files or packages but there are certain differences which are listed below: 

S No.                           #include in C/C++                                                                                          import in Java                                                   
1 It is mandatory to use the #include statement to include standard header files. Import statement in java is optional
2 It loads the file at the beginning only.        No class files will be loaded at the beginning. 
Whenever a particular class is used then only the corresponding class file will be loaded.
3 Unnecessary waste of memory and processor’s time. No such waste of memory and processor’s time.
4 Size of the program increases.      No increase in the size of the program.
5 It is also called as static include. It is also called as dynamic include.
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS