C/C++ Comparing Java and C/C++ for Data Structures

AI Thread Summary
Java and C/C++ both allow for detailed data manipulation down to the bit level, with both languages supporting bitwise logical operators. The introduction of Generics in Java has leveled the playing field in terms of template support, making neither language superior for data structures. However, C++ offers advantages in memory management and speed, as it compiles directly to machine code, which is crucial for performance-intensive applications like video games. Understanding C/C++ can provide deeper insights into memory management and system operations, which is beneficial for programmers. Ultimately, the choice between Java and C/C++ depends on specific project requirements and performance needs.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top