Comparing Java and C/C++ for Data Structures

  • Context: C/C++ 
  • Thread starter Thread starter pairofstrings
  • Start date Start date
  • Tags Tags
    Data Java Structures
Click For Summary

Discussion Overview

The discussion centers on comparing Java and C/C++ in the context of data structures, exploring their capabilities, advantages, and potential use cases. Participants examine technical aspects, performance considerations, and educational perspectives related to these programming languages.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • Some participants argue that both Java and C/C++ allow for data manipulation down to the bit level, suggesting that they are equally capable in this regard.
  • There is a mention of Java's Generics as a feature that brings it closer to C++ in terms of template support, leading to a perception of parity between the two languages.
  • One participant reflects on their educational experience, noting that C++ was emphasized in their university curriculum, although they do not recall the specific reasons for this preference.
  • Another participant highlights the importance of understanding memory management and pointers in C/C++, suggesting that this knowledge provides deeper insights into computer operations.
  • Performance is discussed, with some participants noting that C++ may offer advantages in speed due to its direct compilation to machine code, while Java's reliance on a runtime environment could introduce overhead.
  • There is a specific mention of the gaming industry, where performance demands may favor C++ due to its ability to produce optimized executables.
  • Questions arise about the concepts of flat memory and kernel memory, with explanations provided about their historical context and relevance to programming practices.

Areas of Agreement / Disagreement

Participants express differing views on the advantages of Java versus C/C++ for data structures, with no clear consensus reached. The discussion remains open with multiple competing perspectives on the topic.

Contextual Notes

Some participants reference historical memory models and programming practices, indicating that understanding these concepts may be crucial for evaluating the two languages. However, the discussion does not resolve the implications of these models on current programming practices.

pairofstrings
Messages
411
Reaction score
7
Which is better Java or C/C++ with data structures and why?
 
Technology news on Phys.org
pairofstrings said:
Which is better Java or C/C++ with data structures and why?

Java and C/C++ let you defined data down to the bit level.

Both have bitwise logical operators. Since this is the case you can extract and modify individual bits of larger data words, which means that both are just as good as one another to modifying data in any way you want to do so.

If Java didn't have the logical operators, I would have said C/C++ but since both have these features, you can do literally whatever you want with data retrieval and modification with ease.

Upon searching for template support in Java, I have found that Java added support for templates (they are called Generics). I was going to say C++ had an edge (it's been many many years since I've worked with the original Java), but as a result, again there is no difference between the two.

Based on the above, I can't really see any advantage in terms of data structures for using C++ or Java, but there are other reasons why you may want to use Java or C++ depending on what you are trying to do.
 
It depends on what you want to do. However, C++ was the first programming language I learned. At my University, Computer Science and Engineering students would start with C++. The first day of lecture, my professor said to learn C++ before Java. I don't recall the reasons why.
 
Ivan92 said:
It depends on what you want to do. However, C++ was the first programming language I learned. At my University, Computer Science and Engineering students would start with C++. The first day of lecture, my professor said to learn C++ before Java. I don't recall the reasons why.

Learning C++ for Java is good for different reasons. One is that you understand what is going on. In C/C++ you have to deal with managing memory and working with pointers. This is good because it corresponds more or less with what is happening inside the computer (flat memory in your RAM that is not kernel memory).

That aspect alone helps you out immensely.

The other is speed. Although Java Runtime Environments are getting faster, sometimes you really have a need for speed. Java is compiled to an intermediate interpreted byte code representation which has to be executed by the Java Runtime. In C++ you compile your code for the platform in the most optimal way possible. So a windows EXE, DLL, and so on will have your windows program headers and data and then the machine code that is your program (in a basic sense).

Some things have a need for speed and are also huge in terms source code, complexity, and demand for resources. One area that this is true is computer games. Computer games have to have real-time performance. Gamers get angry when they are running their games on 20 frames per second.

In the above case, you need good compilers, optimal code, or both.

Now I know there are environments that use a mix of interpreted and optimal compiled code (most modern games use this kind of platform), but again the whole code base is not interpreted.
 
chiro said:
Learning C++ for Java is good for different reasons. One is that you understand what is going on. In C/C++ you have to deal with managing memory and working with pointers. This is good because it corresponds more or less with what is happening inside the computer (flat memory in your RAM that is not kernel memory).

What is flat memory in RAM and Kernel memory?
 
pairofstrings said:
What is flat memory in RAM and Kernel memory?

Flat memory is a memory model. It's basically a huge array of memory.

In the old days of DOS the memory model was segmented. In the flat model, you just use a word as a pointer. So basically your address would something like 0x3625371A (just an example), or just a machine word.

In the segmented model your memory was referenced using the segment:address model. In the DOS days if you wanted to get access to the screen buffer you would have to write to the address A000:0000. So to do stuff you put A000 in the segment register and 0000 in the index register, instead of just using one word to point to something.

Also back in the DOS days, everything was free gain for the programs. You could basically read and write anything in memory.

As windows became popular, the protected memory model became standard. Protected memory just means that memory is protected by other programs. We take it for granted now that programs can't access other programs memory, but back in time, this wasn't the case.

Kernel memory just refers to the memory specifically used by the kernel (think Operating System). Back in the DOS days, people could write their own device drivers for their programs and access anything. Typically what the DOS games had to do is write keyboard, sound, and graphics interrupt routines (think device driver) so that it would be smooth and responsive.

When windows 95 and above came along, the kernel memory was protected from other programs so that you couldn't do stuff like this. What happens is that the kernel provides an interface to get information on hardware and you can't just read or write to ports at will.

So yeah basically when you hear kernel think operating system specific stuff at a low level in terms of device drivers and device memory and so forth.
 

Similar threads

Replies
86
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 39 ·
2
Replies
39
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K