Similarity/Difference C & Java

Tarrant64

Diamond Member
Sep 20, 2004
3,203
0
76
Does anyone have a clue what the deal is behind these languages? Is one better for the other depending on what your doing? I know java is 'object-orientated' or whatever, so does that mean C is more 'sequential' in programming? Someone once told me long time ago that one of the languauges, i forget which, was basically used to create the other(ex: c used to create more complex language java or whatever).
If you have a link to information about these two and what their reltionships/differences/similarities are, that would also work.

Thanks!
 

gamefreakgcb

Platinum Member
Sep 2, 2004
2,354
1
76
Theres currently a thread about a similar type of discussion in the forum, well kinda as the OP asked why cant people use java for making drivers instead of C/C++.
 

sao123

Lifer
May 27, 2002
12,656
207
106
C, C++ are compile languages. What this means is that the program in compiled and linked into binary machine code which directly runs on the processor. Every binary program must be recompiled in order to run on different processors, because they all use different binary instruction sets.

Java is an interpreted language. what this means is there is an interpreter or virual machine layer running between the java language and the real processor. The interpretor must run in the processors native binary instruction sets. therefore a different interpretor must exist for every processor type. However the java code is always compiled to the same instruction set which runs on the virtual machine interpretor.
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Originally posted by: Tarrant64
Does anyone have a clue what the deal is behind these languages? Is one better for the other depending on what your doing? I know java is 'object-orientated' or whatever, so does that mean C is more 'sequential' in programming? Someone once told me long time ago that one of the languauges, i forget which, was basically used to create the other(ex: c used to create more complex language java or whatever).
If you have a link to information about these two and what their reltionships/differences/similarities are, that would also work.

Thanks!

C is a procedural language, while C++ is an objected oriented version of C. Java is quite similar to C++, though it has influences from other languages too.

Either language can be compiled to machine code or to byte code or interpreted. That's not a feature of the language, but of the tools. Java is more often byte-compiled, while C is more often compiled to machine code, but you can do either with both languages.

C is a low level language, which is good for directly interacting with hardware. Most operating systems are written in C today. C is an unsafe language; most security flaws that result in CERT alerts are a result of C implementation errors.

Java is a safe, higher level language, which is most often used for written business application software, including many web sites as well. Java is object-oriented, and people who are already familiar with procedural languages like C tend to find object-oriented programming harder to learn.

It all depends on what you want to do. I wouldn't recommend either language as the first one for you learn. For that, I'd recommend Python. It's safe, high level, object-oriented language that's much easier to use than Java. It's also free. O'Reilly's Learning Python is a good place to start, as is the online book How to Think Like a Computer Scientist in Python.
 

Gannon

Senior member
Jul 29, 2004
527
0
0
You can learn C++ as a first language but you needa good primer to go with it. In my opinion C++ primer plus by Stephen Prata - http://www.amazon.com/exec/obidos/ASIN/0672322234/qid=1100949146/sr=2-1/ref=pd_ka_b_2_1/103-4846513-7623052 is a good book to start with just to get a feel for the language, its all console programming. Although I agree with cquark for the most part, C++ can be learned as a first language provided it is appropriately articulated and taught correctly.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
C is the only language I know.... actually, it's the only language taught to engineers here, as long as you're not a computer engineer. Why is Java so popular? Is it like 'easy', just tell it basic commands like 'display bouncing object here.go' or something?
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Originally posted by: bobsmith1492
C is the only language I know.... actually, it's the only language taught to engineers here, as long as you're not a computer engineer. Why is Java so popular? Is it like 'easy', just tell it basic commands like 'display bouncing object here.go' or something?

Java is a more complex language than C, but it does offer one major improvement in ease of use: it's a safe language that handles memory allocation and deallocation for you, so you don't have to spend hours debugging the seemingly random side effects of dangling pointers, double frees, buffer overflows and the like.

Of course, many languages other than Java offer such features too and are easier to use as well, like Python.
 

DoubleE

Junior Member
Nov 24, 2004
4
0
0
I'd add an additional, and potentially huge, benefit of using Java - a very robust class library included with the core distribution. Sun throws in networking, UI, collections, etc., packages into Java that any app running on an appropriate version of the VM can utilize.

Sure, a mature C/C++ development environment can/should have all of these (typically by purchasing them from 3rd parties, or using something like .NET), but for the individual developer, or small business, the time to get 'up and running' with Java is a fraction of that for a typical C/C++ environment.

-Mike
 

uOpt

Golden Member
Oct 19, 2004
1,628
0
0
We could fill this forum easily, but the most important aspects are:

1) Java is safer (against program crashes). Unfortunately the portability argument has been shot in the head by MS.

2) C allows you to pack data, including your own defined data types) in much more customized ways, potentially (and in practice) leading to much faster programs.

3) C++ is a super-complicated nightmare to learn and keep swapped in, but in addition to the C advantage noted it allows you high degrees of control about what exactly your code is doing in a way that doesn't force you to duplicate code. While you still have to write a lot of lines of code compared to other languages, C++ will at least stop somewhere and allow reuses in highly efficient manners. If you know what you are doing, that is, efficient C++ programming is over the top of the head of many full-time C++ programmers.