aspose file tools*
The moose likes Beginning Java and the fly likes How can I run a very simple and my first java source code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I run a very simple and my first java source code?" Watch "How can I run a very simple and my first java source code?" New topic
Author

How can I run a very simple and my first java source code?

David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
Based on what I read on this book, (1) I must save the source file written in notepad with an extension .java, then (2) compile the source code by issuing this statement in the CMD session as follows "javac BeersongCode.java", then (3) run (also in the CMD session) this statement "%java Beersong"

It fails at the second step!!, as follows:

c:\users\David Hernandez\javac BeersongCode.java
'javac' is not recognized as an internal or external command, operable program or batch file.

or

c:\users\David Hernandez\%javac BeersongCode.java
'%javac' is not recognized as an internal or external command, operable program or batch file.

Any ideas?. Thanks. DH
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is there a JDK "bin" directory on your path? If not, you need to make it so there is (or, I suppose, you could type in the full path, but that's really irritating).

I'm not sure why you tried with a "%" character.
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 349
Check java sdk setup instructions for setting the JAVA_HOME environment variable. If you're using Windows, you create the environment variable by clicking on System in the Control Panel -> Advance System Settings -> Environment Variables (button). If JAVA_HOME is set correctly, then javac will be recognized everywhere.


Correlation does not prove causality.
David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
Roger F. Gay wrote:Check java sdk setup instructions for setting the JAVA_HOME environment variable. If you're using Windows, you create the environment variable by clicking on System in the Control Panel -> Advance System Settings -> Environment Variables (button). If JAVA_HOME is set correctly, then javac will be recognized everywhere.


My sys var JAVA_HOME READS C:\Program Files\Java\jdk1.5.0_22 unsure if this is correct.

My sys var PATH reads %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

I have made backups of these variables already.

Do I need to edit any of these variables so I can run a very simple and my first java source code.?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I wrote:Is there a JDK "bin" directory on your path? If not, you need to make it so there is (or, I suppose, you could type in the full path, but that's really irritating).
David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
David Newton wrote:
I wrote:Is there a JDK "bin" directory on your path? If not, you need to make it so there is (or, I suppose, you could type in the full path, but that's really irritating).


This is my sys var PATH which reads %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ ....... but I am not sure where the \bin would go.!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In the path, towards the front. You might want to get acquainted with how your OS works before going too much further--it will reap great dividends and make your life substantially easier.

Assuming your JDK is in c:\jdk1.6:If it's somewhere else, please use that path instead of the placeholder I used.
David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
David Newton wrote:In the path, towards the front. You might want to get acquainted with how your OS works before going too much further--it will reap great dividends and make your life substantially easier.

Assuming your JDK is in c:\jdk1.6:If it's somewhere else, please use that path instead of the placeholder I used.


-------------------------------------------------------------------------
My JDK files are here C:\Program Files\Java\jdk1.5.0_22

The |bin file inside the JDK is here C:\Program Files\Java\jdk1.5.0_22\Bin

The sys var PATH is as follows: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

The original sys var PATH has been backed up. The original does not look like the sample you sent, but Oh well is just a matter of adapting it. The problem is that I have not edited system variables but only one time before, long time ago. Nor sure how to do it. I dont know if it would be as C:\Program Files\Java\jdk1.5.0_22\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

If If can edit these variables and get it going one time, i can run the first 6 exercises I have written so far, test them, edit, fix them and LEARN java, meanwhile I am stuck. Thanks for all the input.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You'll need to put spaces quotes around path names with spaces in them.

I don't understand why you haven't just tried it, or just typed in the complete path to the executable to see if it actually works--it'd be much, much faster than waiting for someone to help you here, no? Recall that even Windows has path completion via the TAB key.

And again: read up on the OS you're using; there are hundreds of tutorials, and Microsoft's own documentation, that tell you how to work in the environment you're working in. Why waste time not knowing how things work?

Edit: quotes, not spaces.
David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
David Newton wrote:You'll need to put spaces around path names with spaces in them.

I don't understand why you haven't just tried it, or just typed in the complete path to the executable to see if it actually works--it'd be much, much faster than waiting for someone to help you here, no? Recall that even Windows has path completion via the TAB key.

And again: read up on the OS you're using; there are hundreds of tutorials, and Microsoft's own documentation, that tell you how to work in the environment you're working in. Why waste time not knowing how things work?


Tried it! c:\program files\java\jdk1.5.0_22\bin>javac SimpleLoopCode.java then hit enter, then I got: Error: Can not read: SimpleLoopCode.java ....written en notepad.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's because you're executing from within the directory where javac is located, not where the Java source code file is located...
David Hernandez
Greenhorn

Joined: Jun 06, 2010
Posts: 13
David Newton wrote:That's because you're executing from within the directory where javac is located, not where the Java source code file is located...


Your are right, I tried as suggested and got "at least" something.

I issued the java and the javac commands, as follows:

c:\Program Files\Java\jdk1.5.0_22\bin>java C:\Users\David Hernandez\Documents\My JAVASE\SimpleLoopCode.java
it returns: Exception in thread "main" java.lang.noClassDefFoundError: c:Users\David

Is it because my dir <david hernandez> has a space in between???

c:\Program Files\Java\jdk1.5.0_22\bin>javac C:\Users\David Hernandez\Documents\My JAVASE\SimpleLoopCode.java
it returns: javac: invalid flag: c:\Users\David <---- Same S---!
Usage: javac <options> <source files>
where possible options include
...........all kind of option follow up.!!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I wrote:You'll need to put spaces quotes around path names with spaces in them.

And yet again: please learn about the environment you're working in--it's really quite important.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And please note that we already went over the path (and PATH) stuff in your previous post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I run a very simple and my first java source code?
 
Similar Threads
Running code
Help
Running java programs on the commamd line
Not able to run java
Setting the classpath