Thursday, July 9, 2009

What is the major difference between <#include>in c & import in java?

Each class in Java defines a namespace which allows functions and variables in separate, unrelated classes to share the same name. When identifying a function or variable in Java, the namespace must be expressed, or implied using an import directive; for example, the method java.lang.Integer.toString() is distinct from java.lang.Long.toString(). Java packages allow distinct classes and interfaces to share the same name; for example, the name Object could refer to either java.lang.Object or org.omg.CORBA.Object.





In C, all functions are global, and must share a single namespace (i.e. one per program). Global variables can also be declared and defined, and they also share that namespace. Care must be taken in choosing names for functions in large projects, and often a strategy of using a common prefix for groups of related functions is employed, e.g. WSA prefixes most of the WinSock functions.





Note that other namespaces exist in C: a single namespace is shared by the tags of all structures, unions and enumerations; each structure and union holds a unique namespace for its members; each block statement holds a namespace for local variables.





i think this will to help you to clear your doubt to some extent.


all the best.


No comments:

Post a Comment