wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Trying to Understand Java and JRE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to Understand Java and JRE" Watch "Trying to Understand Java and JRE" New topic
Author

Trying to Understand Java and JRE

Guy Rich
Ranch Hand

Joined: May 03, 2011
Posts: 33

[Hello all, I've just compiled my first java application and now I'm ready to test it. However I'm just a little confused as how to go about this.
From what I've gathered thus far, I'm supposed to "execute" the source code which actually uses the class files generated by the compiler.
My environment is Windows 2008 32bit server, I have IBM's java SDK 1.6 installed.
Should the JVM be running as a "service" in Windows ? (I looked in the list of system services currently running, but i did not "see" a JVM in the list.
Of course I'm assumming the JVM would be called JVM ...
Any suggestions would be most welcome.

Thanks

Guy
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11443
    
  16

no, it is not a service, it is a program you call from the command line.

start->run->cmd

then, cd to the directory where your .class file is.

then type "java <yourclassname>"

note that you do NOT type the ".class". So, if I had a file named "MyClass.java", after compiling I'd have a "MyClass.class" file. I'd run it with "java MyClass".

and also, even though Windows is not case sensitive, Java is, so "java myclass" would not work.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Guy Rich
Ranch Hand

Joined: May 03, 2011
Posts: 33

Thanks very much Fred
Guy Rich
Ranch Hand

Joined: May 03, 2011
Posts: 33

Hi All ... I'm still getting errors to wit:
C:\>set CLASSPATH=C:\APPC_LU62\java

C:\>java LU62XnsCvr
Exception in thread "main" java.lang.NoClassDefFoundError: LU62XnsCvr (wrong name: APPC_LU62/java/LU62XnsCvr)
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:265)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:506)
at java.net.URLClassLoader.access$300(URLClassLoader.java:77)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:905)
at java.security.AccessController.doPrivileged(AccessController.java:284)
at java.net.URLClassLoader.findClass(URLClassLoader.java:427)
at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:311)
at java.lang.ClassLoader.loadClass(ClassLoader.java:609)

I don't understand what is meant by "wrong name" when there is indeed a class file named LU62XnsCvr.class

e.g.:
C:\>cd APPC_LU62\java

C:\APPC_LU62\java>dir /p
Volume in drive C has no label.
Volume Serial Number is B62B-74FF

Directory of C:\APPC_LU62\java

05/04/2011 05:34 AM <DIR> .
05/04/2011 05:34 AM <DIR> ..
05/03/2011 06:53 PM 1,492 LU62XnsCvr$cntrl_status.class
05/03/2011 06:53 PM 1,253 LU62XnsCvr$recv_status.class
05/03/2011 06:53 PM 1,689 LU62XnsCvr$system_code.class
05/03/2011 06:53 PM 15,230 LU62XnsCvr.class

Below is the source code that I compiled ...



Now it's my understanding that when one uses the "package" option there has to be a corresponding path that matches the package "label"
e.g. package APPC_LU62.java and I have a directory structure C:\APPC_LU62\java where the generated class files are "stored".

There's no apparent mispelling of the class name as far as I can 'see'
public class LU62XnsCvr extends Object
{

and in the directory itsself
05/03/2011 06:53 PM 15,230 LU62XnsCvr.class

All suggestions, ideas, and comments are most appreciated.

Best Regards

Guy
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
Your classpath needs to be set to a directory which is the root of the package; in your case, the classpath should be "C:\". That way, the Java runtime uses the classpath to look up the full name of your class, which is APPC_LU62.java.LU62XnsCvr, and which it expects to find in a directory structure that includes the directories as you have them.

rc
Guy Rich
Ranch Hand

Joined: May 03, 2011
Posts: 33

okay Ralph ...thanks very much ... I'll try that



Best Regards
Guy
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Is it possible to remove your classpath altogether, and then navigate to the root of your directory structure? If there is no classpath at all, the "java" tool will default to using the current directory as its classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to Understand Java and JRE