Friday, August 17, 2007

Java VS C

Differences between Java and C as described in "Java In A Nutshell"

These are something that may well be asked on a university CS exam. (e.g. "List at least 5 differences between Java and C")

1. No preprocessor (e.g. #define, #include, #ifdef)
2. No global varibles -> no possibility of namespace collision
3.Well-defined primitive types :
- Size of short, int, long types are platform (e.g. "What kind of CPU?") dependent in C.
- Not so in Java
4. No pointers
- Java classes and arrays are reference types
- Java references are "opaque" -> no way of converting it to a premitive types or to manipulate it (e.g. ptr++; )
5. Garbage Collection
6. No goto statement
7. Variable declarations anywhere : also true in C++!
8. Forward references : funtions can be used before being defined/declared.
9. Method overloading : multiple methods with same name can be defined as long as parameter lists are different.
10. No struct or union types
11. No bitfields
12. No typedef
13. No method/function pointers

No comments: