June 26, 2014

How to compile and interpret Java code in command line?

Compilation & Interpretation life cycle is shown below

To compile your java code:
Using -d & -cp option
javac -d classes -cs somedirectory/classes/:. JavaOutput.java
Here -d = directory switch telling the compiler to save the output class file in the classes directory. Sub-directories are created according to package names
         classes = destination directory
         JavaOutput.java = is the file to be compiled.
         -cs = classpath switch telling the compiler to find the user-defined classes and packages in the specified directory
         somedirectory/classes - contains the user defined classes
Note that : is a delimiter in POSIX systems and .(period) is the current directory

All the available options are shown below

To interpret your java code:
Interpreter is used to interpret bytecode and execute your program.
java Car
executes Car.class file. Option -cs is similar to compiling code and -D switch is used to set property values

All the available options are shown below

No comments:

Post a Comment