• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why we have to write .java when we compile a program  RSS feed

 
P Malhotra
Greenhorn
Posts: 7
MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello everyone,


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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!