C or Java for Seismology Equipment: What's Best

Click For Summary
SUMMARY

The discussion centers on the choice between learning C or converting existing C code to Java for controlling seismology equipment. Participants agree that learning C is essential due to its differences from Java, particularly in handling pointers and memory management. While there are tools that can translate C to Java, such as JNI for interfacing, the consensus is that rewriting the code in Java is fraught with risks of errors. Ultimately, mastering C is recommended for effective control of the equipment.

PREREQUISITES
  • Understanding of C programming concepts, including pointers and memory management.
  • Familiarity with Java programming and its object-oriented principles.
  • Knowledge of JNI (Java Native Interface) for integrating Java with C code.
  • Basic grasp of seismology equipment operation and control mechanisms.
NEXT STEPS
  • Learn advanced C programming techniques, focusing on pointers and memory safety.
  • Research JNI to understand how to call C functions from Java.
  • Explore existing drivers like CAJ/JCA that allow Java programming for seismology equipment.
  • Investigate tools for translating C code to Java and their limitations.
USEFUL FOR

Software developers, particularly those transitioning from Java to C, and engineers involved in controlling seismology equipment will benefit from this discussion.

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

  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
21
Views
13K
  • · Replies 33 ·
2
Replies
33
Views
8K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K