You are here
Home > Uncategorized > What was the need of JAVA ? Difference between #include and import

What was the need of JAVA ? Difference between #include and import

What was the need of JAVA ?

Difference between #include and import What was the need of JAVA ? Importing of Classes

No preprocessor directives in Java

Which means that, Java uses something else to makeup!

It uses a technique which we would be calling as…

Importing of Classes

Consider the following code in C

# include <stdio.h>
void main()
{
printf(“Hi”);
}

It actually has only four lines of code.

But at compile time it shows that there are 312 lines of code!

The remaining 308 lines of code is from the stdio.h header file. Its added into the program.

In C, its just the standard library functions from the header files.
Java has a different hierarchy for programming!

Java Library——->Packages——->Classes & Interfaces——->Methods

So, if a programmer wants to use a class then only that class imported.

Difference between #include and import

#include directive makes the compiler to go to the c/c++ standard library and then copy from the header files into the program.

import statement makes the JVM go to the java standard library, execute the code there and then substitute the result in the program.

Here no code is copied and hence there is no waste of memory or the process time.

Eg:

import java.lang.system;
import java.lang.string;

Note:

java.lang.*;

is automatically imported to all java programs!

So the code import java.lang.*;
is never needed!

Now the comparison between C and Java is over!
We shall try to get along with Java basics from now on.

Try to recollect the Hello world program in Java.
I would try to get back to you with my next post.

Leave a Reply

Top