How 'java' (command) handles the classname passed

K

kris

Hi,

After compiling the .java file, the .class is passed to 'java'
and that runs the program.
Does the 'java' work this way: when we give "java classname", 'java'
strictly would search for classname.class and proceeds thereafter,
The reason i got this doubt is when i gave a command "java
classname.class" an error was raised pointing no class definition.

Thanks for your time.

Krishna.
 
K

KiLVaiDeN

Does the 'java' work this way: when we give "java classname", 'java'
strictly would search for classname.class and proceeds thereafter,

The JVM(Java Virtual Machine) searches in the classpath folders a file name
"classname.class" when you call the command "java classname".
Calling "java classname.class" would make the JVM search for a file called
"classname.class.class" in all the folders of your classpath, therefor
leading to an error.

K
 
A

Angus Parvis

kris said:
Hi,

After compiling the .java file, the .class is passed to 'java'
and that runs the program.
Does the 'java' work this way: when we give "java classname", 'java'
strictly would search for classname.class and proceeds thereafter,
The reason i got this doubt is when i gave a command "java
classname.class" an error was raised pointing no class definition.

Thanks for your time.

Krishna.

even if it was like you say, strictly searching for "given
classname".class would result in "classname.class.class", so no wonder
that the vm couldn't find it.
 
C

Chris Smith

KiLVaiDeN said:
The JVM(Java Virtual Machine) searches in the classpath folders a file name
"classname.class" when you call the command "java classname".
Calling "java classname.class" would make the JVM search for a file called
"classname.class.class" in all the folders of your classpath, therefor
leading to an error.

I'm in picky mode today. It would look for "classname/class.class",
actually, where '/' is actually the platform-dependent file separator.
In the fully qualified class called "classname.class", the "classname"
piece is the package, and "class" is the simple name. Packages are
represented as directories by the system classloader.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
O

Oscar kind

kris said:
Does the 'java' work this way: when we give "java classname", 'java'
strictly would search for classname.class and proceeds thereafter,
The reason i got this doubt is when i gave a command "java
classname.class" an error was raised pointing no class definition.

Approximately. The JVM (started with the java command) searches for the
named class in the classpath. Thus:
- if the class name is "MainClass", the JVM searches for "MainClass.class"
in each classpath entry (directory or the root of a jar file).
- if the class name is "some.package.MainClass", the JVM searches for
"MainClass.class" in the directory "some/package" in each classpath
entry (directory or the root of a jar file).
 
M

Mike Schilling

Chris Smith said:
I'm in picky mode today. It would look for "classname/class.class",
actually, where '/' is actually the platform-dependent file separator.
In the fully qualified class called "classname.class", the "classname"
piece is the package, and "class" is the simple name. Packages are
represented as directories by the system classloader.

Being even pickier, jar files can exist in the system classloader as well;
they will also be searched

Being pickier still, I don;t know of any JVM restriction that limits it to
files and jars; a JVM implementation could (as far as I know) also search
databases or other sorts of repositories.
 
B

Ben_

Being pickier still, I don;t know of any JVM restriction that limits it to
files and jars; a JVM implementation could (as far as I know) also search
databases or other sorts of repositories.
I could so, I suppose, as it's already able access it over a socket, like
java.net.URLClassLoader.
 
T

Tor Iver Wilhelmsen

Chris Smith said:
I'm in picky mode today. It would look for "classname/class.class",
actually, where '/' is actually the platform-dependent file separator.

Now you are assuming things about the ClassLoader. A VM can perfectly
well default to a ClassLoader that reads classes from a database or
something, e.g. SELECT CLASS_DATA FROM CLASSES WHERE PACKAGE_NAME =
'classname' AND CLASS_NAME = 'class'
 
C

Chris Smith

Tor Iver Wilhelmsen said:
Now you are assuming things about the ClassLoader. A VM can perfectly
well default to a ClassLoader that reads classes from a database or
something, e.g. SELECT CLASS_DATA FROM CLASSES WHERE PACKAGE_NAME =
'classname' AND CLASS_NAME = 'class'

In a discussion about the command line parameters that should be passed
to the JRE, of course I'm assuming things about the VM. Otherwise, the
conversation is impossible to have. There is no specification that
covers which command-line arguments should be accepted by a virtual
machine.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top