I want to know that what is javac (command or a compiler) and when we have to compile a program we say javac Student.java and when we run it we say java Student.
My question is when we compile why its necessary to write .java but not at run time. and i herd that jli.dll is a compiler is it true.
& I know java is so secure because of sandbox not because of bytecode but what is sandbox.
Thanks
D. Ogranos
Ranch Hand
Joined: Feb 02, 2009
Posts: 181
posted
0
Both javac and java are programs which come with the Java Development Kit.
1) You use "javac" to compile your program's source text
The program javac is the compiler. It takes your source file (Student.java) and creates a class file (Student.class) from it, assuming there are no errors in the source of course
2) You use "java" to run your program
When you type "java Student" in your command shell, the java program is started and looks for the file Student.class. If the file is found, java starts execution of the Student program by calling its main() method.
To your other question: sandbox means "an environment in which nothing really harmful can happen". For example, a program running in a sandbox cannot (accidentaly or maliciously) destroy important files or something like that. Note however that Java programs are usually NOT running in a sandbox. That is only true for certain kinds of Java programs (for example, applets).
The javac command (the compiler) expects the file name of the source file, so you must pass it the filename, which includes the .java extension.
The java command (to run a Java program) expects the class name (not a file name). It will look through the directories and JAR files in the classpath to find the class.
Jesper de Jong wrote:The java command (to run a Java program) expects the class name (not a file name). It will look through the directories and JAR files in the classpath to find the class.
You can tell that you're calling a Class, and not a file name, when you run any java class that is not in the default package. You call java my.package.MyClass rather than java my\package\MyClass.class . The first is the Class name, and the second is one example of a file name.
OCPJP
"In preparing for battle I have always found that plans are useless, but planning is indispensable."
-- Dwight D. Eisenhower
subject: Why we have to write .java when we compile a program