Javaコンパイラ
Javaコンパイラは、コンピュータ・プログラミング言語Javaのコンパイラである。
Javaコンパイラは、コンピュータ・プログラミング言語Javaのコンパイラである。
著名なコンパイラ
2020年時点で、以下のようなものが著名である:
- javac
- オラクルから出ているJava Development Kitに含まれている。
- Jikes
- C++で書かれたIBMから出ているオープンソースコンパイラであり、最適化のため静的単一代入形式の変形を使用している。
- GCJ
- GNUコンパイラコレクション (GCC) の一部である。GCCは C、Fortran、Pascal他、Java以外の言語も含む。 GCCのバックエンドを用いてネイティブコードを生成できる。2015年よりメンテナンスモードとなっている。
- ECJ
- the Eclipse Compiler for Java, Eclipse JDTに使用されているオープンソースインクリメンタルコンパイラ。
その他、形式的意味論のために研究されている Featherweight Java のための処理系など、著名ではないが重要なものがいくつかある。
コンパイル方法
2023年時点で、javacを使用して、Javaソースファイルをコンパイルする基本的なコードは、下記の通りである。
なお、この章で示すコードを実際に実行する際は、「hoge」の部分をコンパイルしたいJavaソースファイルのファイル名に書き換える必要がある。
> javac hoge.java
もし、仮にJavaソースファイルの中にUTF-8形式の文章を出力するコードが記述されている場合は、コンパイルして実行した際に文字化けが発生する可能性があるので、このコードは実行できない。代わりに、下記のコードを実行することで対策ができる[1]。
> javac -encoding UTF-8 hoge.java
> javac -J-Dfile.encoding=UTF-8 hoge.java
また、UTF-8以外の文字コードに変換する際でも、コード欄の「UTF-8」を目的の文字コード名へ書き換えることで、正しく変換することができる。(JavaDrive - 実行環境のエンコーディングに合わせてプログラムを実行する : https://www.javadrive.jp/start/encoding/index4.html)
脚注
- ^ “ソースファイルのエンコーディングを指定してコンパイルする”. Let'sプログラミング. 2023年3月14日閲覧。
外部リンク
- Jikes homepage
- JSR 199 - Java Compiler API Java Specification Request for invoking the Java compiler from a Java program
- Oracle Java
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.