English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

5 answers

no one seems to have answered the actual question so far, which was not about what's the difference between c and java.

Things you can do in c, but not in java are mostly those, that include direct interaction with hardware drivers or with the operating system kernel - write a disk sector, send a raw packet over the network, turn a pixel on the monitor on or off, fork a copy of a process, send a signal to another process or communicate with it via shared memory etc.


Everything you can do in java on the other hand can be done in c as well (the java machine itself is written in c after all). Even more precisely, everything you can do with a computer can be done in C. But some things (mostly, having to do with graphics) are easier accomplished in java, that they are in C, unless you have a nice C library - like qt or something - that does the "dirty work" for you.

2006-11-14 23:41:17 · answer #1 · answered by n0body 4 · 1 0

Well the main thing is Java code dosen't have to be changed for each platform.. Unlike C/C++ which needs to be changed around a little bit on each platform it is compiled for.

Java is a make once and run anywhere without recompile.

2006-11-14 23:13:12 · answer #2 · answered by jack 6 · 0 1

The advantages of C are:
1.Its program code is very robust, so its quite hard to break through it.
2.It uses pointer concept.

The advantages of Java:
1.Platform independent.
2.Completely object-oriented concept.
3.User friendly.
4.Wider usability.

2006-11-14 23:18:24 · answer #3 · answered by Anonymous · 0 1

Let me list down the main difference between the two

01. No preprocessor
---------------------------
Java does not include a preprocessor and does not define any analogs of the #define, #include, and #ifdef directives. Constant definitions are replaced with staticfinal fields in Java. (See the java.lang.Math.PI field for an example.) Macro definitions are not available in Java, but advanced compiler technology and inlining has made them less useful. Java does not require an #include directive because Java has no header files. Java class files contain both the class API and the class implementation, and the compiler reads API information from class files as necessary. Java lacks any form of conditional compilation, but its cross-platform portability means that this feature is very rarely needed.

02. No global variables
------------------------------
Java defines a very clean namespace. Packages contain classes, classes contain fields and methods, and methods contain local variables. But there are no global variables in Java, and, thus, there is no possibility of namespace collisions among those variables.

03. Well-defined primitive type sizes
-----------------------------------------------
All the primitive types in Java have well-defined sizes. In C, the size of short, int, and long types is platform-dependent, which hampers portability.

04. No pointers
--------------------
Java classes and arrays are reference types, and references to objects and arrays are akin to pointers in C. Unlike C pointers, however, references in Java are entirely opaque. There is no way to convert a reference to a primitive type, and a reference cannot be incremented or decremented. There is no address-of operator like &, dereference operator like * or −>, or sizeof operator. Pointers are a notorious source of bugs. Eliminating them simplifies the language and makes Java programs more robust and secure.

05. Garbage collection
------------------------------
The Java Virtual Machine performs garbage collection so that Java programmers do not have to explicitly manage the memory used by all objects and arrays. This feature eliminates another entire category of common bugs and all but eliminates memory leaks from Java programs.

06. No goto statement
-----------------------------
Java doesn't support a goto statement. Use of goto except in certain well-defined circumstances is regarded as poor programming practice. Java adds exception handling and labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto.

06. Variable declarations anywhere
----------------------------------------------
C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block. Many programmers prefer to keep all their variable declarations grouped together at the top of a method, however.

07. Forward references
-------------------------------
The Java compiler is smarter than the C compiler, in that it allows methods to be invoked before they are defined. This eliminates the need to declare functions in a header file before defining them in a program file, as is done in C.

08. Method overloading
-------------------------------
Java programs can define multiple methods with the same name, as long as the methods have different parameter lists.

09. No struct and union types
--------------------------------------
Java doesn't support C struct and union types. A Java class can be thought of as an enhanced struct, however.

10. No enumerated types
---------------------------------
Java doesn't support the enum keyword used in C to define types that consist of fixed sets of named values. This is surprising for a strongly typed language like Java, but there are ways to simulate this feature with object constants.

11. No bitfields
--------------------
Java doesn't support the (infrequently used) ability of C to specify the number of individual bits occupied by fields of a struct.

12. No typedef
-------------------
Java doesn't support the typedef keyword used in C to define aliases for type names. Java's lack of pointers makes its type-naming scheme simpler and more consistent than C's, however, so many of the common uses of typedef are not really necessary in Java.

13. No method pointers
-------------------------------
C allows you to store the address of a function in a variable and pass this function pointer to other functions. You cannot do this with Java methods, but you can often achieve similar results by passing an object that implements a particular interface. Also, a Java method can be represented and invoked through a java.lang.reflect.Method object.

14. No variable-length argument lists
-----------------------------------------------
Java doesn't allow you to define methods such as C's printf() that take a variable number of arguments. Method overloading allows you to simulate C varargs functions for simple cases, but there's no general replacement for this feature.

2006-11-14 23:11:02 · answer #4 · answered by Shaj 5 · 1 1

one of the main difference or advantage with c or c++ is the accessibility of pointers, use to access memory directly.

2006-11-14 23:14:24 · answer #5 · answered by joker 2 · 0 1

fedest.com, questions and answers