Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C to Java

  1. Nov 14, 2006 #1
    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
     
  2. jcsd
  3. Nov 14, 2006 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    If you know Java thoroughly, picking up C should be a piece of cake. I personally wouldn't convert anything -- just learn C.

    - Warren
     
  4. Nov 14, 2006 #3
    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.
     
  5. Nov 14, 2006 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  6. Nov 15, 2006 #5

    verty

    User Avatar
    Homework Helper

    Until he finds pointers...
     
  7. Nov 15, 2006 #6

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Almost everything in java is a pointer. :tongue:
     
  8. Nov 15, 2006 #7
    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.
     
  9. Nov 15, 2006 #8
    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.
     
  10. Nov 15, 2006 #9

    -Job-

    User Avatar
    Science Advisor

  11. Nov 15, 2006 #10
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C to Java
  1. C or Java? (Replies: 20)

  2. Java &c++ (Replies: 1)

  3. C or Java? (Replies: 18)

  4. Java or C/C ++ (Replies: 5)

  5. Java OR C# (Replies: 3)

Loading...