Saturday, October 3, 2009

Hope you meditated enough.

It's been quite some time since my last post.

I had been really busy organizing the Intra Virtuoso events for my college juniors. Anyway getting back to the post, we shall continue from where we left...

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.