Difference between Java and C

PrisonLove

Hard Realist
Reaction score
78
Hey, so the past few programming classes I have taken used Java. I am now taking a class that uses C instead and I just wanted to know what the core differences are between Java and C other than syntax and the fact that C requires the user to manually manage memory.

This is just out of curiosity, feel free to reply in whatever amount of depth you feel like.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Java actually does have pointers. The thing is that you don't actually declare pointer variables like you do in C. Java works like this:

Any non-primitive type (think Integer (rather than just int), String, and custom-made object classes) are all initialized as pointers when you create the variables. These variables point to a memory location just like in C. And you can use them as such. Also, if Java doesn't have pointers, why does this exist? http://download.oracle.com/javase/1.4.2/docs/api/java/lang/NullPointerException.html :p

As for whether or not C is faster, that is a matter of opinion and what exactly it is you are doing. There will be times when C is faster and there will be times when Java is faster. Also something you need to consider is how difficult it would be to create something in one language versus another. Some languages lend themselves to a certain coding style. For example, I would not start trying to learn programming by starting with APL. But APL is an extremely powerful language. EX:

APL.jpg

Cookies if you can interpret that without looking it up.
Anyway, I would probably not use C if I were trying to develop a web application. Java would be better suited for that.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Java actually does have pointers. The thing is that you don't actually declare pointer variables like you do in C. Java works like this:

Any non-primitive type (think Integer (rather than just int), String, and custom-made object classes) are all initialized as pointers when you create the variables. These variables point to a memory location just like in C. And you can use them as such. Also, if Java doesn't have pointers, why does this exist? http://download.oracle.com/javase/1.4.2/docs/api/java/lang/NullPointerException.html :p

As for whether or not C is faster, that is a matter of opinion and what exactly it is you are doing. There will be times when C is faster and there will be times when Java is faster. Also something you need to consider is how difficult it would be to create something in one language versus another. Some languages lend themselves to a certain coding style. For example, I would not start trying to learn programming by starting with APL. But APL is an extremely powerful language. EX:

APL.jpg

Cookies if you can interpret that without looking it up.
Anyway, I would probably not use C if I were trying to develop a web application. Java would be better suited for that.

Ya my bad. But you don't use java variables like pointers. And they're handled differently by the garbage collector, I think.

Also I want to mention that Ghan threatened me!
http://i.imgur.com/4xaMe.png
 

Slapshot136

Divide et impera
Reaction score
471
C is not object oriented, Java and c++ are

Java runs in more places (like on android phones) while C is mostly limited to within the windows OS

C has the potential to be faster if it's well-coded, but most of the time this doesn't matter

edit: don't use Java unless you want to promote internet violence
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Java runs in more places (like on android phones) while C is mostly limited to within the windows OS
Um, no. C was pretty much developed in tandem with the UNIX project. If any language can be said to be the most ported language ever, then it's C. Now, Java certainly has the "compile once, debug everywhere" thing down.

For example, here are the architectures supported by gcc. And that's only one compiler, probably the most ported one though.

Now, C was and still is a machine programming language. C is "just" another way of writing assembler. It's much more convenient, but in the end pretty much every design feature of C can be tracked back to the hardware architectures it's intended to be used on (today, hardware architectures are designed around C just as much as C was designed around hardware architectures 40 years ago). Java on the other hand provides lots of abstractions not commonly seen in hardware (garbage collection, class hierarchies, exceptions). Java also loses lots of stuff that is trivial to do in C due to the abstraction from the hardware but also due to safety and simplicity (direct hardware access, pointer arithmetic).

These trade-off naturally makes java and C excel in different domains, but you can often get away with use one in places where the other probably would be a more natural fit. C is probably more multi purpose than Java.

To bring up android again:
The operating system Android is mostly written in C.
The Java runtime that runs on Android is written in C/C++.
The user facing programs on Android are mostly written in Java.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top