In computing, a Java compiler is a computer program that translates programs in the Java programming language source code to Java class files.
As of 2006, the following are major Java compilers:
- javac, included in JDK from Sun Microsystems, open-sourced since the 13 November 2006.
- GCJ, a part of gcc which compiles C, Fortran, Pascal and other programming languages besides Java. It can also generate native code using the back-end of gcc.
- ECJ, the Eclipse Compiler for Java, is an open source incremental compiler used by the Eclipse JDT.
- Jikes, an open source compiler from IBM, which is written in C++ and uses a variant of static single assignment form for optimization. As of early 2006 the project is no longer being actively developed [1].
The compiler compiles the Java source code to a Java class file that contains the generated Java bytecode. Even though each compiler uses a different technique, they all generate the same class file format.
Most Java compilers, Jikes being the only exception, do virtually no optimization, leaving this until runtime to be done by the JRE[citation needed].
Using this generated Java bytecode, the Java Virtual Machine (JVM) loads the class files and either interprets the bytecode or just-in-time compiles it to machine code and then possibly optimizes it using dynamic compilation.
The very first Java compiler developed by Sun Microsystems was written in C using some libraries from C++.[citation needed]
References
import java.io.*; import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.VideoControl; import javax.microedition.midlet.MIDlet;
public class player extends MIDlet
implements CommandListener
{
public player() { exit = new Command("exit", 7, 0); play = new Command("play", 4, 1); time = new Command("time", 4, 1); stop = new Command("stop", 4, 1); play2 = new Command("play", 4, 1); ret = new Command("to begin", 4, 1); }
public void startApp() { dis = Display.getDisplay(this); Form form = new Form("Player"); tf = new TextField("file name without extention, wich saved in Videos", "3", 25, 2); form.append(tf); form.addCommand(exit); form.addCommand(play); form.setCommandListener(this); dis.setCurrent(form); }
public void pauseApp() { }
public void destroyApp(boolean flag) { }
public void commandAction(Command command, Displayable displayable) { if(command == exit) { destroyApp(false); notifyDestroyed(); } if(command == play) playwaw(); if(command == time) { long l = p.getMediaTime(); String s = Long.toString(l); System.out.println(s); } if(command == stop) try { p.stop(); } catch(MediaException mediaexception) { } if(command == play2) try { p.start(); } catch(MediaException mediaexception1) { } if(command == ret) { p.close(); startApp(); } }
public void playwaw() { _cls1 _lcls1 = new Object() /* anonymous class not found */ class _anm1 {}
String s = tf.getString(); try { p = Manager.createPlayer("file://0:/Videos/" + s + ".3gp"); p.realize(); VideoControl videocontrol; if((videocontrol = (VideoControl)p.getControl("VideoControl")) != null) videocontrol.initDisplayMode(1, _lcls1); videocontrol.setVisible(true); _lcls1.addCommand(play2); _lcls1.addCommand(stop); _lcls1.addCommand(exit); _lcls1.addCommand(ret); _lcls1.setCommandListener(this); dis.setCurrent(_lcls1); videocontrol.setDisplaySize(176, 400); videocontrol.setDisplayLocation(0, 15); p.start(); } catch(MediaException mediaexception) { Alert alert = new Alert("no such file"); dis.setCurrent(alert); p.close(); } catch(IOException ioexception) { Alert alert1 = new Alert("no such file"); dis.setCurrent(alert1); p.close(); } }
private Command exit; private Command play; private Command time; private Command stop; private Command play2; private Command ret; private Display dis; private InputStream str; private Form f2; private Player p; private Player p2; private Canvas canvas; private TextField tf;
}
External links
- Sun's OpenJDK javac page
- Jikes homepage
- JSR 199 Java Compiler API Java Specification Request for invoking the Java compiler from a Java program
- Java Sun