Java isn't a language you use an online ide for, the language would be horrific to use like that. Even using a text editor like VS code would suck badly let alone a web based thing. I guess google and try a few out given whatever anyone suggests here isn't going to be anything flash as there is simply no market for it. Answer from yourbank on reddit.com
🌐
Programiz
programiz.com › java-programming › online-compiler
Online Java Compiler - Programiz
// 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"); } }
🌐
OnlineGDB
onlinegdb.com › online_java_compiler
Online Java Compiler - online editor
OnlineGDB is online IDE with java compiler. Quick and easy way to run java program online.
🌐
JDoodle
jdoodle.com › online-java-compiler
Online Compiler and Editor/IDE for Java, C, C++, PHP, Python, Ruby, Perl - Code and Run Online
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.
🌐
OneCompiler
onecompiler.com › java
Java Online Compiler
Write, Run & Share Java code online using OneCompiler's Java online compiler for free. It's one of the robust, feature-rich online compilers for Java language, running the Java LTS version 17. Getting started with the OneCompiler's Java editor is easy and fast.
🌐
Replit
replit.com › languages › java
Java Online Compiler & Interpreter - Replit
5 days ago - Write and run Java code using our Java online compiler & interpreter. You can build, share, and host applications right from your browser!
🌐
Reddit
reddit.com › r/compilers › creating a compiler in java
Creating a compiler in Java : r/Compilers
January 13, 2023 - Then, yes, basically take ANTLR as a parser generator, OW ASM for class files analysis and generation (you'll need it also to compile against binaries). All you actually have to do after that is to implement language-specific stuff "between" parser and writing class files. Regarding literature, you'll need JVM specification (https://docs.oracle.com/javase/specs/), a book on ANTLR (https://pragprog.com/titles/tpantlr2/the-definitive-antlr-4-reference/), and some book on compilers, preferably one with good chapters on type checking and tree rewriting.
Find elsewhere
🌐
GitHub
github.com › 7mind › jopa
GitHub - 7mind/jopa: JOPA: Java compiler in C++
1 week ago - JOPA: Java compiler in C++. Contribute to 7mind/jopa development by creating an account on GitHub.
Starred by 51 users
Forked by 3 users
Languages   C++ 83.6% | Java 12.2% | CMake 1.5% | Shell 0.9% | GAP 0.8% | Python 0.7%
Top answer
1 of 9
66

OK i know this: We write java source code, the compiler which is platform independent translates it into bytecode,

Actually the compiler itself works as a native executable (hence javac.exe). And true, it transforms source file into bytecode. The bytecode is platform independent, because it's targeted at Java Virtual Machine.

then the jvm which is platform dependent translates it into machine code.

Not always. As for Sun's JVM there are two jvms: client and server. They both can, but not certainly have to compile to native code.

So from start, we write java source code. The compiler javac.exe is a .exe file. What exactly is this .exe file? Isn't the java compiler written in java, then how come there is .exe file which executes it?

This exe file is a wrapped java bytecode. It's for convenience - to avoid complicated batch scripts. It starts a JVM and executes the compiler.

If the compiler code is written is java, then how come compiler code is executed at the compilation stage, since its the job of the jvm to execute java code.

That's exactly what wrapping code does.

How can a language itself compile its own language code? It all seems like chicken and egg problem to me.

True, confusing at first glance. Though, it's not only Java's idiom. The Ada's compiler is also written in Ada itself. It may look like a "chicken and egg problem", but in truth, it's only a bootstrapping problem.

Now what exactly does the .class file contain? Is it an abstract syntax tree in text form, is it tabular information, what is it?

It's not Abstract Syntax Tree. AST is only used by tokenizer and compiler at compiling time to represent code in memory. .class file is like an assembly, but for JVM. JVM, in turn, is an abstract machine which can run specialized machine language - targeted only at virtual machine. In it's simplest, .class file has a very similar structure to normal assembly. At the beginning there are declared all static variables, then comes some tables of extern function signatures and lastly the machine code.

If You are really curious You can dig into classfile using "javap" utility. Here is sample (obfuscated) output of invoking javap -c Main:

0:   new #2; //class SomeObject
3:   dup
4:   invokespecial   #3; //Method SomeObject."<init>":()V
7:   astore_1
8:   aload_1
9:   invokevirtual   #4; //Method SomeObject.doSomething:()V
12:  return

So You should have an idea already what it really is.

can anybody tell me clear and detailed way about how my java source code gets converted in machine code.

I think it should be more clear right now, but here's short summary:

  • You invoke javac pointing to your source code file. The internal reader (or tokenizer) of javac reads your file and builds an actual AST out of it. All syntax errors come from this stage.

  • The javac hasn't finished its job yet. When it has the AST the true compilation can begin. It's using visitor pattern to traverse AST and resolves external dependencies to add meaning (semantics) to the code. The finished product is saved as a .class file containing bytecode.

  • Now it's time to run the thing. You invoke java with the name of .class file. Now the JVM starts again, but to interpret Your code. The JVM may, or may not compile Your abstract bytecode into the native assembly. The Sun's HotSpot compiler in conjunction with Just In Time compilation may do so if needed. The running code is constantly being profiled by the JVM and recompiled to native code if certain rules are met. Most commonly the hot code is the first to compile natively.

Edit: Without the javac one would have to invoke compiler using something similar to this:

%JDK_HOME%/bin/java.exe -cp:myclasspath com.sun.tools.javac.Main fileToCompile

As you can see it's calling Sun's private API so it's bound to Sun JDK implementation. It would make build systems dependent on it. If one switched to any other JDK (wiki lists 5 other than Sun's) then above code should be updated to reflect the change (since it's unlikely the compiler would reside in com.sun.tools.javac package). Other compilers could be written in native code.

So the standard way is to ship javac wrapper with JDK.

2 of 9
16

Isn't the java compiler written in java, then how come there is .exe file which executes it?

Where do you get this information from? The javac executable could be written in any programming language, it is irrelevant, all that is important is that it is an executable which turns .java files into .class files.

For details on the binary specification of a .class file you might find these chapters in the Java Language Specification useful (although possibly a bit technical):

  • Virtual Machine Startup
  • Loading of Classes and Interfaces

You can also take a look at the Virtual Machine Specification which covers:

  • The class file format
  • The Java Virtual Machine instruction set
  • Compiling for the Java Virtual Machine
🌐
Coding Shuttle
codingshuttle.com › compilers › java
Online Java Compiler | Coding Shuttle
An Online Java Compiler is a web-based application that enables users to write, edit, and run Java code directly from their web browsers without any local installations or configurations.
🌐
Oracle
java.com › en › download › manual.jsp
Download Java
» What is Java » Remove older versions » Security » Support » Other help · This download is for end users who need Java for running applications on desktops or laptops. Java 8 integrates with your operating system to run separately installed Java applications.
🌐
Wikipedia
en.wikipedia.org › wiki › Java_compiler
Java compiler - Wikipedia
October 21, 2025 - A Java compiler is a compiler for the Java programming language. Some Java compilers output optimized machine code for a particular hardware/operating system combination, called a domain specific computer system. An example would be the now discontinued GNU Compiler for Java.
Top answer
1 of 9
290

Java implementations typically use a two-step compilation process. Java source code is compiled down to bytecode by the Java compiler. The bytecode is executed by a Java Virtual Machine (JVM). Modern JVMs use a technique called Just-in-Time (JIT) compilation to compile the bytecode to native instructions understood by hardware CPU on the fly at runtime.

Some implementations of JVM may choose to interpret the bytecode instead of JIT compiling it to machine code, and running it directly. While this is still considered an "interpreter," It's quite different from interpreters that read and execute the high level source code (i.e. in this case, Java source code is not interpreted directly, the bytecode, output of Java compiler, is.)

It is technically possible to compile Java down to native code ahead-of-time and run the resulting binary. It is also possible to interpret the Java code directly.

To summarize, depending on the execution environment, bytecode can be:

  • compiled ahead of time and executed as native code (similar to most C++ compilers)
  • compiled just-in-time and executed
  • interpreted
  • directly executed by a supported processor (bytecode is the native instruction set of some CPUs)
2 of 9
136

Code written in Java is:

  • First compiled to bytecode by a program called javac as shown in the left section of the image above;
  • Then, as shown in the right section of the above image, another program called java starts the Java runtime environment and it may compile and/or interpret the bytecode by using the Java Interpreter/JIT Compiler.

When does java interpret the bytecode and when does it compile it? The application code is initially interpreted, but the JVM monitors which sequences of bytecode are frequently executed and translates them to machine code for direct execution on the hardware. For bytecode which is executed only a few times, this saves the compilation time and reduces the initial latency; for frequently executed bytecode, JIT compilation is used to run at high speed, after an initial phase of slow interpretation. Additionally, since a program spends most time executing a minority of its code, the reduced compilation time is significant. Finally, during the initial code interpretation, execution statistics can be collected before compilation, which helps to perform better optimization.

🌐
W3Schools
w3schools.com › java › java_compiler.asp
Java Online Compiler (Editor / Interpreter)
With our online Java compiler, you can edit Java code, and view the result in your browser.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.compiler › module-summary.html
java.compiler (Java SE 17 & JDK 17)
July 15, 2025 - Interfaces used to model Java programming language types. ... Utilities to assist in the processing of program elements and types. ... Provides interfaces for tools which can be invoked from a program, for example, compilers.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.compiler › module-summary.html
java.compiler (Java SE 11 & JDK 11 )
October 20, 2025 - These APIs model declarations and types of the Java programming language, and define interfaces for tools such as compilers which can be invoked from a program.
🌐
Google Play
play.google.com › store › apps › details
Compile Java - Run .java Code - Apps on Google Play
Java Compiler is an Advanced IDE enabling you to compile Java Programs on your Mobile Phone for Free. It comes with a code editor with in-built syntax highlighting capabilities. Java Compiler is - Free with no hidden charges!
Rating: 2.8 ​ - ​ 283 votes
🌐
Oracle
docs.oracle.com › javase › 7 › docs › technotes › tools › windows › javac.html
javac - Java programming language compiler
If you do need to do this, use the -J option to pass through options to the underlying java launcher. ... Disable warning messages. This has the same meaning as -Xlint:none. ... Controls whether annotation processing and/or compilation is done. -proc:none means that compilation takes place without annotation processing.
Top answer
1 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.
2 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.
🌐
CodeChef
codechef.com › java-online-compiler
Online Java Compiler and Visualizer
Welcome to our AI-powered online Java compiler and interpreter, the perfect platform to run and test your Java code efficiently. Our tool makes coding easy for developers of any skill level, whether you're a beginner or experienced.