Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling First Java Program in Command Prompt  RSS feed

 
Ryan Daniele
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I'm trying to get the command prompt to run Java from a notepad saved file. I have a little programming background with Game Maker. One of my students wants to create Mine Craft mods so we're learning Java together.

We're going through the Java tutorials on their website: https://www.tutorialspoint.com/java/java_basic_syntax.htm

I've set the environment variable path to: C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin

I've created a folder in C:\Users\Ryan\Java and that's where I am in the command prompt. When I type java MyFirstJavaProgram I just keep getting this 'java' is not recognized as an internal or external command, operable program or batch file.

Any suggestions what I'm doing wrong?

I appreciate the help!

Ryan
 
fred rosenberger
lowercase baba
Bartender
Posts: 12515
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
was your command prompt opened before you updated your path? If so, close it and open a new one.  Or, type "path" to see what that window thinks the path is, and confirm that directory is there.

navigate to the c:\Program Files\java\jdk\bin  and see if there really is a "java.exe".

try calling it with the full path:

\Program Files\java\jdk\bin\java.exe MyFirstJavaProgram

and let us know if any of those work.
 
Ryan Daniele
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were right, my path was wrong. The name of the folder was jdk1.8.0_131.

Thanks so much, it worked! I'm sure I'll have many more questions in the future!

Does this website have good learning tools/examples?
 
Norm Radder
Rancher
Posts: 2052
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you used the javac.exe command to compile the source file and create a class file?  Normally the JRE install sets the PATH variable so the java command works.
So I'm confused about an error getting to the java command.  The path would have been set or found for the javac command to have been executed.
 
Pete Letkeman
Ranch Hand
Posts: 184
8
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Daniele - Does this website have good learning tools/examples?


I don't think that they web site has any online tutorials, but many if you were to search this site I'm sure that you would find people mentioning and/or linking to sites on the web or books etc.
Java is also rather large with many different areas/specialties, much like programming itself. You may want to either open up your mind to narrow your focus, depending on what exactly you are planning on doing.
Some people have come to this web site for help with Java certification, others have come solely to help other people out and still others came post questions to problems (usually fairly specific) or to read and learn from the community posts.

If you are trying to get into Java then you may want to look into the book titled Head First Java.
Once you can navigate your way though the different loops (for, do, while) and decision constructs (if/else/switch) you may want to start learning methods, classes and then other object orientated programming.
Do not be discouraged when learning Java or programming for that matter. Nearly everyone started out printing something like "Hello World" to the screen and everyone makes mistakes, some more then others. It's though making mistakes that you learn (or hopefully learn eventually).
Programming is something that is usually easy to start, but difficult to master.
 
Ryan Daniele
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the advice. I will look into that book. I ran into a problem with the student, I did the exact same setup of everything on his computer as on mine but it ran into the same error. I'll work more on it next week.

Thanks again.
 
Campbell Ritchie
Marshal
Posts: 54909
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is usually easy to set up a computer to run Java®; here are three likely problems:-
  • 1: Failure to install Java┬« correctly in the first place.
  • 2: Failure to set the PATH correctly.
  • 3: Setting a CLASSPATH; it is usually more trouble than it is worth to have a system CLASSPATH at all.
  •  
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!