• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please note that we already went over the path (and PATH) stuff in your previous post.
 
No, tomorrow we rule the world! With this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic