English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am working on a university machine through ssh. I know they have a java compiler installed. What is the the equilvance in java to g++ foo.cpp -o foo ???

Thanks!

2007-08-07 06:08:36 · 2 answers · asked by Jorge 3 in Computers & Internet Programming & Design

Also how would i compile a multi file program? How would I create object files ? What are the basic arguments the compiler takes.

Thanks!

2007-08-07 06:09:29 · update #1

2 answers

Compilation is done with the Java compiler, javac. To compile a single file:

javac foo.java

This will create foo.class, and maybe additional class files if you use some advanced Java features (specifically inner classes).

Java .class files are more or less the equivalent of object files, though they're Java bytecode rather than the machine's native code.

To compile multiple files, just list them on the command line as well:

javac foo.java bar.java
or
javac *.java

There's no true Java equivalent to "-o foo", as Java doesn't make executable programs from the OS point of view. You can package your classes up into an "application archive" that the Java virtual machine will execute, though.

Once you have all your .class files created, you package them in a jar (Java ARchive) with the "jar" command, which takes the same arguments (more or less) as the Unix "tar" command:

jar cvf myapp.jar *.class

Note that the class package naming and directory structure must match. If you place your classes in the package "foo.bar", you'll want to create the .jar so that it archives a directory "foo", which contains a directory "bar", which contains your classes.

If you need to see the common command-line options for the Java compiler, see the documentation for the appropriate version (execute "java -version" to see which it is, then go to java.sun.com), or execute "javac -help" for a brief overview.

2007-08-07 06:26:07 · answer #1 · answered by McFate 7 · 0 0

% javac -g Foo.java

Links below is how to compile java programs and the javac (Java compiler) options.

2007-08-08 14:57:49 · answer #2 · answered by nonlinear 6 · 0 0

fedest.com, questions and answers