Java C or Java for Seismology Equipment: What's Best

AI Thread Summary
Taking control of seismology equipment that runs on C code presents a challenge for someone with limited C knowledge but a solid understanding of Java. While converting the software from C to Java may seem like a tempting shortcut, the consensus is that learning C is the more practical approach. C and Java share similar syntax, but C lacks object-oriented features and requires careful management of memory and pointers, making it more complex. There are suggestions to explore C to Java translators, but caution is advised as direct conversion can lead to errors and does not guarantee functionality. Using Java Native Interface (JNI) to call C functions from Java is an advanced option, but learning C is recommended for effective control of the equipment. Additionally, there may be existing Java drivers for the equipment that could simplify the process. Overall, investing time in learning C is seen as essential for successfully managing the seismology equipment.
mgiddy911
Messages
331
Reaction score
0
I may be taking control of the running of some seismology equipment, which is run via C code. I know very very little about C code. Would it be better for me to spend the time to thoughroughly learn C, or could it be possible for me to convert the software to Java. I have a pretty god understanding of Java. If I knew the concepts behind the C code I may be able to formulate an dea of how to do the same thing with java.
Let me know what you think
 
Technology news on Phys.org
If you know Java thoroughly, picking up C should be a piece of cake. I personally wouldn't convert anything -- just learn C.

- Warren
 
Thank you for the suggestion, I sort of knew the answer was going to be just learn C, but I am very busy and it will take me a long time to learn C right now, i was hoping just somehow there'd be an easier way, But it looks like I'll just have to brush up on C, which I am assuming is going to be quite different than any programming I am used to.
 
The syntax of C is virtually identical to the syntax of Java, with the exception that C does not have classes or exceptions. Java syntax was actually chosen specifically because it would be familiar to C programmers. Don't worry, it probably won't be nearly as difficult as you might imagine. Picking up a second programming language is much, much easier than learning the first.

- Warren
 
Until he finds pointers...
 
Almost everything in java is a pointer. :-p
 
I would say going backwards (Java to C) would be much easier than the other way around.

I thought there is some tranlators that can convert C to Java (or at least C++ to Java which would work). You could look into that and give it a test run. As long as you save your original code, trying a translator couldn't hurt.
 
Java and C might look similar but they are a few light-years away. Most notably Java is an OOP language, C is not. Java makes it hard to screw things up while in C...

In C you must be very very careful. Even at simple things such as reading a line from the Console is pain. e.g. you should not use fgets function since the user can supply null input or gets() is also a dangerous function that can be overflown. Therefore you should use the getline() function but it is not part of the ANSI C only GNU C there is ... complicated even at simple things, and don't get me started on pointers...

You can't just automagically convert C program to Java and expect it to work. You can rewrite the same C program in Java but you should be very careful, it is very easy to make a copy paste error.

I would recommend you, if you have the programm running in C, learn good C programming and just use C to do the job.

On the other hand you can make a GUI or whatever in Java and call C functions from Java via the JNI but that is a bit advanced.

Controlling equipment? Maybe there is a "driver" for Java? I am only a bit familiar with EPICS but I know that you need not program in C, you can get a "driver" that enables you to program in Java (CAJ/JCA) and the driver then takes care of the C part.
 
I don't think it will be a piece of cake, to be honest. I went from Java to C and though the elementary syntax is the same, the general approach is very different. Especially since you'll be reading someone else's code. If the code is more than a small app, expect on spending some time on it. These will be helpful:
http://beej.us/guide/bgc/output/htmlsingle/bgc.html
http://www.cs.cf.ac.uk/Dave/C/
 
Last edited by a moderator:

Similar threads

Back
Top