• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Virtual Machine running .class  RSS feed

 
Charles Jonesy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm a JavaNewb and I want to learn all I can about this language. I taught myself how to write basic basic scripts and figured out how to compile javac using archaic DOS commands. I now have a .class version of MyFirstApp ready to be run as a java program. This may seem like a simple question but where do I go or what do I do to actually USE MyFirstApp.class? Keep in mind I am teaching this to myself.

I heard something about "classpath" does that have anything to do with the class files running? Do I run this in DOS too just like the javac compiler? Any help is appreciated.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath is a collection of directories where Java looks for any class files it may need. Since you have just one class, and it is in the directory you happen to be in, it's very simple: just ".", which stands for the current directory. Type in:

java -classpath . MyFirstApp

and see what happens.
 
Charles Jonesy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I typed that exactly as you had it into the DOS command line and I got:

'java' is not recognized as an internal or external command, operable program or batch file

You run the Java Virtual Machine from the DOS prompt? Please clarify
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, your Windows PATH variable does not include the directory where all the binaries of the Java installation (java, javac, jar, javadoc, ...) are kept. Which makes me wonder how you got javac to compile the source file? What did you type in?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles, welcome to the Ranch. Ulf was about to tell you where to get the installation instructions. Here. You will have to set up your classpath and path variables. For path, you have to remember where you put the JDK. The instructions here are for J2SE5.0, which is the most recent supported version, although there is a version 6 out in beta only.

You have to follow the instructions to the letter. One tiny mistake and the whole thing will fail to work.

CR
 
Charles Jonesy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got my first java program to work tonight. It is very basic and ridiculously simple, but it has been compiled and works ("Hello World" or as Head First Java suggested "I Rule the World"). My first step into a larger world. Can't wait to compile some more complex programs now
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got my first java program to work tonight.
Well done. It is a big first step.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiling them is easy.

WRITING them is hard

Seriously, gratz on your first few steps. come back often - we're happy to help!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!