Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

Why javac requires .java extension and java doesn't require .class extension

Why javac looks for .java extensions in filenames. While java doesn't look for .class in its argument? And goes to the .class file by itself automatically? Is there any reason for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's no automatic adding of .class: you just run java specifying which class to use as main. The details of classloading and classpath are on a different level of abstraction: it is possible that there's no .class file, or e.g. it's in a JAR.

If you look closer, by the way, you'll find that java does not ask you for a path: there are no slashes (or, worse yet, backslashes) in the parameters, only the proper dots separating package names. So it's never a "file."

javac, on the other hand, does indeed work with files, hence you need to specify those.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...