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 Overflow
🌐
OnlineGDB
onlinegdb.com › online_java_compiler
Online Java Compiler - online editor
code. compile. run. debug. share. IDE · My Projects · Classroom new · Learn Programming · Programming Questions · Sign Up · Login · connecting to server · Source Code · Run Toggle Dropdown · Run with display screen (beta) Debug Stop Share Save { } Beautify · Toggle Dropdown · Download all files Language · -- select -- C · C++ C++ 14 · C++ 17 · C++ 20 · C++ 23 · C (TurboC) C++ (TurboC) Java ·
🌐
GitHub
github.com › ivmai › JCGO
GitHub - ivmai/JCGO: Java source to C code translator (JCGO)
JCGO takes Java source files as input and translates them into a set of files in the platform-independent C programming language, which is further compiled to a binary executable for your target platform by a standard ANSI C/C++ compiler.
Starred by 83 users
Forked by 21 users
Languages   Java 88.9% | C 10.8% | Java 88.9% | C 10.8%
Discussions

Java to C cross compilation - Stack Overflow
Does anyone know of a good Java to C cross compiler? Do they work well? More on stackoverflow.com
🌐 stackoverflow.com
CONVERT CODE FROM JAVA TO C
Aside from the line Scanner sc = new Scanner (System.in); which, who knows what code gets ran there, this will easily convert to C. This will be more than enough to learn some syntax: https://computer.howstuffworks.com/c.htm More on reddit.com
🌐 r/cprogramming
2
0
November 16, 2021
Javac is written in java how it compiles its self to machine code?
JavaC compiles Java to byte code, which is an IR (intermediate representation). It’s the JVM that may in turn compile from that IR to machine code. More on reddit.com
🌐 r/Compilers
10
0
January 17, 2024
C compiler written in java - Stack Overflow
I want to integrate a c language compiler in to java application to compile c sources without file creation (Like Java Compiler Api). Is there any c compiler that has entirely written in java? More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What types of Java code can be converted to C?
This tool can convert a wide range of Java code to C, from simple functions and algorithms to complete programs with classes, error handling, and complex logic. The AI understands both Java and C idioms and produces natural-looking code.
🌐
codeconvert.ai
codeconvert.ai › java-to-c-converter
Free Java to C Converter — AI Code Translation | CodeConvert AI
What types of C code can be converted to Java?
This tool can convert a wide range of C code to Java, from simple functions and algorithms to complete programs with classes, error handling, and complex logic. The AI understands both C and Java idioms and produces natural-looking code.
🌐
codeconvert.ai
codeconvert.ai › c-to-java-converter
Free C to Java Converter — AI Code Translation
Is the Java to C converter free?
Yes. You can convert Java to C for free without creating an account for up to 5 conversions per day. For higher limits and additional features, you can sign up for a Pro account.
🌐
codeconvert.ai
codeconvert.ai › java-to-c-converter
Free Java to C Converter — AI Code Translation | CodeConvert AI
🌐
ResearchGate
researchgate.net › figure › Structure-of-our-Java-to-C-compiler_fig1_226005814
Structure of our Java-to-C compiler. | Download Scientific Diagram
In this paper we present code generation and optimization techniques for a Java-to-C compiler, which translates Java bytecode into C codes while the generated codes preserve Java’s programming semantics such as inheritance, method overloading, virtual method invocation, garbage collection and so on.
🌐
CodeConvert AI
codeconvert.ai › java-to-c-converter
Free Java to C Converter — AI Code Translation | CodeConvert AI
Instantly convert Java to C code with AI. Free, fast, and accurate code translation — 60+ languages supported, no signup required.
Top answer
1 of 2
6

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.

2 of 2
5

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.

🌐
CodeConvert AI
codeconvert.ai › c-to-java-converter
Free C to Java Converter — AI Code Translation
The AI understands both C and Java idioms and produces natural-looking code. ... Signing in unlocks CodeConvert AI's Pro tool, which includes more powerful AI models, an integrated chat assistant, code execution, personal notes, conversion history, and an enhanced interface.
Find elsewhere
🌐
GitHub
github.com › digitalgust › tinyj2c
GitHub - digitalgust/tinyj2c: Convert JAVA source to C source, Build standlone binary without any class file.
Clion/vs/xcode open /tinyj2c/app , compile c source and run . Run binary no java classes dependence.
Starred by 71 users
Forked by 17 users
Languages   Java 76.5% | C 23.3% | Java 76.5% | C 23.3%
🌐
Mtsystems
mtsystems.com
mtSystems - C Source Code to Java Source Code Translation
We cannot provide a description for this page right now
🌐
Favtutor
favtutor.com › java-to-c-converter
Free Java to C Converter Online
Use this AI tool by FavTutor to convert Java code to C programming language online in a single click for free.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › c/c++
Convert Java to C? - Raspberry Pi Forums
Given you successfully decompiled and generated the Java code then it would be almost impossible job to translate Java to C. You'll need to implement the object oriented features of Java in C. Use already existing formal grammar of Java and then use flex/bison to generate a intermediate code.
🌐
Programiz
programiz.com › java-programming › online-compiler
Online Java Compiler - Programiz
Online Python Compiler Online R Compiler Online SQL Editor Online HTML/CSS Editor Online Java Compiler Online C Compiler Online C++ Compiler Online C# Compiler Online JavaScript Compiler Online Typescript Compiler Online GoLang Compiler Online Rust Compiler Scala Online Compiler Dart Online Compiler Ruby Online Compiler Online PHP Compiler Online Swift Compiler ... // Online Java Compiler // Use this editor to write, compile and run your Java code online class Main { public static void main(String[] args) { System.out.println("Try programiz.pro"); } }
🌐
JDoodle
jdoodle.com › online-java-compiler
Online Java Compiler - Run Java Code in Browser
JDoodle is an Online Compiler, Editor, IDE for Java, C, C++, PHP, Perl, Python, Ruby and many more. You can run your programs on the fly online, and you can save and share them with others. Quick and Easy way to compile and run programs online.
🌐
CodeChef
codechef.com › ide
Online Compiler & IDE for Python, C++, C, Java, Rust - CodeChef
Compile & run your code with the CodeChef online IDE. Our online compiler supports multiple programming languages like Python, C++, C, JavaScript, Rust, Go, Kotlin, and many more.
🌐
Reddit
reddit.com › r/cprogramming › convert code from java to c
r/cprogramming on Reddit: CONVERT CODE FROM JAVA TO C
November 16, 2021 -

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);
	
}}
🌐
Quora
quora.com › Is-it-possible-to-write-a-C-compiler-in-Java-if-you-know-Java-but-not-C
Is it possible to write a C compiler in Java if you know Java but not C? - Quora
Answer (1 of 12): I see a lot of “no” answers. I’m going to be contrarian and answer “yes.” But, I’ll slather on a few caveats. Some years ago, I took Alex Aiken’s online Compilers course. In that course, I wrote a compiler for an academic language called Cool95.
🌐
Quora
quora.com › Is-it-possible-to-compile-C-code-in-Java
Is it possible to compile C code in Java? - Quora
Answer (1 of 3): Hmm. I’m not certain I understand by what you mean when you say “in Java.” Do you mean “is it possible to compile C code using a Java compiler?” The answer, of course, is NO. C and Java are different languages, and so the compiler for Java won’t correctly compile C. Do you mean...
Top answer
1 of 5
5
JavaC compiles Java to byte code, which is an IR (intermediate representation). It’s the JVM that may in turn compile from that IR to machine code.
2 of 5
5
Javac is the Java Compiler. AFAIK, It compiles to JVM classes, not (necessarily) to machine code. A compiler is just a regular program that takes some input and produces some output. You can write a compiler in any language A that reads any language B and compiles it to any language C, as long as there's a valid translation that can be made for that program between languages B and C. For example, you can write a compiler in Python that reads Ruby code and outputs equivalent C# code, or any other strange combination of languages. Of course, languages A and B can even be the same; you can write a compiler in Java that takes Java and compiles it to, say, C or Assembly (or straight to machine code). To create an executable, you just need to open a file and write a very specific and carefully-constructed sequence of bytes - you could even do that manually, by typing it by hand if you knew what you were supposed to write. So, as long as you have some way of turning a Java program into an executable (say, a basic Java compiler written in a different language), then you can write javac in Java itself and use that way to get an executable. Then you can throw away the basic compiler and keep using javac. That's often called "bootstrapping". To bootstrap a new programming language, you can write two compilers, both of which take that language as an input. The first one is the "proper" one, like javac in this case, which is written in the new language itself. The second one is a temporary one, which needs to be written in any other language that has an existing working compiler. You can use the temporary compiler to compile the "proper" compiler, at which point you can throw the temporary compiler away and keep developing the language using a compiler written in itself.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › technotes › tools › windows › javac.html
javac - Java programming language compiler
For example, if you keep all your source files in C:\workspace, the source code for com.mysoft.mypack.MyClass should be in C:\workspace\com\mysoft\mypack\MyClass.java. By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with -d (see Options, below). The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the future.
🌐
Quora
quora.com › How-do-I-run-a-Java-program-using-a-C-compiler
How to run a Java program using a C compiler - Quora
C compiler is for C. Java compiler is for Java. If you want to compile Java get a Java compiler. Although if you want to run a Java program from a C program, you can do a system call in your program to run the Java execut...