This is very similar to this question, and answers may be helpful to you: Compiler to translate Java to C.
Summary: There are tools for this (Toba, GCJ, etc), but you may run into problems with not all of the Java libraries being ported. In the end, tools will probably only do PART of the work, and you'll have to hand-code some of the rest.
A good first step is to convert your Java code to only use standard libraries available in Java 1.4. In fact, you'll probably want to wean as much as possible off of anything not in java.lang.* or java.util.* packages in order to simplify the porting procedure.
Depending on the size of your codebase, it may actually be easier to rewrite the bulk directly rather than relying on tools. Java and C have a lot of syntax similarity, but the mismatch between C's straight procedural code, and Java's object oriented features could cause problems. Automated tools may generate virtually unmaintainable C code when trying to work around this, and there's always the possibility for subtle bugs.
2016 update: Don't do this, not now, not ever. The options that used to provide this have not been maintained (GCJ, for example), and it's arguably easier to find a developer fluent in java than C. Also, Java performance has continued to improve, and baseline implementations tend to have similar performance. Optimized C is still faster, but the edge gets smaller and smaller with every JRE version.
Answer from BobMcGee on Stack OverflowJava to C cross compilation - Stack Overflow
CONVERT CODE FROM JAVA TO C
Javac is written in java how it compiles its self to machine code?
C compiler written in java - Stack Overflow
What types of Java code can be converted to C?
What types of C code can be converted to Java?
Is the Java to C converter free?
Videos
This is very similar to this question, and answers may be helpful to you: Compiler to translate Java to C.
Summary: There are tools for this (Toba, GCJ, etc), but you may run into problems with not all of the Java libraries being ported. In the end, tools will probably only do PART of the work, and you'll have to hand-code some of the rest.
A good first step is to convert your Java code to only use standard libraries available in Java 1.4. In fact, you'll probably want to wean as much as possible off of anything not in java.lang.* or java.util.* packages in order to simplify the porting procedure.
Depending on the size of your codebase, it may actually be easier to rewrite the bulk directly rather than relying on tools. Java and C have a lot of syntax similarity, but the mismatch between C's straight procedural code, and Java's object oriented features could cause problems. Automated tools may generate virtually unmaintainable C code when trying to work around this, and there's always the possibility for subtle bugs.
2016 update: Don't do this, not now, not ever. The options that used to provide this have not been maintained (GCJ, for example), and it's arguably easier to find a developer fluent in java than C. Also, Java performance has continued to improve, and baseline implementations tend to have similar performance. Optimized C is still faster, but the edge gets smaller and smaller with every JRE version.
Can you explain why you want to port your Java code to c?
If it's for performance you likely won't see much of an improvement. Java is a garbage collected language and currently there isn't an algorithm that can insert memory allocation and deallocation calls efficiently. There have been many researchers trying to solve this problem and they have some interesting solutions but I have not seen a good commercial product that can scale to large programs yet. You can look at the conference proceeding for previous ISMM conferences for more information.
If you want to speed your code up I suggest that you use a profiler and find the hot methods. Try and optimize the hot methods and if that is still not enough try and use JNI.
HI, I am a little bit off topic, but I need your help. I was writing code for a friend in Java that is fairly simple. He does not now that much about programming and is just attending an extra course in University. He needed to do a task so he asked for my help. I said I can help him if the language of use is in Java (asked him twice which language they are using). Long Story short the following code is in Java but I need a translation in c. Do you guys have an idea to approach this? Or is anyone here able to translate it ? I appreciate every tip. Thank u guys.
import java.util.Arrays;
import java.util.Scanner;
public class ascii {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
String[] cMtr = new String [3]; // NIMMT 16 ZEICHEN VOM TYP 'char' ENTGEGEN
String matrikelNummerString = "ES3080809";
int matrikelNummerInt = 3080809;
for (int i = 0;i < cMtr.length ; i++) { // LESEN DIE CHARACTERS EIN VOM Char ARRAY - TURN INTO STRING
System.out.println("Enter a string : " + i );
cMtr[i] = sc.next();
}
System.out.println(Arrays.toString(cMtr));
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cMtr.length;i++) {
sb.append(cMtr[i]);
}
String str = sb.toString();
System.out.println(str);
char [] ch = new char [str.length()];
for(int i = 0; i < str.length();i++) {
ch[i] = str.charAt(i);
}
for (char c : ch) {
System.out.print(c);
}
int [] asciiArray = new int [ch.length];
for (int i= 0; i < asciiArray.length;i++) {
asciiArray[i] = (int) ch[i];
}
for (int i =0; i < asciiArray.length;i++) {
asciiArray [i] += matrikelNummerInt ;
asciiArray [i] = asciiArray[i] << 3;
}
for (int i =0; i < asciiArray.length;i++) {
asciiArray [i] = asciiArray[i] << 3;
}
boolean swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < asciiArray.length - j; i++) {
if (asciiArray[i] < asciiArray[i + 1]) {
tmp = asciiArray[i];
asciiArray[i] = asciiArray[i + 1];
asciiArray[i + 1] = tmp;
swapped = true;
}
}
}
int summe = 0;
for (int i = 0; i <= 2 ; i++) {
summe += asciiArray[i];
}
//String b = cMtr.toString();
System.out.println(Arrays.toString(asciiArray));
System.out.println(summe);
}}How javac creates an executable of himself?
You can check this link from Google Code C compiler written in Java
and say congratz to the developer :) -it's not me :p-
Another option is this one: JCPP
ANTRL has a grammar for C. The problem of generating assembly code for a particular platform isn't solved for you, but you can walk the AST and emit the instructions provided you know what they should be.