C to Java

  • Java
  • Thread starter mgiddy911
  • Start date
  • #1
333
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
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
If you know Java thoroughly, picking up C should be a piece of cake. I personally wouldn't convert anything -- just learn C.

- Warren
 
  • #3
333
0
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.
 
  • #4
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
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
 
  • #5
verty
Homework Helper
2,164
198
Until he finds pointers...
 
  • #6
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
19
Almost everything in java is a pointer. :tongue:
 
  • #7
131
0
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.
 
  • #8
161
0
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.
 
  • #9
-Job-
Science Advisor
1,146
1
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 [Broken]
http://www.cs.cf.ac.uk/Dave/C/
 
Last edited by a moderator:

Related Threads on C to Java

  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
18
Views
4K
  • Last Post
Replies
20
Views
5K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
2
Views
2K
Replies
26
Views
8K
Top