We use the import keyword instead of the #include directive in the Java programming language. We will discuss the difference between these two keywords.

Java was created to be OS-independent and to be used with a variety of operating systems.

Java was created to be OS-independent and to be used with a variety of operating systems. Java is not tied to any one operating system. It can run on Linux, Unix, Windows, Mac OS X, and more.

Java also supports portability in its code and binary files (class files). You can write your program once and compile it into a single file or write multiple interrelated pieces of code and combine them into one Java file or class before compiling them all into a single file or class.

Why do we use import in Java rather than #include?

The #include directive is used in the C/C++ programming language for the following purposes.

The #include directive is used in the C/C++ programming language for the following purposes:

  • Include a file.
  • Include a library.
  • Include a header file.
  • Include a preprocessor directive (a special type of comment).

This functionality is similar to including directives in other programming languages, such as Java or Perl, but with some notable differences. In C and C++, an #include preprocesses its contents as if they were part of the current source code file being compiled; this process involves searching directories specified by any -I command line compiler options and replacing occurrences of #include “filename” with “filename.”

The import keyword is only used to import a package in the java program.

The import keyword is only used to import a package in the java program. It’s not used to import a package’s classes, constants, and variables.

You can also use wildcards (*) with the import statement to import multiple classes from one or more packages, like this:

Import java.io.*;

The #include directive includes the contents of one file into another, while the import keyword is used to include classes of a package in the java file.

  • The #include directive includes the contents of one file into another, while the import keyword is used to include classes of a package in the java file.
  • The import keyword is used to import a package in the java program.
  • The import keyword is used to import classes from a package in the java program.

Conclusion

In conclusion, the #include directive is used to include the contents of one file into another, while the import keyword is used to include classes of a package in java files. The main difference between these two statements lies in their usage and functionality. The #include directive includes the contents of one file into another, while the import keyword is only used for importing classes from packages.